Skip to content

Commit 26fd95f

Browse files
committed
Optionally allow nullable pk in column tables
1 parent f6b4b02 commit 26fd95f

File tree

6 files changed

+84
-7
lines changed

6 files changed

+84
-7
lines changed

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,7 +5024,8 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
50245024
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
50255025
}
50265026

5027-
{ // no partition by
5027+
{ // nullable pk columns are disabled by default
5028+
kikimr.GetTestServer().GetRuntime()->GetAppData().ColumnShardConfig.SetAllowNullableColumnsInPK(false);
50285029
auto query = TStringBuilder() << R"(
50295030
--!syntax_v1
50305031
CREATE TABLE `)" << tableName << R"(` (
@@ -8645,11 +8646,11 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) {
86458646
};
86468647
TTestHelper::TColumnTableStore testTableStore;
86478648
testTableStore.SetName("/Root/TableStoreTest").SetPrimaryKey({"id"}).SetSchema(schema);
8648-
testHelper.CreateTable(testTableStore, EStatus::SCHEME_ERROR);
8649+
testHelper.CreateTable(testTableStore, EStatus::SUCCESS);
86498650

86508651
TTestHelper::TColumnTable testTable;
86518652
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSchema(schema);
8652-
testHelper.CreateTable(testTable, EStatus::SCHEME_ERROR);
8653+
testHelper.CreateTable(testTable, EStatus::SUCCESS);
86538654
}
86548655

86558656
Y_UNIT_TEST(DropColumnAfterInsert) {

ydb/core/protos/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ message TColumnShardConfig {
16621662
optional uint32 SmallPortionDetectSizeLimit = 24 [default = 1048576]; // 1 << 20
16631663
optional bool ColumnChunksV0Usage = 25 [default = true];
16641664
optional bool ColumnChunksV1Usage = 26 [default = true];
1665+
optional bool AllowNullableColumnsInPK = 27 [default = false];
16651666
}
16661667

16671668
message TSchemeShardConfig {

ydb/core/tx/schemeshard/olap/operations/alter/standalone/update.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ NKikimr::TConclusionStatus TStandaloneSchemaUpdate::DoInitializeImpl(const TUpda
7676
return TConclusionStatus::Success();
7777
}
7878

79-
}
79+
}

ydb/core/tx/schemeshard/olap/operations/create_table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class TOlapTableConstructor : public TTableConstructorBase {
192192
}
193193

194194
TOlapSchemaUpdate schemaDiff;
195-
if (!schemaDiff.Parse(description.GetSchema(), errors)) {
195+
if (!schemaDiff.Parse(description.GetSchema(), errors, AppData()->ColumnShardConfig.GetAllowNullableColumnsInPK())) {
196196
return false;
197197
}
198198

ydb/core/tx/schemeshard/olap/store/store.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bool TOlapStoreInfo::ParseFromRequest(const NKikimrSchemeOp::TColumnStoreDescrip
153153
preset.SetProtoIndex(protoIndex++);
154154

155155
TOlapSchemaUpdate schemaDiff;
156-
if (!schemaDiff.Parse(presetProto.GetSchema(), errors)) {
156+
if (!schemaDiff.Parse(presetProto.GetSchema(), errors, AppData()->ColumnShardConfig.GetAllowNullableColumnsInPK())) {
157157
return false;
158158
}
159159

ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,81 @@ Y_UNIT_TEST_SUITE(TOlap) {
9999
TestLs(runtime, "/MyRoot/DirA/DirB/OlapStore", false, NLs::PathExist);
100100
}
101101

102+
Y_UNIT_TEST(CreateTableWithNullableKeysNotAllowed) {
103+
TTestBasicRuntime runtime;
104+
TTestEnv env(runtime);
105+
ui64 txId = 100;
106+
107+
auto& appData = runtime.GetAppData();
108+
appData.ColumnShardConfig.SetAllowNullableColumnsInPK(false);
109+
110+
TestCreateOlapStore(runtime, ++txId, "/MyRoot", R"(
111+
Name: "MyStore"
112+
ColumnShardCount: 1
113+
SchemaPresets {
114+
Name: "default"
115+
Schema {
116+
Columns { Name: "timestamp" Type: "Timestamp" NotNull: true }
117+
Columns { Name: "key1" Type: "Uint32" }
118+
Columns { Name: "data" Type: "Utf8" }
119+
KeyColumnNames: [ "timestamp", "key1" ]
120+
}
121+
}
122+
)", {NKikimrScheme::StatusSchemeError});
123+
env.TestWaitNotification(runtime, txId);
124+
}
125+
126+
Y_UNIT_TEST(CreateTableWithNullableKeys) {
127+
TTestBasicRuntime runtime;
128+
TTestEnv env(runtime);
129+
ui64 txId = 100;
130+
131+
auto& appData = runtime.GetAppData();
132+
appData.ColumnShardConfig.SetAllowNullableColumnsInPK(true);
133+
134+
TestCreateOlapStore(runtime, ++txId, "/MyRoot", R"(
135+
Name: "MyStore"
136+
ColumnShardCount: 1
137+
SchemaPresets {
138+
Name: "default"
139+
Schema {
140+
Columns { Name: "timestamp" Type: "Timestamp" NotNull: true }
141+
Columns { Name: "key1" Type: "Uint32" }
142+
Columns { Name: "data" Type: "Utf8" }
143+
KeyColumnNames: [ "timestamp", "key1" ]
144+
}
145+
}
146+
)");
147+
env.TestWaitNotification(runtime, txId);
148+
149+
TestLs(runtime, "/MyRoot/MyStore", false, NLs::PathExist);
150+
151+
TestMkDir(runtime, ++txId, "/MyRoot", "MyDir");
152+
env.TestWaitNotification(runtime, txId);
153+
154+
TestLs(runtime, "/MyRoot/MyDir", false, NLs::PathExist);
155+
156+
TestCreateColumnTable(runtime, ++txId, "/MyRoot/MyDir", R"(
157+
Name: "MyTable"
158+
ColumnShardCount: 1
159+
Schema {
160+
Columns { Name: "timestamp" Type: "Timestamp" NotNull: true }
161+
Columns { Name: "key1" Type: "Uint32" }
162+
Columns { Name: "data" Type: "Utf8" }
163+
KeyColumnNames: [ "timestamp", "key1" ]
164+
}
165+
)");
166+
env.TestWaitNotification(runtime, txId);
167+
168+
TestLsPathId(runtime, 4, NLs::PathStringEqual("/MyRoot/MyDir/MyTable"));
169+
170+
TestDropColumnTable(runtime, ++txId, "/MyRoot/MyDir", "MyTable");
171+
env.TestWaitNotification(runtime, txId);
172+
173+
TestLs(runtime, "/MyRoot/MyDir/MyTable", false, NLs::PathNotExist);
174+
TestLsPathId(runtime, 4, NLs::PathStringEqual(""));
175+
}
176+
102177
Y_UNIT_TEST(CreateTable) {
103178
TTestBasicRuntime runtime;
104179
TTestEnv env(runtime);
@@ -794,5 +869,5 @@ Y_UNIT_TEST_SUITE(TOlap) {
794869
env.TestWaitNotification(runtime, txId);
795870

796871
TestLs(runtime, "/MyRoot/OlapStore", false, NLs::PathExist);
797-
}
872+
}
798873
}

0 commit comments

Comments
 (0)