From 08d9d53051ef4fb92b23a2fa58d7898ec4b9bd36 Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Wed, 29 Sep 2021 18:28:10 +0300 Subject: [PATCH] test: add tests for JSON path Part of #166 Part of #219 --- test/entrypoint/srv_ddl.lua | 40 +++++++++++ test/integration/ddl_sharding_key_test.lua | 82 ++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/test/entrypoint/srv_ddl.lua b/test/entrypoint/srv_ddl.lua index a6b4e7e07..05a98bbb4 100755 --- a/test/entrypoint/srv_ddl.lua +++ b/test/entrypoint/srv_ddl.lua @@ -7,6 +7,7 @@ local log = require('log') local errors = require('errors') local cartridge = require('cartridge') local ddl = require('ddl') +local crud_utils = require('crud.common.utils') package.preload['customers-storage'] = function() return { @@ -109,11 +110,50 @@ package.preload['customers-storage'] = function() } } + -- DDL module doesn't support map and array types and JSON path in + -- sharding key, see https://github.com/tarantool/ddl/issues/81, + -- so we create space with jsonpath index manually. + local function create_space_with_jsonpath() + local customers_jsonpath_key = box.schema.space.create('customers_jsonpath_key', { + format = { + {name = 'id', is_nullable = false, type = 'map'}, + {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, + {name = 'name', is_nullable = false, type = 'string'}, + {name = 'age', is_nullable = false, type = 'number'}, + {name = 'data', is_nullable = false, type = 'map'}, + }, + if_not_exists = true, + engine = engine, + }) + customers_jsonpath_key:create_index('pk', { + parts = { + {1, 'unsigned', path = 'customer_id.unsigned'}, + {5, 'unsigned', path = 'customer.weight'}, + }, + if_not_exists = true, + }) + customers_jsonpath_key:create_index('bucket_id', { + parts = { 'bucket_id' }, + unique = false, + if_not_exists = true, + }) + box.space['_ddl_sharding_key']:insert({ + 'customers_jsonpath_key', + {'name'} + }) + end + if not box.info.ro then local ok, err = ddl.set_schema(schema) if not ok then error(err) end + if crud_utils.tarantool_supports_jsonpath_indexes() then + local ok, err = pcall(create_space_with_jsonpath) + if not ok then + error(err) + end + end end rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def) diff --git a/test/integration/ddl_sharding_key_test.lua b/test/integration/ddl_sharding_key_test.lua index 4ff4f5404..655fece1c 100644 --- a/test/integration/ddl_sharding_key_test.lua +++ b/test/integration/ddl_sharding_key_test.lua @@ -1,5 +1,6 @@ local fio = require('fio') local crud = require('crud') +local crud_utils = require('crud.common.utils') local t = require('luatest') local helpers = require('test.helper') @@ -43,6 +44,9 @@ pgroup.before_each(function(g) helpers.truncate_space_on_cluster(g.cluster, 'customers_name_key_non_uniq_index') helpers.truncate_space_on_cluster(g.cluster, 'customers_secondary_idx_name_key') helpers.truncate_space_on_cluster(g.cluster, 'customers_age_key') + if crud_utils.tarantool_supports_jsonpath_indexes() then + helpers.truncate_space_on_cluster(g.cluster, 'customers_jsonpath_key') + end end) local function check_get(g, space_name, id, name) @@ -566,3 +570,81 @@ pgroup.test_update_sharding_keys_cache = function(g) sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name) t.assert_equals(sharding_key, {'name'}) end + +pgroup.test_jsonpath_insert = function(g) + t.skip('JSONpath is unsupported, see issue #219') + + local space_name = 'customers_jsonpath_key' + local customers = helpers.insert_objects(g, space_name, { + { + id = {customer_id = {unsigned = 1}}, + name = 'Viktor Pelevin', + age = 58, + data = {customer = {weight = 82}}, + }, + { + id = {customer_id = {unsigned = 2}}, + name = 'Isaac Asimov', + age = 72, + data = {customer = {weight = 70}}, + }, + { + id = {customer_id = {unsigned = 3}}, + name = 'Aleksandr Solzhenitsyn', + age = 89, + data = {customer = {weight = 78}}, + }, + { + id = {customer_id = {unsigned = 4}}, + name = 'James Joyce', + age = 59, + data = {customer = {weight = 82}}, + }, + { + id = {customer_id = {unsigned = 5}}, + name = 'Oscar Wilde', + age = 46, + data = {customer = {weight = 79}}, + }, + }) + t.assert_equals(#customers, 5) +end + +pgroup.test_jsonpath_delete = function(g) + t.skip('JSONpath is unsupported, see issue #219') + + local space_name = 'customers_jsonpath_key' + local customers = helpers.insert_objects(g, space_name, { + { + id = {customer_id = {unsigned = 1}}, + name = 'Viktor Pelevin', + age = 58, + data = {customer = {weight = 82}}, + }, + { + id = {customer_id = {unsigned = 2}}, + name = 'Isaac Asimov', + age = 72, + data = {customer = {weight = 70}}, + }, + { + id = {customer_id = {unsigned = 3}}, + name = 'Aleksandr Solzhenitsyn', + age = 89, + data = {customer = {weight = 78}}, + }, + { + id = {customer_id = {unsigned = 4}}, + name = 'James Joyce', + age = 59, + data = {customer = {weight = 82}}, + }, + { + id = {customer_id = {unsigned = 5}}, + name = 'Oscar Wilde', + age = 46, + data = {customer = {weight = 79}}, + }, + }) + t.assert_equals(#customers, 5) +end