diff options
| author | vitya-smirnov <[email protected]> | 2025-07-09 14:16:01 +0300 |
|---|---|---|
| committer | vitya-smirnov <[email protected]> | 2025-07-09 14:38:43 +0300 |
| commit | 59c3167c208900bb714ff5cc477476e3ab14f4f0 (patch) | |
| tree | 043a4d70e21ede0da9df08806fe5a8c0d656e201 /yql/essentials/sql/v1/format/sql_format.cpp | |
| parent | 40a6e6e096b3533857b70c79a8ac9820655c7bf3 (diff) | |
YQL-17269: Support UNION/INTERSECT/EXCEPT combinations
Introduce `UNION` and `INTERSECT/EXCEPT` grammar rules
for precedence. Rewrote `Build` procedure into `BuildStmt`,
`BuildUnion`, `BuildIntersection`. Added tests, modify format.
It took a lot of time trying to adapt the existing `Build` procedure.
The I noticed that the logic for `union` and `intersection` is
different, since `union` groups arguments into bundles, but
`intersection` is a strictly binary operation.
commit_hash:70008ae3c2603364b6dfbeeb189fdc7f5237433d
Diffstat (limited to 'yql/essentials/sql/v1/format/sql_format.cpp')
| -rw-r--r-- | yql/essentials/sql/v1/format/sql_format.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/yql/essentials/sql/v1/format/sql_format.cpp b/yql/essentials/sql/v1/format/sql_format.cpp index 4979a75d4e8..e45adc280d8 100644 --- a/yql/essentials/sql/v1/format/sql_format.cpp +++ b/yql/essentials/sql/v1/format/sql_format.cpp @@ -833,10 +833,21 @@ private: void VisitSelect(const TRule_select_stmt& msg) { NewLine(); + Visit(msg.GetRule_select_stmt_intersect1()); + for (const auto& block : msg.GetBlock2()) { + NewLine(); + Visit(block.GetRule_union_op1()); + NewLine(); + Visit(block.GetRule_select_stmt_intersect2()); + } + } + + void VisitSelectIntersect(const TRule_select_stmt_intersect& msg) { + NewLine(); Visit(msg.GetRule_select_kind_parenthesis1()); for (const auto& block : msg.GetBlock2()) { NewLine(); - Visit(block.GetRule_select_op1()); + Visit(block.GetRule_intersect_op1()); NewLine(); Visit(block.GetRule_select_kind_parenthesis2()); } @@ -844,10 +855,21 @@ private: void VisitSelectUnparenthesized(const TRule_select_unparenthesized_stmt& msg) { NewLine(); + Visit(msg.GetRule_select_unparenthesized_stmt_intersect1()); + for (const auto& block : msg.GetBlock2()) { + NewLine(); + Visit(block.GetRule_union_op1()); + NewLine(); + Visit(block.GetRule_select_stmt_intersect2()); + } + } + + void VisitSelectUnparenthesizedIntersect(const TRule_select_unparenthesized_stmt_intersect& msg) { + NewLine(); Visit(msg.GetRule_select_kind_partial1()); for (const auto& block : msg.GetBlock2()) { NewLine(); - Visit(block.GetRule_select_op1()); + Visit(block.GetRule_intersect_op1()); NewLine(); Visit(block.GetRule_select_kind_parenthesis2()); } @@ -3012,7 +3034,9 @@ TStaticData::TStaticData() {TRule_pragma_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitPragma)}, {TRule_select_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitSelect)}, + {TRule_select_stmt_intersect::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitSelectIntersect)}, {TRule_select_unparenthesized_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitSelectUnparenthesized)}, + {TRule_select_unparenthesized_stmt_intersect::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitSelectUnparenthesizedIntersect)}, {TRule_named_nodes_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitNamedNodes)}, {TRule_create_table_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitCreateTable)}, {TRule_drop_table_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitDropTable)}, |
