From baf039b608818749b4dacbab09db44554fb1ec7c Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 10 May 2012 09:45:11 +0200 Subject: [PATCH] cleanup, remove deprecated stuff --- Makefile.files | 1 - Makefile.in | 7 +- V8/v8-execution.cpp | 96 -- V8/v8-execution.h | 22 - V8/v8-globals.h | 48 - V8/v8-vocbase.cpp | 1501 +---------------------------- VocBase/query-context.h | 33 +- VocBase/query-data-feeder.c | 185 ---- VocBase/query-data-feeder.h | 41 - VocBase/query-join-execute.c | 419 -------- VocBase/query-join-execute.h | 18 - VocBase/query-join.c | 173 ---- VocBase/query-join.h | 30 - VocBase/query-result.c | 141 --- VocBase/query-result.h | 10 - VocBase/query-where.h | 207 ---- VocBase/query.c | 1750 ---------------------------------- VocBase/query.h | 438 --------- 18 files changed, 42 insertions(+), 5078 deletions(-) delete mode 100644 VocBase/query.c delete mode 100644 VocBase/query.h diff --git a/Makefile.files b/Makefile.files index b3024ce2b7..c07c5702a1 100644 --- a/Makefile.files +++ b/Makefile.files @@ -235,7 +235,6 @@ avocado_SOURCES = \ VocBase/query-order.c \ VocBase/query-parse.c \ VocBase/query-result.c \ - VocBase/query.c \ VocBase/shadow-data.c \ VocBase/simple-collection.c \ VocBase/synchroniser.c \ diff --git a/Makefile.in b/Makefile.in index f55729601e..e0f6179834 100644 --- a/Makefile.in +++ b/Makefile.in @@ -413,7 +413,7 @@ am_avocado_OBJECTS = Admin/ApplicationAdminServer.$(OBJEXT) \ VocBase/query-locks.$(OBJEXT) VocBase/query-memory.$(OBJEXT) \ VocBase/query-node.$(OBJEXT) VocBase/query-order.$(OBJEXT) \ VocBase/query-parse.$(OBJEXT) VocBase/query-result.$(OBJEXT) \ - VocBase/query.$(OBJEXT) VocBase/shadow-data.$(OBJEXT) \ + VocBase/shadow-data.$(OBJEXT) \ VocBase/simple-collection.$(OBJEXT) \ VocBase/synchroniser.$(OBJEXT) VocBase/voc-shaper.$(OBJEXT) \ VocBase/vocbase.$(OBJEXT) @@ -868,7 +868,6 @@ avocado_SOURCES = \ VocBase/query-order.c \ VocBase/query-parse.c \ VocBase/query-result.c \ - VocBase/query.c \ VocBase/shadow-data.c \ VocBase/simple-collection.c \ VocBase/synchroniser.c \ @@ -1943,8 +1942,6 @@ VocBase/query-parse.$(OBJEXT): VocBase/$(am__dirstamp) \ VocBase/$(DEPDIR)/$(am__dirstamp) VocBase/query-result.$(OBJEXT): VocBase/$(am__dirstamp) \ VocBase/$(DEPDIR)/$(am__dirstamp) -VocBase/query.$(OBJEXT): VocBase/$(am__dirstamp) \ - VocBase/$(DEPDIR)/$(am__dirstamp) VocBase/shadow-data.$(OBJEXT): VocBase/$(am__dirstamp) \ VocBase/$(DEPDIR)/$(am__dirstamp) VocBase/simple-collection.$(OBJEXT): VocBase/$(am__dirstamp) \ @@ -2243,7 +2240,6 @@ mostlyclean-compile: -rm -f VocBase/query-order.$(OBJEXT) -rm -f VocBase/query-parse.$(OBJEXT) -rm -f VocBase/query-result.$(OBJEXT) - -rm -f VocBase/query.$(OBJEXT) -rm -f VocBase/shadow-data.$(OBJEXT) -rm -f VocBase/simple-collection.$(OBJEXT) -rm -f VocBase/synchroniser.$(OBJEXT) @@ -2492,7 +2488,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/query-order.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/query-parse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/query-result.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/query.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/shadow-data.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/simple-collection.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@VocBase/$(DEPDIR)/synchroniser.Po@am__quote@ diff --git a/V8/v8-execution.cpp b/V8/v8-execution.cpp index e3cf018025..6f66a98da3 100644 --- a/V8/v8-execution.cpp +++ b/V8/v8-execution.cpp @@ -166,78 +166,6 @@ bool TRI_DefineJsonArrayExecutionContext (TRI_js_exec_context_t context, return true; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief defines documents in a join/where - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_DefineWhereExecutionContextX (TRI_js_exec_context_t context, - const TRI_select_join_t* join, - const size_t level, - const bool isJoin) { - js_exec_context_t* ctx; - TRI_doc_mptr_t* document; - - ctx = (js_exec_context_t*) context; - - for (size_t i = 0; i <= level; i++) { - TRI_join_part_t* part = (TRI_join_part_t*) join->_parts._buffer[i]; - - if (part->_type != JOIN_TYPE_LIST || (isJoin && (level == i))) { - // part is a single-document container - document = (TRI_doc_mptr_t*) part->_singleDocument; - if (!document) { - ctx->_arguments->Set(v8::String::New(part->_alias), v8::Null()); - } - else { - v8::Handle result; - bool ok = TRI_ObjectDocumentPointer(part->_collection->_collection, document, &result); - if (!ok) { - return false; - } - ctx->_arguments->Set(v8::String::New(part->_alias), result); - } - - if (part->_extraData._size) { - // make extra values available - ctx->_arguments->Set(v8::String::New(part->_extraData._alias), v8::Number::New(*((double*) part->_extraData._singleValue))); - } - } - else { - // part is a multi-document container - v8::Handle array = v8::Array::New(); - size_t pos = 0; - for (size_t n = 0; n < part->_listDocuments._length; n++) { - document = (TRI_doc_mptr_t*) part->_listDocuments._buffer[n]; - if (document) { - v8::Handle result; - bool ok = TRI_ObjectDocumentPointer(part->_collection->_collection, document, &result); - if (!ok) { - return false; - } - array->Set(pos++, result); - } - } - ctx->_arguments->Set(v8::String::New(part->_alias), array); - - if (part->_extraData._size) { - // make extra values available - v8::Handle array = v8::Array::New(); - uint32_t pos = 0; - for (size_t n = 0; n < part->_extraData._listValues._length; n++) { - double* data = (double*) part->_extraData._listValues._buffer[n]; - if (data) { - v8::Handle result; - array->Set(pos++, v8::Number::New(*data)); - } - } - ctx->_arguments->Set(v8::String::New(part->_extraData._alias), array); - } - } - } - - return true; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief defines documents in a join/where //////////////////////////////////////////////////////////////////////////////// @@ -536,30 +464,6 @@ bool TRI_ExecuteExecutionContext (TRI_js_exec_context_t context, void* storage) return true; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes an execution context for a condition - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_ExecuteConditionExecutionContextX (TRI_js_exec_context_t context, bool* r) { - js_exec_context_t* ctx; - - ctx = (js_exec_context_t*) context; - - // convert back into a handle - v8::Persistent func = ctx->_func; - - // and execute the function - v8::Handle args[] = { ctx->_arguments }; - v8::Handle result = func->Call(func, 1, args); - - if (result.IsEmpty()) { - return false; - } - - *r = TRI_ObjectToBoolean(result); - return true; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief executes an execution context for a condition //////////////////////////////////////////////////////////////////////////////// diff --git a/V8/v8-execution.h b/V8/v8-execution.h index 39a25e4da1..61ff374b5d 100644 --- a/V8/v8-execution.h +++ b/V8/v8-execution.h @@ -58,15 +58,6 @@ bool TRI_DefineJsonArrayExecutionContext (TRI_js_exec_context_t, TRI_json_t*); -//////////////////////////////////////////////////////////////////////////////// -/// @brief defines documents in a join/where - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_DefineWhereExecutionContextX (TRI_js_exec_context_t, - const TRI_select_join_t*, - const size_t, - const bool); - //////////////////////////////////////////////////////////////////////////////// /// @brief defines documents in a join/where //////////////////////////////////////////////////////////////////////////////// @@ -101,25 +92,12 @@ bool TRI_DefineCompareExecutionContext (TRI_js_exec_context_t, TRI_sr_documents_t*, TRI_sr_documents_t*); -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes an execution context - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_ExecuteExecutionContextX (TRI_js_exec_context_t, void* storage); - - //////////////////////////////////////////////////////////////////////////////// /// @brief executes an execution context //////////////////////////////////////////////////////////////////////////////// bool TRI_ExecuteExecutionContext (TRI_js_exec_context_t, void* storage); -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes an execution context for a condition - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_ExecuteConditionExecutionContextX (TRI_js_exec_context_t, bool* result); - //////////////////////////////////////////////////////////////////////////////// /// @brief executes an execution context for a condition //////////////////////////////////////////////////////////////////////////////// diff --git a/V8/v8-globals.h b/V8/v8-globals.h index 51f4a65ed4..8ed941ed66 100644 --- a/V8/v8-globals.h +++ b/V8/v8-globals.h @@ -63,9 +63,6 @@ typedef struct TRI_v8_global_s { TRI_v8_global_s () : JSGeneralCursors(), - JSQueries(), // DEPRECATED - JSCursors(), // DEPRECATED - JSWheres(), // DEPRECATED JSBarriers(), Actions(), ActionsLock(), @@ -73,11 +70,8 @@ typedef struct TRI_v8_global_s { EdgesColTempl(), ErrorTempl(), GeneralCursorTempl(), - QueryTempl(), // DEPRECATED - WhereTempl(), // DEPRECATED VocbaseColTempl(), VocbaseTempl(), - SLOperatorTempl(), // DEPRECATED DictionaryTempl(), CollectionQueryType(), OutputFuncName(), @@ -104,24 +98,6 @@ typedef struct TRI_v8_global_s { std::map< void*, v8::Persistent > JSGeneralCursors; -//////////////////////////////////////////////////////////////////////////////// -/// @brief query mapping for weak pointers - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - std::map< void*, v8::Persistent > JSQueries; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief cursor mapping for weak pointers - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - std::map< void*, v8::Persistent > JSCursors; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief where clause mapping for weak pointers - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - std::map< void*, v8::Persistent > JSWheres; - //////////////////////////////////////////////////////////////////////////////// /// @brief barrier mapping for weak pointers //////////////////////////////////////////////////////////////////////////////// @@ -189,24 +165,6 @@ typedef struct TRI_v8_global_s { v8::Persistent GeneralCursorTempl; -//////////////////////////////////////////////////////////////////////////////// -/// @brief query template - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - v8::Persistent QueryTempl; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief cursor template - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - v8::Persistent CursorTempl; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief where clause template - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - v8::Persistent WhereTempl; - //////////////////////////////////////////////////////////////////////////////// /// @brief TRI_vocbase_col_t template //////////////////////////////////////////////////////////////////////////////// @@ -225,12 +183,6 @@ typedef struct TRI_v8_global_s { v8::Persistent ShapedJsonTempl; -//////////////////////////////////////////////////////////////////////////////// -/// @brief skiplistoperator template - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - v8::Persistent SLOperatorTempl; - //////////////////////////////////////////////////////////////////////////////// /// @brief dictionary template //////////////////////////////////////////////////////////////////////////////// diff --git a/V8/v8-vocbase.cpp b/V8/v8-vocbase.cpp index 138505d5a3..51dee10395 100644 --- a/V8/v8-vocbase.cpp +++ b/V8/v8-vocbase.cpp @@ -38,7 +38,6 @@ #include "V8/v8-conv.h" #include "V8/v8-utils.h" #include "V8/v8-execution.h" -#include "VocBase/query.h" #include "VocBase/simple-collection.h" #include "VocBase/general-cursor.h" #include "SkipLists/sl-operator.h" @@ -79,18 +78,30 @@ static int const SLOT_END = 4; //////////////////////////////////////////////////////////////////////////////// /// @brief wrapped class for TRI_vocbase_t +/// +/// Layout: +/// - SLOT_CLASS_TYPE +/// - SLOT_CLASS //////////////////////////////////////////////////////////////////////////////// static int32_t const WRP_VOCBASE_TYPE = 1; //////////////////////////////////////////////////////////////////////////////// /// @brief wrapped class for TRI_vocbase_col_t +/// +/// Layout: +/// - SLOT_CLASS_TYPE +/// - SLOT_CLASS //////////////////////////////////////////////////////////////////////////////// static int32_t const WRP_VOCBASE_COL_TYPE = 2; //////////////////////////////////////////////////////////////////////////////// /// @brief wrapped class for general cursors +/// +/// Layout: +/// - SLOT_CLASS_TYPE +/// - SLOT_CLASS //////////////////////////////////////////////////////////////////////////////// static int32_t const WRP_GENERAL_CURSOR_TYPE = 3; @@ -106,30 +117,6 @@ static int32_t const WRP_GENERAL_CURSOR_TYPE = 3; static int32_t const WRP_SHAPED_JSON_TYPE = 4; -//////////////////////////////////////////////////////////////////////////////// -/// @brief wrapped class for TRI_qry_where_t - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static int32_t const WRP_QRY_WHERE_TYPE = 5; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief wrapped class for TRI_rc_cursor_t - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static int32_t const WRP_RC_CURSOR_TYPE = 6; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief wrapped class for TRI_query_t - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static int32_t const WRP_QUERY_TYPE = 7; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief wrapped class for SL Operator - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static int32_t const WRP_SL_OPERATOR_TYPE = 8; - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -1452,217 +1439,6 @@ static v8::Handle EdgesQuery (TRI_edge_direction_e direction, v8::Arg return scope.Close(documents); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief weak reference callback for query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void WeakQueryCallback (v8::Persistent object, void* parameter) { - TRI_query_t* query; - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - query = (TRI_query_t*) parameter; - - LOG_TRACE("weak-callback for query called"); - - // find the persistent handle - v8::Persistent persistent = v8g->JSQueries[query]; - v8g->JSQueries.erase(query); - - // dispose and clear the persistent handle - persistent.Dispose(); - persistent.Clear(); - - // and free the instance - TRI_FreeQuery(query); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief stores a query in a javascript object - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle WrapQuery (TRI_query_t* query) { - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - - v8::Handle queryObject = v8g->QueryTempl->NewInstance(); - map< void*, v8::Persistent >::iterator i = v8g->JSQueries.find(query); - - if (i == v8g->JSQueries.end()) { - v8::Persistent persistent = v8::Persistent::New(v8::External::New(query)); - - queryObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_QUERY_TYPE)); - queryObject->SetInternalField(SLOT_CLASS, persistent); - - v8g->JSQueries[query] = persistent; - - persistent.MakeWeak(query, WeakQueryCallback); - } - else { - queryObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_QUERY_TYPE)); - queryObject->SetInternalField(SLOT_CLASS, i->second); - } - - return queryObject; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a query or uses existing result set - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_rc_cursor_t* ExecuteQuery (v8::Handle queryObject, - v8::Handle* err) { - v8::TryCatch tryCatch; - - TRI_query_t* query = TRI_UnwrapClass(queryObject, WRP_QUERY_TYPE); - if (query == 0) { - *err = v8::String::New("corrupted query"); - return 0; - } - - LOG_TRACE("executing query"); - - TRI_rc_context_t* context = TRI_CreateContextQuery(query); - - if (context == 0) { - if (tryCatch.HasCaught()) { - *err = tryCatch.Exception(); - } - else { - *err = v8::String::New("cannot create query context"); - } - - return 0; - } - - TRI_rc_cursor_t* cursor = TRI_ExecuteQueryAql(query, context); - if (cursor == 0) { - TRI_FreeContextQuery(context); - - if (tryCatch.HasCaught()) { - *err = tryCatch.Exception(); - } - else { - *err = v8::String::New("cannot execute query"); - } - - return 0; - } - - return cursor; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief weak reference callback for cursors - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void WeakCursorCallback (v8::Persistent object, void* parameter) { - TRI_rc_cursor_t* cursor; - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - cursor = (TRI_rc_cursor_t*) parameter; - - LOG_TRACE("weak-callback for cursor called"); - - // find the persistent handle - v8::Persistent persistent = v8g->JSCursors[cursor]; - v8g->JSCursors.erase(cursor); - - // dispose and clear the persistent handle - persistent.Dispose(); - persistent.Clear(); - - // and free the result set -// cursor->free(cursor); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief stores a cursor in a javascript object - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle WrapCursor (TRI_rc_cursor_t* cursor) { - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - - v8::Handle cursorObject = v8g->CursorTempl->NewInstance(); - map< void*, v8::Persistent >::iterator i = v8g->JSCursors.find(cursor); - - if (i == v8g->JSCursors.end()) { - v8::Persistent persistent = v8::Persistent::New(v8::External::New(cursor)); - - cursorObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_RC_CURSOR_TYPE)); - cursorObject->SetInternalField(SLOT_CLASS, persistent); - - v8g->JSCursors[cursor] = persistent; - - persistent.MakeWeak(cursor, WeakCursorCallback); - } - else { - cursorObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_RC_CURSOR_TYPE)); - cursorObject->SetInternalField(SLOT_CLASS, i->second); - } - - return cursorObject; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief weak reference callback for wheres - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void WeakWhereCallback (v8::Persistent object, void* parameter) { - TRI_qry_where_t* where; - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - where = (TRI_qry_where_t*) parameter; - - LOG_TRACE("weak-callback for where called"); - - // find the persistent handle - v8::Persistent persistent = v8g->JSWheres[where]; - v8g->JSWheres.erase(where); - - // dispose and clear the persistent handle - persistent.Dispose(); - persistent.Clear(); - - // and free the result set - where->free(where); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief stores a where clause in a javascript object - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle WrapWhere (TRI_qry_where_t* where) { - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - - v8::Handle whereObject = v8g->WhereTempl->NewInstance(); - map< void*, v8::Persistent >::iterator i = v8g->JSWheres.find(where); - - if (i == v8g->JSWheres.end()) { - v8::Persistent persistent = v8::Persistent::New(v8::External::New(where)); - - whereObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_QRY_WHERE_TYPE)); - whereObject->SetInternalField(SLOT_CLASS, persistent); - - v8g->JSWheres[where] = persistent; - - persistent.MakeWeak(where, WeakWhereCallback); - } - else { - whereObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_QRY_WHERE_TYPE)); - whereObject->SetInternalField(SLOT_CLASS, i->second); - } - - return whereObject; -} - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -1967,6 +1743,11 @@ static v8::Handle JS_ByExampleHashIndex (v8::Arguments const& argv) { TRI_sim_collection_t* sim = (TRI_sim_collection_t*) doc; TRI_shaper_t* shaper = sim->base._shaper; + ##### use TRI_PidNamesByAttributeNames ##### + + + + // extract example if (argv.Length() == 0 || (argv.Length() % 2 == 1)) { ReleaseCollection(collection); @@ -2025,10 +1806,17 @@ static v8::Handle JS_ByExampleHashIndex (v8::Arguments const& argv) { collection->_collection->beginRead(collection->_collection); // find a suitable hash index - idx = TRI_LookupHashIndexSimCollection(collection, &paths, true); + idx = TRI_LookupHashIndexSimCollection(collection, &paths, false); + if (idx == NULL) { + idx = TRI_LookupHashIndexSimCollection(collection, &paths, false); + } + if (idx != NULL) { + TRI_hash_index_elements_t* result = TRI_LookupShapedJsonHashIndex(idx, + + // find documents by example TRI_vector_t filtered = TRI_SelectByExample(sim, n, pids, values); @@ -3130,1105 +2918,6 @@ static v8::Handle JS_ParseAhuacatl (v8::Arguments const& argv) { /// @} //////////////////////////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- -// --SECTION-- AVOCADO QUERY LANGUAGE -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- javascript functions -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new constant where clause using a boolean - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WhereBooleanAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: whereConstant()"))); - } - - // extract the where clause - v8::Handle whereArg = argv[0]; - TRI_qry_where_t* where = 0; - - where = TRI_CreateQueryWhereBoolean(TRI_ObjectToBoolean(whereArg)); - - // wrap it up - return scope.Close(WrapWhere(where)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new where clause from JavaScript - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WhereGeneralAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: whereGeneral()"))); - } - - // extract the where clause - v8::Handle whereArg = argv[0]; - TRI_qry_where_t* where = 0; - - string cmd = TRI_ObjectToString(whereArg); - - if (cmd.empty()) { - return scope.Close(v8::ThrowException(v8::String::New(" must be a valid expression"))); - } - - where = TRI_CreateQueryWhereGeneral(cmd.c_str()); - - // wrap it up - return scope.Close(WrapWhere(where)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new constant where clause for primary index - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WherePrimaryConstAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: wherePrimaryConst()"))); - } - - // extract the document handle - TRI_voc_cid_t cid = 0; - TRI_voc_did_t did = 0; - bool ok = IsDocumentHandle(argv[0], cid, did); - - if (! ok) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a "))); - } - - // build document hash access - TRI_qry_where_t* where = TRI_CreateQueryWherePrimaryConstant(did); - - // wrap it up - return scope.Close(WrapWhere(where)); -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WhereHashConstAql (const v8::Arguments& argv) { - v8::HandleScope scope; - TRI_json_t* parameterList; - - if (argv.Length() < 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_WHERE_HASH_CONST(, , ,..., )"))); - } - - - // .......................................................................... - // check that the first parameter sent is a double value - // .......................................................................... - bool inValidType = true; - TRI_idx_iid_t iid = TRI_ObjectToDouble(argv[0], inValidType); - - if (inValidType || iid == 0) { - return scope.Close(v8::ThrowException(v8::String::New(" must be an positive integer"))); - } - - - // .......................................................................... - // Store the index field parameters in a json object - // .......................................................................... - parameterList = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); - if (!parameterList) { - return scope.Close(v8::ThrowException(v8::String::New("out of memory"))); - } - - for (int j = 1; j < argv.Length(); ++j) { - v8::Handle parameter = argv[j]; - TRI_json_t* jsonParameter = TRI_JsonObject(parameter); - - if (jsonParameter == 0) { // NOT the null json value! - return scope.Close(v8::ThrowException(v8::String::New("type value not currently supported for hash index"))); - } - TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, parameterList, jsonParameter); - - /* - if (parameter->IsBoolean() ) { - v8::Handle booleanParameter = parameter->ToBoolean(); - TRI_PushBackListJson(parameterList, TRI_CreateBooleanJson(booleanParameter->Value() )); - } - else if ( parameter->IsNumber() ) { - v8::Handle numberParameter = parameter->ToNumber(); - TRI_PushBackListJson(parameterList, TRI_CreateNumberJson(numberParameter->Value() )); - } - else if ( parameter->IsString() ) { - v8::Handle stringParameter= parameter->ToString(); - v8::String::Utf8Value str(stringParameter); - TRI_PushBackListJson(parameterList, TRI_CreateStringCopyJson(*str)); - } - else if ( parameter->IsArray() ) { - v8::Handle arrayParameter = v8::Handle(v8::Array::Cast(*parameter)); - } - else { - return scope.Close(v8::ThrowException(v8::String::New("type value not currently supported for hash index"))); - } - */ - } - - - // build document hash access - TRI_qry_where_t* where = TRI_CreateQueryWhereHashConstant(iid, parameterList); - - // wrap it up - return scope.Close(WrapWhere(where)); - -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WherePQConstAql (const v8::Arguments& argv) { - v8::HandleScope scope; - TRI_json_t* parameterList; - - if (argv.Length() > 2 || argv.Length() == 0) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_WHERE_PQ_CONST( {,})"))); - } - - - // .......................................................................... - // check that the first parameter sent is a double value -- the index id - // .......................................................................... - - bool inValidType = true; - TRI_idx_iid_t iid = TRI_ObjectToDouble(argv[0], inValidType); - - if (inValidType || iid == 0) { - return scope.Close(v8::ThrowException(v8::String::New(" must be an positive integer"))); - } - - - // .......................................................................... - // Store the index field parameters in a json object -- there is only one - // possible parameter to be sent - the number of top documents to query. - // .......................................................................... - - parameterList = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); - if (!parameterList) { - return scope.Close(v8::ThrowException(v8::String::New("out of memory in JS_WherePQConstAql"))); - } - - - if (argv.Length() == 1) { - TRI_json_t* jsonParameter = TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, 1); - if (jsonParameter == 0) { // failure of some sort - return scope.Close(v8::ThrowException(v8::String::New("internal error in JS_WherePQConstAql"))); - } - TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, parameterList, jsonParameter); - } - - else { - for (int j = 1; j < argv.Length(); ++j) { - v8::Handle parameter = argv[j]; - TRI_json_t* jsonParameter = TRI_JsonObject(parameter); - - if (jsonParameter == 0) { // NOT the null json value! - return scope.Close(v8::ThrowException(v8::String::New("type value not currently supported for priority queue index"))); - } - TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, parameterList, jsonParameter); - } - } - - // build document priority queue access - TRI_qry_where_t* where = TRI_CreateQueryWherePQConstant(iid, parameterList); - - // wrap it up - return scope.Close(WrapWhere(where)); - -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WhereSkiplistConstAql (const v8::Arguments& argv) { - v8::HandleScope scope; - TRI_json_t* parameterList; - bool haveOperators; - TRI_qry_where_t* where; - - if (argv.Length() < 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_WHERE_SL_CONST(, , ,..., )"))); - } - - - // .......................................................................... - // check that the first parameter sent is a double value - // .......................................................................... - bool inValidType = true; - TRI_idx_iid_t iid = TRI_ObjectToDouble(argv[0], inValidType); - if (inValidType || iid == 0) { - return scope.Close(v8::ThrowException(v8::String::New(" must be an positive integer"))); - } - - // .......................................................................... - // Do we have logical/relational operators or just constants - // Only one or the other allowed - // .......................................................................... - haveOperators = false; - for (int j = 1; j < argv.Length(); ++j) { - v8::Handle parameter = argv[j]; - v8::Handle operatorObject = parameter->ToObject(); - TRI_sl_operator_t* op = TRI_UnwrapClass(operatorObject, WRP_SL_OPERATOR_TYPE); - if (op == 0) { - if (!haveOperators) { - continue; - } - return scope.Close(v8::ThrowException(v8::String::New("either logical/relational operators or constants allowed, but not both"))); - } - else { - if (!haveOperators) { - haveOperators = true; - } - } - } - - - // .......................................................................... - // We have a list of operators as parameters: - // If more than one operator, all of the operators will be anded. - // .......................................................................... - if (haveOperators) { - if (argv.Length() > 2) { - TRI_sl_operator_t* leftOp = 0; - v8::Handle leftParameter = argv[1]; - v8::Handle leftObject = leftParameter->ToObject(); - leftOp = TRI_UnwrapClass(leftObject, WRP_SL_OPERATOR_TYPE); - if (leftOp == 0) { - return scope.Close(v8::ThrowException(v8::String::New("either logical/relational operators or constants allowed, but not both"))); - } - - for (int j = 2; j < argv.Length(); ++j) { - v8::Handle rightParameter = argv[j]; - v8::Handle rightObject = rightParameter->ToObject(); - TRI_sl_operator_t* rightOp = TRI_UnwrapClass(rightObject, WRP_SL_OPERATOR_TYPE); - if (rightOp == 0) { - TRI_FreeSLOperator(leftOp); - return scope.Close(v8::ThrowException(v8::String::New("either logical/relational operators or constants allowed, but not both"))); - } - TRI_sl_operator_t* tempAndOperator = CreateSLOperator(TRI_SL_AND_OPERATOR,leftOp, rightOp, 0, 0, 0, 2, 0); - leftOp = tempAndOperator; - } - where = TRI_CreateQueryWhereSkiplistConstant(iid, leftOp); - } - else { - v8::Handle parameter = argv[1]; - v8::Handle operatorObject = parameter->ToObject(); - TRI_sl_operator_t* op = TRI_UnwrapClass(operatorObject, WRP_SL_OPERATOR_TYPE); - where = TRI_CreateQueryWhereSkiplistConstant(iid, op); - } - } - - // .............................................................................. - // fallback: simple eq operator - // .............................................................................. - - else { - // .......................................................................... - // Store the index field parameters in a json object - // .......................................................................... - parameterList = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); - if (!parameterList) { - return scope.Close(v8::ThrowException(v8::String::New("out of memory"))); - } - - for (int j = 1; j < argv.Length(); ++j) { - v8::Handle parameter = argv[j]; - TRI_json_t* jsonParameter = TRI_JsonObject(parameter); - - if (jsonParameter == 0) { // NOT the null json value! - return scope.Close(v8::ThrowException(v8::String::New("type value not currently supported for skiplist index"))); - } - TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, parameterList, jsonParameter); - } - TRI_sl_operator_t* eqOperator = CreateSLOperator(TRI_SL_EQ_OPERATOR,0, 0, parameterList, 0, 0, - parameterList->_value._objects._length, 0); - where = TRI_CreateQueryWhereSkiplistConstant(iid, eqOperator); - } - - if (where == 0) { - return scope.Close(v8::ThrowException(v8::String::New("Error detected in where statement"))); - } - - // wrap it up - return scope.Close(WrapWhere(where)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new constant where clause for geo index - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_WhereWithinConstAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - char* nameDistance; - - if (argv.Length() == 4) { - nameDistance = 0; - } - else if (argv.Length() == 5) { - v8::String::Utf8Value name(argv[4]); - - if (*name == 0) { - return scope.Close(v8::ThrowException(v8::String::New(" must be an attribute name"))); - } - - nameDistance = TRI_DuplicateString(*name); - } - else { - return scope.Close(v8::ThrowException(v8::String::New("usage: whereWithinConst(, , , [, ])"))); - } - - // extract the document handle - TRI_idx_iid_t iid = TRI_ObjectToDouble(argv[0]); - double latitude = TRI_ObjectToDouble(argv[1]); - double longitude = TRI_ObjectToDouble(argv[2]); - double radius = TRI_ObjectToDouble(argv[3]); - - // build document hash access - TRI_qry_where_t* where = TRI_CreateQueryWhereWithinConstant(iid, nameDistance, latitude, longitude, radius); - - if (nameDistance != 0) { - TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, nameDistance); - } - - // wrap it up - return scope.Close(WrapWhere(where)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new query from given parts - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_HashSelectAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_SELECT(collection, where)"))); - } - - // ........................................................................... - // extract the primary collection - // ........................................................................... - - v8::Handle collectionArg = argv[0]; - - if (! collectionArg->IsObject()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a COLLECTION as second argument"))); - } - v8::Handle collectionObj = collectionArg->ToObject(); - - v8::Handle err; - const TRI_vocbase_col_t* collection = UseCollection(collectionObj, &err); - - if (collection == 0) { - return scope.Close(v8::ThrowException(err)); - } - - // ........................................................................... - // Extract there hash where clause - // ........................................................................... - - v8::Handle whereArg = argv[1]; - - if (whereArg->IsNull()) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("expecting a WHERE object as third argument"))); - } - - TRI_qry_where_t* where = 0; - v8::Handle whereObj = whereArg->ToObject(); - where = TRI_UnwrapClass(whereObj, WRP_QRY_WHERE_TYPE); - - if (where == 0) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("corrupted WHERE"))); - } - - // ........................................................................... - // Create the hash query - // ........................................................................... - - TRI_query_t* query = TRI_CreateHashQuery(where, collection->_collection); - - if (!query) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("could not create query object"))); - } - - // ........................................................................... - // wrap it up - // ........................................................................... - - ReleaseCollection(collection); - return scope.Close(WrapQuery(query)); -} - - - - - -static v8::Handle JS_PQSelectAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_PQ_SELECT(collection, where)"))); - } - - // ........................................................................... - // extract the primary collection - // ........................................................................... - v8::Handle collectionArg = argv[0]; - if (! collectionArg->IsObject()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a COLLECTION as first argument"))); - } - v8::Handle collectionObj = collectionArg->ToObject(); - - v8::Handle err; - const TRI_vocbase_col_t* collection = UseCollection(collectionObj, &err); - - if (collection == 0) { - return scope.Close(v8::ThrowException(err)); - } - - // ........................................................................... - // Extract the where clause - // ........................................................................... - v8::Handle whereArg = argv[1]; - TRI_qry_where_t* where = 0; - if (whereArg->IsNull()) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("expecting a WHERE object as second argument"))); - } - v8::Handle whereObj = whereArg->ToObject(); - where = TRI_UnwrapClass(whereObj, WRP_QRY_WHERE_TYPE); - if (where == 0) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("corrupted WHERE"))); - } - - // ........................................................................... - // Check the operators - // ........................................................................... - TRI_qry_where_priorityqueue_const_t* pqWhere = (TRI_qry_where_priorityqueue_const_t*)(where); - TRI_priorityqueue_index_t* idx = (TRI_priorityqueue_index_t*)(TRI_LookupIndex(collection->_collection, pqWhere->_iid)); - if (idx == 0) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("invalid index in where statement"))); - } - - // ........................................................................... - // Create the skiplist query - // ........................................................................... - TRI_query_t* query = TRI_CreatePriorityQueueQuery(where, collection->_collection); - if (!query) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("could not create query object"))); - } - - - // ........................................................................... - // wrap it up - // ........................................................................... - - ReleaseCollection(collection); - return scope.Close(WrapQuery(query)); -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new query from given parts - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool CheckWhereSkiplistOperators(size_t fieldCount, TRI_sl_operator_t* slOperator) { - TRI_sl_logical_operator_t* logicalOperator; - TRI_sl_relation_operator_t* relationOperator; - bool ok = false; - - logicalOperator = (TRI_sl_logical_operator_t*)(slOperator); - relationOperator = (TRI_sl_relation_operator_t*)(slOperator); - - switch (slOperator->_type) { - case TRI_SL_EQ_OPERATOR: - case TRI_SL_NE_OPERATOR: - case TRI_SL_LE_OPERATOR: - case TRI_SL_LT_OPERATOR: - case TRI_SL_GE_OPERATOR: - case TRI_SL_GT_OPERATOR: - { - ok = (relationOperator->_numFields <= fieldCount); - break; - } - case TRI_SL_AND_OPERATOR: - case TRI_SL_OR_OPERATOR: - { - ok = (CheckWhereSkiplistOperators(fieldCount,logicalOperator->_left) && - CheckWhereSkiplistOperators(fieldCount,logicalOperator->_right)); - break; - } - case TRI_SL_NOT_OPERATOR: - { - ok = (CheckWhereSkiplistOperators(fieldCount,logicalOperator->_left)); - break; - } - } - return ok; -} - -static v8::Handle JS_SkiplistSelectAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_SL_SELECT(collection, where)"))); - } - - // ........................................................................... - // extract the primary collection - // ........................................................................... - v8::Handle collectionArg = argv[0]; - if (! collectionArg->IsObject()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a COLLECTION as first argument"))); - } - v8::Handle collectionObj = collectionArg->ToObject(); - - v8::Handle err; - const TRI_vocbase_col_t* collection = UseCollection(collectionObj, &err); - - if (collection == 0) { - return scope.Close(v8::ThrowException(err)); - } - - // ........................................................................... - // Extract the where clause - // ........................................................................... - v8::Handle whereArg = argv[1]; - TRI_qry_where_t* where = 0; - if (whereArg->IsNull()) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("expecting a WHERE object as second argument"))); - } - v8::Handle whereObj = whereArg->ToObject(); - where = TRI_UnwrapClass(whereObj, WRP_QRY_WHERE_TYPE); - if (where == 0) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("corrupted WHERE"))); - } - - // ........................................................................... - // Check the operators - // ........................................................................... - TRI_qry_where_skiplist_const_t* slWhere = (TRI_qry_where_skiplist_const_t*)(where); - TRI_skiplist_index_t* idx = (TRI_skiplist_index_t*)(TRI_LookupIndex(collection->_collection, slWhere->_iid)); - if (idx == 0) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("invalid index in where statement"))); - } - if (! CheckWhereSkiplistOperators(idx->_paths._length, slWhere->_operator)) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("One or more operators has invalid number of attributes"))); - } - - // ........................................................................... - // Create the skiplist query - // ........................................................................... - TRI_query_t* query = TRI_CreateSkiplistQuery(where, collection->_collection); - if (!query) { - ReleaseCollection(collection); - return scope.Close(v8::ThrowException(v8::String::New("could not create query object"))); - } - - // ........................................................................... - // wrap it up - // ........................................................................... - - ReleaseCollection(collection); - return scope.Close(WrapQuery(query)); -} - -//////////////////////////////////////////////////////////////////////////////// -// SKIP LIST OPERATOR functions -//////////////////////////////////////////////////////////////////////////////// - -static void WeakSLOperatorCallback(v8::Persistent object, void* parameter) { - TRI_sl_operator_t* slOperator; - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - slOperator = (TRI_sl_operator_t*)(parameter); - - LOG_TRACE("weak-callback for query operators called"); - - // find the persistent handle - v8::Persistent persistent = v8g->JSOperators[slOperator]; - - // remove it from the associative map - v8g->JSOperators.erase(slOperator); - - // dispose and clear the persistent handle - persistent.Dispose(); - persistent.Clear(); - - // and free the left and right operand -- depends on the type - TRI_FreeSLOperator(slOperator); -} - -static v8::Handle WrapSLOperator (TRI_sl_operator_t* slOperator) { - TRI_v8_global_t* v8g; - - v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - - v8::Handle operatorObject = v8g->SLOperatorTempl->NewInstance(); - map< void*, v8::Persistent >::iterator i = v8g->JSOperators.find(slOperator); - - if (i == v8g->JSOperators.end()) { - v8::Persistent persistent = v8::Persistent::New(v8::External::New(slOperator)); - operatorObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_SL_OPERATOR_TYPE)); - operatorObject->SetInternalField(SLOT_CLASS, persistent); - v8g->JSCursors[slOperator] = persistent; - persistent.MakeWeak(slOperator, WeakSLOperatorCallback); - } - else { - operatorObject->SetInternalField(SLOT_CLASS_TYPE, v8::Integer::New(WRP_SL_OPERATOR_TYPE)); - operatorObject->SetInternalField(SLOT_CLASS, i->second); - } - - return operatorObject; -} - -static TRI_json_t* parametersToJson(v8::Arguments const& argv, int startPos, int endPos) { - TRI_json_t* result = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); - - if (result == 0) { - v8::ThrowException(v8::String::New("out of memory")); - return 0; - } - - for (int j = startPos; j < endPos; ++j) { - v8::Handle parameter = argv[j]; - TRI_json_t* jsonParameter = TRI_JsonObject(parameter); - - if (jsonParameter == 0) { // NOT the null json value! - v8::ThrowException(v8::String::New("type value not currently supported for skiplist index")); - return 0; - } - TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, result, jsonParameter); - } - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -// Extracts one or more parameters which are values for the skip list index -// fields previously defined in the skip list index -- in the same order -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_Operator_AND (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_logical_operator_t* logicalOperator; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() != 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AND(, )"))); - } - - // ........................................................................... - // We expect a two parameters AND(,) - // ........................................................................... - v8::Handle leftOperatorArg = argv[0]; - v8::Handle rightOperatorArg = argv[1]; - - if (leftOperatorArg->IsNull()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a relational or logical operator as first argument"))); - } - if (rightOperatorArg->IsNull()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a relational or logical operator as second argument"))); - } - - - // ........................................................................... - // Extract the left and right operands from the context - // ........................................................................... - v8::Handle leftOperatorObject = leftOperatorArg->ToObject(); - v8::Handle rightOperatorObject = rightOperatorArg->ToObject(); - TRI_sl_operator_t* leftOperator = TRI_UnwrapClass(leftOperatorObject, WRP_SL_OPERATOR_TYPE); - TRI_sl_operator_t* rightOperator = TRI_UnwrapClass(rightOperatorObject, WRP_SL_OPERATOR_TYPE); - if (leftOperator == 0 || rightOperator == 0) { - return scope.Close(v8::ThrowException(v8::String::New("corrupted AND, possibly invalid parameters"))); - } - - // ........................................................................... - // Allocate the storage for a logial (AND) operator and assign it that type - // ........................................................................... - logicalOperator = (TRI_sl_logical_operator_t*)(CreateSLOperator(TRI_SL_AND_OPERATOR, - CopySLOperator(leftOperator), - CopySLOperator(rightOperator),0, 0, 0, 2, 0)); - // ........................................................................... - // Wrap it up for later use and return. - // ........................................................................... - return scope.Close(WrapSLOperator(&(logicalOperator->_base))); -} - - -static v8::Handle JS_Operator_OR (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_logical_operator_t* logicalOperator; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() != 2) { - return scope.Close(v8::ThrowException(v8::String::New("usage: OR(, )"))); - } - - - // ........................................................................... - // We expect a two parameters AND(,) - // ........................................................................... - v8::Handle leftOperatorArg = argv[0]; - v8::Handle rightOperatorArg = argv[1]; - - if (leftOperatorArg->IsNull()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a relational or logical operator as first argument"))); - } - if (rightOperatorArg->IsNull()) { - return scope.Close(v8::ThrowException(v8::String::New("expecting a relational or logical operator as second argument"))); - } - - - - v8::Handle leftOperatorObject = leftOperatorArg->ToObject(); - v8::Handle rightOperatorObject = rightOperatorArg->ToObject(); - TRI_sl_operator_t* leftOperator = TRI_UnwrapClass(leftOperatorObject, WRP_SL_OPERATOR_TYPE); - TRI_sl_operator_t* rightOperator = TRI_UnwrapClass(rightOperatorObject, WRP_SL_OPERATOR_TYPE); - - if (leftOperator == 0 || rightOperator == 0) { - return scope.Close(v8::ThrowException(v8::String::New("corrupted OR, possibly invalid parameters"))); - } - - - // ........................................................................... - // Allocate the storage for a logial (AND) operator and assign it that type - // ........................................................................... - logicalOperator = (TRI_sl_logical_operator_t*)(CreateSLOperator(TRI_SL_OR_OPERATOR, - CopySLOperator(leftOperator), - CopySLOperator(rightOperator),0, 0, 0, 2, 0)); - - return scope.Close(WrapSLOperator(&(logicalOperator->_base))); -} - - -static v8::Handle JS_Operator_EQ (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_relation_operator_t* relationOperator; - TRI_json_t* parameters; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() < 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: EQ(, ,..., )"))); - } - - - // ........................................................................... - // We expect a two parameters EQ("a.b.c",23.32) - // the first parameter is the name of the field we wish to ensure equality - // with the value of 23.32. - // ........................................................................... - - parameters = parametersToJson(argv,0,argv.Length()); - if (parameters == 0) { - return scope.Close(v8::ThrowException(v8::String::New("unsupported type in EQ(...) parameter list"))); - } - - // ........................................................................... - // Allocate the storage for a relation (EQ) operator and assign it that type - // ........................................................................... - relationOperator = (TRI_sl_relation_operator_t*)(CreateSLOperator(TRI_SL_EQ_OPERATOR, 0, 0, parameters, 0, 0, - parameters->_value._objects._length, 0)); - - return scope.Close(WrapSLOperator(&(relationOperator->_base))); -} - -static v8::Handle JS_Operator_GE (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_relation_operator_t* relationOperator; - TRI_json_t* parameters; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() < 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: GE(, ,..., )"))); - } - - - // ........................................................................... - // We expect a two parameters GE("abc",23.32) - // the first parameter is the name of the field we wish to ensure equality - // with the value of 23.32. - // ........................................................................... - - parameters = parametersToJson(argv,0,argv.Length()); - if (parameters == 0) { - return scope.Close(v8::ThrowException(v8::String::New("unsupported type in GE(...) parameter list"))); - } - - // ........................................................................... - // Allocate the storage for a relation (GE) operator and assign it that type - // ........................................................................... - relationOperator = (TRI_sl_relation_operator_t*)( CreateSLOperator(TRI_SL_GE_OPERATOR, 0, 0, parameters, 0, 0, - parameters->_value._objects._length, 0) ); - - return scope.Close(WrapSLOperator(&(relationOperator->_base))); -} - - -static v8::Handle JS_Operator_GT (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_relation_operator_t* relationOperator; - TRI_json_t* parameters; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() < 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: GT(, ,..., )"))); - } - - - // ........................................................................... - // We expect a two parameters GT("abc",23.32) - // the first parameter is the name of the field we wish to ensure equality - // with the value of 23.32. - // ........................................................................... - - parameters = parametersToJson(argv,0,argv.Length()); - if (parameters == 0) { - return scope.Close(v8::ThrowException(v8::String::New("unsupported type in GT(...) parameter list"))); - } - - // ........................................................................... - // Allocate the storage for a relation (GT) operator and assign it that type - // ........................................................................... - relationOperator = (TRI_sl_relation_operator_t*)( CreateSLOperator(TRI_SL_GT_OPERATOR, 0, 0, parameters, 0, 0, - parameters->_value._objects._length, 0) ); - - return scope.Close(WrapSLOperator(&(relationOperator->_base))); -} - - -static v8::Handle JS_Operator_LE (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_relation_operator_t* relationOperator; - TRI_json_t* parameters; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() < 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: LE(, ,..., )"))); - } - - - // ........................................................................... - // We expect a two parameters LE("field value",23.32) - // the first parameter is the name of the field we wish to ensure equality - // with the value of 23.32. - // ........................................................................... - - parameters = parametersToJson(argv,0,argv.Length()); - if (parameters == 0) { - return scope.Close(v8::ThrowException(v8::String::New("unsupported type in LE(...) parameter list"))); - } - - // ........................................................................... - // Allocate the storage for a relation (LE) operator and assign it that type - // ........................................................................... - relationOperator = (TRI_sl_relation_operator_t*)( CreateSLOperator(TRI_SL_LE_OPERATOR, 0, 0,parameters, 0, 0, - parameters->_value._objects._length, 0) ); - - return scope.Close(WrapSLOperator(&(relationOperator->_base))); -} - - -static v8::Handle JS_Operator_LT (v8::Arguments const& argv) { - v8::HandleScope scope; - TRI_sl_relation_operator_t* relationOperator; - TRI_json_t* parameters; - - // ........................................................................... - // We expect a list of constant values in the order in which the skip list - // index has been defined. An unknown value can have a 0 - // ........................................................................... - if (argv.Length() < 1) { - return scope.Close(v8::ThrowException(v8::String::New("usage: LT(, ,..., )"))); - } - - - // ........................................................................... - // We expect a two parameters LT("field_string_value",23.32) - // the first parameter is the name of the field we wish to ensure equality - // with the value of 23.32. - // ........................................................................... - - parameters = parametersToJson(argv,0,argv.Length()); - if (parameters == 0) { - return scope.Close(v8::ThrowException(v8::String::New("unsupported type in LT(...) parameter list"))); - } - - // ........................................................................... - // Allocate the storage for a relation (LT) operator and assign it that type - // ........................................................................... - relationOperator = (TRI_sl_relation_operator_t*)( CreateSLOperator(TRI_SL_LT_OPERATOR, 0,0,parameters, 0, 0, - parameters->_value._objects._length, 0) ); - - return scope.Close(WrapSLOperator(&(relationOperator->_base))); -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a select query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_SelectAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - if (argv.Length() != 4) { - return scope.Close(v8::ThrowException(v8::String::New("usage: AQL_SELECT(, , , )"))); - } - - v8::Handle dbArg = argv[0]->ToObject(); - TRI_vocbase_t* vocbase = TRI_UnwrapClass(dbArg, WRP_VOCBASE_TYPE); - - if (vocbase == 0) { - return scope.Close(v8::ThrowException(v8::String::New("corrupted vocbase"))); - } - - // select clause - TRI_qry_select_t* select; - select = TRI_CreateQuerySelectDocument(); - - v8::Handle nameArg = argv[1]; - string name = TRI_ObjectToString(nameArg); - - if (name.empty()) { - select->free(select); - return scope.Close(v8::ThrowException(v8::String::New("expecting a non-empty name for "))); - } - - // extract the skip value - TRI_voc_size_t skip = 0; - v8::Handle skipArg = argv[2]; - - if (skipArg->IsNull()) { - skip = TRI_QRY_NO_SKIP; - } - else { - double s = TRI_ObjectToDouble(skipArg); - - if (s < 0.0) { - skip = 0; - } - else { - skip = (TRI_voc_size_t) s; - } - } - - // extract the limit value - TRI_voc_ssize_t limit = 0; - v8::Handle limitArg = argv[3]; - - if (limitArg->IsNull()) { - limit = TRI_QRY_NO_LIMIT; - } - else { - double l = TRI_ObjectToDouble(limitArg); - - limit = (TRI_voc_ssize_t) l; - } - - TRI_select_join_t* join; - join = TRI_CreateSelectJoin(); - if (!join) { - select->free(select); - return scope.Close(v8::ThrowException(v8::String::New("could not create join struct"))); - } - - TRI_AddPartSelectJoinX(join, - JOIN_TYPE_PRIMARY, - 0, - (char*) name.c_str(), - (char*) "alias", - 0); - - // create the query - TRI_query_t* query = TRI_CreateQuery(vocbase, - select, - 0, - join, - skip, - limit); - - if (!query) { - select->free(select); - return scope.Close(v8::ThrowException(v8::String::New("could not create query object"))); - } - - // wrap it up - return scope.Close(WrapQuery(query)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static v8::Handle JS_ExecuteAql (v8::Arguments const& argv) { - v8::HandleScope scope; - - v8::Handle err; - TRI_rc_cursor_t* cursor = ExecuteQuery(argv.Holder(), &err); - - if (cursor == 0) { - return v8::ThrowException(err); - } - - return scope.Close(WrapCursor(cursor)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- TRI_VOCBASE_COL_T FUNCTIONS // ----------------------------------------------------------------------------- @@ -4613,7 +3302,7 @@ static v8::Handle JS_EnsureGeoIndexVocbaseCol (v8::Arguments const& a } //////////////////////////////////////////////////////////////////////////////// -/// @brief ensures that a geo index exists +/// @brief ensures that a geo constraint exists /// /// @FUN{@FA{collection}.ensureGeoConstraint(@FA{location}, @FA{ignore-null})} /// @@ -4632,7 +3321,7 @@ static v8::Handle JS_EnsureGeoConstraintVocbaseCol (v8::Arguments con } //////////////////////////////////////////////////////////////////////////////// -/// @brief ensures that a hash index exists +/// @brief ensures that a unique constraint exists /// /// @FUN{ensureUniqueConstraint(@FA{field1}, @FA{field2}, ...,@FA{fieldn})} /// @@ -6558,7 +5247,7 @@ void TRI_InitV8VocBridge (v8::Handle context, TRI_vocbase_t* vocbas ft->SetClassName(v8::String::New("ShapedJson")); rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(3); // TODO check the 3 + rt->SetInternalFieldCount(3); rt->SetNamedPropertyHandler(MapGetShapedJson, // NamedPropertyGetter, 0, // NamedPropertySetter setter = 0 @@ -6582,7 +5271,7 @@ void TRI_InitV8VocBridge (v8::Handle context, TRI_vocbase_t* vocbas ft->SetClassName(v8::String::New("AvocadoCollection")); rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(SLOT_END); // FIXME + rt->SetInternalFieldCount(2); v8g->VocbaseColTempl = v8::Persistent::New(rt); @@ -6628,7 +5317,7 @@ void TRI_InitV8VocBridge (v8::Handle context, TRI_vocbase_t* vocbas ft->SetClassName(v8::String::New("AvocadoEdgesCollection")); rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(SLOT_END); // FIXME + rt->SetInternalFieldCount(2); rt->Set(AllFuncName, v8::FunctionTemplate::New(JS_AllQuery)); rt->Set(ByExampleFuncName, v8::FunctionTemplate::New(JS_ByExampleQuery)); @@ -6678,7 +5367,6 @@ void TRI_InitV8VocBridge (v8::Handle context, TRI_vocbase_t* vocbas ft->SetClassName(v8::String::New("AvocadoError")); rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(2); v8g->ErrorTempl = v8::Persistent::New(rt); @@ -6710,135 +5398,6 @@ void TRI_InitV8VocBridge (v8::Handle context, TRI_vocbase_t* vocbas // must come after SetInternalFieldCount context->Global()->Set(v8::String::New("AvocadoCursor"), ft->GetFunction()); - -/* DEPRECATED START */ - - // ............................................................................. - // generate the query template - // ............................................................................. - - ft = v8::FunctionTemplate::New(); - ft->SetClassName(v8::String::New("AvocadoDeprecatedQuery")); - - rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(2); - - rt->Set(ExecuteFuncName, v8::FunctionTemplate::New(JS_ExecuteAql)); - - v8g->QueryTempl = v8::Persistent::New(rt); - - // must come after SetInternalFieldCount - context->Global()->Set(v8::String::New("AvocadoDeprecatedQuery"), - ft->GetFunction()); - - // ............................................................................. - // generate the where clause template - // ............................................................................. - - ft = v8::FunctionTemplate::New(); - ft->SetClassName(v8::String::New("AvocadoWhereClause")); - - rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(2); - - v8g->WhereTempl = v8::Persistent::New(rt); - - // must come after SetInternalFieldCount - context->Global()->Set(v8::String::New("AvocadoWhereClause"), - ft->GetFunction()); - - // ............................................................................. - // generate the skip list operator template - // ............................................................................. - - ft = v8::FunctionTemplate::New(); - ft->SetClassName(v8::String::New("SLOperator")); - - rt = ft->InstanceTemplate(); - rt->SetInternalFieldCount(2); - v8g->SLOperatorTempl = v8::Persistent::New(rt); - - // must come after SetInternalFieldCount - context->Global()->Set(v8::String::New("SLOperator"),ft->GetFunction()); - - // ............................................................................. - // create the global functions - // ............................................................................. - - context->Global()->Set(v8::String::New("AQL_WHERE_BOOLEAN"), - v8::FunctionTemplate::New(JS_WhereBooleanAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_WHERE_GENERAL"), - v8::FunctionTemplate::New(JS_WhereGeneralAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_WHERE_HASH_CONST"), - v8::FunctionTemplate::New(JS_WhereHashConstAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_WHERE_PQ_CONST"), - v8::FunctionTemplate::New(JS_WherePQConstAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_WHERE_SL_CONST"), - v8::FunctionTemplate::New(JS_WhereSkiplistConstAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_WHERE_PRIMARY_CONST"), - v8::FunctionTemplate::New(JS_WherePrimaryConstAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_WHERE_WITHIN_CONST"), - v8::FunctionTemplate::New(JS_WhereWithinConstAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_SELECT"), - v8::FunctionTemplate::New(JS_SelectAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_HASH_SELECT"), - v8::FunctionTemplate::New(JS_HashSelectAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_PQ_SELECT"), - v8::FunctionTemplate::New(JS_PQSelectAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AQL_SL_SELECT"), - v8::FunctionTemplate::New(JS_SkiplistSelectAql)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("AND"), - v8::FunctionTemplate::New(JS_Operator_AND)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("OR"), - v8::FunctionTemplate::New(JS_Operator_OR)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("EQ"), - v8::FunctionTemplate::New(JS_Operator_EQ)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("GE"), - v8::FunctionTemplate::New(JS_Operator_GE)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("GT"), - v8::FunctionTemplate::New(JS_Operator_GT)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("LE"), - v8::FunctionTemplate::New(JS_Operator_LE)->GetFunction(), - v8::ReadOnly); - - context->Global()->Set(v8::String::New("LT"), - v8::FunctionTemplate::New(JS_Operator_LT)->GetFunction(), - v8::ReadOnly); - -/* DEPRECATED END */ - context->Global()->Set(v8::String::New("CURSOR"), v8::FunctionTemplate::New(JS_Cursor)->GetFunction(), v8::ReadOnly); diff --git a/VocBase/query-context.h b/VocBase/query-context.h index 696451ce1e..3eddd0a110 100644 --- a/VocBase/query-context.h +++ b/VocBase/query-context.h @@ -35,11 +35,6 @@ extern "C" { #endif -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- EXECUTION CONTEXT // ----------------------------------------------------------------------------- @@ -48,6 +43,11 @@ extern "C" { // --SECTION-- public types // ----------------------------------------------------------------------------- +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup VocBase +/// @{ +//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// /// @brief JavaScript execution context //////////////////////////////////////////////////////////////////////////////// @@ -55,29 +55,18 @@ extern "C" { typedef void* TRI_js_exec_context_t; //////////////////////////////////////////////////////////////////////////////// -/// @brief execution context of a query -/// -/// In order to execute a query, you need an execution context. The results are -/// only valid as long as the context exists. After freeing the context you -/// should no longer access the result cursor or the result documents. -/// -/// When creating an execution context, parts of clauses might use JavaScript. -/// A JavaScript execution context is created for these clauses. +/// @} //////////////////////////////////////////////////////////////////////////////// -typedef struct TRI_rc_context_s { // DEPRECATED - TRI_doc_collection_t* _primary; - - TRI_js_exec_context_t _selectClause; - TRI_js_exec_context_t _whereClause; - TRI_js_exec_context_t _orderClause; -} -TRI_rc_context_t; - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup VocBase +/// @{ +//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// /// @brief creates a new execution context //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-data-feeder.c b/VocBase/query-data-feeder.c index a6e5724eeb..9fc9a38f85 100644 --- a/VocBase/query-data-feeder.c +++ b/VocBase/query-data-feeder.c @@ -43,37 +43,6 @@ // --SECTION-- type independent functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @brief create a new base data data feeder struct - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_data_feeder_t* CreateDataFeederX (const TRI_data_feeder_type_e type, - const TRI_doc_collection_t* collection, - const TRI_join_t* join, - size_t level) { - TRI_data_feeder_t* feeder; - - feeder = (TRI_data_feeder_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_data_feeder_t), false); - if (!feeder) { - return NULL; - } - - feeder->_type = type; - feeder->_level = level; - feeder->_join = (TRI_select_join_t*) join; - feeder->_part = (TRI_join_part_t*) ((TRI_select_join_t*) join)->_parts._buffer[level]; - feeder->_collection = collection; - feeder->_ranges = NULL; - feeder->_state = NULL; - - feeder->init = NULL; - feeder->rewind = NULL; - feeder->current = NULL; - feeder->free = NULL; - - return feeder; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief create a new base data data feeder struct //////////////////////////////////////////////////////////////////////////////// @@ -218,36 +187,6 @@ static void FreeFeederTableScan (TRI_data_feeder_t* feeder) { TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief create a new table scan data feeder - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederTableScanX (const TRI_doc_collection_t* collection, - TRI_join_t* join, - size_t level) { - TRI_data_feeder_t* feeder; - - feeder = CreateDataFeederX(FEEDER_TABLE_SCAN, collection, join, level); - if (!feeder) { - return NULL; - } - - feeder->_state = (TRI_data_feeder_table_scan_t*) - TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_data_feeder_table_scan_t), false); - - if (!feeder->_state) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); - return NULL; - } - - feeder->init = InitFeederTableScan; - feeder->rewind = RewindFeederTableScan; - feeder->current = CurrentFeederTableScan; - feeder->free = FreeFeederTableScan; - - return feeder; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief create a new table scan data feeder //////////////////////////////////////////////////////////////////////////////// @@ -445,36 +384,6 @@ static void FreeFeederPrimaryLookup (TRI_data_feeder_t* feeder) { TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief create a new primary index data feeder - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederPrimaryLookupX (const TRI_doc_collection_t* collection, - TRI_join_t* join, - size_t level) { - TRI_data_feeder_t* feeder; - - feeder = CreateDataFeederX(FEEDER_PRIMARY_LOOKUP, collection, join, level); - if (!feeder) { - return NULL; - } - - feeder->_state = (TRI_data_feeder_primary_lookup_t*) - TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_data_feeder_primary_lookup_t), false); - if (!feeder->_state) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); - return NULL; - } - - // init feeder - feeder->init = InitFeederPrimaryLookup; - feeder->rewind = RewindFeederPrimaryLookup; - feeder->current = CurrentFeederPrimaryLookup; - feeder->free = FreeFeederPrimaryLookup; - - return feeder; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief create a new primary index data feeder //////////////////////////////////////////////////////////////////////////////// @@ -694,35 +603,6 @@ static void FreeFeederHashLookup (TRI_data_feeder_t* feeder) { TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder for hash lookups - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederHashLookupX (const TRI_doc_collection_t* collection, - TRI_join_t* join, - size_t level) { - TRI_data_feeder_t* feeder; - - feeder = CreateDataFeederX(FEEDER_HASH_LOOKUP, collection, join, level); - if (!feeder) { - return NULL; - } - - feeder->_state = (TRI_data_feeder_hash_lookup_t*) - TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_data_feeder_hash_lookup_t), false); - if (!feeder->_state) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); - return NULL; - } - - feeder->init = InitFeederHashLookup; - feeder->rewind = RewindFeederHashLookup; - feeder->current = CurrentFeederHashLookup; - feeder->free = FreeFeederHashLookup; - - return feeder; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder for hash lookups //////////////////////////////////////////////////////////////////////////////// @@ -1157,35 +1037,6 @@ static void FreeFeederSkiplistLookup (TRI_data_feeder_t* feeder) { TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder for skiplist lookups - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederSkiplistLookupX (const TRI_doc_collection_t* collection, - TRI_join_t* join, - size_t level) { - TRI_data_feeder_t* feeder; - - feeder = CreateDataFeederX(FEEDER_SKIPLIST_LOOKUP, collection, join, level); - if (!feeder) { - return NULL; - } - - feeder->_state = (TRI_data_feeder_skiplist_lookup_t*) - TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_data_feeder_skiplist_lookup_t), false); - if (!feeder->_state) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); - return NULL; - } - - feeder->init = InitFeederSkiplistLookup; - feeder->rewind = RewindFeederSkiplistLookup; - feeder->current = CurrentFeederSkiplistLookup; - feeder->free = FreeFeederSkiplistLookup; - - return feeder; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder for skiplist lookups //////////////////////////////////////////////////////////////////////////////// @@ -1329,42 +1180,6 @@ static void FreeFeederGeoLookup (TRI_data_feeder_t* feeder) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder for geo lookups - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederGeoLookupX (const TRI_doc_collection_t* collection, - TRI_join_t* join, - size_t level, - QL_ast_query_geo_restriction_t* restriction) { - TRI_data_feeder_t* feeder; - TRI_data_feeder_geo_lookup_t* state; - - feeder = CreateDataFeederX(FEEDER_GEO_LOOKUP, collection, join, level); - if (!feeder) { - return NULL; - } - - feeder->_state = (TRI_data_feeder_geo_lookup_t*) - TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_data_feeder_geo_lookup_t), false); - - state = (TRI_data_feeder_geo_lookup_t*) feeder->_state; - - if (!state) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, feeder); - return NULL; - } - - state->_restriction = restriction; - - feeder->init = InitFeederGeoLookup; - feeder->rewind = RewindFeederGeoLookup; - feeder->current = CurrentFeederGeoLookup; - feeder->free = FreeFeederGeoLookup; - - return feeder; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder for geo lookups //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-data-feeder.h b/VocBase/query-data-feeder.h index 5f8046f415..66fae75731 100644 --- a/VocBase/query-data-feeder.h +++ b/VocBase/query-data-feeder.h @@ -280,14 +280,6 @@ typedef struct TRI_data_feeder_table_scan_s { } TRI_data_feeder_table_scan_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder (table scan) - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederTableScanX (const TRI_doc_collection_t*, - TRI_join_t*, - size_t); - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder (table scan) //////////////////////////////////////////////////////////////////////////////// @@ -317,14 +309,6 @@ typedef struct TRI_data_feeder_primary_lookup_s { TRI_data_feeder_primary_lookup_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder (primary index lookup) - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederPrimaryLookupX (const TRI_doc_collection_t*, - TRI_join_t*, - size_t); - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder (primary index lookup) //////////////////////////////////////////////////////////////////////////////// @@ -355,14 +339,6 @@ typedef struct TRI_data_feeder_hash_lookup_s { } TRI_data_feeder_hash_lookup_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder (hash index lookup) - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederHashLookupX (const TRI_doc_collection_t*, - TRI_join_t*, - size_t); - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder (hash index lookup) //////////////////////////////////////////////////////////////////////////////// @@ -395,14 +371,6 @@ typedef struct TRI_data_feeder_skiplist_lookup_s { } TRI_data_feeder_skiplist_lookup_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder (skiplist lookup) - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederSkiplistLookupX (const TRI_doc_collection_t*, - TRI_join_t*, - size_t); - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder (skiplist lookup) //////////////////////////////////////////////////////////////////////////////// @@ -430,15 +398,6 @@ typedef struct TRI_data_feeder_geo_lookup_s { } TRI_data_feeder_geo_lookup_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new data feeder (geo index lookup) - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_data_feeder_t* TRI_CreateDataFeederGeoLookupX (const TRI_doc_collection_t*, - TRI_join_t*, - size_t, - QL_ast_query_geo_restriction_t*); - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new data feeder (geo index lookup) //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-join-execute.c b/VocBase/query-join-execute.c index 2b80d309ba..66f9576997 100644 --- a/VocBase/query-join-execute.c +++ b/VocBase/query-join-execute.c @@ -67,85 +67,6 @@ static void LogIndexString(TRI_index_t const* idx, } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Determine which geo indexes to use in a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_data_feeder_t* DetermineGeoIndexUsageX (const TRI_vocbase_t* vocbase, - const TRI_select_join_t* join, - const size_t level, - const TRI_join_part_t* part) { - assert(false); - -#if 0 - TRI_vector_pointer_t* indexDefinitions; - TRI_index_definition_t* indexDefinition; - TRI_data_feeder_t* feeder = NULL; - size_t i; - - assert(part->_geoRestriction); - - indexDefinitions = TRI_GetCollectionIndexes(vocbase, part->_collectionName); - if (!indexDefinitions) { - return feeder; - } - - // enum all indexes - for (i = 0; i < indexDefinitions->_length; i++) { - indexDefinition = (TRI_index_definition_t*) indexDefinitions->_buffer[i]; - - if (indexDefinition->_type != TRI_IDX_TYPE_GEO_INDEX) { - // ignore all indexes except geo indexes here - continue; - } - - if (indexDefinition->_fields->_length != 2) { - continue; - } - - if (strcmp(indexDefinition->_fields->_buffer[0], - part->_geoRestriction->_compareLat._field) != 0) { - continue; - } - - if (strcmp(indexDefinition->_fields->_buffer[1], - part->_geoRestriction->_compareLon._field) != 0) { - continue; - } - - feeder = - TRI_CreateDataFeederGeoLookupX((TRI_doc_collection_t*) part->_collection, - (TRI_join_t*) join, - level, - part->_geoRestriction); - - if (feeder) { - // set up addtl data for feeder - feeder->_indexId = indexDefinition->_iid; - break; - } - } - - TRI_FreeIndexDefinitions(indexDefinitions); - - return feeder; -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Determine which indexes to use in a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_data_feeder_t* DetermineIndexUsageX (const TRI_vocbase_t* vocbase, - const TRI_select_join_t* join, - const size_t level, - const TRI_join_part_t* part) { - - return TRI_CreateDataFeederTableScanX((TRI_doc_collection_t*) part->_collection->_collection, - (TRI_join_t*) join, - level); -} - //////////////////////////////////////////////////////////////////////////////// /// @brief determines which geo indexes to use in a query //////////////////////////////////////////////////////////////////////////////// @@ -461,107 +382,6 @@ static inline TRI_select_part_e GetValueDataPartType(const TRI_join_type_e type) return RESULT_PART_VALUE_SINGLE; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new select result from a join definition - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_select_result_t* TRI_JoinSelectResultX (const TRI_vocbase_t* vocbase, - TRI_select_join_t* join) { - TRI_select_result_t* result; - TRI_vector_pointer_t* dataparts; - TRI_select_datapart_t* datapart; - TRI_join_part_t* part; - size_t i; - bool error = false; - - dataparts = (TRI_vector_pointer_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_vector_pointer_t), false); - if (!dataparts) { - return NULL; - } - - TRI_InitVectorPointer(dataparts, TRI_UNKNOWN_MEM_ZONE); - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - if (part) { - datapart = TRI_CreateDataPart(part->_alias, - part->_collection->_collection, - GetDocumentDataPartType(part->_type), - 0, - part->_mustMaterialize._select, - part->_mustMaterialize._order); - if (datapart) { - TRI_PushBackVectorPointer(dataparts, datapart); - - // if result contains some artificial extra data, create an additional - // result part for it - if (part->_extraData._size) { - datapart = TRI_CreateDataPart(part->_extraData._alias, - NULL, - GetValueDataPartType(part->_type), - part->_extraData._size, - part->_mustMaterialize._select, - part->_mustMaterialize._order); - - if (datapart) { - TRI_PushBackVectorPointer(dataparts, datapart); - } - else { - error = true; - } - } - } - else { - error = true; - } - - // determine the access type (index usage/full table scan) for collection - if (part->_geoRestriction) { - part->_feeder = DetermineGeoIndexUsageX(vocbase, join, i, part); - } - else { - part->_feeder = DetermineIndexUsageX(vocbase, join, i, part); - } - - if (!part->_feeder) { - error = true; - } - } - else { - error = true; - } - } - - // set up the data structures to retrieve the result documents - result = TRI_CreateSelectResult(dataparts); - if (!result) { - error = true; - } - - if (error) { - // clean up - for (i = 0; i < dataparts->_length; i++) { - datapart = (TRI_select_datapart_t*) dataparts->_buffer[i]; - if (datapart) { - datapart->free(datapart); - } - } - - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - if (part->_feeder) { - part->_feeder->free(part->_feeder); - part->_feeder = NULL; - } - } - - TRI_DestroyVectorPointer(dataparts); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, dataparts); - return NULL; - } - - return result; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Free join data parts //////////////////////////////////////////////////////////////////////////////// @@ -716,37 +536,6 @@ TRI_select_result_t* TRI_JoinSelectResult (TRI_query_instance_t* const instance) return result; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Check an ON condition for a join - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static inline bool CheckJoinClauseX (const TRI_select_join_t const* join, - const size_t level) { - TRI_join_part_t* part; - bool whereResult; - - part = (TRI_join_part_t*) join->_parts._buffer[level]; - TRI_DefineWhereExecutionContextX(part->_context, join, level, true); - TRI_ExecuteConditionExecutionContextX(part->_context, &whereResult); - - return whereResult; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Check a WHERE condition - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static inline bool CheckWhereClauseX (const TRI_rc_context_t *context, - const TRI_select_join_t const* join, - const size_t level) { - bool whereResult; - - TRI_DefineWhereExecutionContextX(context->_whereClause, join, level, false); - TRI_ExecuteConditionExecutionContextX(context->_whereClause, &whereResult); - - return whereResult; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Check an ON condition for a join //////////////////////////////////////////////////////////////////////////////// @@ -783,165 +572,6 @@ static inline bool CheckWhereClause (TRI_query_instance_t* const instance, return whereResult; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Execute join part recursively - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void RecursiveJoinX (TRI_select_result_t* results, - TRI_select_join_t* join, - const size_t level, - TRI_qry_where_t *where, - TRI_rc_context_t *context, - TRI_voc_size_t *skip, - TRI_voc_ssize_t *limit) { - TRI_join_part_t* part; - TRI_data_feeder_t* feeder; - size_t numJoins; - bool joinMatch = false; - - if (*limit == 0) { - return; - } - - numJoins = join->_parts._length - 1; - assert(level <= numJoins); - - part = (TRI_join_part_t*) join->_parts._buffer[level]; - feeder = part->_feeder; - feeder->rewind(feeder); - - - // distinction between aggregates (list joins) and - // non-aggregates (inner join, left join) - - if (part->_type == JOIN_TYPE_LIST) { - // join type is aggregate (list join) - assert(level > 0); - TRI_ClearVectorPointer(&part->_listDocuments); - TRI_ClearVectorPointer(&part->_extraData._listValues); - - while (true) { - // get next document - if (!feeder->current(feeder)) { - // end of documents in collection - // exit this join - break; - } - - if (part->_context) { - // check ON clause - if (!CheckJoinClauseX(join, level)) { - continue; - } - } - - // push documents into vector - TRI_PushBackVectorPointer(&part->_listDocuments, part->_singleDocument); - TRI_PushBackVectorPointer(&part->_extraData._listValues, part->_extraData._singleValue); - } - - // all documents collected in vector - if (level == numJoins) { - // last join was executed - - if (where != 0) { - // check WHERE clause for full row - if (!CheckWhereClauseX(context, join, level)) { - return; - } - } - - // apply SKIP limits - if (*skip > 0) { - (*skip)--; - return; - } - - // full match, now add documents to result sets - TRI_AddJoinSelectResultX(results, join); - - (*limit)--; - // apply LIMIT - if (*limit == 0) { - return; - } - } - else { - // recurse into next join - RecursiveJoinX(results, join, level + 1, where, context, skip, limit); - } - - return; - // end of list join - } - - // join type is non-aggregate - - while (true) { - // get next document - if (!feeder->current(feeder)) { - // end of documents in collection - // exit this join - break; - } - - if (level > 0 && part->_context) { - // check ON clause - if (!CheckJoinClauseX(join, level)) { - if (part->_type == JOIN_TYPE_OUTER) { - // set document to null in outer join - part->_singleDocument = NULL; - part->_extraData._singleValue = NULL; - - // left join: if we are not at the last document of the left - // joined collection, we continue - // if we are at the last document and there hasn't been a - // match, we must still include the left document if the where - // condition matches - if (joinMatch) { - continue; - } - } - else { - // inner join: always go to next record - continue; - } - } - joinMatch = true; - } - - if (level == numJoins) { - // last join was executed - - if (where != 0) { - // check WHERE clause for full row - if (!CheckWhereClauseX(context, join, level)) { - continue; - } - } - - // apply SKIP limits - if (*skip > 0) { - (*skip)--; - continue; - } - - // full match, now add documents to result sets - TRI_AddJoinSelectResultX(results, join); - - (*limit)--; - // apply LIMIT - if (*limit == 0) { - return; - } - } - else { - // recurse into next join - RecursiveJoinX(results, join, level + 1, where, context, skip, limit); - } - } -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Forward declaration //////////////////////////////////////////////////////////////////////////////// @@ -1131,55 +761,6 @@ static void DeinitJoin (TRI_query_instance_t* const instance) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Execute joins - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_ExecuteJoinsX (TRI_select_result_t* results, - TRI_select_join_t* join, - TRI_qry_where_t* where, - TRI_rc_context_t* context, - const TRI_voc_size_t skip, - const TRI_voc_ssize_t limit) { - TRI_join_part_t* part; - TRI_voc_size_t _skip; - TRI_voc_ssize_t _limit; - size_t i; - - // set skip and limit to initial values - // (values will be decreased during join execution) - _skip = skip; - _limit = limit; - - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - assert(part->_feeder); - - part->_feeder->init(part->_feeder); - } - // execute the join - RecursiveJoinX(results, join, 0, where, context, &_skip, &_limit); - - // deallocate vectors for list joins (would be done later anyway, but we can - // free the memory here already) - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - if (part->_type == JOIN_TYPE_LIST) { - TRI_DestroyVectorPointer(&part->_listDocuments); - part->_listDocuments._buffer = NULL; - - TRI_DestroyVectorPointer(&part->_extraData._listValues); - part->_extraData._listValues._buffer = NULL; - } - - if (part->_feeder) { - // free data feeder early, we don't need it any longer - part->_feeder->free(part->_feeder); - part->_feeder = NULL; - } - } -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Execute joins //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-join-execute.h b/VocBase/query-join-execute.h index 25f99205ca..d9d373dae9 100644 --- a/VocBase/query-join-execute.h +++ b/VocBase/query-join-execute.h @@ -44,30 +44,12 @@ extern "C" { /// @{ //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new select result from a join definition - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_select_result_t* TRI_JoinSelectResultX (const TRI_vocbase_t*, - TRI_select_join_t*); - //////////////////////////////////////////////////////////////////////////////// /// @brief Create a new select result from a join definition //////////////////////////////////////////////////////////////////////////////// TRI_select_result_t* TRI_JoinSelectResult (TRI_query_instance_t* const); -//////////////////////////////////////////////////////////////////////////////// -/// @brief Execute joins - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_ExecuteJoinsX (TRI_select_result_t*, - TRI_select_join_t*, - TRI_qry_where_t*, - TRI_rc_context_t*, - const TRI_voc_size_t, - const TRI_voc_ssize_t); - //////////////////////////////////////////////////////////////////////////////// /// @brief Execute joins //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-join.c b/VocBase/query-join.c index 3e5180a8ef..e69de29bb2 100644 --- a/VocBase/query-join.c +++ b/VocBase/query-join.c @@ -1,173 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief joins -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2010-2012 triagens GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is triAGENS GmbH, Cologne, Germany -/// -/// @author Jan Steemann -/// @author Copyright 2012, triagens GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#include "VocBase/query-join.h" - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief get size of extra data in standard join parts - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static size_t GetExtraDataSizeVoid (TRI_join_part_t* part) { - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief get size of extra data in geo join parts - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static size_t GetExtraDataSizeGeo (TRI_join_part_t* part) { - return sizeof(double); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Free join part memory - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreePart (TRI_join_part_t* part) { - if (part->_alias) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, part->_alias); - } - - if (part->_ranges) { - // TODO: free ranges - } - - if (part->_collectionName) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, part->_collectionName); - } - - if (part->_feeder) { - part->_feeder->free(part->_feeder); - } - - if (part->_context) { - TRI_FreeExecutionContext(part->_context); - } - - if (part->_listDocuments._buffer) { - TRI_DestroyVectorPointer(&part->_listDocuments); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, part); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Free join memory - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeSelectJoin (TRI_select_join_t* join) { - TRI_join_part_t* part; - size_t i; - - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - part->free(part); - } - - TRI_DestroyVectorPointer(&join->_parts); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, join); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Add a part to a select join - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_AddPartSelectJoinX (TRI_select_join_t* join, - const TRI_join_type_e type, - TRI_vector_pointer_t* ranges, - char* collectionName, - char* alias, - QL_ast_query_geo_restriction_t* geoRestriction) { - - TRI_join_part_t* part; - - assert(join != NULL); - part = (TRI_join_part_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_join_part_t), false); - - if (!part) { - return false; - } - - // initialize vector for list joins - TRI_InitVectorPointer(&part->_listDocuments, TRI_UNKNOWN_MEM_ZONE); - part->_context = NULL; - part->_singleDocument = NULL; - part->_feeder = NULL; - part->_type = type; - part->_ranges = ranges; - part->_collection = NULL; - part->_collectionName = TRI_DuplicateString(collectionName); - part->_alias = TRI_DuplicateString(alias); - part->_geoRestriction = geoRestriction; - - // determine size of extra data to store - if (part->_geoRestriction) { - part->_extraData._size = GetExtraDataSizeGeo(part); - part->_extraData._alias = part->_geoRestriction->_alias; - } - else { - part->_extraData._size = GetExtraDataSizeVoid(part); - part->_extraData._alias = NULL; - } - part->free = FreePart; - - TRI_PushBackVectorPointer(&join->_parts, part); - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new join - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_select_join_t* TRI_CreateSelectJoin (void) { - TRI_select_join_t* join; - - join = (TRI_select_join_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_select_join_t), false); - if (!join) { - return NULL; - } - - TRI_InitVectorPointer(&join->_parts, TRI_UNKNOWN_MEM_ZONE); - join->free = FreeSelectJoin; - - return join; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// Local Variables: -// mode: outline-minor -// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" -// End: - diff --git a/VocBase/query-join.h b/VocBase/query-join.h index bc06417fb7..1f01edd46c 100644 --- a/VocBase/query-join.h +++ b/VocBase/query-join.h @@ -97,36 +97,6 @@ typedef struct TRI_join_part_s { } TRI_join_part_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief join container data structure for select queries - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_select_join_s { - TRI_vector_pointer_t _parts; - TRI_vocbase_t* _vocbase; - - void (*free) (struct TRI_select_join_s*); -} -TRI_select_join_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Add a part to a select join - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_AddPartSelectJoinX (TRI_select_join_t*, - const TRI_join_type_e, - TRI_vector_pointer_t*, - char*, - char*, - QL_ast_query_geo_restriction_t*); - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Create a new join - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_select_join_t* TRI_CreateSelectJoin (void); - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-result.c b/VocBase/query-result.c index 794e0459f8..8a92ac5d45 100644 --- a/VocBase/query-result.c +++ b/VocBase/query-result.c @@ -292,49 +292,6 @@ static bool IncreaseDocumentsStorageSelectResult (TRI_select_result_t* result, return true; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Get the required storage size for a row result of a join - DEPRECATED -/// -/// A result row of a join might contain data from multiple collections. Results -/// might also be single documents or multiple documents, depending on the join -/// type. -/// This function will calculate the total required size to store all documents -/// of all collections of the row result. -//////////////////////////////////////////////////////////////////////////////// - -static size_t GetJoinDocumentSizeX (const TRI_select_join_t* join) { - TRI_join_part_t* part; - size_t i, n, total; - - total = 0; - - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - if (part->_type == JOIN_TYPE_LIST) { - n = part->_listDocuments._length; - - // adjust for extra data - total += part->_extraData._size * n; - } - else { - n = 1; - } - - // number of documents - total += sizeof(TRI_select_size_t); - // document pointers - total += (size_t) (sizeof(TRI_sr_documents_t) * n); - - // adjust for extra data - if (part->_extraData._size) { - total += sizeof(TRI_select_size_t); - total += part->_extraData._size; - } - } - - return total; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Get the required storage size for a row result of a join /// @@ -384,104 +341,6 @@ static size_t GetJoinDocumentSize (const TRI_query_instance_t* const instance) { return total; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief Add documents from a join to the result set - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_AddJoinSelectResultX (TRI_select_result_t* result, TRI_select_join_t* join) { - TRI_sr_index_t* indexPtr; - TRI_sr_documents_t* docPtr; - TRI_select_size_t* numPtr; - TRI_join_part_t* part; - TRI_doc_mptr_t* document; - size_t numNeeded; - size_t bytesNeeded; - size_t i, j; - - // need space for one pointer - numNeeded = 1; - - if (result->_index._numUsed + numNeeded > result->_index._numAllocated) { - if (!IncreaseIndexStorageSelectResult(result, numNeeded)) { - return false; - } - } - - bytesNeeded = GetJoinDocumentSizeX(join); - if (result->_documents._bytesUsed + bytesNeeded > result->_documents._bytesAllocated) { - if (!IncreaseDocumentsStorageSelectResult(result, bytesNeeded)) { - return false; - } - } - - // store pointer to document in index - docPtr = result->_documents._current; - indexPtr = (TRI_sr_index_t*) result->_index._current; - *indexPtr++ = (TRI_sr_index_t) docPtr; - - result->_index._current = (TRI_sr_index_t*) indexPtr; - result->_index._numUsed++; - - // store document data - numPtr = (TRI_select_size_t*) docPtr; - for (i = 0; i < join->_parts._length; i++) { - part = (TRI_join_part_t*) join->_parts._buffer[i]; - if (part->_type == JOIN_TYPE_LIST) { - // multiple documents - *numPtr++ = part->_listDocuments._length; - docPtr = (TRI_sr_documents_t*) numPtr; - for (j = 0; j < part->_listDocuments._length; j++) { - document = (TRI_doc_mptr_t*) part->_listDocuments._buffer[j]; - - *docPtr++ = (TRI_sr_documents_t) document->_data; - } - - if (part->_extraData._size) { - // copy extra data - assert(part->_listDocuments._length == part->_extraData._listValues._length); - numPtr = (TRI_select_size_t*) docPtr; - *numPtr++ = part->_listDocuments._length; - docPtr = (TRI_sr_documents_t*) numPtr; - - for (j = 0; j < part->_extraData._listValues._length; j++) { - memcpy(docPtr, part->_extraData._listValues._buffer[j], part->_extraData._size); - docPtr = (TRI_sr_documents_t*) ((uint8_t*) docPtr + part->_extraData._size); - } - } - } - else { - // single document - *numPtr++ = 1; - docPtr = (TRI_sr_documents_t*) numPtr; - document = (TRI_doc_mptr_t*) part->_singleDocument; - if (document) { - *docPtr++ = (TRI_sr_documents_t) document->_data; - } - else { - // document is null - *docPtr++ = 0; - } - - if (part->_extraData._size) { - // copy extra data - numPtr = (TRI_select_size_t*) docPtr; - *numPtr++ = 1; - docPtr = (TRI_sr_documents_t*) numPtr; - memcpy(docPtr, part->_extraData._singleValue, part->_extraData._size); - docPtr = (TRI_sr_documents_t*) ((uint8_t*) docPtr + part->_extraData._size); - } - } - numPtr = (TRI_select_size_t*) docPtr; - } - - result->_documents._bytesUsed += bytesNeeded; - result->_documents._current = (TRI_sr_documents_t*) numPtr; - - result->_numRows++; - - return true; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief Add documents from a join to the result set //////////////////////////////////////////////////////////////////////////////// diff --git a/VocBase/query-result.h b/VocBase/query-result.h index d28ce93f2d..8d2e90de73 100644 --- a/VocBase/query-result.h +++ b/VocBase/query-result.h @@ -148,12 +148,6 @@ typedef struct TRI_select_result_s { } TRI_select_result_t; -//////////////////////////////////////////////////////////////////////////////// -/// @brief Add documents from a join to the result set - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_AddJoinSelectResultX (TRI_select_result_t*, TRI_select_join_t*); - //////////////////////////////////////////////////////////////////////////////// /// @brief Add documents from a join to the result set //////////////////////////////////////////////////////////////////////////////// @@ -193,14 +187,10 @@ TRI_select_result_t* TRI_CreateSelectResult (TRI_vector_pointer_t*); //////////////////////////////////////////////////////////////////////////////// typedef struct TRI_rc_result_s { - TRI_rc_context_t* _context; // TODO: REMOVE - TRI_js_exec_context_t* _orderContext; - TRI_doc_mptr_t* _primary; // TODO: REMOVE TRI_select_result_t* _selectResult; TRI_sr_documents_t* _dataPtr; - TRI_json_t _augmention; // TODO: REMOVE } TRI_rc_result_t; diff --git a/VocBase/query-where.h b/VocBase/query-where.h index f066afe8ac..e69de29bb2 100644 --- a/VocBase/query-where.h +++ b/VocBase/query-where.h @@ -1,207 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief where conditions -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2010-2012 triagens GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is triAGENS GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -/// @author Jan Steemann -/// @author Copyright 2012, triagens GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#ifndef TRIAGENS_DURHAM_VOC_BASE_WHERE_H -#define TRIAGENS_DURHAM_VOC_BASE_WHERE_H 1 - -#include "VocBase/vocbase.h" -#include "VocBase/document-collection.h" -#include "VocBase/index.h" -#include "VocBase/query-context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief where clause type -//////////////////////////////////////////////////////////////////////////////// - -typedef enum { - TRI_QRY_WHERE_BOOLEAN, - TRI_QRY_WHERE_GENERAL, - TRI_QRY_WHERE_HASH_CONSTANT, - TRI_QRY_WHERE_PRIORITY_QUEUE_CONSTANT, - TRI_QRY_WHERE_SKIPLIST_CONSTANT, - TRI_QRY_WHERE_WITHIN_CONSTANT, - TRI_QRY_WHERE_PRIMARY_CONSTANT -} -TRI_qry_where_type_e; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief abstract where clause -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_s { - TRI_qry_where_type_e _type; - - struct TRI_qry_where_s* (*clone) (struct TRI_qry_where_s const*); - void (*free) (struct TRI_qry_where_s*); -} -TRI_qry_where_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief abstract where clause for conditions -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_cond_s { - TRI_qry_where_t base; -} -TRI_qry_where_cond_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constant where clause -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_boolean_s { - TRI_qry_where_cond_t base; - - bool _value; -} -TRI_qry_where_boolean_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief JavaScript where clause -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_general_s { - TRI_qry_where_cond_t base; - - char* _code; -} -TRI_qry_where_general_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief abstract primary index where clause -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_primary_s { - TRI_qry_where_t base; - - TRI_voc_did_t (*did) (struct TRI_qry_where_primary_s*, TRI_rc_context_t*); -} -TRI_qry_where_primary_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief primary index where clause with a constant document identifier -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_primary_const_s { - TRI_qry_where_primary_t base; - - TRI_voc_did_t _did; -} -TRI_qry_where_primary_const_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief geo index where clause -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_within_s { - TRI_qry_where_t base; - - TRI_idx_iid_t _iid; - char* _nameDistance; - - double* (*coordinates) (struct TRI_qry_where_within_s*, TRI_rc_context_t*); - double (*radius) (struct TRI_qry_where_within_s*, TRI_rc_context_t*); -} -TRI_qry_where_within_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief geo index where clause with a constant document identifier -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_within_const_s { - TRI_qry_where_within_t base; - - double _coordinates[2]; - double _radius; -} -TRI_qry_where_within_const_t; - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief hash index where -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_hash_const_s { - TRI_qry_where_t base; - TRI_idx_iid_t _iid; - TRI_json_t* _parameters; // a json list object -} -TRI_qry_where_hash_const_t; - - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief skiplist index where -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_priorityqueue_const_s { - TRI_qry_where_t base; - TRI_idx_iid_t _iid; - TRI_json_t* _parameters; -} -TRI_qry_where_priorityqueue_const_t; - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief skiplist index where -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_where_skiplist_const_s { - TRI_qry_where_t base; - TRI_idx_iid_t _iid; - //TRI_json_t* _parameters; - // simple operator - TRI_sl_operator_t* _operator; -} -TRI_qry_where_skiplist_const_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - -#endif - -// Local Variables: -// mode: outline-minor -// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" -// End: - - diff --git a/VocBase/query.c b/VocBase/query.c deleted file mode 100644 index 1330ac4692..0000000000 --- a/VocBase/query.c +++ /dev/null @@ -1,1750 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief query -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2010-2012 triagens GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is triAGENS GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#include "query.h" - -#include "BasicsC/logging.h" -#include "BasicsC/string-buffer.h" -#include "BasicsC/strings.h" -#include "V8/v8-c-utils.h" -#include "VocBase/query-cursor.h" -#include "VocBase/query-join-execute.h" -#include "VocBase/simple-collection.h" - -// ----------------------------------------------------------------------------- -// --SECTION-- SELECT DOCUMENT -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query selection for unaltered documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_select_t* CloneQuerySelectDocument (TRI_qry_select_t const* s) { - return TRI_CreateQuerySelectDocument(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query selection for unaltered documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQuerySelectDocument (TRI_qry_select_t* s) { - TRI_qry_select_direct_t* selectClause; - - selectClause = (TRI_qry_select_direct_t*) s; - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, selectClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief converts result to JavaScript - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool ToJavaScriptSelectDocument (TRI_qry_select_t* s, - TRI_rc_result_t* result, - void* storage) { - - TRI_doc_mptr_t masterPointer; - TRI_doc_mptr_t* document; - TRI_select_size_t* numPtr; - TRI_select_size_t num; - TRI_select_result_t* selectResult = result->_selectResult; - TRI_select_datapart_t* part = (TRI_select_datapart_t*) selectResult->_dataParts->_buffer[0]; - - numPtr = (TRI_select_size_t*) result->_dataPtr; - num = *numPtr++; - assert(num == 1); - document = *((TRI_sr_documents_t*) numPtr); - TRI_MarkerMasterPointer(document, &masterPointer); - - return TRI_ObjectDocumentPointer(part->_collection, &masterPointer, storage); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query selection for unaltered documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_select_t* TRI_CreateQuerySelectDocument () { - TRI_qry_select_direct_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_select_direct_t), false); - - result->base._type = TRI_QRY_SELECT_DOCUMENT; - - result->base.clone = CloneQuerySelectDocument; - result->base.free = FreeQuerySelectDocument; - result->base.toJavaScript = ToJavaScriptSelectDocument; - - return &result->base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- SELECT GENERAL -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query selection for general documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_select_t* CloneQuerySelectGeneral (TRI_qry_select_t const* s) { - TRI_qry_select_general_t* selectClause; - - selectClause = (TRI_qry_select_general_t*) s; - - return TRI_CreateQuerySelectGeneral(selectClause->_code); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query selection for general documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQuerySelectGeneral (TRI_qry_select_t* s) { - TRI_qry_select_general_t* selectClause; - - selectClause = (TRI_qry_select_general_t*) s; - - TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, selectClause->_code); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, selectClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief converts result to JavaScript - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool ToJavaScriptSelectGeneral (TRI_qry_select_t* s, - TRI_rc_result_t* result, - void* storage) { - TRI_rc_context_t* context; - TRI_js_exec_context_t* execContext; - - context = result->_context; - execContext = context->_selectClause; - - if (execContext == NULL) { - LOG_ERROR("no JavaScript context for select is known"); - return false; - } - - // first define the augumentation, they might get overwritten - if (result->_augmention._type == TRI_JSON_ARRAY) { - TRI_DefineJsonArrayExecutionContext(execContext, &result->_augmention); - } - - // define the documents - TRI_DefineSelectExecutionContext(execContext, result); - - // execute everything - return TRI_ExecuteExecutionContext(execContext, storage); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query selection for general, generated documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_select_t* TRI_CreateQuerySelectGeneral (char const* clause) { - TRI_qry_select_general_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_select_general_t), false); - - result->base._type = TRI_QRY_SELECT_GENERAL; - - result->base.clone = CloneQuerySelectGeneral; - result->base.free = FreeQuerySelectGeneral; - result->base.toJavaScript = ToJavaScriptSelectGeneral; - - result->_code = TRI_DuplicateString(clause); - - return &result->base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- DOCUMENTS LIST -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private types -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief list of all documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -typedef struct collection_cursor_s { - TRI_rc_cursor_t base; - - TRI_select_size_t _length; - TRI_select_size_t _currentRow; - - TRI_doc_mptr_t* _documents; - TRI_doc_mptr_t* _current; - TRI_doc_mptr_t* _end; - - TRI_json_t* _augmentions; - TRI_json_t* _currentAugmention; - - TRI_rc_result_t _result; - - void* _iterator; -} -collection_cursor_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief fill function - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -typedef void (*cond_fptr) (collection_cursor_t*, - TRI_sim_collection_t*, - TRI_rc_context_t*, - TRI_qry_where_t*, - TRI_voc_size_t, - TRI_voc_ssize_t); - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief returns the next element - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_rc_result_t* NextCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - - cursor = (collection_cursor_t*) c; - if (cursor->_currentRow < cursor->_length) { - cursor->_result._dataPtr = - cursor->_result._selectResult->getAt(cursor->_result._selectResult, cursor->_currentRow++); - - if (cursor->_augmentions != NULL) { - cursor->_result._augmention = *cursor->_currentAugmention++; - } - - return &cursor->_result; - } - - return NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool ToJavaScriptHashDocument (TRI_qry_select_t* s, - TRI_rc_result_t* result, - void* storage) { - - TRI_doc_mptr_t* document; - TRI_doc_collection_t* collection; - - collection = result->_context->_primary; - - document = (TRI_doc_mptr_t*) result->_dataPtr; - return TRI_ObjectDocumentPointer(collection, document, storage); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_rc_result_t* NextHashCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - - cursor = (collection_cursor_t*) c; - - if (cursor->_currentRow == cursor->_length) { - return NULL; - } - - cursor->_current = &(cursor->_documents[cursor->_currentRow]); - cursor->_result._dataPtr = (TRI_sr_documents_t*) (cursor->_current); - ++(cursor->_currentRow); - - return &cursor->_result; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool ToJavaScriptPQDocument (TRI_qry_select_t* s, - TRI_rc_result_t* result, - void* storage) { - - TRI_doc_mptr_t* document; - TRI_doc_collection_t* collection; - - collection = result->_context->_primary; - - document = (TRI_doc_mptr_t*) result->_dataPtr; - return TRI_ObjectDocumentPointer(collection, document, storage); -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_rc_result_t* NextPQCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - - cursor = (collection_cursor_t*) c; - - if (cursor->_currentRow == cursor->_length) { - return NULL; - } - - cursor->_current = &(cursor->_documents[cursor->_currentRow]); - cursor->_result._dataPtr = (TRI_sr_documents_t*) (cursor->_current); - ++(cursor->_currentRow); - - return &cursor->_result; -} - - -//////////////////////////////////////////////////////////////////////////////// -// For a collection, advances a given cursor by one. Cursor is associated with -// a skip list index. Note: for now the field will store -// the iterator which is associated with a skip list index. There is no -// notion of the number of documents -- these have to be counted. So whenever -// a count() request is received, the iterator advances to the end of the -// interval. -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_rc_result_t* NextSkiplistCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - SkiplistIndexElement* element; - TRI_skiplist_iterator_t* iterator; - - cursor = (collection_cursor_t*)(c); - if (cursor == NULL) { - return NULL; - } - - iterator = (TRI_skiplist_iterator_t*)(cursor->_iterator); - if (iterator == NULL) { - return NULL; - } - - element = (SkiplistIndexElement*)(iterator->_next(iterator)); - if (element == NULL) { - return NULL; - } - - cursor->_current = element->data; - cursor->_result._dataPtr = (TRI_sr_documents_t*) (cursor->_current); - ++(cursor->_currentRow); - return &cursor->_result; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks if the cursor is exhausted - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool HasNextSkiplistCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - TRI_skiplist_iterator_t* iterator; - - cursor = (collection_cursor_t*)(c); - if (cursor == NULL) { - return false; - } - - iterator = (TRI_skiplist_iterator_t*)(cursor->_iterator); - if (iterator == NULL) { - return false; - } - - return (iterator->_hasNext(iterator)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks if the cursor associated with is exhausted -//////////////////////////////////////////////////////////////////////////////// - -static bool HasNextCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - - cursor = (collection_cursor_t*) c; - - return cursor->_currentRow < cursor->_length; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a cursor - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeCollectionCursor (TRI_rc_cursor_t* c) { - collection_cursor_t* cursor; - TRI_qry_select_t* slct; - size_t i; - - cursor = (collection_cursor_t*) c; - - // free result set - if (cursor->_result._selectResult != NULL) { - cursor->_result._selectResult->free(cursor->_result._selectResult); - } - - // free select - slct = cursor->base._select; - slct->free(slct); - - TRI_RemoveCollectionsCursor(&cursor->base); - - TRI_DestroyVectorPointer(&cursor->base._containers); - - TRI_FreeContextQuery(cursor->base._context); - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, cursor->_documents); - - if (cursor->_augmentions != NULL) { - for (i = 0; i < cursor->_length; ++i) { - TRI_DestroyJson(TRI_UNKNOWN_MEM_ZONE, &cursor->_augmentions[i]); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, cursor->_augmentions); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, cursor); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief apply a skip and limit on the result set -//////////////////////////////////////////////////////////////////////////////// - -static bool TransformDataSkipLimit (TRI_rc_result_t* result, - TRI_voc_size_t skip, - TRI_voc_ssize_t limit) { - - TRI_select_result_t* _result = result->_selectResult; - - // return nothing - if (limit == 0 || _result->_numRows <= skip) { - return TRI_SliceSelectResult(_result, 0, 0); - } - - // positive limit, skip and slice from front - if (limit > 0) { - if (_result->_numRows - skip < limit) { - return TRI_SliceSelectResult(_result, skip, _result->_numRows - skip); - } - - return TRI_SliceSelectResult(_result, skip, limit); - } - - // negative limit, slice from back - if (_result->_numRows - skip < -limit) { - return TRI_SliceSelectResult(_result, 0, _result->_numRows - skip); - } - - return TRI_SliceSelectResult(_result, _result->_numRows - skip + limit, -limit); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- WHERE BOOLEAN -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query condition for constant conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWhereBoolean (TRI_qry_where_t const* w) { - TRI_qry_where_boolean_t* whereClause; - - whereClause = (TRI_qry_where_boolean_t*) w; - - return TRI_CreateQueryWhereBoolean(whereClause->_value); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query condition for constant conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQueryWhereBoolean (TRI_qry_where_t* w) { - TRI_qry_where_boolean_t* whereClause; - - whereClause = (TRI_qry_where_boolean_t*) w; - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for constant conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereBoolean (bool where) { - TRI_qry_where_boolean_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_boolean_t), false); - - result->base.base._type = TRI_QRY_WHERE_BOOLEAN; - - result->base.base.clone = CloneQueryWhereBoolean; - result->base.base.free = FreeQueryWhereBoolean; - - result->_value = where; - - return &result->base.base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- WHERE PRIMARY INDEX WITH CONSTANT -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query condition using the primary index and a constant - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWherePrimaryConstant (TRI_qry_where_t const* w) { - TRI_qry_where_primary_const_t* whereClause; - - whereClause = (TRI_qry_where_primary_const_t*) w; - - return TRI_CreateQueryWherePrimaryConstant(whereClause->_did); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query condition using the primary index and a constant - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQueryWherePrimaryConstant (TRI_qry_where_t* w) { - TRI_qry_where_primary_const_t* whereClause; - - whereClause = (TRI_qry_where_primary_const_t*) w; - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief returns document identifier for a constant - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_voc_did_t DidQueryWherePrimaryConstant (TRI_qry_where_primary_t* w, - TRI_rc_context_t* context) { - TRI_qry_where_primary_const_t* whereClause; - - whereClause = (TRI_qry_where_primary_const_t*) w; - - return whereClause->_did; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition using the primary index and a constant - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWherePrimaryConstant (TRI_voc_did_t did) { - TRI_qry_where_primary_const_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_primary_const_t), false); - - result->base.base._type = TRI_QRY_WHERE_PRIMARY_CONSTANT; - - result->base.base.clone = CloneQueryWherePrimaryConstant; - result->base.base.free = FreeQueryWherePrimaryConstant; - - result->base.did = DidQueryWherePrimaryConstant; - - result->_did = did; - - return &result->base.base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- WHERE GENERAL -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query condition for general, JavaScript conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWhereGeneral (TRI_qry_where_t const* w) { - TRI_qry_where_general_t* whereClause; - - whereClause = (TRI_qry_where_general_t*) w; - - return TRI_CreateQueryWhereGeneral(whereClause->_code); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query condition for general, JavaScript conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQueryWhereGeneral (TRI_qry_where_t* w) { - TRI_qry_where_general_t* whereClause; - - whereClause = (TRI_qry_where_general_t*) w; - - TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, whereClause->_code); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for general, JavaScript conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereGeneral (char const* clause) { - TRI_qry_where_general_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_general_t), false); - - result->base.base._type = TRI_QRY_WHERE_GENERAL; - - result->base.base.clone = CloneQueryWhereGeneral; - result->base.base.free = FreeQueryWhereGeneral; - - //result->base.checkCondition = CheckConditionWhereGeneral; - - result->_code = TRI_DuplicateString(clause); - - return &result->base.base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- WHERE WITHIN GEO INDEX -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query condition using the geo index and constants - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWhereHashConstant (const TRI_qry_where_t* w) { - TRI_qry_where_hash_const_t* whereClause; - - whereClause = (TRI_qry_where_hash_const_t*) w; - - return TRI_CreateQueryWhereHashConstant(whereClause->_iid, whereClause->_parameters); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief clones a query condition - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWherePQConstant (const TRI_qry_where_t* w) { - TRI_qry_where_priorityqueue_const_t* whereClause; - - whereClause = (TRI_qry_where_priorityqueue_const_t*) w; - - return TRI_CreateQueryWherePQConstant(whereClause->_iid, whereClause->_parameters); -} - -//////////////////////////////////////////////////////////////////////////////// -/// DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWhereSkiplistConstant (const TRI_qry_where_t* w) { - const TRI_qry_where_skiplist_const_t* whereClause; - - whereClause = (const TRI_qry_where_skiplist_const_t*) w; - - return TRI_CreateQueryWhereSkiplistConstant(whereClause->_iid, whereClause->_operator); -} - -//////////////////////////////////////////////////////////////////////////////// -/// DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static TRI_qry_where_t* CloneQueryWhereWithinConstant (const TRI_qry_where_t* w) { - const TRI_qry_where_within_const_t* whereClause; - - whereClause = (const TRI_qry_where_within_const_t*) w; - - return TRI_CreateQueryWhereWithinConstant(whereClause->base._iid, - whereClause->base._nameDistance, - whereClause->_coordinates[0], - whereClause->_coordinates[1], - whereClause->_radius); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query condition using the geo index and constants - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQueryWhereHashConstant (TRI_qry_where_t* w) { - TRI_qry_where_hash_const_t* whereClause; - whereClause = (TRI_qry_where_hash_const_t*) w; - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, whereClause->_parameters); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query condition priority queue - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQueryWherePQConstant (TRI_qry_where_t* w) { - TRI_qry_where_priorityqueue_const_t* whereClause; - whereClause = (TRI_qry_where_priorityqueue_const_t*) w; - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, whereClause->_parameters); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FreeQueryWhereSkiplistConstant (TRI_qry_where_t* w) { - TRI_qry_where_skiplist_const_t* whereClause; - whereClause = (TRI_qry_where_skiplist_const_t*) w; - TRI_FreeSLOperator(whereClause->_operator); -} - -static void FreeQueryWhereWithinConstant (TRI_qry_where_t* w) { - TRI_qry_where_within_const_t* whereClause; - - whereClause = (TRI_qry_where_within_const_t*) w; - - if (whereClause->base._nameDistance != NULL) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause->base._nameDistance); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, whereClause); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief returns the latitude and longitude for constants - probably DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static double* CoordinatesQueryWhereWithinConstant (TRI_qry_where_within_t* w, - TRI_rc_context_t* context) { - TRI_qry_where_within_const_t* whereClause; - - whereClause = (TRI_qry_where_within_const_t*) w; - - return whereClause->_coordinates; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief returns the radius for constants - probably DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static double RadiusQueryWhereWithinConstant (TRI_qry_where_within_t* w, - TRI_rc_context_t* context) { - TRI_qry_where_within_const_t* whereClause; - - whereClause = (TRI_qry_where_within_const_t*) w; - - return whereClause->_radius; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition using the geo index and a constant - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereWithinConstant (TRI_idx_iid_t iid, - char const* nameDistance, - double latitiude, - double longitude, - double radius) { - TRI_qry_where_within_const_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_within_const_t), false); - - result->base.base._type = TRI_QRY_WHERE_WITHIN_CONSTANT; - - result->base.base.clone = CloneQueryWhereWithinConstant; - result->base.base.free = FreeQueryWhereWithinConstant; - - result->base.coordinates = CoordinatesQueryWhereWithinConstant; - result->base.radius = RadiusQueryWhereWithinConstant; - - result->base._iid = iid; - result->base._nameDistance = nameDistance == NULL ? NULL : TRI_DuplicateString(nameDistance); - - result->_coordinates[0] = latitiude; - result->_coordinates[1] = longitude; - result->_radius = radius; - - return &result->base.base; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for hash index - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereHashConstant (TRI_idx_iid_t iid, TRI_json_t* parameters) { - TRI_qry_where_hash_const_t* result; - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_hash_const_t), false); - result->base._type = TRI_QRY_WHERE_HASH_CONSTANT; - result->base.clone = CloneQueryWhereHashConstant; - result->base.free = FreeQueryWhereHashConstant; - result->_iid = iid; - result->_parameters = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, parameters); - return &result->base; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for priority queue index - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWherePQConstant (TRI_idx_iid_t iid, TRI_json_t* parameters) { - TRI_qry_where_priorityqueue_const_t* result; - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_priorityqueue_const_t), false); - result->base._type = TRI_QRY_WHERE_PRIORITY_QUEUE_CONSTANT; - result->base.clone = CloneQueryWherePQConstant; - result->base.free = FreeQueryWherePQConstant; - result->_iid = iid; - result->_parameters = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, parameters); - return &result->base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for skiplist index - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - - -TRI_qry_where_t* TRI_CreateQueryWhereSkiplistConstant (TRI_idx_iid_t iid, TRI_sl_operator_t* slOperator) { - TRI_qry_where_skiplist_const_t* result; - - result = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_qry_where_skiplist_const_t), false); - result->base._type = TRI_QRY_WHERE_SKIPLIST_CONSTANT; - result->base.clone = CloneQueryWhereSkiplistConstant; - result->base.free = FreeQueryWhereSkiplistConstant; - result->_iid = iid; - result->_operator = CopySLOperator(slOperator); - return &result->base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- QUERY -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static bool InitCollectionsQuery (TRI_query_t* query) { - TRI_vocbase_col_t* collection; - size_t i; - - assert(query->_vocbase); - - for (i = 0 ; i < query->_joins->_parts._length; i++) { - TRI_join_part_t* part; - - part = (TRI_join_part_t*) query->_joins->_parts._buffer[i]; - assert(part->_collection == NULL); - assert(part->_alias); - collection = TRI_UseCollectionByNameVocBase(query->_vocbase, part->_collectionName); - if (!collection) { - size_t j; - - // unlock collections again - for (j = 0; j < i; ++j) { - part = (TRI_join_part_t*) query->_joins->_parts._buffer[j]; - if (part->_collection) { - TRI_ReleaseCollectionVocBase(query->_vocbase, part->_collection); - part->_collection = NULL; - } - } - return false; - } - part->_collection = collection; - if (part->_type == JOIN_TYPE_PRIMARY) { - query->_primary = collection->_collection; - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a hash query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_query_t* TRI_CreateHashQuery(const TRI_qry_where_t* whereStmt, - TRI_doc_collection_t* collection) { - TRI_query_t* query; - - query = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_query_t), false); - if (!query) { - return NULL; - } - - query->_where = ( whereStmt == NULL ? NULL : whereStmt->clone(whereStmt)); - query->_skip = TRI_QRY_NO_SKIP; - query->_limit = TRI_QRY_NO_LIMIT; - query->_primary = collection; - query->_joins = NULL; - query->_select = TRI_CreateQuerySelectDocument(); - return query; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a priority queue query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_query_t* TRI_CreatePriorityQueueQuery(const TRI_qry_where_t* whereStmt, - TRI_doc_collection_t* collection) { - TRI_query_t* query; - - query = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_query_t), false); - if (!query) { - return NULL; - } - - query->_where = ( whereStmt == NULL ? NULL : whereStmt->clone(whereStmt)); - query->_skip = TRI_QRY_NO_SKIP; - query->_limit = TRI_QRY_NO_LIMIT; - query->_primary = collection; - query->_joins = NULL; - query->_select = TRI_CreateQuerySelectDocument(); - return query; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a skiplist query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_query_t* TRI_CreateSkiplistQuery(const TRI_qry_where_t* whereStmt, - TRI_doc_collection_t* collection) { - TRI_query_t* query; - - query = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_query_t), false); - if (!query) { - return NULL; - } - - query->_where = ( whereStmt == NULL ? NULL : whereStmt->clone(whereStmt)); - query->_skip = TRI_QRY_NO_SKIP; - query->_limit = TRI_QRY_NO_LIMIT; - query->_primary = collection; - query->_joins = NULL; - query->_select = TRI_CreateQuerySelectDocument(); - return query; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_query_t* TRI_CreateQuery (TRI_vocbase_t* vocbase, - TRI_qry_select_t* selectStmt, - TRI_qry_where_t* whereStmt, - TRI_select_join_t* joins, - TRI_voc_size_t skip, - TRI_voc_ssize_t limit) { - TRI_query_t* query; - - query = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_query_t), false); - if (!query) { - return NULL; - } - - query->_vocbase = vocbase; - query->_select = selectStmt; - query->_where = whereStmt; - query->_joins = joins; - query->_skip = skip; - query->_limit = limit; - - if (!InitCollectionsQuery(query)) { - TRI_FreeQuery(query); - return NULL; - } - - return query; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeQuery (TRI_query_t* query) { - query->_select->free(query->_select); - - if (query->_where != NULL) { - query->_where->free(query->_where); - } - if (query->_joins != NULL) { - TRI_join_part_t* part; - size_t i; - - // unlock collections - for (i = 0; i < query->_joins->_parts._length; ++i) { - part = (TRI_join_part_t*) query->_joins->_parts._buffer[i]; - if (part->_collection) { - TRI_ReleaseCollectionVocBase(query->_vocbase, part->_collection); - } - } - - query->_joins->free(query->_joins); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, query); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a context - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_rc_context_t* TRI_CreateContextQuery (TRI_query_t* query) { - TRI_rc_context_t* context; - TRI_qry_select_general_t* selectGeneral; - TRI_qry_where_general_t* whereGeneral; - - context = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_rc_context_t), false); - - context->_primary = query->_primary; - - // check if we need a JavaScript execution context - if (query->_select->_type == TRI_QRY_SELECT_GENERAL) { - selectGeneral = (TRI_qry_select_general_t*) query->_select; - - context->_selectClause = TRI_CreateExecutionContext(selectGeneral->_code); - - if (context->_selectClause == NULL) { - TRI_FreeContextQuery(context); - return NULL; - } - } - - if (query->_where != NULL && query->_where->_type == TRI_QRY_WHERE_GENERAL) { - whereGeneral = (TRI_qry_where_general_t*) query->_where; - - context->_whereClause = TRI_CreateExecutionContext(whereGeneral->_code); - - if (context->_whereClause == NULL) { - TRI_FreeContextQuery(context); - return NULL; - } - } - - return context; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a context - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeContextQuery (TRI_rc_context_t* context) { - if (context->_selectClause != NULL) { - TRI_FreeExecutionContext(context->_selectClause); - } - - if (context->_whereClause != NULL) { - TRI_FreeExecutionContext(context->_whereClause); - } - - if (context->_orderClause != NULL) { - TRI_FreeExecutionContext(context->_orderClause); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, context); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- public methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief read locks all collections of a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_ReadLockCollectionsQuery (TRI_query_t* query) { - TRI_join_part_t* part; - size_t i; - - if (query->_joins == NULL) { - query->_primary->beginRead(query->_primary); - return; - } - - - // note: the same collection might be read-locked multiple times here - for (i = 0; i < query->_joins->_parts._length; i++) { - part = (TRI_join_part_t*) query->_joins->_parts._buffer[i]; - assert(part->_collection); - part->_collection->_collection->beginRead(part->_collection->_collection); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief read unlocks all collections of a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_ReadUnlockCollectionsQuery (TRI_query_t* query) { - TRI_join_part_t* part; - size_t i; - - if (query->_joins == NULL) { - query->_primary->endRead(query->_primary); - return; - } - - // note: the same collection might be read-unlocked multiple times here - i = query->_joins->_parts._length; - while (i > 0) { - i--; - part = (TRI_join_part_t*) query->_joins->_parts._buffer[i]; - assert(part->_collection); - part->_collection->_collection->endRead(part->_collection->_collection); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief adds a gc marker for all collections - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_AddCollectionsCursor (TRI_rc_cursor_t* cursor, TRI_query_t* query) { - TRI_join_part_t* part; - TRI_barrier_t* ce; - size_t i; - - if (query->_joins == NULL) { - ce = TRI_CreateBarrierElement(&query->_primary->_barrierList); - TRI_PushBackVectorPointer(&cursor->_containers, ce); - return; - } - - - // note: the same collection might be added multiple times here - for (i = 0; i < query->_joins->_parts._length; i++) { - part = (TRI_join_part_t*) query->_joins->_parts._buffer[i]; - assert(part->_collection); - ce = TRI_CreateBarrierElement(&part->_collection->_collection->_barrierList); - TRI_PushBackVectorPointer(&cursor->_containers, ce); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief removes the gc markers for all collections of a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_RemoveCollectionsCursor (TRI_rc_cursor_t* cursor) { - size_t i; - - for (i = 0; i < cursor->_containers._length; ++i) { - TRI_barrier_t* ce = cursor->_containers._buffer[i]; - assert(ce); - TRI_FreeBarrier(ce); - } - - cursor->_containers._length = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FilterDataHashQuery(collection_cursor_t* cursor,TRI_query_t* query, - TRI_rc_context_t* context) { - - bool ok; - TRI_index_t* idx; - TRI_qry_where_hash_const_t* where; - TRI_sim_collection_t* collection; - TRI_hash_index_elements_t* hashElements; - TRI_doc_mptr_t* wtr; - TRI_doc_mptr_t* doc; - size_t j; - - cursor->base._context = context; - cursor->base._select = query->_select->clone(query->_select); - - cursor->base.next = NextHashCollectionCursor; - cursor->base.hasNext = HasNextCollectionCursor; - cursor->base.free = FreeCollectionCursor; - cursor->_result._selectResult = NULL; - - cursor->_result._context = context; - cursor->_result._dataPtr = NULL; - - cursor->base._select->toJavaScript = ToJavaScriptHashDocument; - - TRI_InitVectorPointer(&cursor->base._containers, TRI_UNKNOWN_MEM_ZONE); - - TRI_ReadLockCollectionsQuery(query); - - TRI_AddCollectionsCursor(&cursor->base, query); - - ok = (query->_primary->base._type == TRI_COL_TYPE_SIMPLE_DOCUMENT); - - if (ok) { - where = (TRI_qry_where_hash_const_t*)(query->_where); - ok = (where->base._type == TRI_QRY_WHERE_HASH_CONSTANT); - } - - if (ok) { - collection = (TRI_sim_collection_t*) query->_primary; - idx = TRI_IndexSimCollection(collection, where->_iid); - ok = (idx != NULL); - } - - if (ok) { - hashElements = TRI_LookupJsonHashIndex(idx,where->_parameters); - ok = (hashElements != NULL); - } - - - if (ok) { - cursor->_documents = (TRI_doc_mptr_t*) (TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_doc_mptr_t) * hashElements->_numElements, false)); - - wtr = cursor->_documents; - cursor->_length = 0; - cursor->base._matchedDocuments = 0; - cursor->_current = 0; - cursor->_currentRow = 0; - - for (j = 0; j < hashElements->_numElements; ++j) { - // should not be necessary to check that documents have not been deleted - doc = (TRI_doc_mptr_t*)((hashElements->_elements[j]).data); - if (doc->_deletion) { - continue; - } - if (cursor->_current == 0) { - cursor->_current = wtr; - } - ++cursor->base._matchedDocuments; - ++cursor->_length; - *wtr = *doc; - ++wtr; - } - - - if (hashElements->_elements != NULL) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, hashElements->_elements); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, hashElements); - } - } - - TRI_ReadUnlockCollectionsQuery(query); - - if (!ok) { - cursor->_length = 0; - cursor->_currentRow = 0; - } - -} - - - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FilterDataPQQuery(collection_cursor_t* cursor,TRI_query_t* query, - TRI_rc_context_t* context) { - - bool ok; - TRI_index_t* idx; - TRI_qry_where_priorityqueue_const_t* where; - TRI_sim_collection_t* collection; - PQIndexElements* pqElements; - TRI_doc_mptr_t* wtr; - TRI_doc_mptr_t* doc; - size_t j; - - cursor->base._context = context; - cursor->base._select = query->_select->clone(query->_select); - - cursor->base.next = NextPQCollectionCursor; - cursor->base.hasNext = HasNextCollectionCursor; - cursor->base.free = FreeCollectionCursor; - cursor->_result._selectResult = NULL; - - cursor->_result._context = context; - cursor->_result._dataPtr = NULL; - - cursor->base._select->toJavaScript = ToJavaScriptPQDocument; - - TRI_InitVectorPointer(&cursor->base._containers, TRI_UNKNOWN_MEM_ZONE); - - TRI_ReadLockCollectionsQuery(query); - - TRI_AddCollectionsCursor(&cursor->base, query); - - - ok = (query->_primary->base._type == TRI_COL_TYPE_SIMPLE_DOCUMENT); - - if (ok) { - where = (TRI_qry_where_priorityqueue_const_t*)(query->_where); - ok = (where->base._type == TRI_QRY_WHERE_PRIORITY_QUEUE_CONSTANT); - } - - if (ok) { - collection = (TRI_sim_collection_t*) query->_primary; - idx = TRI_IndexSimCollection(collection, where->_iid); - ok = (idx != NULL); - } - - if (ok) { - pqElements = TRI_LookupPriorityQueueIndex(idx,where->_parameters); - ok = (pqElements != NULL); - } - - - if (ok) { - cursor->_documents = (TRI_doc_mptr_t*) (TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_doc_mptr_t) * pqElements->_numElements, false)); - - wtr = cursor->_documents; - cursor->_length = 0; - cursor->base._matchedDocuments = 0; - cursor->_current = 0; - cursor->_currentRow = 0; - - for (j = 0; j < pqElements->_numElements; ++j) { - // should not be necessary to check that documents have not been deleted - doc = (TRI_doc_mptr_t*)((pqElements->_elements[j]).data); - if (doc->_deletion) { - continue; - } - if (cursor->_current == 0) { - cursor->_current = wtr; - } - ++cursor->base._matchedDocuments; - ++cursor->_length; - *wtr = *doc; - ++wtr; - } - - - if (pqElements->_elements != NULL) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, pqElements->_elements); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, pqElements); - } - } - - TRI_ReadUnlockCollectionsQuery(query); - - if (!ok) { - cursor->_length = 0; - cursor->_currentRow = 0; - } - -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -static void FilterDataSLQuery(collection_cursor_t* cursor,TRI_query_t* query, - TRI_rc_context_t* context) { - - bool ok; - TRI_index_t* idx; - TRI_qry_where_skiplist_const_t* where; - TRI_sim_collection_t* collection; - TRI_skiplist_iterator_t* skiplistIterator; - - cursor->base._context = context; - cursor->base._select = query->_select->clone(query->_select); - - cursor->base.next = NextSkiplistCollectionCursor; - cursor->base.hasNext = HasNextSkiplistCollectionCursor; - cursor->base.free = FreeCollectionCursor; - cursor->_result._selectResult = NULL; - - cursor->_result._context = context; - cursor->_result._dataPtr = NULL; - - cursor->base._select->toJavaScript = ToJavaScriptHashDocument; - - TRI_InitVectorPointer(&cursor->base._containers, TRI_UNKNOWN_MEM_ZONE); - - TRI_ReadLockCollectionsQuery(query); - - TRI_AddCollectionsCursor(&cursor->base, query); - - ok = (query->_primary->base._type == TRI_COL_TYPE_SIMPLE_DOCUMENT); - - if (ok) { - where = (TRI_qry_where_skiplist_const_t*)(query->_where); - ok = (where->base._type == TRI_QRY_WHERE_SKIPLIST_CONSTANT); - } - - if (ok) { - collection = (TRI_sim_collection_t*) query->_primary; - idx = TRI_IndexSimCollection(collection, where->_iid); - ok = (idx != NULL); - } - - if (ok) { - skiplistIterator = TRI_LookupSkiplistIndex(idx,where->_operator); - ok = (skiplistIterator != NULL); - } - - - if (ok) { - cursor->_documents = NULL; - cursor->_length = 0; - cursor->base._matchedDocuments = 0; - cursor->_current = 0; - cursor->_currentRow = 0; - cursor->_iterator = skiplistIterator; - } - - TRI_ReadUnlockCollectionsQuery(query); - - if (!ok) { - cursor->_length = 0; - cursor->_currentRow = 0; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_rc_cursor_t* TRI_ExecuteQueryAql (TRI_query_t* query, TRI_rc_context_t* context) { - TRI_qry_where_t* where; - TRI_voc_size_t skip; - TRI_voc_ssize_t limit; - TRI_select_result_t* selectResult; - collection_cursor_t* cursor; - bool applyPostSkipLimit; - bool emptyQuery; - - skip = query->_skip; - limit = query->_limit; - applyPostSkipLimit = false; - - if (limit < 0) { - limit = TRI_QRY_NO_LIMIT; - skip = 0; - applyPostSkipLimit = true; - } - - // set up where condition - emptyQuery = false; - where = 0; - - if (query->_where != NULL) { - - where = query->_where; - - if (where->_type == TRI_QRY_WHERE_BOOLEAN) { - TRI_qry_where_boolean_t* b; - b = (TRI_qry_where_boolean_t*) where; - if (!b->_value) { - emptyQuery = true; - } - where = NULL; - } - - else if (where->_type == TRI_QRY_WHERE_PRIMARY_CONSTANT) { - assert(false); - } - - else if (where->_type == TRI_QRY_WHERE_WITHIN_CONSTANT) { - assert(false); - } - - else if (where->_type == TRI_QRY_WHERE_HASH_CONSTANT) { - cursor = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(collection_cursor_t), false); - if (cursor == NULL) { - return NULL; - } - FilterDataHashQuery(cursor,query,context); - return &cursor->base; - } - - else if (where->_type == TRI_QRY_WHERE_PRIORITY_QUEUE_CONSTANT) { - cursor = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(collection_cursor_t), false); - if (cursor == NULL) { - return NULL; - } - FilterDataPQQuery(cursor,query,context); - return &cursor->base; - } - - else if (where->_type == TRI_QRY_WHERE_SKIPLIST_CONSTANT) { - cursor = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(collection_cursor_t), false); - if (cursor == NULL) { - return NULL; - } - FilterDataSLQuery(cursor,query,context); - return &cursor->base; - } - } - - // create a select result container for the joins - selectResult = TRI_JoinSelectResultX(query->_vocbase, query->_joins); - if (!selectResult) { - return NULL; - } - - // ............................................................................. - // construct a collection subset - // ............................................................................. - - cursor = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(collection_cursor_t), false); - if (!cursor) { - selectResult->free(selectResult); - return NULL; - } - cursor->base._context = context; - cursor->base._select = query->_select->clone(query->_select); - cursor->base.next = NextCollectionCursor; - cursor->base.hasNext = HasNextCollectionCursor; - cursor->base.free = FreeCollectionCursor; - cursor->_result._selectResult = selectResult; - cursor->_result._dataPtr = NULL; - cursor->_result._context = context; - cursor->_result._augmention._type = TRI_JSON_UNUSED; - - TRI_InitVectorPointer(&cursor->base._containers, TRI_UNKNOWN_MEM_ZONE); - - // ............................................................................. - // inside a read transaction - // ............................................................................. - - TRI_ReadLockCollectionsQuery(query); - TRI_AddCollectionsCursor(&cursor->base, query); - - // Execute joins - if (!emptyQuery) { - TRI_ExecuteJoinsX(selectResult, query->_joins, where, context, skip, limit); - } - - TRI_ReadUnlockCollectionsQuery(query); - - // ............................................................................. - // outside a read transaction - // ............................................................................. - - // apply a negative limit or a limit after ordering - if (applyPostSkipLimit) { - TransformDataSkipLimit(&cursor->_result, query->_skip, query->_limit); - } - - // adjust cursor length - cursor->_length = selectResult->_numRows; - cursor->_currentRow = 0; - - return &cursor->base; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// Local Variables: -// mode: outline-minor -// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" -// End: - diff --git a/VocBase/query.h b/VocBase/query.h deleted file mode 100644 index cdbaa90f08..0000000000 --- a/VocBase/query.h +++ /dev/null @@ -1,438 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief query -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2010-2011 triagens GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is triAGENS GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -/// @author Copyright 2011, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#ifndef TRIAGENS_DURHAM_VOC_BASE_QUERY_H -#define TRIAGENS_DURHAM_VOC_BASE_QUERY_H 1 - -#include "VocBase/vocbase.h" - -#include "ShapedJson/shaped-json.h" -#include "VocBase/document-collection.h" -#include "VocBase/index.h" -#include "VocBase/query-join.h" -#include "VocBase/query-where.h" -#include "VocBase/query-order.h" -#include "VocBase/query-cursor.h" -#include "VocBase/query-base.h" -#include "SkipLists/sl-operator.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @page BuildExecuteQuery Building and Executing a Query -/// -/// @section LifeCycleQuery Life-Cycle of a Query -/// -/// The query life-cycle starts with a string describing the query in the -/// Avocado query language. For example: -/// -/// @verbinclude query1 -/// -/// In order to get the result the following steps are taken. -/// -/// - the query is parsed -/// - an @CODE{TRI_query_t} representation is constructed -/// -/// Later the query is executed: -/// -/// - an @CODE{TRI_rc_context_t} is created -/// - the query is executed in this context -/// - a @CODE{TRI_rc_cursor_t} is returned -/// -/// Later the result are accessed: -/// -/// - the @CODE{next} method returns a @CODE{TRI_rc_result_t} -/// - which can be convert into a JSON or JavaScript object using -/// the @CODE{TRI_qry_select_t} -/// -/// @section QueryRepresentation Query Representation -/// -/// @copydetails TRI_query_t -/// -/// @subsection QueryRepresentationSelect Query Select Representation -/// -/// @copydetails TRI_qry_select_t -/// -/// @section QueryExecution Query Execution -/// -/// @subsection QueryContext Query Execution Context -/// -/// @copydetails TRI_rc_context_t -/// -/// @subsection ResultCursor Result Cursor -/// -/// @copydetails TRI_rc_cursor_t -/// -/// @subsection QueryResult Building the Query Result -/// -/// @copydetails TRI_rc_result_t -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- public types -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief select clause type - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -typedef enum { - TRI_QRY_SELECT_DOCUMENT, - TRI_QRY_SELECT_GENERAL -} -TRI_qry_select_type_e; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief abstract select clause - DEPRECATED -/// -/// A description of the @CODE{select} statement of the Avocado query language. -/// This class is respsonible for taking an element of type -/// @CODE{TRI_rc_result_t} as returned by the cursor and transforming it into -/// either a shaped json object of type @CODE{TRI_shaped_json_t} or a JavaScript -/// object of type @CODE{v8::Value}. The returned objects are either freed when -/// the @CODE{TRI_rc_result_t} is deleted or are garbage collected in case of -/// JavaScript. -/// -/// The following implementations exist. -/// -/// @copydetails TRI_qry_select_direct_t -/// -/// @copydetails TRI_qry_select_general_t -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_select_s { - TRI_qry_select_type_e _type; - - struct TRI_qry_select_s* (*clone) (struct TRI_qry_select_s const*); - void (*free) (struct TRI_qry_select_s*); - - TRI_shaped_json_t* (*shapedJson) (struct TRI_qry_select_s*, TRI_rc_result_t*); - bool (*toJavaScript) (struct TRI_qry_select_s*, TRI_rc_result_t*, void*); -} -TRI_qry_select_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief built-in select clause for a single, unaltered document - DEPRECATED -/// -/// If a query returns a document unaltered, then @CODE{TRI_qry_select_direct_t} -/// can be used. It extracts a given document from the result set and returns -/// this document without any modification. The member @CODE{_variable} contains -/// the variable identifier of the result document of the next result to use. -/// -/// For example -/// -/// @verbinclude query2 -/// -/// will generate a query whose select part consists of an instance of -/// @CODE{TRI_qry_select_direct_t}. -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_select_direct_s { - TRI_qry_select_t base; -} -TRI_qry_select_direct_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief JavaScript select clause - DEPRECATED -/// -/// If a query returns a newly created document, then -/// @CODE{TRI_qry_select_general_t} can be used. It uses the V8 engine to -/// compute the document. The member @CODE{_code} contains the JavaScript code -/// used to generate the document. When this code is executed, then the result -/// documents of the next result are passed into the JavaScript code bound to -/// variables. -/// -/// For example -/// -/// @verbinclude query3 -/// -/// will generate new documents containing only @LIT{name} and @LIT{email}. -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_qry_select_general_s { - TRI_qry_select_t base; - - char* _code; -} -TRI_qry_select_general_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief general query - DEPRECATED -/// -/// A query is built using the fluent-interface or the Avocado Query -/// Language. It is of type @CODE{TRI_query_t}. After the query is built, it can -/// be executed. An execution returns a result cursor of type -/// @CODE{TRI_rc_cursor_t}. An execution requires a context of type -/// @CODE{TRI_rc_context_t}. All result are only vaild for the life-time of this -/// context. -/// -/// It is possible to execute the same query multiple times - even in -/// parallel. However, each execution run requires it's own context. -/// -/// A query contains the following parts: -/// -/// - a description of the result in @CODE{_select} -/// - the primary collection for the query in @CODE{_primary} -/// - a list of joins in @CODE{_joins} -/// - a description of the where clause in @CODE{_where} -/// - an optional order by clause in @CODE{_order} -/// - a number limiting the number of returned documents in @CODE{_limit} -/// - a number of documents to skip in @CODE{_skip} -/// -/// The @CODE{_select} is of type @CODE{TRI_qry_select_t}. This is in general a -/// representation of the part following the @CODE{select} statement. There are -/// at least two implementions. The first one uses a built-in evaluator to -/// generate the result document from the next set of selected documents. The -/// second one uses the V8 engine to generate the result. -/// -/// The @CODE{_primary} is of type @CODE{TRI_doc_collection_t}. This is the -/// collection following the @CODE{from} statement. The Avocado query language -/// only supports one collection after the @CODE{from}, this is the primary -/// collection of the query. All other collections must be joined with this -/// primary collection. -/// -/// The @CODE{_joins} attributes contains a vector of joined collections -/// together with the join condition. The vector elements are of type -/// @CODE{TRI_qry_join_t}. -/// -/// The @CODE{_where} attributes contains a description of the where -/// clause. There are at least two implementations. The first one uses a -/// built-in evaluator to evaluate the predicate. The second one uses the V8 -/// engine. -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_query_s { - TRI_vocbase_t* _vocbase; - TRI_qry_select_t* _select; - TRI_doc_collection_t* _primary; - TRI_qry_where_t* _where; - TRI_select_join_t* _joins; - - TRI_voc_size_t _skip; - TRI_voc_ssize_t _limit; -} -TRI_query_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief the result cursor - DEPRECATED -/// -/// The result of a query execution. The metod @FN{next} returns the next -/// result documents. There is one document for the primary collection and a -/// list of documents for a list join. The next result documents are delivered -/// as instance of @CODE{TRI_rc_result_t}. You must call the @FN{free} method -/// for these instances. -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_rc_cursor_s { - TRI_rc_context_t* _context; - TRI_qry_select_t* _select; - TRI_select_result_t* _selectResult; - TRI_js_exec_context_t* _selectContext; - - TRI_vector_pointer_t _containers; - - TRI_voc_size_t _scannedIndexEntries; - TRI_voc_size_t _scannedDocuments; - TRI_voc_size_t _matchedDocuments; - - void (*free) (struct TRI_rc_cursor_s*); - TRI_rc_result_t* (*next)(struct TRI_rc_cursor_s*); - bool (*hasNext)(struct TRI_rc_cursor_s*); -} -TRI_rc_cursor_t; - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- constructors and destructors -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_query_t* TRI_CreateHashQuery (const TRI_qry_where_t*, TRI_doc_collection_t*); - -TRI_query_t* TRI_CreatePriorityQueueQuery (const TRI_qry_where_t*, TRI_doc_collection_t*); - -TRI_query_t* TRI_CreateSkiplistQuery (const TRI_qry_where_t*, TRI_doc_collection_t*); - -TRI_query_t* TRI_CreateQuery (TRI_vocbase_t*, - TRI_qry_select_t*, - TRI_qry_where_t*, - TRI_select_join_t*, - TRI_voc_size_t, - TRI_voc_ssize_t); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeQuery (TRI_query_t* query); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a context - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_rc_context_t* TRI_CreateContextQuery (TRI_query_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief frees a context - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeContextQuery (TRI_rc_context_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query selection for unaltered documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_select_t* TRI_CreateQuerySelectDocument (void); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query selection for general, generated documents - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_select_t* TRI_CreateQuerySelectGeneral (char const*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for constant conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereBoolean (bool where); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for general, JavaScript conditions - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereGeneral (char const*); - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for a hash with constant parameters - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereHashConstant (TRI_idx_iid_t, TRI_json_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for a priority queue with constant parameters - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWherePQConstant (TRI_idx_iid_t, TRI_json_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition for a hash with constant parameters - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereSkiplistConstant (TRI_idx_iid_t, TRI_sl_operator_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition using the primary index and a constant - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWherePrimaryConstant (TRI_voc_did_t did); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a query condition using an geo index and a constants - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_qry_where_t* TRI_CreateQueryWhereWithinConstant (TRI_idx_iid_t iid, - char const* nameDistance, - double latitiude, - double longitude, - double radius); - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- public methods -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief read locks all collections of a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_ReadLockCollectionsQuery (TRI_query_t* query); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief read unlocks all collections of a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -void TRI_ReadUnlockCollectionsQuery (TRI_query_t* query); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief adds a gc marker for all collections -//////////////////////////////////////////////////////////////////////////////// - -void TRI_AddCollectionsCursor (TRI_rc_cursor_t* cursor, TRI_query_t* query); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief read unlocks all collections of a query -//////////////////////////////////////////////////////////////////////////////// - -void TRI_RemoveCollectionsCursor (TRI_rc_cursor_t* cursor); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes a query - DEPRECATED -//////////////////////////////////////////////////////////////////////////////// - -TRI_rc_cursor_t* TRI_ExecuteQueryAql (TRI_query_t*, TRI_rc_context_t*); - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - -#endif - -// Local Variables: -// mode: outline-minor -// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" -// End: