1
0
Fork 0

make geo index work with nested attributes

This commit is contained in:
jsteemann 2017-02-03 13:07:20 +01:00
parent 593c38769d
commit 512672b3a4
2 changed files with 37 additions and 31 deletions

View File

@ -418,7 +418,6 @@ struct AstNode {
bool isAttributeAccessForVariable(Variable const* variable, bool allowIndexedAccess) const { bool isAttributeAccessForVariable(Variable const* variable, bool allowIndexedAccess) const {
auto node = getAttributeAccessForVariable(allowIndexedAccess); auto node = getAttributeAccessForVariable(allowIndexedAccess);
if (node == nullptr) { if (node == nullptr) {
return false; return false;
} }

View File

@ -4100,47 +4100,54 @@ MMFilesGeoIndexInfo iterativePreorderWithCondition(EN::NodeType type, AstNode* r
return MMFilesGeoIndexInfo{}; return MMFilesGeoIndexInfo{};
} }
MMFilesGeoIndexInfo geoDistanceFunctionArgCheck(std::pair<AstNode*,AstNode*> const& pair, ExecutionPlan* plan, MMFilesGeoIndexInfo info){ MMFilesGeoIndexInfo geoDistanceFunctionArgCheck(std::pair<AstNode const*, AstNode const*> const& pair,
using SV = std::vector<std::string>; ExecutionPlan* plan, MMFilesGeoIndexInfo info){
std::pair<Variable const*, std::vector<arangodb::basics::AttributeName>> attributeAccess1;
std::pair<Variable const*, std::vector<arangodb::basics::AttributeName>> attributeAccess2;
// first and second should be based on the same document - need to provide the document // first and second should be based on the same document - need to provide the document
// in order to see which collection is bound to it and if that collections supports geo-index // in order to see which collection is bound to it and if that collections supports geo-index
if( !pair.first->isAttributeAccessForVariable() || !pair.second->isAttributeAccessForVariable()){ if (!pair.first->isAttributeAccessForVariable(attributeAccess1) ||
!pair.second->isAttributeAccessForVariable(attributeAccess2)) {
info.invalidate(); info.invalidate();
return info; return info;
} }
TRI_ASSERT(attributeAccess1.first != nullptr);
TRI_ASSERT(attributeAccess2.first != nullptr);
// expect access of the for doc.attribute // expect access of the for doc.attribute
// TODO: more complex access path have to be added: loop until REFERENCE TYPE IS FOUND auto setter1 = plan->getVarSetBy(attributeAccess1.first->id);
auto setter1 = plan->getVarSetBy(static_cast<Variable const*>(pair.first->getMember(0)->getData())->id); auto setter2 = plan->getVarSetBy(attributeAccess2.first->id);
auto setter2 = plan->getVarSetBy(static_cast<Variable const*>(pair.second->getMember(0)->getData())->id);
SV accessPath1{pair.first->getString()};
SV accessPath2{pair.second->getString()};
if(setter1 == setter2){ if (setter1 != nullptr &&
if(setter1->getType() == EN::ENUMERATE_COLLECTION){ setter2 != nullptr &&
auto collNode = reinterpret_cast<EnumerateCollectionNode*>(setter1); setter1 == setter2 &&
setter1->getType() == EN::ENUMERATE_COLLECTION) {
auto collNode = reinterpret_cast<EnumerateCollectionNode*>(setter1);
auto coll = collNode->collection(); //what kind of indexes does it have on what attributes
auto lcoll = coll->getCollection();
// TODO - check collection for suitable geo-indexes
for(auto indexShardPtr : lcoll->getIndexes()){
// get real index
arangodb::Index& index = *indexShardPtr.get();
auto coll = collNode->collection(); //what kind of indexes does it have on what attributes // check if current index is a geo-index
auto lcoll = coll->getCollection(); if( index.type() != arangodb::Index::IndexType::TRI_IDX_TYPE_GEO1_INDEX
// TODO - check collection for suitable geo-indexes && index.type() != arangodb::Index::IndexType::TRI_IDX_TYPE_GEO2_INDEX) {
for(auto indexShardPtr : lcoll->getIndexes()){ continue;
// get real index }
arangodb::Index& index = *indexShardPtr.get();
// check if current index is a geo-index TRI_ASSERT(index.fields().size() == 2);
if( index.type() != arangodb::Index::IndexType::TRI_IDX_TYPE_GEO1_INDEX
&& index.type() != arangodb::Index::IndexType::TRI_IDX_TYPE_GEO2_INDEX){
continue;
}
//check access paths of attributes in ast and those in index match //check access paths of attributes in ast and those in index match
if( index.fieldNames()[0] == accessPath1 && index.fieldNames()[1] == accessPath2 ){ if (index.fields()[0] == attributeAccess1.second &&
info.collectionNode = collNode; index.fields()[1] == attributeAccess2.second) {
info.index = indexShardPtr; info.collectionNode = collNode;
info.longitude = std::move(accessPath1); info.index = indexShardPtr;
info.latitude = std::move(accessPath2); TRI_AttributeNamesJoinNested(attributeAccess1.second, info.longitude, true);
return info; TRI_AttributeNamesJoinNested(attributeAccess2.second, info.latitude, true);
} return info;
} }
} }
} }