summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/sql_into_tables.cpp
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/sql/v1/sql_into_tables.cpp
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/sql/v1/sql_into_tables.cpp')
-rw-r--r--yql/essentials/sql/v1/sql_into_tables.cpp58
1 files changed, 36 insertions, 22 deletions
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: