8000 [zkd] Forward Compat (#13694) · arangodb/arangodb@1d4928b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d4928b

Browse files
author
Lars Maier
authored
[zkd] Forward Compat (#13694)
* Added required field fieldValueTypes: double. * Refactored index attribute validation. Disallowed attribute expansions. * Added tests for restrictions. * Fixing normalization of zkd index definition.
1 parent 7618470 commit 1d4928b

7 files changed

+119
-11
lines changed

arangod/Indexes/IndexFactory.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,34 @@ Result IndexFactory::enhanceJsonIndexFulltext(VPackSlice definition,
581581
return res;
582582
}
583583

584+
/// @brief enhances the json of a fulltext index
585+
Result IndexFactory::enhanceJsonIndexZkd(VPackSlice definition,
586+
VPackBuilder& builder, bool create) {
587+
if (auto fieldValueTypes = definition.get("fieldValueTypes");
588+
!fieldValueTypes.isString() || !fieldValueTypes.isEqualString("double")) {
589+
return Result(
590+
TRI_ERROR_BAD_PARAMETER,
591+
"zkd index requires `fieldValueTypes` to be set to `double` - future "
592+
"releases might lift this requirement");
593+
}
594+
595+
builder.add("fieldValueTypes", VPackValue("double"));
596+
Result res = processIndexFields(definition, builder, 1, INT_MAX, create, false);
597+
598+
if (res.ok()) {
599+
if (auto isSparse = definition.get(StaticStrings::IndexSparse).isTrue(); isSparse) {
600+
return Result(TRI_ERROR_BAD_PARAMETER,
601+
"zkd index does not support sparse property");
602+
}
603+
604+
processIndexUniqueFlag(definition, builder);
605+
606+
bool bck = basics::VelocyPackHelper::getBooleanValue(definition, StaticStrings::IndexInBackground,
607+
false);
608+
builder.add(StaticStrings::IndexInBackground, VPackValue(bck));
609+
}
610+
611+
return res;
612+
}
613+
584614
} // namespace arangodb

arangod/Indexes/IndexFactory.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,15 @@ class IndexFactory {
157157
static Result enhanceJsonIndexGeo(arangodb::velocypack::Slice definition,
158158
arangodb::velocypack::Builder& builder, bool create,
159159
int minFields, int maxFields);
160-
160+
161161
/// @brief enhances the json of a fulltext index
162162
static Result enhanceJsonIndexFulltext(arangodb::velocypack::Slice definition,
163163
arangodb::velocypack::Builder& builder, bool create);
164164

165+
/// @brief enhances the json of a zkd index
166+
static Result enhanceJsonIndexZkd(arangodb::velocypack::Slice definition,
167+
arangodb::velocypack::Builder& builder, bool create);
168+
165169
protected:
166170
/// @brief clear internal factory/normalizer maps
167171
void clear();

arangod/RocksDBEngine/RocksDBIndexFactory.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,7 @@ struct ZkdIndexFactory : public DefaultIndexFactory {
295295
arangodb::velocypack::Value(std::to_string(TRI_NewTickServer())));
296296
}
297297

298-
if (auto isSparse = definition.get(StaticStrings::IndexSparse).isTrue(); isSparse) {
299-
THROW_ARANGO_EXCEPTION_MESSAGE(
300-
TRI_ERROR_BAD_PARAMETER,
301-
"zkd index does not support sparse property");
302-
}
303-
304-
return IndexFactory::enhanceJsonIndexGeneric(definition, normalized, isCreation);
298+
return IndexFactory::enhanceJsonIndexZkd(definition, normalized, isCreation);
305299
}
306300
};
307301

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function optimizerRuleZkd2dIndexTestSuite() {
100100
let testObject = {
101101
setUpAll: function () {
102102
col = db._create(colName);
103-
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y', 'z', 'a.w']});
103+
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y', 'z', 'a.w'], fieldValueTypes: 'double'});
104104
db._query(aql`
105105
FOR x IN 0..10
106106
FOR y IN 0..10
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* global AQL_EXPLAIN, AQL_EXECUTE */
2+
////////////////////////////////////////////////////////////////////////////////
3+
/// DISCLAIMER
4+
///
5+
/// Copyright 2021-2021 ArangoDB GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Apache License, Version 2.0 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// http://www.apache.org/licenses/LICENSE-2.0
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Tobias Gödderz
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
'use strict';
25+
26+
const jsunity = require("jsunity");
27+
const arangodb = require("@arangodb");
28+
const internal = require("internal");
29+
const db = arangodb.db;
30+
const {assertEqual} = jsunity.jsUnity.assertions;
31+
32+
function optimizerRuleZkd2dIndexTestSuite() {
33+
const colName = 'UnitTestZkdIndexCollection';
34+
let col;
35+
36+
return {
37+
setUpAll: function () {
38+
col = db._create(colName);
39+
},
40+
41+
tearDownAll: function () {
42+
col.drop();
43+
},
44+
45+
testNoFieldValueTypes: function () {
46+
try {
47+
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y']});
48+
} catch (e) {
49+
assertEqual(e.errorNum, internal.errors.ERROR_BAD_PARAMETER.code);
50+
}
51+
},
52+
53+
testSparseProperty: function () {
54+
try {
55+
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y'], fieldValueTypes: 'double', sparse: true});
56+
} catch (e) {
57+
assertEqual(e.errorNum, internal.errors.ERROR_BAD_PARAMETER.code);
58+
}
59+
},
60+
61+
testArrayExpansions: function () {
62+
try {
63+
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x[*]', 'y'], fieldValueTypes: 'double'});
64+
} catch (e) {
65+
assertEqual(e.errorNum, internal.errors.ERROR_BAD_PARAMETER.code);
66+
}
67+
}
68+
69+
};
70+
}
71+
72+
jsunity.run(optimizerRuleZkd2dIndexTestSuite);
73+
74+
return jsunity.done();

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ function optimizerRuleZkd2dIndexTestSuite() {
4242
return {
4343
setUpAll: function () {
4444
col = db._create(colName);
45-
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y'], unique: true});
45+
col.ensureIndex({
46+
type: 'zkd',
47+
name: 'zkdIndex',
48+
fields: ['x', 'y'],
49+
unique: true,
50+
fieldValueTypes: 'double'
51+
});
4652
// Insert 1001 points
4753
// (-500, -499.5), (-499.1, -499.4), ..., (0, 0.5), ..., (499.9, 500.4), (500, 500.5)
4854
db._query(aql`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function optimizerRuleZkd2dIndexTestSuite() {
4141
return {
4242
setUpAll: function () {
4343
col = db._create(colName);
44-
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y']});
44+
col.ensureIndex({type: 'zkd', name: 'zkdIndex', fields: ['x', 'y'], fieldValueTypes: 'double'});
4545
// Insert 1001 points
4646
// (-500, -499.5), (-499.1, -499.4), ..., (0, 0.5), ..., (499.9, 500.4), (500, 500.5)
4747
db._query(aql`

0 commit comments

Comments
 (0)
0