summaryrefslogtreecommitdiffstats
path: root/yql/essentials
diff options
context:
space:
mode:
authorvitya-smirnov <[email protected]>2025-08-13 16:27:43 +0300
committervitya-smirnov <[email protected]>2025-08-13 17:02:13 +0300
commit3b79116cac370b648c75323b866927d32aab08f4 (patch)
tree6bee7aeb2461e72070e8d85f1043c2278bea5944 /yql/essentials
parent0412ed8db0700d3897e00be3a0cad6b2e8625883 (diff)
YQL-20257: Parse cluster at simple_table_ref bind_parameter
- Add `cluster_expr` to `simple_table_ref_core` alternative. - Added `Sql2Yql` unit test with a statement that is not parsed on trunk: https://nda.ya.ru/t/qHRri7r57HK3r2. commit_hash:eada89e88e3f2bc03c47cd22b73ba58b75f20681
Diffstat (limited to 'yql/essentials')
-rw-r--r--yql/essentials/sql/v1/SQLv1.g.in2
-rw-r--r--yql/essentials/sql/v1/SQLv1Antlr4.g.in2
-rw-r--r--yql/essentials/sql/v1/complete/name/cache/local/cache.h2
-rw-r--r--yql/essentials/sql/v1/sql_into_tables.cpp58
-rw-r--r--yql/essentials/sql/v1/sql_translation.cpp15
-rw-r--r--yql/essentials/sql/v1/sql_ut_common.h16
6 files changed, 63 insertions, 32 deletions
diff --git a/yql/essentials/sql/v1/SQLv1.g.in b/yql/essentials/sql/v1/SQLv1.g.in
index b8892cc449d..55b650d796a 100644
--- a/yql/essentials/sql/v1/SQLv1.g.in
+++ b/yql/essentials/sql/v1/SQLv1.g.in
@@ -982,7 +982,7 @@ table_hint:
;
object_ref: (cluster_expr DOT)? id_or_at;
-simple_table_ref_core: object_ref | COMMAT? bind_parameter;
+simple_table_ref_core: object_ref | (cluster_expr DOT)? COMMAT? bind_parameter;
simple_table_ref: simple_table_ref_core table_hints?;
into_simple_table_ref: simple_table_ref (ERASE BY pure_column_list)?;
diff --git a/yql/essentials/sql/v1/SQLv1Antlr4.g.in b/yql/essentials/sql/v1/SQLv1Antlr4.g.in
index 421efdd3ee4..fa26fd74415 100644
--- a/yql/essentials/sql/v1/SQLv1Antlr4.g.in
+++ b/yql/essentials/sql/v1/SQLv1Antlr4.g.in
@@ -982,7 +982,7 @@ table_hint:
;
object_ref: (cluster_expr DOT)? id_or_at;
-simple_table_ref_core: object_ref | COMMAT? bind_parameter;
+simple_table_ref_core: object_ref | (cluster_expr DOT)? COMMAT? bind_parameter;
simple_table_ref: simple_table_ref_core table_hints?;
into_simple_table_ref: simple_table_ref (ERASE BY pure_column_list)?;
diff --git a/yql/essentials/sql/v1/complete/name/cache/local/cache.h b/yql/essentials/sql/v1/complete/name/cache/local/cache.h
index 9e4438f0022..b5149caa608 100644
--- a/yql/essentials/sql/v1/complete/name/cache/local/cache.h
+++ b/yql/essentials/sql/v1/complete/name/cache/local/cache.h
@@ -60,7 +60,7 @@ namespace NSQLComplete {
with_lock (Mutex_) {
if (auto it = Origin_.Find(key); it != Origin_.End()) {
entry.Value = it->Value;
- entry.IsExpired = (it->Deadline < Clock_->Now());
+ entry.IsExpired = (it->Deadline <= Clock_->Now());
}
}
diff --git a/yql/essentials/sql/v1/sql_into_tables.cpp b/yql/essentials/sql/v1/sql_into_tables.cpp
index c4b4fd0c21a..2bdd48a81d1 100644
--- a/yql/essentials/sql/v1/sql_into_tables.cpp
+++ b/yql/essentials/sql/v1/sql_into_tables.cpp
@@ -90,31 +90,49 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
auto cluster = Ctx_.Scoped->CurrCluster;
std::pair<bool, TDeferredAtom> nameOrAt;
bool isBinding = false;
- switch (tableRefCore.Alt_case()) {
- case TRule_simple_table_ref_core::AltCase::kAltSimpleTableRefCore1: {
- if (tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().HasBlock1()) {
- const auto& clusterExpr = tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().GetBlock1().GetRule_cluster_expr1();
- bool hasAt = tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().GetRule_id_or_at2().HasBlock1();
- bool result = !hasAt ?
- ClusterExprOrBinding(clusterExpr, service, cluster, isBinding) : ClusterExpr(clusterExpr, false, service, cluster);
- if (!result) {
- return nullptr;
- }
- }
- if (!isBinding && cluster.Empty()) {
- Ctx_.Error() << "No cluster name given and no default cluster is selected";
- return nullptr;
- }
+ const bool isClusterSpecified = (
+ (tableRefCore.HasAlt_simple_table_ref_core1() &&
+ tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().HasBlock1()) ||
+ (tableRefCore.HasAlt_simple_table_ref_core2() &&
+ tableRefCore.GetAlt_simple_table_ref_core2().HasBlock1())
+ );
+
+ const bool hasAt = (
+ (tableRefCore.HasAlt_simple_table_ref_core1() &&
+ tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().GetRule_id_or_at2().HasBlock1()) ||
+ (tableRefCore.HasAlt_simple_table_ref_core2() &&
+ tableRefCore.GetAlt_simple_table_ref_core2().HasBlock2())
+ );
+
+ if (isClusterSpecified) {
+ const auto& clusterExpr = tableRefCore.HasAlt_simple_table_ref_core1()
+ ? tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().GetBlock1().GetRule_cluster_expr1()
+ : tableRefCore.GetAlt_simple_table_ref_core2().GetBlock1().GetRule_cluster_expr1();
+
+ const bool result = !hasAt
+ ? ClusterExprOrBinding(clusterExpr, service, cluster, isBinding)
+ : ClusterExpr(clusterExpr, false, service, cluster);
+
+ if (!result) {
+ return nullptr;
+ }
+ }
+ if (!isBinding && cluster.Empty()) {
+ Ctx_.Error() << "No cluster name given and no default cluster is selected";
+ return nullptr;
+ }
+
+ switch (tableRefCore.Alt_case()) {
+ case TRule_simple_table_ref_core::AltCase::kAltSimpleTableRefCore1: {
auto id = Id(tableRefCore.GetAlt_simple_table_ref_core1().GetRule_object_ref1().GetRule_id_or_at2(), *this);
nameOrAt = std::make_pair(id.first, TDeferredAtom(Ctx_.Pos(), id.second));
break;
}
case TRule_simple_table_ref_core::AltCase::kAltSimpleTableRefCore2: {
- auto at = tableRefCore.GetAlt_simple_table_ref_core2().HasBlock1();
TString name;
- if (!NamedNodeImpl(tableRefCore.GetAlt_simple_table_ref_core2().GetRule_bind_parameter2(), name, *this)) {
+ if (!NamedNodeImpl(tableRefCore.GetAlt_simple_table_ref_core2().GetRule_bind_parameter3(), name, *this)) {
return nullptr;
}
auto named = GetNamedNode(name);
@@ -123,14 +141,10 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
}
named->SetRefPos(Ctx_.Pos());
- if (cluster.Empty()) {
- Ctx_.Error() << "No cluster name given and no default cluster is selected";
- return nullptr;
- }
TDeferredAtom table;
MakeTableFromExpression(Ctx_.Pos(), Ctx_, named, table);
- nameOrAt = std::make_pair(at, table);
+ nameOrAt = std::make_pair(hasAt, table);
break;
}
case TRule_simple_table_ref_core::AltCase::ALT_NOT_SET:
diff --git a/yql/essentials/sql/v1/sql_translation.cpp b/yql/essentials/sql/v1/sql_translation.cpp
index f4adf24ce62..52b1dc75dd4 100644
--- a/yql/essentials/sql/v1/sql_translation.cpp
+++ b/yql/essentials/sql/v1/sql_translation.cpp
@@ -3648,11 +3648,6 @@ bool TSqlTranslation::SimpleTableRefCoreImpl(const TRule_simple_table_ref_core&
switch (node.Alt_case()) {
case TRule_simple_table_ref_core::AltCase::kAltSimpleTableRefCore1: {
if (node.GetAlt_simple_table_ref_core1().GetRule_object_ref1().HasBlock1()) {
- if (Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW) {
- Error() << "Cluster should not be used in limited view";
- return false;
- }
-
if (!ClusterExpr(node.GetAlt_simple_table_ref_core1().GetRule_object_ref1().GetBlock1().GetRule_cluster_expr1(), false, service, cluster)) {
return false;
}
@@ -3671,14 +3666,20 @@ bool TSqlTranslation::SimpleTableRefCoreImpl(const TRule_simple_table_ref_core&
break;
}
case TRule_simple_table_ref_core::AltCase::kAltSimpleTableRefCore2: {
+ if (node.GetAlt_simple_table_ref_core2().HasBlock1()) {
+ if (!ClusterExpr(node.GetAlt_simple_table_ref_core2().GetBlock1().GetRule_cluster_expr1(), false, service, cluster)) {
+ return false;
+ }
+ }
+
if (cluster.Empty()) {
Error() << "No cluster name given and no default cluster is selected";
return false;
}
- auto at = node.GetAlt_simple_table_ref_core2().HasBlock1();
+ auto at = node.GetAlt_simple_table_ref_core2().HasBlock2();
TString bindName;
- if (!NamedNodeImpl(node.GetAlt_simple_table_ref_core2().GetRule_bind_parameter2(), bindName, *this)) {
+ if (!NamedNodeImpl(node.GetAlt_simple_table_ref_core2().GetRule_bind_parameter3(), bindName, *this)) {
return false;
}
auto named = GetNamedNode(bindName);
diff --git a/yql/essentials/sql/v1/sql_ut_common.h b/yql/essentials/sql/v1/sql_ut_common.h
index e9cc67e0e3b..95bd2ce5e40 100644
--- a/yql/essentials/sql/v1/sql_ut_common.h
+++ b/yql/essentials/sql/v1/sql_ut_common.h
@@ -2170,6 +2170,14 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
UNIT_ASSERT(res.Root);
}
+ Y_UNIT_TEST(InsertIntoNamedExpr) {
+ NYql::TAstParseResult res = SqlToYql(R"sql(
+ $target = "target";
+ INSERT INTO plato.$target (x) VALUES ((1));
+ )sql");
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(WarnMissingIsBeforeNotNull) {
NYql::TAstParseResult res = SqlToYql("select 1 NOT NULL");
UNIT_ASSERT(res.Root);
@@ -4988,6 +4996,14 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
}
+ Y_UNIT_TEST(DropTableNamedNode) {
+ NYql::TAstParseResult res = SqlToYql(R"sql(
+ $x = "y";
+ DROP TABLE plato.$x;
+ )sql");
+ UNIT_ASSERT_C(res.Root, res.Issues.ToString());
+ }
+
Y_UNIT_TEST(TooManyErrors) {
const char* q = R"(
USE plato;