diff options
author | zhvv117 <[email protected]> | 2024-12-04 12:40:18 +0300 |
---|---|---|
committer | zhvv117 <[email protected]> | 2024-12-04 13:00:39 +0300 |
commit | 2e229c177b8e374062c3fd82fca76cccec5ec16e (patch) | |
tree | d35b8072ad46bb4ac96f5a9576ee0fe75ad9c614 /yql/essentials/sql/v1 | |
parent | aefea967d5f49fd714d0cd3d6083014d2c610a29 (diff) |
change EVALUATE IF and EVALUATE FOR formatting
commit_hash:435092fd6b4de1e8a0df445829d40475c5c4a166
Diffstat (limited to 'yql/essentials/sql/v1')
-rw-r--r-- | yql/essentials/sql/v1/format/sql_format.cpp | 50 | ||||
-rw-r--r-- | yql/essentials/sql/v1/format/sql_format_ut.h | 24 |
2 files changed, 18 insertions, 56 deletions
diff --git a/yql/essentials/sql/v1/format/sql_format.cpp b/yql/essentials/sql/v1/format/sql_format.cpp index 7422b37a938..bb8d20b9a00 100644 --- a/yql/essentials/sql/v1/format/sql_format.cpp +++ b/yql/essentials/sql/v1/format/sql_format.cpp @@ -1166,10 +1166,11 @@ private: } void VisitDo(const TRule_do_stmt& msg) { - NewLine(); VisitKeyword(msg.GetToken1()); switch (msg.GetBlock2().Alt_case()) { case TRule_do_stmt_TBlock2::kAlt1: { // CALL + PushCurrentIndent(); + NewLine(); const auto& alt = msg.GetBlock2().GetAlt1().GetRule_call_action1(); Visit(alt.GetBlock1()); AfterInvokeExpr = true; @@ -1177,8 +1178,9 @@ private: if (alt.HasBlock3()) { Visit(alt.GetBlock3()); } - Visit(alt.GetToken4()); + PopCurrentIndent(); + NewLine(); break; } case TRule_do_stmt_TBlock2::kAlt2: { // INLINE @@ -1222,52 +1224,12 @@ private: void VisitIf(const TRule_if_stmt& msg) { NewLine(); - if (msg.HasBlock1()) { - Visit(msg.GetBlock1()); - } - - Visit(msg.GetToken2()); - Visit(msg.GetRule_expr3()); - NewLine(); - PushCurrentIndent(); - Visit(msg.GetRule_do_stmt4()); - PopCurrentIndent(); - if (msg.HasBlock5()) { - NewLine(); - Visit(msg.GetBlock5().GetToken1()); - NewLine(); - PushCurrentIndent(); - Visit(msg.GetBlock5().GetRule_do_stmt2()); - PopCurrentIndent(); - } + VisitAllFields(TRule_if_stmt::GetDescriptor(), msg); } void VisitFor(const TRule_for_stmt& msg) { NewLine(); - if (msg.HasBlock1()) { - Visit(msg.GetBlock1()); - } - - if (msg.HasBlock2()) { - Visit(msg.GetBlock2()); - } - - Visit(msg.GetToken3()); - Visit(msg.GetRule_bind_parameter4()); - Visit(msg.GetToken5()); - Visit(msg.GetRule_expr6()); - NewLine(); - PushCurrentIndent(); - Visit(msg.GetRule_do_stmt7()); - PopCurrentIndent(); - if (msg.HasBlock8()) { - NewLine(); - Visit(msg.GetBlock8().GetToken1()); - NewLine(); - PushCurrentIndent(); - Visit(msg.GetBlock8().GetRule_do_stmt2()); - PopCurrentIndent(); - } + VisitAllFields(TRule_for_stmt::GetDescriptor(), msg); } void VisitValues(const TRule_values_stmt& msg) { diff --git a/yql/essentials/sql/v1/format/sql_format_ut.h b/yql/essentials/sql/v1/format/sql_format_ut.h index bed9e055abc..abf893c72eb 100644 --- a/yql/essentials/sql/v1/format/sql_format_ut.h +++ b/yql/essentials/sql/v1/format/sql_format_ut.h @@ -532,7 +532,7 @@ Y_UNIT_TEST(TopicExistsStatement) { Y_UNIT_TEST(Do) { TCases cases = { {"do $a(1,2,3)", - "DO $a(1, 2, 3);\n"}, + "DO\n\t$a(1, 2, 3)\n;\n"}, {"do begin values(1); end do;", "DO BEGIN\n\tVALUES\n\t\t(1);\nEND DO;\n"}, }; @@ -556,7 +556,7 @@ Y_UNIT_TEST(DefineActionOrSubquery) { "DEFINE ACTION $a() AS\n\tDEFINE ACTION $b() AS\n\t\t" "VALUES\n\t\t\t(1);\n\tEND DEFINE;\n\n\t" "DEFINE SUBQUERY $c() AS\n\t\tSELECT\n\t\t\t1;\n\t" - "END DEFINE;\n\tDO $b();\n\n\tPROCESS $c();\nEND DEFINE;\n"}, + "END DEFINE;\n\tDO\n\t\t$b()\n\t;\n\n\tPROCESS $c();\nEND DEFINE;\n"}, }; TSetup setup; @@ -566,14 +566,14 @@ Y_UNIT_TEST(DefineActionOrSubquery) { Y_UNIT_TEST(If) { TCases cases = { {"evaluate if 1=1 do $a()", - "EVALUATE IF 1 == 1\n\tDO $a();\n"}, + "EVALUATE IF 1 == 1 DO\n\t$a()\n;\n"}, {"evaluate if 1=1 do $a() else do $b()", - "EVALUATE IF 1 == 1\n\tDO $a()\nELSE\n\tDO $b();\n"}, + "EVALUATE IF 1 == 1 DO\n\t$a()\nELSE DO\n\t$b()\n;\n"}, {"evaluate if 1=1 do begin select 1; end do", - "EVALUATE IF 1 == 1\n\tDO BEGIN\n\t\tSELECT\n\t\t\t1;\n\tEND DO;\n"}, + "EVALUATE IF 1 == 1 DO BEGIN\n\tSELECT\n\t\t1;\nEND DO;\n"}, {"evaluate if 1=1 do begin select 1; end do else do begin select 2; end do", - "EVALUATE IF 1 == 1\n\tDO BEGIN\n\t\tSELECT\n\t\t\t1;\n\tEND DO\n" - "ELSE\n\tDO BEGIN\n\t\tSELECT\n\t\t\t2;\n\tEND DO;\n"}, + "EVALUATE IF 1 == 1 DO BEGIN\n\tSELECT\n\t\t1;\nEND DO " + "ELSE DO BEGIN\n\tSELECT\n\t\t2;\nEND DO;\n"}, }; TSetup setup; @@ -583,15 +583,15 @@ Y_UNIT_TEST(If) { Y_UNIT_TEST(For) { TCases cases = { {"evaluate for $x in [] do $a($x)", - "EVALUATE FOR $x IN []\n\tDO $a($x);\n"}, + "EVALUATE FOR $x IN [] DO\n\t$a($x)\n;\n"}, {"evaluate for $x in [] do $a($x) else do $b()", - "EVALUATE FOR $x IN []\n\tDO $a($x)\nELSE\n\tDO $b();\n"}, + "EVALUATE FOR $x IN [] DO\n\t$a($x)\nELSE DO\n\t$b()\n;\n"}, {"evaluate for $x in [] do begin select $x; end do", - "EVALUATE FOR $x IN []\n\tDO BEGIN\n\t\tSELECT\n\t\t\t$x;\n\tEND DO;\n"}, + "EVALUATE FOR $x IN [] DO BEGIN\n\tSELECT\n\t\t$x;\nEND DO;\n"}, {"evaluate for $x in [] do begin select $x; end do else do begin select 2; end do", - "EVALUATE FOR $x IN []\n\tDO BEGIN\n\t\tSELECT\n\t\t\t$x;\n\tEND DO\nELSE\n\tDO BEGIN\n\t\tSELECT\n\t\t\t2;\n\tEND DO;\n"}, + "EVALUATE FOR $x IN [] DO BEGIN\n\tSELECT\n\t\t$x;\nEND DO ELSE DO BEGIN\n\tSELECT\n\t\t2;\nEND DO;\n"}, {"evaluate parallel for $x in [] do $a($x)", - "EVALUATE PARALLEL FOR $x IN []\n\tDO $a($x);\n"}, + "EVALUATE PARALLEL FOR $x IN [] DO\n\t$a($x)\n;\n"}, }; TSetup setup; |