static TRI_json_t* JsonGeo2Index (TRI_index_t const* idx) { TRI_json_t* json; TRI_json_t* fields; TRI_shape_path_t const* path; char const* latitude; char const* longitude; TRI_geo_index_t const* geo = (TRI_geo_index_t const*) idx; TRI_document_collection_t* document = idx->_collection; // convert latitude to string path = document->getShaper()->lookupAttributePathByPid(document->getShaper(), geo->_latitude); // ONLY IN INDEX, PROTECTED by RUNTIME if (path == 0) { return nullptr; } latitude = TRI_NAME_SHAPE_PATH(path); // convert longitude to string path = document->getShaper()->lookupAttributePathByPid(document->getShaper(), geo->_longitude); // ONLY IN INDEX, PROTECTED by RUNTIME if (path == 0) { return nullptr; } longitude = TRI_NAME_SHAPE_PATH(path); // create json json = TRI_JsonIndex(TRI_CORE_MEM_ZONE, idx); if (json == nullptr) { return nullptr; } // "constraint" and "unique" are identical for geo indexes. // we return "constraint" just for downwards-compatibility TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "constraint", TRI_CreateBooleanJson(TRI_CORE_MEM_ZONE, idx->_unique)); TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "ignoreNull", TRI_CreateBooleanJson(TRI_CORE_MEM_ZONE, geo->base._ignoreNull)); fields = TRI_CreateListJson(TRI_CORE_MEM_ZONE); TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, latitude)); TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, longitude)); TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "fields", fields); return json; }
static TRI_json_t* JsonHashIndex (TRI_index_t* idx, TRI_primary_collection_t const* primary) { TRI_json_t* json; TRI_json_t* fields; TRI_hash_index_t* hashIndex; char const** fieldList; size_t j; // ............................................................................. // Recast as a hash index // ............................................................................. hashIndex = (TRI_hash_index_t*) idx; // ............................................................................. // Allocate sufficent memory for the field list // ............................................................................. fieldList = TRI_FieldListByPathList(primary->_shaper, &hashIndex->_paths); if (fieldList == NULL) { return NULL; } // .......................................................................... // create json object and fill it // .......................................................................... json = TRI_JsonIndex(TRI_CORE_MEM_ZONE, idx); fields = TRI_CreateListJson(TRI_CORE_MEM_ZONE); for (j = 0; j < hashIndex->_paths._length; ++j) { TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, fieldList[j])); } TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "fields", fields); TRI_Free(TRI_CORE_MEM_ZONE, fieldList); return json; }
TRI_json_t* TRI_NodeJsonAql (TRI_aql_context_t* const context, const TRI_aql_node_t* const node) { switch (node->_type) { case TRI_AQL_NODE_VALUE: { switch (node->_value._type) { case TRI_AQL_TYPE_FAIL: case TRI_AQL_TYPE_NULL: return TRI_CreateNullJson(TRI_UNKNOWN_MEM_ZONE); case TRI_AQL_TYPE_BOOL: return TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, node->_value._value._bool); case TRI_AQL_TYPE_INT: return TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, (double) node->_value._value._int); case TRI_AQL_TYPE_DOUBLE: return TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, node->_value._value._double); case TRI_AQL_TYPE_STRING: return TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, node->_value._value._string); } } case TRI_AQL_NODE_LIST: { TRI_json_t* result = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); if (result) { size_t i, n; n = node->_members._length; for (i = 0; i < n; ++i) { TRI_json_t* subValue = TRI_NodeJsonAql(context, TRI_AQL_NODE_MEMBER(node, i)); if (subValue) { TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, result, subValue); } } } return result; } case TRI_AQL_NODE_ARRAY: { TRI_json_t* result = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE); if (result) { size_t i, n; n = node->_members._length; for (i = 0; i < n; ++i) { TRI_aql_node_t* element = TRI_AQL_NODE_MEMBER(node, i); TRI_json_t* subValue = TRI_NodeJsonAql(context, TRI_AQL_NODE_MEMBER(element, 0)); if (subValue) { TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, result, TRI_AQL_NODE_STRING(element), subValue); } } } return result; } default: { return NULL; } } }
static inline bool AddRow (TRI_aql_explain_t* const explain, TRI_json_t* value) { return TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, explain->_result, value) == TRI_ERROR_NO_ERROR; }