Skip to content

Commit 9bc3a93

Browse files
Bogdan Degtyariovsilvakid
Bogdan Degtyariov
authored andcommitted
WL12151 DevAPI: Indexing array fields
1 parent a35eb61 commit 9bc3a93

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

common/collection.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct Field_conv
144144
Any_prc* key_val(const string &key) override
145145
{
146146
static const std::set<std::string> allowed_keys =
147-
{ "field", "type", "required", "options", "srid" };
147+
{ "field", "type", "required", "options", "srid", "array" };
148148

149149
std::string field_name = to_lower(key);
150150

devapi/tests/ddl-t.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ TEST_F(Ddl, create_index)
324324
R"({ "type" : "SPATIAL", "fields": [{ "field": "$.coords", "type" : "GEOJSON", "required" : false }] })")
325325
);
326326

327+
SKIP_IF_SERVER_VERSION_LESS(8, 0, 17);
328+
329+
cout << "Array index" << endl;
330+
coll.createIndex("arr_idx",
331+
R"-({ "fields": [{ "field": "$.zip", "type" : "CHAR(5)", "array" : true }] })-"
332+
);
333+
coll.dropIndex("arr_idx");
334+
327335
cout << "Done!" << endl;
328336
}
329337

xapi/tests/xapi_crud-t.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,19 @@ TEST_F(xapi, test_create_collection_index)
217217
const char *schema_name = "cc_crud_test";
218218
const char *coll_name = "index_test";
219219
const char *json[] = {
220-
"{\"zip\": \"34239\", \"zcount\": \"10\", \"some_text\": \"just some text\"}",
221-
"{\"zip\": \"30001\", \"zcount\": \"20\", \"some_text\": \"some more text\"}"
220+
"{\"zip\": [\"34239\", \"23456\"], \"zcount\": \"10\", \"some_text\": \"just some text\"}",
221+
"{\"zip\": [\"00001\", \"23456\"], \"zcount\": \"20\", \"some_text\": \"some more text\"}"
222222
};
223223

224224
const char *geo_json =
225225
"{\"zip\": \"34239\", \"coords\" : { \"type\": \"Point\", \"coordinates\": [102.0, 0.0] }}";
226226

227227
const char *json_idx = "{"\
228228
"\"fields\": ["\
229-
"{ \"field\": \"$.zip\", \"required\" : true , \"type\" : \"TEXT(10)\" },"\
229+
"{ \"field\": \"$.zip\", \"required\" : true , \"type\" : \"TEXT(10)\"},"\
230230
"{ \"field\": \"$.zcount\", \"type\" : \"INT UNSIGNED\" }]}";
231231

232+
232233
const char *geo_json_idx = "{"
233234
"\"type\" : \"SPATIAL\","
234235
"\"fields\": [{"
@@ -284,6 +285,20 @@ TEST_F(xapi, test_create_collection_index)
284285

285286
EXPECT_EQ(RESULT_OK,
286287
mysqlx_collection_drop_index(collection, "geo_idx1"));
288+
289+
SKIP_IF_SERVER_VERSION_LESS(8, 0, 17);
290+
291+
EXPECT_EQ(RESULT_OK, mysqlx_collection_drop(schema, coll_name));
292+
EXPECT_EQ(RESULT_OK, mysqlx_collection_create(schema, coll_name));
293+
collection = mysqlx_get_collection(schema, coll_name, 0);
294+
295+
const char *multival_idx = "{"\
296+
"\"fields\": ["\
297+
"{ \"field\": \"$.zip\", \"type\" : \"CHAR(10)\", \"array\" : true}]}";
298+
printf("\nCreate multivalue index.");
299+
EXPECT_EQ(RESULT_OK,
300+
mysqlx_collection_create_index(collection, "multival_idx1", multival_idx));
301+
EXPECT_EQ(RESULT_OK, mysqlx_collection_drop(schema, coll_name));
287302
}
288303

289304

0 commit comments

Comments
 (0)