Skip to content

Commit

Permalink
Fix PARTITION_COUNT option name and add tests (#9012)
Browse files Browse the repository at this point in the history
  • Loading branch information
fexolm authored Sep 10, 2024
1 parent ce3201c commit 26c9911
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
12 changes: 6 additions & 6 deletions ydb/core/kqp/ut/olap/kqp_olap_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
PARTITION BY HASH(timestamp)
WITH (
STORE = COLUMN,
PARTITIONS_COUNT = %d
PARTITION_COUNT = %d
)
)",
storeName.data(), tableName.data(), shardsCount);
Expand Down Expand Up @@ -1846,7 +1846,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
PARTITION BY HASH(WatchID)
WITH (
STORE = COLUMN,
PARTITIONS_COUNT =)" << numShards
PARTITION_COUNT =)" << numShards
<< ")";
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
Expand Down Expand Up @@ -1934,7 +1934,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_BY_SIZE = ENABLED,
PARTITIONS_COUNT = 1
PARTITION_COUNT = 1
);
)");

Expand Down Expand Up @@ -1988,7 +1988,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_BY_SIZE = ENABLED,
PARTITIONS_COUNT = 1
PARTITION_COUNT = 1
);
)");

Expand Down Expand Up @@ -2039,7 +2039,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_BY_SIZE = ENABLED,
PARTITIONS_COUNT = 8
PARTITION_COUNT = 8
);
)"
);
Expand Down Expand Up @@ -2510,7 +2510,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
PRIMARY KEY (a)
)
PARTITION BY HASH(a)
WITH (STORE = COLUMN, PARTITIONS_COUNT = 4);
WITH (STORE = COLUMN, PARTITION_COUNT = 4);
)";

auto result = session.ExecuteSchemeQuery(query).GetValueSync();
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/sql/v1/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ namespace NSQLTranslationV1 {
TMaybe<TIdentifier> AutoPartitioningByLoad;
TNodePtr MinPartitions;
TNodePtr MaxPartitions;
TNodePtr PartitionsCount;
TNodePtr PartitionCount;
TNodePtr UniformPartitions;
TVector<TVector<TNodePtr>> PartitionAtKeys;
TMaybe<TIdentifier> KeyBloomFilter;
Expand Down
6 changes: 3 additions & 3 deletions ydb/library/yql/sql/v1/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ static INode::TPtr CreateTableSettings(const TTableSettings& tableSettings, ETab
if (tableSettings.MaxPartitions) {
settings = L(settings, Q(Y(Q("maxPartitions"), tableSettings.MaxPartitions)));
}
if (tableSettings.PartitionsCount) {
settings = L(settings, Q(Y(Q("maxPartitions"), tableSettings.PartitionsCount)));
settings = L(settings, Q(Y(Q("minPartitions"), tableSettings.PartitionsCount)));
if (tableSettings.PartitionCount) {
settings = L(settings, Q(Y(Q("maxPartitions"), tableSettings.PartitionCount)));
settings = L(settings, Q(Y(Q("minPartitions"), tableSettings.PartitionCount)));
}
if (tableSettings.KeyBloomFilter) {
const auto& ref = tableSettings.KeyBloomFilter.GetRef();
Expand Down
6 changes: 3 additions & 3 deletions ydb/library/yql/sql/v1/sql_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ bool TSqlTranslation::StoreExternalTableSettingsEntry(const TIdentifier& id, con
}

bool TSqlTranslation::ValidateTableSettings(const TTableSettings& settings) {
if (settings.PartitionsCount) {
if (settings.PartitionCount) {
if (!settings.StoreType || to_lower(settings.StoreType->Name) != "column") {
Ctx.Error() << " PARTITION_COUNT can be used only with STORE=COLUMN";
return false;
Expand Down Expand Up @@ -2109,13 +2109,13 @@ bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule
Ctx.Error() << to_upper(id.Name) << " value should be an integer";
return false;
}
} else if (to_lower(id.Name) == "partitions_count") {
} else if (to_lower(id.Name) == "partition_count") {
if (reset) {
Ctx.Error() << to_upper(id.Name) << " reset is not supported";
return false;
}

if (!StoreInt(*value, settings.PartitionsCount, Ctx)) {
if (!StoreInt(*value, settings.PartitionCount, Ctx)) {
Ctx.Error() << to_upper(id.Name) << " value should be an integer";
return false;
}
Expand Down
25 changes: 25 additions & 0 deletions ydb/library/yql/sql/v1/sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7204,3 +7204,28 @@ Y_UNIT_TEST_SUITE(ResourcePoolClassifier) {
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
}
}

Y_UNIT_TEST_SUITE(OlapPartitionCount) {
Y_UNIT_TEST(CorrectUsage) {
NYql::TAstParseResult res = SqlToYql(R"sql(
USE plato;
CREATE TABLE `mytable` (id Uint32, PRIMARY KEY (id))
PARTITION BY HASH(id)
WITH (STORE = COLUMN, PARTITION_COUNT = 8);
)sql");

UNIT_ASSERT_C(res.IsOk(), res.Issues.ToString());
}

Y_UNIT_TEST(UseWithoutColumnStore) {
NYql::TAstParseResult res = SqlToYql(R"sql(
USE plato;
CREATE TABLE `mytable` (id Uint32, PRIMARY KEY (id))
WITH (PARTITION_COUNT = 8);
)sql");

UNIT_ASSERT(!res.IsOk());
UNIT_ASSERT(res.Issues.Size() == 1);
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "PARTITION_COUNT can be used only with STORE=COLUMN");
}
}

0 comments on commit 26c9911

Please sign in to comment.