From e3c9123b97c1ddd8b6f787943729ca52e64af455 Mon Sep 17 00:00:00 2001 From: Kirill Shcherbatov <kshcherbatov@tarantool.org> Date: Tue, 8 Oct 2019 11:48:15 +0300 Subject: [PATCH] box: fix is_nullable fileds in space having format Is_nullable JSON-path indexes used to lose is_nullable property being defined on a space having format. This patch fixes this problem. Closes #4520 (cherry picked from commit 3d01b3af23ccef5b05789c1b23c7fe3f2b2c4eec) --- src/box/tuple_format.c | 3 ++- test/engine/json.result | 40 +++++++++++++++++++++++++++++++++++++++ test/engine/json.test.lua | 18 ++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index 514d5d9c05..34d8c5a906 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -378,7 +378,8 @@ tuple_format_use_key_part(struct tuple_format *format, uint32_t field_count, * i.e. DEFAULT. */ if (field->nullable_action == ON_CONFLICT_ACTION_DEFAULT) { - if (part->nullable_action != ON_CONFLICT_ACTION_NONE) + if (part->nullable_action != ON_CONFLICT_ACTION_NONE || + part->path != NULL) field->nullable_action = part->nullable_action; } else if (part->nullable_action == ON_CONFLICT_ACTION_DEFAULT) { if (field->nullable_action == ON_CONFLICT_ACTION_NONE) diff --git a/test/engine/json.result b/test/engine/json.result index 9f0c896844..2175266fcc 100644 --- a/test/engine/json.result +++ b/test/engine/json.result @@ -801,3 +801,43 @@ s.index.sk:select() s:drop() --- ... +-- +-- gh-4520: Nullable fields in JSON index are not working with a +-- space having a format defined. +-- +s = box.schema.space.create('x', {engine = engine}) +--- +... +pk = s:create_index('pk') +--- +... +_ = s:create_index( '_rawdata', { type='tree', unique=false, parts={{ 5, 'scalar', path='pay_date_to', is_nullable=true }} } ) +--- +... +_ = s:insert{6, 1569246252, 2, 77, { f1 = 123, pay_date_to = box.NULL }, 21, 1, 361 } +--- +... +s:format({{type='any', name='1'}, {type='any', name='2'}, {type='any', name='3'}, {type='any', name='4'}, {type='map', name='_rawdata', is_nullable=true}}) +--- +... +s:drop() +--- +... +s = box.schema.space.create('sp', {engine = engine, format = {{type='string', name='key'}, {type='map', name='value', is_nullable=true}}}) +--- +... +_ = s:create_index('pk', {parts = {'key'}}) +--- +... +_ = s:create_index('clid', {parts = {{'value.clid', 'str', is_nullable = true}}}) +--- +... +_ = s:insert({'01', {clid = 'AA', cltp = 20}}) +--- +... +_ = s:insert({'02', {cltp = 'BB'}}) +--- +... +s:drop() +--- +... diff --git a/test/engine/json.test.lua b/test/engine/json.test.lua index c6c207dc9b..4771c3162a 100644 --- a/test/engine/json.test.lua +++ b/test/engine/json.test.lua @@ -229,3 +229,21 @@ s:insert{11, {{b = 1}}} -- ok s:insert{12, {{a = box.NULL}}} -- ok s.index.sk:select() s:drop() + +-- +-- gh-4520: Nullable fields in JSON index are not working with a +-- space having a format defined. +-- +s = box.schema.space.create('x', {engine = engine}) +pk = s:create_index('pk') +_ = s:create_index( '_rawdata', { type='tree', unique=false, parts={{ 5, 'scalar', path='pay_date_to', is_nullable=true }} } ) +_ = s:insert{6, 1569246252, 2, 77, { f1 = 123, pay_date_to = box.NULL }, 21, 1, 361 } +s:format({{type='any', name='1'}, {type='any', name='2'}, {type='any', name='3'}, {type='any', name='4'}, {type='map', name='_rawdata', is_nullable=true}}) +s:drop() + +s = box.schema.space.create('sp', {engine = engine, format = {{type='string', name='key'}, {type='map', name='value', is_nullable=true}}}) +_ = s:create_index('pk', {parts = {'key'}}) +_ = s:create_index('clid', {parts = {{'value.clid', 'str', is_nullable = true}}}) +_ = s:insert({'01', {clid = 'AA', cltp = 20}}) +_ = s:insert({'02', {cltp = 'BB'}}) +s:drop() -- GitLab