8000 Added support for nested fields - excluding expansions. by maierlars · Pull Request #13681 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Added support for nested fields - excluding expansions. #13681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arangod/Indexes/IndexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Result IndexFactory::emplace(std::string const& type, IndexTypeFactory const& fa
return arangodb::Result();
}

Result IndexFactory::enhanceIndexDefinition( // normalizze deefinition
Result IndexFactory::enhanceIndexDefinition( // normalize definition
velocypack::Slice const definition, // source definition
velocypack::Builder& normalized, // normalized definition (out-param)
bool isCreation, // definition for index creation
Expand Down
68 changes: 35 additions & 33 deletions arangod/RocksDBEngine/RocksDBZkdIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,31 @@ auto nodeExtractDouble(aql::AstNode const* node) -> std::optional<zkd::byte_stri
return std::nullopt;
}

auto accessDocumentPath(VPackSlice doc, std::vector<basics::AttributeName> const& path) -> VPackSlice {
for (auto&& attrib : path) {
TRI_ASSERT(attrib.shouldExpand == false);
if (!doc.isObject()) {
return VPackSlice::noneSlice();
}

doc = doc.get(attrib.name);
}

return doc;
}

auto readDocumentKey(VPackSlice doc,
std::vector<std::vector<basics::AttributeName>> const& fields)
-> zkd::byte_string {
std::vector<zkd::byte_string> v;
v.reserve(fields.size());

for (auto const& path : fields) {
TRI_ASSERT(path.size() == 1);
TRI_ASSERT(path[0].shouldExpand == false);
VPackSlice value = doc.get(path[0].name);
VPackSlice value = accessDocumentPath(doc, path);
if (!value.isNumber<double>()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE);
}
double dv = value.getNumericValue<double>();
auto dv = value.getNumericValue<double>();
if (std::isnan(dv)) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "NaN is not allowed");
}
Expand Down Expand Up @@ -238,39 +249,30 @@ void zkd::extractBoundsFromCondition(
return false;
}

auto& path = attributeData.second;
// TODO -- make this more generic
TRI_ASSERT(path.size() == 1 && !path[0].shouldExpand);

auto& name = path[0].name;
for (auto&& [idx, field] : enumerate(index->fields())) {
TRI_ASSERT(field.size() == 1);

if (name != field[0].name) {
if (attributeData.second != field) {
continue;
}

if (name == field[0].name) {
switch (op->type) {
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_EQ:
useAsBound(idx, op, access, other, true, false);
useAsBound(idx, op, access, other, false, false);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LE:
useAsBound(idx, op, access, other, reverse, false);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GE:
useAsBound(idx, op, access, other, !reverse, false);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LT:
useAsBound(idx, op, access, other, reverse, true);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GT:
useAsBound(idx, op, access, other, !reverse, true);
return true;
default:
break;
}
switch (op->type) {
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_EQ:
useAsBound(idx, op, access, other, true, false);
useAsBound(idx, op, access, other, false, false);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LE:
useAsBound(idx, op, access, other, reverse, false);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GE:
useAsBound(idx, op, access, other, !reverse, false);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LT:
useAsBound(idx, op, access, other, reverse, true);
return true;
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GT:
useAsBound(idx, op, access, other, !reverse, true);
return true;
default:
break;
}
}

Expand Down
10 changes: 0 additions & 10 deletions tests/Zkd/Conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ TEST(Zkd_byte_string_conversion, int64_compare) {
}
}

TEST(Zkd_byte_string_conversion, double_float) {
auto tests = {std::pair{0.0, byte_string{0b10111111_b, 0b11110000_b, 0_b, 0_b,
0_b, 0_b, 0_b, 0_b}}};

for (auto&& [v, bs] : tests) {
auto result = to_byte_string_fixed_length(v);
EXPECT_EQ(result, bs);
}
}

auto const doubles_worth_testing = {0.0,
0.1,
0.2,
Expand Down
8 changes: 4 additions & 4 deletions tests/js/server/aql/aql-optimizer-zkdindex-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ function optimizerRuleZkd2dIndexTestSuite() {
let testObject = {
setUpAll: function () {
col = db._create(colName);
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y', 'z', 'w']});
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y', 'z', 'a.w']});
db._query(aql`
FOR x IN 0..10
FOR y IN 0..10
FOR z IN 0..10
FOR w IN 0..10
INSERT {x, y, z, w} INTO ${col}
INSERT {x, y, z, a: {w}} INTO ${col}
`);
},

Expand All @@ -131,8 +131,8 @@ function optimizerRuleZkd2dIndexTestSuite() {
FILTER ${conditionForVariable(x, "d.x")}
FILTER ${conditionForVariable(y, "d.y")}
FILTER ${conditionForVariable(z, "d.z")}
FILTER ${conditionForVariable(w, "d.w")}
RETURN [d.x, d.y, d.z, d.w]
FILTER ${conditionForVariable(w, "d.a.w")}
RETURN [d.x, d.y, d.z, d.a.w]
`;
const explainRes = AQL_EXPLAIN(query);
const appliedRules 417E = explainRes.plan.rules;
Expand Down
0