Skip to content

Commit 2ab0fd8

Browse files
authored
Add PARTITIONS_COUNT setting to yql (#7602)
1 parent 0549026 commit 2ab0fd8

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

ydb/core/kqp/ut/olap/kqp_olap_ut.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
5151
PARTITION BY HASH(timestamp)
5252
WITH (
5353
STORE = COLUMN,
54-
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = %d
54+
PARTITIONS_COUNT = %d
5555
)
56-
)", storeName.data(), tableName.data(), shardsCount);
56+
)",
57+
storeName.data(), tableName.data(), shardsCount);
5758
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
5859
if (result.GetStatus() != EStatus::SUCCESS) {
5960
Cerr << result.GetIssues().ToOneLineString() << Endl;
@@ -1845,8 +1846,8 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
18451846
PARTITION BY HASH(WatchID)
18461847
WITH (
18471848
STORE = COLUMN,
1848-
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT =)" << numShards
1849-
<< ")";
1849+
PARTITIONS_COUNT =)" << numShards
1850+
<< ")";
18501851
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
18511852
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
18521853

@@ -1933,10 +1934,9 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
19331934
WITH (
19341935
STORE = COLUMN,
19351936
AUTO_PARTITIONING_BY_SIZE = ENABLED,
1936-
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1
1937+
PARTITIONS_COUNT = 1
19371938
);
1938-
)"
1939-
);
1939+
)");
19401940

19411941
lHelper.StartDataRequest(
19421942
R"(
@@ -1988,10 +1988,9 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
19881988
WITH (
19891989
STORE = COLUMN,
19901990
AUTO_PARTITIONING_BY_SIZE = ENABLED,
1991-
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1
1991+
PARTITIONS_COUNT = 1
19921992
);
1993-
)"
1994-
);
1993+
)");
19951994

19961995
lHelper.StartDataRequest(
19971996
R"(
@@ -2000,7 +1999,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
20001999
);
20012000

20022001
}
2003-
/*
2002+
/*
20042003
Y_UNIT_TEST(OlapDeletePlanned) {
20052004
TPortManager pm;
20062005
@@ -2040,7 +2039,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
20402039
WITH (
20412040
STORE = COLUMN,
20422041
AUTO_PARTITIONING_BY_SIZE = ENABLED,
2043-
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 8
2042+
PARTITIONS_COUNT = 8
20442043
);
20452044
)"
20462045
);
@@ -2511,7 +2510,7 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
25112510
PRIMARY KEY (a)
25122511
)
25132512
PARTITION BY HASH(a)
2514-
WITH (STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 4);
2513+
WITH (STORE = COLUMN, PARTITIONS_COUNT = 4);
25152514
)";
25162515

25172516
auto result = session.ExecuteSchemeQuery(query).GetValueSync();

ydb/library/yql/sql/v1/node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,7 @@ namespace NSQLTranslationV1 {
11211121
TMaybe<TIdentifier> AutoPartitioningByLoad;
11221122
TNodePtr MinPartitions;
11231123
TNodePtr MaxPartitions;
1124+
TNodePtr PartitionsCount;
11241125
TNodePtr UniformPartitions;
11251126
TVector<TVector<TNodePtr>> PartitionAtKeys;
11261127
TMaybe<TIdentifier> KeyBloomFilter;

ydb/library/yql/sql/v1/query.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ static INode::TPtr CreateTableSettings(const TTableSettings& tableSettings, ETab
224224
if (tableSettings.MaxPartitions) {
225225
settings = L(settings, Q(Y(Q("maxPartitions"), tableSettings.MaxPartitions)));
226226
}
227+
if (tableSettings.PartitionsCount) {
228+
settings = L(settings, Q(Y(Q("maxPartitions"), tableSettings.PartitionsCount)));
229+
settings = L(settings, Q(Y(Q("minPartitions"), tableSettings.PartitionsCount)));
230+
}
227231
if (tableSettings.KeyBloomFilter) {
228232
const auto& ref = tableSettings.KeyBloomFilter.GetRef();
229233
settings = L(settings, Q(Y(Q("keyBloomFilter"), BuildQuotedAtom(ref.Pos, ref.Name))));

ydb/library/yql/sql/v1/sql_translation.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,17 @@ bool TSqlTranslation::StoreExternalTableSettingsEntry(const TIdentifier& id, con
20402040
return true;
20412041
}
20422042

2043+
bool TSqlTranslation::ValidateTableSettings(const TTableSettings& settings) {
2044+
if (settings.PartitionsCount) {
2045+
if (!settings.StoreType || to_lower(settings.StoreType->Name) != "column") {
2046+
Ctx.Error() << " PARTITION_COUNT can be used only with STORE=COLUMN";
2047+
return false;
2048+
}
2049+
}
2050+
2051+
return true;
2052+
}
2053+
20432054
bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule_table_setting_value* value,
20442055
TTableSettings& settings, bool alter, bool reset) {
20452056
YQL_ENSURE(value || reset);
@@ -2098,6 +2109,16 @@ bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule
20982109
Ctx.Error() << to_upper(id.Name) << " value should be an integer";
20992110
return false;
21002111
}
2112+
} else if (to_lower(id.Name) == "partitions_count") {
2113+
if (reset) {
2114+
Ctx.Error() << to_upper(id.Name) << " reset is not supported";
2115+
return false;
2116+
}
2117+
2118+
if (!StoreInt(*value, settings.PartitionsCount, Ctx)) {
2119+
Ctx.Error() << to_upper(id.Name) << " value should be an integer";
2120+
return false;
2121+
}
21012122
} else if (to_lower(id.Name) == "uniform_partitions") {
21022123
if (alter) {
21032124
Ctx.Error() << to_upper(id.Name) << " alter is not supported";
@@ -2188,7 +2209,8 @@ bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule
21882209
Ctx.Error() << "Unknown table setting: " << id.Name;
21892210
return false;
21902211
}
2191-
return true;
2212+
2213+
return ValidateTableSettings(settings);
21922214
}
21932215

21942216
bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule_table_setting_value& value,

ydb/library/yql/sql/v1/sql_translation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ class TSqlTranslation: public TTranslation {
266266

267267
bool ClusterExpr(const TRule_cluster_expr& node, bool allowWildcard, bool allowBinding, TString& service, TDeferredAtom& cluster, bool& isBinding);
268268
bool StructLiteralItem(TVector<TNodePtr>& labels, const TRule_expr& label, TVector<TNodePtr>& values, const TRule_expr& value);
269+
bool ValidateTableSettings(const TTableSettings& settings);
270+
269271
protected:
270272
NSQLTranslation::ESqlMode Mode;
271273
};

0 commit comments

Comments
 (0)