Skip to content

Add PARTITIONS_COUNT setting to yql #7602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions ydb/core/kqp/ut/olap/kqp_olap_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
PARTITION BY HASH(timestamp)
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = %d
PARTITIONS_COUNT = %d
)
)", storeName.data(), tableName.data(), shardsCount);
)",
storeName.data(), tableName.data(), shardsCount);
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
if (result.GetStatus() != EStatus::SUCCESS) {
Cerr << result.GetIssues().ToOneLineString() << Endl;
Expand Down Expand Up @@ -1843,8 +1844,8 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
PARTITION BY HASH(WatchID)
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT =)" << numShards
<< ")";
PARTITIONS_COUNT =)" << numShards
<< ")";
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());

Expand Down Expand Up @@ -1931,10 +1932,9 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_BY_SIZE = ENABLED,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1
PARTITIONS_COUNT = 1
);
)"
);
)");

lHelper.StartDataRequest(
R"(
Expand Down Expand Up @@ -1986,10 +1986,9 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_BY_SIZE = ENABLED,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1
PARTITIONS_COUNT = 1
);
)"
);
)");

lHelper.StartDataRequest(
R"(
Expand All @@ -1998,7 +1997,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
);

}
/*
/*
Y_UNIT_TEST(OlapDeletePlanned) {
TPortManager pm;

Expand Down Expand Up @@ -2038,7 +2037,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_BY_SIZE = ENABLED,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 8
PARTITIONS_COUNT = 8
);
)"
);
Expand Down Expand Up @@ -2478,7 +2477,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
PRIMARY KEY (a)
)
PARTITION BY HASH(a)
WITH (STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 4);
WITH (STORE = COLUMN, PARTITIONS_COUNT = 4);
)";

auto result = session.ExecuteSchemeQuery(query).GetValueSync();
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/sql/v1/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ namespace NSQLTranslationV1 {
TMaybe<TIdentifier> AutoPartitioningByLoad;
TNodePtr MinPartitions;
TNodePtr MaxPartitions;
TNodePtr PartitionsCount;
TNodePtr UniformPartitions;
TVector<TVector<TNodePtr>> PartitionAtKeys;
TMaybe<TIdentifier> KeyBloomFilter;
Expand Down
4 changes: 4 additions & 0 deletions ydb/library/yql/sql/v1/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ 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.KeyBloomFilter) {
const auto& ref = tableSettings.KeyBloomFilter.GetRef();
settings = L(settings, Q(Y(Q("keyBloomFilter"), BuildQuotedAtom(ref.Pos, ref.Name))));
Expand Down
24 changes: 23 additions & 1 deletion ydb/library/yql/sql/v1/sql_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,17 @@ bool TSqlTranslation::StoreExternalTableSettingsEntry(const TIdentifier& id, con
return true;
}

bool TSqlTranslation::ValidateTableSettings(const TTableSettings& settings) {
if (settings.PartitionsCount) {
if (!settings.StoreType || to_lower(settings.StoreType->Name) != "column") {
Ctx.Error() << " PARTITION_COUNT can be used only with STORE=COLUMN";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавь, пожалуйста, тестов, проверяющий что запросы с неправильной комбинацией параметров не будут проходить

return false;
}
}

return true;
}

bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule_table_setting_value* value,
TTableSettings& settings, bool alter, bool reset) {
YQL_ENSURE(value || reset);
Expand Down Expand Up @@ -2096,6 +2107,16 @@ 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") {
if (reset) {
Ctx.Error() << to_upper(id.Name) << " reset is not supported";
return false;
}

if (!StoreInt(*value, settings.PartitionsCount, Ctx)) {
Ctx.Error() << to_upper(id.Name) << " value should be an integer";
return false;
}
} else if (to_lower(id.Name) == "uniform_partitions") {
if (alter) {
Ctx.Error() << to_upper(id.Name) << " alter is not supported";
Expand Down Expand Up @@ -2186,7 +2207,8 @@ bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule
Ctx.Error() << "Unknown table setting: " << id.Name;
return false;
}
return true;

return ValidateTableSettings(settings);
}

bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule_table_setting_value& value,
Expand Down
2 changes: 2 additions & 0 deletions ydb/library/yql/sql/v1/sql_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class TSqlTranslation: public TTranslation {

bool ClusterExpr(const TRule_cluster_expr& node, bool allowWildcard, bool allowBinding, TString& service, TDeferredAtom& cluster, bool& isBinding);
bool StructLiteralItem(TVector<TNodePtr>& labels, const TRule_expr& label, TVector<TNodePtr>& values, const TRule_expr& value);
bool ValidateTableSettings(const TTableSettings& settings);

protected:
NSQLTranslation::ESqlMode Mode;
};
Expand Down
Loading