diff --git a/ydb/library/yql/sql/v1/SQLv1.g.in b/ydb/library/yql/sql/v1/SQLv1.g.in index 05da99626b15..67790de6eae7 100644 --- a/ydb/library/yql/sql/v1/SQLv1.g.in +++ b/ydb/library/yql/sql/v1/SQLv1.g.in @@ -623,7 +623,7 @@ object_features: object_feature | LPAREN object_feature (COMMA object_feature)* object_type_ref: an_id_or_type; -create_table_stmt: CREATE (OR REPLACE)? (TABLE | TABLESTORE | EXTERNAL TABLE) (IF NOT EXISTS)? simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* COMMA? RPAREN +create_table_stmt: CREATE (OR REPLACE)? (TABLE | TABLESTORE | EXTERNAL TABLE | TEMP TABLE) (IF NOT EXISTS)? simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* COMMA? RPAREN table_inherits? table_partition_by? with_table_settings? 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 cef8e235cc83..b8aec0b08b25 100644 --- a/ydb/library/yql/sql/v1/format/sql_format_ut.cpp +++ b/ydb/library/yql/sql/v1/format/sql_format_ut.cpp @@ -307,7 +307,8 @@ Y_UNIT_TEST_SUITE(CheckSqlFormatter) { ")\n" "PARTITION BY HASH (a, b, hash)\n" "WITH (tiering = 'some');\n"}, - {"create table if not exists user(user int32)", "CREATE TABLE IF NOT EXISTS user (\n\tuser int32\n);\n"} + {"create table if not exists user(user int32)", "CREATE TABLE IF NOT EXISTS user (\n\tuser int32\n);\n"}, + {"create temp table user(user int32)", "CREATE TEMP TABLE user (\n\tuser int32\n);\n"} }; TSetup setup; diff --git a/ydb/library/yql/sql/v1/node.h b/ydb/library/yql/sql/v1/node.h index 8bb0ba2030bd..26c0d1d30aff 100644 --- a/ydb/library/yql/sql/v1/node.h +++ b/ydb/library/yql/sql/v1/node.h @@ -1046,6 +1046,7 @@ namespace NSQLTranslationV1 { TVector Changefeeds; TTableSettings TableSettings; ETableType TableType = ETableType::Table; + bool Temporary = false; }; struct TAlterTableParameters { diff --git a/ydb/library/yql/sql/v1/query.cpp b/ydb/library/yql/sql/v1/query.cpp index 4ea558ead15c..a9185ddf3413 100644 --- a/ydb/library/yql/sql/v1/query.cpp +++ b/ydb/library/yql/sql/v1/query.cpp @@ -1140,6 +1140,10 @@ class TCreateTableNode final: public TAstListNode { break; } + if (Params.Temporary) { + opts = L(opts, Q(Y(Q("temporary")))); + } + Add("block", Q(Y( Y("let", "sink", Y("DataSink", BuildQuotedAtom(Pos, Table.Service), Scoped->WrapCluster(Table.Cluster, ctx))), Y("let", "world", Y(TString(WriteName), "world", "sink", keys, Y("Void"), Q(opts))), diff --git a/ydb/library/yql/sql/v1/sql_query.cpp b/ydb/library/yql/sql/v1/sql_query.cpp index 1b450cc64018..c1576fffe546 100644 --- a/ydb/library/yql/sql/v1/sql_query.cpp +++ b/ydb/library/yql/sql/v1/sql_query.cpp @@ -166,10 +166,14 @@ bool TSqlQuery::Statement(TVector& blocks, const TRule_sql_stmt_core& const auto& block = rule.GetBlock3(); ETableType tableType = ETableType::Table; + bool temporary = false; if (block.HasAlt2() && block.GetAlt2().GetToken1().GetId() == SQLv1LexerTokens::TOKEN_TABLESTORE) { tableType = ETableType::TableStore; } else if (block.HasAlt3() && block.GetAlt3().GetToken1().GetId() == SQLv1LexerTokens::TOKEN_EXTERNAL) { tableType = ETableType::ExternalTable; + } else if (block.HasAlt4() && block.GetAlt4().GetToken1().GetId() == SQLv1LexerTokens::TOKEN_TEMP) { + temporary = true; + Y_DEBUG_ABORT_UNLESS(block.GetAlt4().GetToken2().GetId() == SQLv1LexerTokens::TOKEN_TABLE); } bool existingOk = false; @@ -193,7 +197,7 @@ bool TSqlQuery::Statement(TVector& blocks, const TRule_sql_stmt_core& return false; } - TCreateTableParameters params{.TableType=tableType}; + TCreateTableParameters params{.TableType=tableType, .Temporary=temporary}; if (!CreateTableEntry(rule.GetRule_create_table_entry7(), params)) { return false; } diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index 6da68c791bf7..a376b67b42bd 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -1007,6 +1007,23 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]); } + Y_UNIT_TEST(CreateTempTable) { + NYql::TAstParseResult res = SqlToYql("USE plato; CREATE TEMP TABLE t (a int32, primary key(a));"); + UNIT_ASSERT(res.Root); + + TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) { + if (word == "Write!") { + UNIT_ASSERT_VALUES_UNEQUAL_C(TString::npos, + line.find(R"__((Write! world sink (Key '('tablescheme (String '"t"))) (Void) '('('mode 'create) '('columns '('('"a" (AsOptionalType (DataType 'Int32)) '('columnConstrains '()) '()))) '('primarykey '('"a")) '('temporary))))__"), line); + } + }; + + TWordCountHive elementStat = {{TString("Write!"), 0}}; + VerifyProgram(res, elementStat, verifyLine); + + UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]); + } + Y_UNIT_TEST(CreateTableDuplicatedPkColumnsFail) { NYql::TAstParseResult res = SqlToYql("USE plato; CREATE TABLE t (a int32 not null, primary key(a, a));"); UNIT_ASSERT(!res.Root);