diff options
author | nsofya <nsofya@yandex-team.com> | 2023-04-07 14:26:31 +0300 |
---|---|---|
committer | nsofya <nsofya@yandex-team.com> | 2023-04-07 14:26:31 +0300 |
commit | bcaaf7514561a925d14b81a86b96b9ed80c16f33 (patch) | |
tree | 73943f1b197c6684e921ed9259fbab4edab8acd1 | |
parent | 88e107dbcda60d575859dc0e7add4d21d509d698 (diff) | |
download | ydb-bcaaf7514561a925d14b81a86b96b9ed80c16f33.tar.gz |
Check sharding key condition
Check sharding key condition
-rw-r--r-- | ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 41 | ||||
-rw-r--r-- | ydb/core/testlib/cs_helper.cpp | 1 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp | 6 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/ut_olap.cpp | 3 | ||||
-rw-r--r-- | ydb/services/ydb/ydb_common_ut.h | 1 |
5 files changed, 39 insertions, 13 deletions
diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index d4e0b1289e4..60a3fa53c16 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -3261,7 +3261,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) { Value2 Int64 NOT NULL, PRIMARY KEY (Key) ) - PARTITION BY HASH(Value1, Value2) + PARTITION BY HASH(Key) WITH ( STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10 @@ -3293,9 +3293,8 @@ Y_UNIT_TEST_SUITE(KqpScheme) { auto partSettings = description.GetPartitioningSettings().GetProto(); auto& partition_by = partSettings.partition_by(); - UNIT_ASSERT_VALUES_EQUAL(partition_by.size(), 2); - UNIT_ASSERT_VALUES_EQUAL(partition_by[0], "Value1"); - UNIT_ASSERT_VALUES_EQUAL(partition_by[1], "Value2"); + UNIT_ASSERT_VALUES_EQUAL(partition_by.size(), 1); + UNIT_ASSERT_VALUES_EQUAL(partition_by[0], "Key"); // TODO: TTL } @@ -3306,7 +3305,32 @@ Y_UNIT_TEST_SUITE(KqpScheme) { UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); } - Y_UNIT_TEST(AddColumnOlapTable) { + Y_UNIT_TEST(OlapSharding_KeyOnly) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + TKikimrRunner kikimr(runnerSettings); + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().GetValueSync().GetSession(); + TString tableName = "/Root/ColumnTableTest"; + + auto query = TStringBuilder() << R"( + --!syntax_v1 + CREATE TABLE `)" << tableName << R"(` ( + Key Uint64 NOT NULL, + Value1 String, + Value2 Int64 NOT NULL, + PRIMARY KEY (Key) + ) + PARTITION BY HASH(Key, Value1) + WITH ( + STORE = COLUMN, + AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10 + );)"; + auto result = session.ExecuteSchemeQuery(query).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString()); + } + + Y_UNIT_TEST(AddColumnOlapTable) { TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false; TKikimrRunner kikimr(runnerSettings); @@ -3322,7 +3346,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) { Value2 Int64 NOT NULL, PRIMARY KEY (Key) ) - PARTITION BY HASH(Value1, Value2) + PARTITION BY HASH(Key) WITH ( STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10 @@ -3335,7 +3359,6 @@ Y_UNIT_TEST_SUITE(KqpScheme) { ALTER TABLE `)" << tableName << R"(`ADD COLUMN Value3 Uint64;)"; result = session.ExecuteSchemeQuery(query2).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SCHEME_ERROR, result.GetIssues().ToString()); - } Y_UNIT_TEST(CreateDropColumnTableNegative) { @@ -3413,7 +3436,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) { Value2 Datetime NOT NULL, PRIMARY KEY (Key) ) - PARTITION BY HASH(Value1, Value2) + PARTITION BY HASH(Key) WITH ( STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10 @@ -3468,7 +3491,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) { Value2 Int64 NOT NULL, PRIMARY KEY (Key) ) - PARTITION BY HASH(Value1, Value2) + PARTITION BY HASH(Key) WITH ( STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10, diff --git a/ydb/core/testlib/cs_helper.cpp b/ydb/core/testlib/cs_helper.cpp index ff4e639389f..0a7374d8d7c 100644 --- a/ydb/core/testlib/cs_helper.cpp +++ b/ydb/core/testlib/cs_helper.cpp @@ -175,6 +175,7 @@ TString THelper::GetTestTableSchema() const { } sb << R"( KeyColumnNames: "timestamp" + KeyColumnNames: "uid" Engine : COLUMN_ENGINE_REPLACING_TIMESERIES )"; return sb; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp index 91f53bf1841..404cb6d4f31 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp @@ -99,7 +99,6 @@ private: errors.AddError(Sprintf("Hash sharding requires a non-empty list of columns")); return false; } - bool keysOnly = true; for (const TString& columnName : sharding.GetColumns()) { auto* pColumn = schema.GetColumnByName(columnName); if (!pColumn) { @@ -107,11 +106,12 @@ private: return false; } if (!pColumn->IsKeyColumn()) { - keysOnly = false; + errors.AddError(Sprintf("Hash sharding is using a non-key column '%s'", columnName.c_str())); + return false; } } sharding.SetUniqueShardKey(true); - tableInfo->Sharding.SetUniquePrimaryKey(keysOnly); + tableInfo->Sharding.SetUniquePrimaryKey(true); break; } default: { diff --git a/ydb/core/tx/schemeshard/ut_olap.cpp b/ydb/core/tx/schemeshard/ut_olap.cpp index 656919d64db..9f22d440f6c 100644 --- a/ydb/core/tx/schemeshard/ut_olap.cpp +++ b/ydb/core/tx/schemeshard/ut_olap.cpp @@ -415,8 +415,9 @@ Y_UNIT_TEST_SUITE(TOlap) { Schema { Columns { Name: "timestamp" Type: "Timestamp" NotNull: true } Columns { Name: "some" Type: "Uint64" NotNull: true } - Columns { Name: "data" Type: "Utf8" } + Columns { Name: "data" Type: "Utf8" NotNull: true } KeyColumnNames: "some" + KeyColumnNames: "data" Engine: COLUMN_ENGINE_REPLACING_TIMESERIES } Sharding { diff --git a/ydb/services/ydb/ydb_common_ut.h b/ydb/services/ydb/ydb_common_ut.h index e8b4fa75bdf..0ef3d871e52 100644 --- a/ydb/services/ydb/ydb_common_ut.h +++ b/ydb/services/ydb/ydb_common_ut.h @@ -234,6 +234,7 @@ struct TTestOlap { Columns { Name: "saved_at" Type: "Timestamp" } Columns { Name: "request_id" Type: "Utf8" } KeyColumnNames: "timestamp" + KeyColumnNames: "uid" Engine: COLUMN_ENGINE_REPLACING_TIMESERIES } } |