8000 Added support for nested fields - excluding expansions. (#13681) · arangodb/arangodb@3d1ce4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d1ce4b

Browse files
author
Lars Maier
authored
Added support for nested fields - excluding expansions. (#13681)
* Added support for nested fields - excluding expansions. * Added tests for nested attributes.
1 parent 94dd02e commit 3d1ce4b

File tree

4 files changed

+40
-48
lines changed

4 files changed

+40
-48
lines changed

arangod/Indexes/IndexFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Result IndexFactory::emplace(std::string const& type, IndexTypeFactory const& fa
204204
return arangodb::Result();
205205
}
206206

207-
Result IndexFactory::enhanceIndexDefinition( // normalizze deefinition
207+
Result IndexFactory::enhanceIndexDefinition( // normalize definition
208208
velocypack::Slice const definition, // source definition
209209
velocypack::Builder& normalized, // normalized definition (out-param)
210210
bool isCreation, // definition for index creation

arangod/RocksDBEngine/RocksDBZkdIndex.cpp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,31 @@ auto nodeExtractDouble(aql::AstNode const* node) -> std::optional<zkd::byte_stri
167167
return std::nullopt;
168168
}
169169

170+
auto accessDocumentPath(VPackSlice doc, std::vector<basics::AttributeName> const& path) -> VPackSlice {
171+
for (auto&& attrib : path) {
172+
TRI_ASSERT(attrib.shouldExpand == false);
173+
if (!doc.isObject()) {
174+
return VPackSlice::noneSlice();
175+
}
176+
177+
doc = doc.get(attrib.name);
178< 8000 /code>+
}
179+
180+
return doc;
181+
}
182+
170183
auto readDocumentKey(VPackSlice doc,
171184
std::vector<std::vector<basics::AttributeName>> const& fields)
172185
-> zkd::byte_string {
173186
std::vector<zkd::byte_string> v;
174187
v.reserve(fields.size());
175188

176189
for (auto const& path : fields) {
177-
TRI_ASSERT(path.size() == 1);
178-
TRI_ASSERT(path[0].shouldExpand == false);
179-
VPackSlice value = doc.get(path[0].name);
190+
VPackSlice value = accessDocumentPath(doc, path);
180191
if (!value.isNumber<double>()) {
181192
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE);
182193
}
183-
double dv = value.getNumericValue<double>();
194+
auto dv = value.getNumericValue<double>();
184195
if (std::isnan(dv)) {
185196
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "NaN is not allowed");
186197
}
@@ -238,39 +249,30 @@ void zkd::extractBoundsFromCondition(
238249
return false;
239250
}
240251

241-
auto& path = attributeData.second;
242-
// TODO -- make this more generic
243-
TRI_ASSERT(path.size() == 1 && !path[0].shouldExpand);
244-
245-
auto& name = path[0].name;
246252
for (auto&& [idx, field] : enumerate(index->fields())) {
247-
TRI_ASSERT(field.size() == 1);
248-
249-
if (name != field[0].name) {
253+
if (attributeData.second != field) {
250254
continue;
251255
}
252256

253-
if (name == field[0].name) {
254-
switch (op->type) {
255-
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_EQ:
256-
useAsBound(idx, op, access, other, true, false);
257-
useAsBound(idx, op, access, other, false, false);
258-
return true;
259-
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LE:
260-
useAsBound(idx, op, access, other, reverse, false);
261-
return true;
262-
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GE:
263-
useAsBound(idx, op, access, other, !reverse, false);
264-
return true;
265-
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LT:
266-
useAsBound(idx, op, access, other, reverse, true);
267-
return true;
268-
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GT:
269-
useAsBound(idx, op, access, other, !reverse, true);
270-
return true;
271-
default:
272-
break;
273-
}
257+
switch (op->type) {
258+
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_EQ:
259+
useAsBound(idx, op, access, other, true, false);
260+
useAsBound(idx, op, access, other, false, false);
261+
return true;
262+
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LE:
263+
useAsBound(idx, op, access, other, reverse, false);
264+
return true;
265+
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GE:
266+
useAsBound(idx, op, access, other, !reverse, false);
267+
return true;
268+
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LT:
269+
useAsBound(idx, op, access, other, reverse, true);
270+
return true;
271+
case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GT:
272+
useAsBound(idx, op, access, other, !reverse, true);
273+
return true;
274+
default:
275+
break;
274276
}
275277
}
276278

tests/Zkd/Conversion.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ TEST(Zkd_byte_string_conversion, int64_compare) {
7272
}
7373
}
7474

75-
TEST(Zkd_byte_string_conversion, double_float) {
76-
auto tests = {std::pair{0.0, byte_string{0b10111111_b, 0b11110000_b, 0_b, 0_b,
77-
0_b, 0_b, 0_b, 0_b}}};
78-
79-
for (auto&& [v, bs] : tests) {
80-
auto result = to_byte_string_fixed_length(v);
81-
EXPECT_EQ(result, bs);
82-
}
83-
}
84-
8575
auto const doubles_worth_testing = {0.0,
8676
0.1,
8777
0.2,

tests/js/server/aql/aql-optimizer-zkdindex-multi.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ function optimizerRuleZkd2dIndexTestSuite() {
100100
let testObject = {
101101
setUpAll: function () {
102102
col = db._create(colName);
103-
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y', 'z', 'w']});
103+
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y', 'z', 'a.w']});
104104
db._query(aql`
105105
FOR x IN 0..10
106106
FOR y IN 0..10
107107
FOR z IN 0..10
108108
FOR w IN 0..10
109-
INSERT {x, y, z, w} INTO ${col}
109+
INSERT {x, y, z, a: {w}} INTO ${col}
110110
`);
111111
},
112112

@@ -131,8 +131,8 @@ function optimizerRuleZkd2dIndexTestSuite() {
131131
FILTER ${conditionForVariable(x, "d.x")}
132132
FILTER ${conditionForVariable(y, "d.y")}
133133
FILTER ${conditionForVariable(z, "d.z")}
134-
FILTER ${conditionForVariable(w, "d.w")}
135-
RETURN [d.x, d.y, d.z, d.w]
134+
FILTER ${conditionForVariable(w, "d.a.w")}
135+
RETURN [d.x, d.y, d.z, d.a.w]
136136
`;
137137
const explainRes = AQL_EXPLAIN(query);
138138
const appliedRules = explainRes.plan.rules;

0 commit comments

Comments
 (0)
0