mirror of https://gitee.com/bigwinds/arangodb
Moved the insertion of elements into an indox to the super class. Is only used for Skiplist and Hash. Might probably be used by other indicies later
This commit is contained in:
parent
d69c9a920e
commit
5a5d1de7ea
|
@ -89,81 +89,25 @@ static void FreeSubObjectsHashIndexElement (T* element) {
|
|||
/// hashed and the shape identifier of each part.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
static int HashIndexHelper (HashIndex const* hashIndex,
|
||||
T* hashElement,
|
||||
TRI_doc_mptr_t const* document) {
|
||||
TRI_shaped_json_t shapedJson; // the object behind document
|
||||
|
||||
auto shaper = hashIndex->collection()->getShaper(); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
bool const sparse = hashIndex->sparse();
|
||||
|
||||
// .............................................................................
|
||||
// Assign the document to the TRI_hash_index_element_t structure - so that it
|
||||
// can later be retreived.
|
||||
// .............................................................................
|
||||
|
||||
TRI_EXTRACT_SHAPED_JSON_MARKER(shapedJson, document->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
hashElement->_document = const_cast<TRI_doc_mptr_t*>(document);
|
||||
char const* ptr = document->getShapedJsonPtr(); // ONLY IN INDEX
|
||||
|
||||
// .............................................................................
|
||||
// Extract the attribute values
|
||||
// .............................................................................
|
||||
|
||||
int res = TRI_ERROR_NO_ERROR;
|
||||
|
||||
auto const& paths = hashIndex->paths();
|
||||
size_t const n = paths.size();
|
||||
|
||||
for (size_t j = 0; j < n; ++j) {
|
||||
TRI_shape_pid_t path = paths[j];
|
||||
|
||||
// determine if document has that particular shape
|
||||
TRI_shape_access_t const* acc = shaper->findAccessor(shapedJson._sid, path);
|
||||
|
||||
// field not part of the object
|
||||
if (acc == nullptr || acc->_resultSid == TRI_SHAPE_ILLEGAL) {
|
||||
hashElement->_subObjects[j]._sid = BasicShapes::TRI_SHAPE_SID_NULL;
|
||||
|
||||
res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING;
|
||||
|
||||
if (sparse) {
|
||||
// no need to continue
|
||||
return res;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// extract the field
|
||||
TRI_shaped_json_t shapedObject;
|
||||
if (! TRI_ExecuteShapeAccessor(acc, &shapedJson, &shapedObject)) {
|
||||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
if (shapedObject._sid == BasicShapes::TRI_SHAPE_SID_NULL) {
|
||||
res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING;
|
||||
|
||||
if (sparse) {
|
||||
// no need to continue
|
||||
return res;
|
||||
/*
|
||||
// TODO needs to be extracted as a helper function
|
||||
if ( triagens::basics::TRI_AttributeNamesHaveExpansion(hashIndex->fields()[j]) ) {
|
||||
TRI_shape_t const* shape = shaper->lookupShapeId(shapedObject._sid);
|
||||
if (shape->_type >= TRI_SHAPE_LIST && shape->_type <= TRI_SHAPE_HOMOGENEOUS_SIZED_LIST) {
|
||||
std::cout << "Should expand here" << std::endl;
|
||||
auto json = triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, TRI_JsonShapedJson(shaper, &shapedObject));
|
||||
std::cout << "Is Array " << json.isArray() << " :: " << json << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
TRI_FillShapedSub(&hashElement->_subObjects[j], &shapedObject, ptr);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief index helper for hashing with allocation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
static int HashIndexHelperAllocate (HashIndex const* hashIndex,
|
||||
static int HashIndexHelperAllocate (HashIndex* hashIndex,
|
||||
T* hashElement,
|
||||
TRI_doc_mptr_t const* document) {
|
||||
// .............................................................................
|
||||
|
@ -177,7 +121,7 @@ static int HashIndexHelperAllocate (HashIndex const* hashIndex,
|
|||
return TRI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int res = HashIndexHelper<T>(hashIndex, hashElement, document);
|
||||
int res = hashIndex->fillElement<T>(hashElement, hashElement->_subObjects, document, hashIndex->paths(), hashIndex->sparse());
|
||||
|
||||
if (res == TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING) {
|
||||
// if the document does not have the indexed attribute or has it, and it is null,
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#include "Index.h"
|
||||
#include "Basics/Exceptions.h"
|
||||
#include "Basics/json-utilities.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
#include "VocBase/server.h"
|
||||
#include "VocBase/VocShaper.h"
|
||||
|
||||
using namespace triagens::arango;
|
||||
|
||||
|
|
|
@ -33,7 +33,11 @@
|
|||
#include "Basics/Common.h"
|
||||
#include "Basics/AttributeNameParser.h"
|
||||
#include "Basics/JsonHelper.h"
|
||||
#include "Basics/logging.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
#include "VocBase/shaped-json.h"
|
||||
#include "VocBase/vocbase.h"
|
||||
#include "VocBase/VocShaper.h"
|
||||
#include "VocBase/voc-types.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -208,8 +212,98 @@ namespace triagens {
|
|||
|
||||
struct TRI_document_collection_t* _collection;
|
||||
|
||||
std::vector<std::vector<triagens::basics::AttributeName>> const _fields;
|
||||
std::vector<std::vector<triagens::basics::AttributeName>> const _fields;
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- protected methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief helper function to insert a document into any index type
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Idx_Element>
|
||||
int fillElement(Idx_Element* element,
|
||||
TRI_shaped_sub_t* subObjects,
|
||||
TRI_doc_mptr_t const* document,
|
||||
std::vector<TRI_shape_pid_t> const& paths,
|
||||
bool const sparse) {
|
||||
TRI_ASSERT(document != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(document->getDataPtr() != nullptr); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
TRI_shaped_json_t shapedJson;
|
||||
|
||||
TRI_EXTRACT_SHAPED_JSON_MARKER(shapedJson, document->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
if (shapedJson._sid == TRI_SHAPE_ILLEGAL) {
|
||||
LOG_WARNING("encountered invalid marker with shape id 0");
|
||||
|
||||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
int res = TRI_ERROR_NO_ERROR;
|
||||
|
||||
element->_document = const_cast<TRI_doc_mptr_t*>(document);
|
||||
char const* ptr = element->_document->getShapedJsonPtr(); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
// auto subObjects = ;
|
||||
|
||||
size_t const n = paths.size();
|
||||
|
||||
for (size_t j = 0; j < n; ++j) {
|
||||
TRI_shape_pid_t path = paths[j];
|
||||
|
||||
// ..........................................................................
|
||||
// Determine if document has that particular shape
|
||||
// ..........................................................................
|
||||
|
||||
TRI_shape_access_t const* acc = _collection->getShaper()->findAccessor(shapedJson._sid, path); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
if (acc == nullptr || acc->_resultSid == TRI_SHAPE_ILLEGAL) {
|
||||
// OK, the document does not contain the attributed needed by
|
||||
// the index, are we sparse?
|
||||
subObjects[j]._sid = BasicShapes::TRI_SHAPE_SID_NULL;
|
||||
|
||||
res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING;
|
||||
|
||||
if (sparse) {
|
||||
// no need to continue
|
||||
return res;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// ..........................................................................
|
||||
// Extract the field
|
||||
// ..........................................................................
|
||||
|
||||
TRI_shaped_json_t shapedObject;
|
||||
if (! TRI_ExecuteShapeAccessor(acc, &shapedJson, &shapedObject)) {
|
||||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
if (shapedObject._sid == BasicShapes::TRI_SHAPE_SID_NULL) {
|
||||
res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING;
|
||||
|
||||
if (sparse) {
|
||||
// no need to continue
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// .........................................................................
|
||||
// Store the field
|
||||
// .........................................................................
|
||||
|
||||
TRI_FillShapedSub(&subObjects[j], &shapedObject, ptr);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -183,7 +183,8 @@ int SkiplistIndex2::insert (TRI_doc_mptr_t const* doc,
|
|||
return TRI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int res = fillElement(skiplistElement, doc);
|
||||
int res = fillElement<TRI_skiplist_index_element_t>(skiplistElement, SkiplistIndex_Subobjects(skiplistElement), doc, _paths, _sparse);
|
||||
|
||||
// ...........................................................................
|
||||
// most likely the cause of this error is that the index is sparse
|
||||
// and not all attributes the index needs are set -- so the document
|
||||
|
@ -231,7 +232,7 @@ int SkiplistIndex2::remove (TRI_doc_mptr_t const* doc,
|
|||
return TRI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int res = fillElement(skiplistElement, doc);
|
||||
int res = fillElement<TRI_skiplist_index_element_t>(skiplistElement, SkiplistIndex_Subobjects(skiplistElement), doc, _paths, _sparse);
|
||||
|
||||
// ..........................................................................
|
||||
// Error returned generally implies that the document never was part of the
|
||||
|
@ -290,93 +291,6 @@ TRI_skiplist_iterator_t* SkiplistIndex2::lookup (TRI_index_operator_t* slOperato
|
|||
reverse);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief helper for skiplist methods
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int SkiplistIndex2::fillElement(TRI_skiplist_index_element_t* skiplistElement,
|
||||
TRI_doc_mptr_t const* document) {
|
||||
// ..........................................................................
|
||||
// Assign the document to the SkiplistIndexElement structure so that it can
|
||||
// be retrieved later.
|
||||
// ..........................................................................
|
||||
|
||||
TRI_ASSERT(document != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(document->getDataPtr() != nullptr); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
TRI_shaped_json_t shapedJson;
|
||||
TRI_EXTRACT_SHAPED_JSON_MARKER(shapedJson, document->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
if (shapedJson._sid == TRI_SHAPE_ILLEGAL) {
|
||||
LOG_WARNING("encountered invalid marker with shape id 0");
|
||||
|
||||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
int res = TRI_ERROR_NO_ERROR;
|
||||
|
||||
skiplistElement->_document = const_cast<TRI_doc_mptr_t*>(document);
|
||||
char const* ptr = skiplistElement->_document->getShapedJsonPtr(); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
auto subObjects = SkiplistIndex_Subobjects(skiplistElement);
|
||||
|
||||
size_t const n = _paths.size();
|
||||
|
||||
for (size_t j = 0; j < n; ++j) {
|
||||
TRI_shape_pid_t shape = _paths[j];
|
||||
|
||||
// ..........................................................................
|
||||
// Determine if document has that particular shape
|
||||
// ..........................................................................
|
||||
|
||||
TRI_shape_access_t const* acc = _collection->getShaper()->findAccessor(shapedJson._sid, shape); // ONLY IN INDEX, PROTECTED by RUNTIME
|
||||
|
||||
if (acc == nullptr || acc->_resultSid == TRI_SHAPE_ILLEGAL) {
|
||||
// OK, the document does not contain the attributed needed by
|
||||
// the index, are we sparse?
|
||||
subObjects[j]._sid = BasicShapes::TRI_SHAPE_SID_NULL;
|
||||
|
||||
res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING;
|
||||
|
||||
if (_sparse) {
|
||||
// no need to continue
|
||||
return res;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// ..........................................................................
|
||||
// Extract the field
|
||||
// ..........................................................................
|
||||
|
||||
TRI_shaped_json_t shapedObject;
|
||||
if (! TRI_ExecuteShapeAccessor(acc, &shapedJson, &shapedObject)) {
|
||||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
if (shapedObject._sid == BasicShapes::TRI_SHAPE_SID_NULL) {
|
||||
res = TRI_ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING;
|
||||
|
||||
if (_sparse) {
|
||||
// no need to continue
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// .........................................................................
|
||||
// Store the field
|
||||
// .........................................................................
|
||||
|
||||
TRI_FillShapedSub(&subObjects[j], &shapedObject, ptr);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -109,15 +109,6 @@ namespace triagens {
|
|||
return _unique;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
int fillElement(TRI_skiplist_index_element_t*,
|
||||
struct TRI_doc_mptr_t const*);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue