diff options
author | chertus <azuikov@ydb.tech> | 2023-01-13 18:14:34 +0300 |
---|---|---|
committer | chertus <azuikov@ydb.tech> | 2023-01-13 18:14:34 +0300 |
commit | 657681dd6711ffd594a272b9bd92208250f4a7be (patch) | |
tree | 01946364cbf1ab844765d360adf65a00907f0766 | |
parent | 6ba153ea01c99e3084f4ca75e3260f89da8d8527 (diff) | |
download | ydb-657681dd6711ffd594a272b9bd92208250f4a7be.tar.gz |
(Re)set tiering at YQL layer
-rw-r--r-- | ydb/library/yql/sql/v1/format/sql_format_ut.cpp | 11 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/node.h | 5 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/query.cpp | 16 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql.cpp | 11 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_ut.cpp | 29 |
5 files changed, 65 insertions, 7 deletions
diff --git a/ydb/library/yql/sql/v1/format/sql_format_ut.cpp b/ydb/library/yql/sql/v1/format/sql_format_ut.cpp index e263fe979e..222784f367 100644 --- a/ydb/library/yql/sql/v1/format/sql_format_ut.cpp +++ b/ydb/library/yql/sql/v1/format/sql_format_ut.cpp @@ -233,7 +233,7 @@ Y_UNIT_TEST_SUITE(CheckSqlFormatter) { "CREATE TABLE user (\n\tCHANGEFEED user WITH (user = 'foo')\n);\n"}, {"create table user(changefeed user with (user='foo',user='bar'))", "CREATE TABLE user (\n\tCHANGEFEED user WITH (user = 'foo', user = 'bar')\n);\n"}, - {"create table user(foo int32, bar bool ?) inherits (s3:$cluster.xxx) partition by hash(a,b,hash) with (inherits=interval('PT1D') ON logical_time) tablestore tablestore", + {"create table user(foo int32, bar bool ?) inherits (s3:$cluster.xxx) partition by hash(a,b,hash) with (inherits=interval('PT1D') ON logical_time) tablestore tablestore", "CREATE TABLE user (\n" "\tfoo int32,\n" "\tbar bool?\n" @@ -241,7 +241,14 @@ Y_UNIT_TEST_SUITE(CheckSqlFormatter) { "INHERITS (s3: $cluster.xxx)\n" "PARTITION BY HASH (a, b, hash)\n" "WITH (inherits = interval('PT1D') ON logical_time)\n" - "TABLESTORE tablestore;\n"} + "TABLESTORE tablestore;\n"}, + {"create table user(foo int32, bar bool ?) partition by hash(a,b,hash) with (tiering='some')", + "CREATE TABLE user (\n" + "\tfoo int32,\n" + "\tbar bool?\n" + ")\n" + "PARTITION BY HASH (a, b, hash)\n" + "WITH (tiering = 'some');\n"} }; TSetup setup; diff --git a/ydb/library/yql/sql/v1/node.h b/ydb/library/yql/sql/v1/node.h index 9d0b152c88..ec613cd5cc 100644 --- a/ydb/library/yql/sql/v1/node.h +++ b/ydb/library/yql/sql/v1/node.h @@ -750,7 +750,7 @@ namespace NSQLTranslationV1 { const bool Ordered; }; - + class TUdfNode: public INode { public: TUdfNode(TPosition pos, const TVector<TNodePtr>& args); @@ -1129,13 +1129,14 @@ namespace NSQLTranslationV1 { TMaybe<TIdentifier> KeyBloomFilter; TNodePtr ReadReplicasSettings; NYql::TResetableSetting<TTtlSettings, void> TtlSettings; + NYql::TResetableSetting<TNodePtr, void> Tiering; TMaybe<TIdentifier> StoreType; TNodePtr PartitionByHashFunction; bool IsSet() const { return CompactionPolicy || AutoPartitioningBySize || PartitionSizeMb || AutoPartitioningByLoad || MinPartitions || MaxPartitions || UniformPartitions || PartitionAtKeys || KeyBloomFilter - || ReadReplicasSettings || TtlSettings || StoreType || PartitionByHashFunction; + || ReadReplicasSettings || TtlSettings || Tiering || StoreType || PartitionByHashFunction; } }; diff --git a/ydb/library/yql/sql/v1/query.cpp b/ydb/library/yql/sql/v1/query.cpp index cc66bb0d3d..beb67703fb 100644 --- a/ydb/library/yql/sql/v1/query.cpp +++ b/ydb/library/yql/sql/v1/query.cpp @@ -872,6 +872,13 @@ public: YQL_ENSURE(false, "Can't reset TTL settings"); } } + if (const auto& tiering = Params.TableSettings.Tiering) { + if (tiering.IsSet()) { + settings = L(settings, Q(Y(Q("setTiering"), tiering.GetValueSet()))); + } else { + YQL_ENSURE(false, "Can't reset TIERING"); + } + } if (Params.TableSettings.StoreType) { const auto& ref = Params.TableSettings.StoreType.GetRef(); settings = L(settings, Q(Y(Q("storeType"), BuildQuotedAtom(ref.Pos, ref.Name)))); @@ -1049,6 +1056,13 @@ public: settings = L(settings, Q(Y(Q("resetTtlSettings"), Q(Y())))); } } + if (const auto& tiering = Params.TableSettings.Tiering) { + if (tiering.IsSet()) { + settings = L(settings, Q(Y(Q("setTiering"), tiering.GetValueSet()))); + } else { + settings = L(settings, Q(Y(Q("resetTiering"), Q(Y())))); + } + } actions = L(actions, Q(Y(Q("setTableSettings"), Q(settings)))); } @@ -1148,7 +1162,7 @@ public: auto opts = Y(); opts = L(opts, Q(Y(Q("mode"), Q("drop")))); - + if (TableType == ETableType::TableStore) { opts = L(opts, Q(Y(Q("tableType"), Q("tableStore")))); } diff --git a/ydb/library/yql/sql/v1/sql.cpp b/ydb/library/yql/sql/v1/sql.cpp index d2cca8d29e..fafa57f747 100644 --- a/ydb/library/yql/sql/v1/sql.cpp +++ b/ydb/library/yql/sql/v1/sql.cpp @@ -2334,6 +2334,17 @@ bool TSqlTranslation::StoreTableSettingsEntry(const TIdentifier& id, const TRule } else { settings.TtlSettings.Reset(); } + } else if (to_lower(id.Name) == "tiering") { + if (!reset) { + TNodePtr tieringNode; + if (!StoreString(*value, tieringNode, Ctx)) { + Ctx.Error() << to_upper(id.Name) << " value should be a string literal"; + return false; + } + settings.Tiering.Set(tieringNode); + } else { + settings.Tiering.Reset(); + } } else if (to_lower(id.Name) == "store") { if (reset) { Ctx.Error() << to_upper(id.Name) << " reset is not supported"; diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index 853147d324..f35080c29b 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -1559,7 +1559,7 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { auto expected = "(SqlCall '\"DateTime.FromString\" '((PositionalArgs (String '\"2022-01-01\")) (AsStruct)) (TupleType (TypeOf '((String '\"2022-01-01\"))) (TypeOf (AsStruct)) (TupleType (DataType 'String) (TupleType (DataType 'Int32) (DataType 'Float)))) '\"\" (Void))"; UNIT_ASSERT(programm.find(expected) != TString::npos); } - + Y_UNIT_TEST(UdfSyntaxSugarFullTest) { auto req = "SELECT Udf(DateTime::FromString, String, Tuple<Int32, Float>, 'foo' as TypeConfig, Void() As RunConfig)('2022-01-01');"; auto res = SqlToYql(req); @@ -1681,6 +1681,27 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]); } + Y_UNIT_TEST(TieringParseCorrect) { + NYql::TAstParseResult res = SqlToYql( + R"( USE plato; + CREATE TABLE tableName (Key Uint32, Value String, PRIMARY KEY (Key)) + WITH ( TIERING = 'my_tiering' );)" + ); + UNIT_ASSERT(res.Root); + + TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) { + if (word == "Write") { + UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("tiering")); + UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("my_tiering")); + } + }; + + TWordCountHive elementStat = { {TString("Write"), 0} }; + VerifyProgram(res, elementStat, verifyLine); + + UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]); + } + Y_UNIT_TEST(ChangefeedParseCorrect) { auto res = SqlToYql(R"( USE plato; CREATE TABLE tableName ( @@ -1869,6 +1890,10 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { UNIT_ASSERT(SqlToYql("USE plato; ALTER TABLE table SET (TTL = Interval(\"PT3H\") ON column)").IsOk()); } + Y_UNIT_TEST(AlterTableSetTieringIsCorrect) { + UNIT_ASSERT(SqlToYql("USE plato; ALTER TABLE table SET (TIERING = 'my_tiering')").IsOk()); + } + Y_UNIT_TEST(AlterTableAddChangefeedIsCorrect) { UNIT_ASSERT(SqlToYql("USE plato; ALTER TABLE table ADD CHANGEFEED feed WITH (MODE = 'UPDATES', FORMAT = 'json')").IsOk()); } @@ -2004,7 +2029,7 @@ Y_UNIT_TEST_SUITE(ExternalFunction) { } } -Y_UNIT_TEST_SUITE(SqlToYQLErrors) { +Y_UNIT_TEST_SUITE(SqlToYQLErrors) { Y_UNIT_TEST(UdfSyntaxSugarMissingCall) { auto req = "SELECT Udf(DateTime::FromString, \"foo\" as RunConfig);"; auto res = SqlToYql(req); |