aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ydb/library/yql/sql/v1/format/sql_format.cpp43
-rw-r--r--ydb/library/yql/sql/v1/format/sql_format_ut.cpp12
2 files changed, 42 insertions, 13 deletions
diff --git a/ydb/library/yql/sql/v1/format/sql_format.cpp b/ydb/library/yql/sql/v1/format/sql_format.cpp
index 90cd1e3cce..b2088089a6 100644
--- a/ydb/library/yql/sql/v1/format/sql_format.cpp
+++ b/ydb/library/yql/sql/v1/format/sql_format.cpp
@@ -424,6 +424,10 @@ private:
AfterInvokeExpr = true;
}
+ if (descr == TRule_unary_op::GetDescriptor()) {
+ AfterUnaryOp = true;
+ }
+
if (scopePtr) {
if (*scopePtr == EScope::TypeName) {
++InsideType;
@@ -1156,19 +1160,30 @@ private:
//Cerr << str << "\n";
auto currentScope = Scopes.back();
- if (AfterLess && str == ">") {
- Out(' ');
- } else if (AfterDigits && str == ".") {
- Out(' ');
- } else if (OutColumn && (currentScope == EScope::DoubleQuestion || str != "?")
- && str != ":" && str != "." && str != "," && str != ";" && str != ")" && str != "]"
- && str != "}" && str != "|>" && str != "::" && !AfterNamespace && !AfterBracket
- && !AfterInvokeExpr && !AfterDollarOrAt && !AfterDot && (!AfterQuestion || str != "?")
- && (!InsideType || (str != "<" && str != ">" && str != "<>"))
- && (!InsideType || !AfterLess)
- && (!AfterKeyExpr || str != "[")
- ) {
- Out(' ');
+ if (!SkipSpaceAfterUnaryOp) {
+ if (AfterLess && str == ">") {
+ Out(' ');
+ } else if (AfterDigits && str == ".") {
+ Out(' ');
+ } else if (OutColumn && (currentScope == EScope::DoubleQuestion || str != "?")
+ && str != ":" && str != "." && str != "," && str != ";" && str != ")" && str != "]"
+ && str != "}" && str != "|>" && str != "::" && !AfterNamespace && !AfterBracket
+ && !AfterInvokeExpr && !AfterDollarOrAt && !AfterDot && (!AfterQuestion || str != "?")
+ && (!InsideType || (str != "<" && str != ">" && str != "<>"))
+ && (!InsideType || !AfterLess)
+ && (!AfterKeyExpr || str != "[")
+ ) {
+ Out(' ');
+ }
+ }
+
+ SkipSpaceAfterUnaryOp = false;
+ if (AfterUnaryOp) {
+ if (str == "+" || str == "-" || str == "~") {
+ SkipSpaceAfterUnaryOp = true;
+ }
+
+ AfterUnaryOp = false;
}
AfterInvokeExpr = false;
@@ -1901,6 +1916,8 @@ private:
bool AfterNamespace = false;
bool AfterBracket = false;
bool AfterInvokeExpr = false;
+ bool AfterUnaryOp = false;
+ bool SkipSpaceAfterUnaryOp = false;
bool AfterDollarOrAt = false;
bool AfterDot = false;
bool AfterDigits = false;
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 41a6b5fd0e..87c1b56598 100644
--- a/ydb/library/yql/sql/v1/format/sql_format_ut.cpp
+++ b/ydb/library/yql/sql/v1/format/sql_format_ut.cpp
@@ -1183,4 +1183,16 @@ Y_UNIT_TEST_SUITE(CheckSqlFormatter) {
TSetup setup;
setup.Run(cases);
}
+
+ Y_UNIT_TEST(UnaryOp) {
+ TCases cases = {
+ {"select -x,+x,~x,-1,-1.0,+1,+1.0,~1u",
+ "SELECT\n\t-x,\n\t+x,\n\t~x,\n\t-1,\n\t-1.0,\n\t+1,\n\t+1.0,\n\t~1u;\n\n"},
+ };
+
+ TSetup setup;
+ setup.Run(cases);
+ }
+
+
}