diff options
| author | zhvv117 <[email protected]> | 2024-12-13 19:30:08 +0300 |
|---|---|---|
| committer | zhvv117 <[email protected]> | 2024-12-13 20:29:52 +0300 |
| commit | 8afd0e6dc9d41134a0cccfd6b6c5fe843efd80fb (patch) | |
| tree | 23189019cfd74abfbc507c2a9e6d6fd58f360c6c /yql/essentials/sql | |
| parent | 9eadcaf3657f3c430e7c845f68d80e3bbb5a2b4d (diff) | |
change double quotes to single quotes
commit_hash:7890ab16bc6488d4f13fd6ec6cd512107c0cba51
Diffstat (limited to 'yql/essentials/sql')
| -rw-r--r-- | yql/essentials/sql/v1/format/sql_format.cpp | 20 | ||||
| -rw-r--r-- | yql/essentials/sql/v1/format/sql_format_ut.h | 64 |
2 files changed, 52 insertions, 32 deletions
diff --git a/yql/essentials/sql/v1/format/sql_format.cpp b/yql/essentials/sql/v1/format/sql_format.cpp index 8c4b04760f1..72007d15e27 100644 --- a/yql/essentials/sql/v1/format/sql_format.cpp +++ b/yql/essentials/sql/v1/format/sql_format.cpp @@ -87,6 +87,15 @@ TParsedToken TransformTokenForValidate(TParsedToken token) { return token; } +TStringBuf SkipQuotes(const TString& content) { + TStringBuf str = content; + str.SkipPrefix("\""); + str.ChopSuffix("\""); + str.SkipPrefix("'"); + str.ChopSuffix("'"); + return str; +} + bool Validate(const TParsedTokenList& query, const TParsedTokenList& formattedQuery) { auto in = query.begin(); auto out = formattedQuery.begin(); @@ -105,6 +114,10 @@ bool Validate(const TParsedTokenList& query, const TParsedTokenList& formattedQu if (!AsciiEqualsIgnoreCase(inToken.Content, outToken.Content)) { return false; } + } else if (inToken.Name == "STRING_VALUE") { + if (SkipQuotes(inToken.Content) != SkipQuotes(outToken.Content)) { + return false; + } } else { if (inToken.Content != outToken.Content) { return false; @@ -1698,6 +1711,13 @@ private: } } + if (ParsedTokens[TokenIndex].Name == "STRING_VALUE") { + TStringBuf checkStr = str; + if (checkStr.SkipPrefix("\"") && checkStr.ChopSuffix("\"") && !checkStr.Contains("'")) { + str = TStringBuilder() << '\'' << checkStr << '\''; + } + } + Out(str); if (TokenIndex + 1 >= ParsedTokens.size() || ParsedTokens[TokenIndex + 1].Line > LastLine) { diff --git a/yql/essentials/sql/v1/format/sql_format_ut.h b/yql/essentials/sql/v1/format/sql_format_ut.h index 79272673789..c56c5636b7f 100644 --- a/yql/essentials/sql/v1/format/sql_format_ut.h +++ b/yql/essentials/sql/v1/format/sql_format_ut.h @@ -329,20 +329,20 @@ Y_UNIT_TEST(TableStoreOperations) { Y_UNIT_TEST(ExternalDataSourceOperations) { TCases cases = { {"creAte exTernAl daTa SouRce usEr With (a = \"b\")", - "CREATE EXTERNAL DATA SOURCE usEr WITH (a = \"b\");\n"}, - {"creAte exTernAl daTa SouRce if not exists usEr With (a = \"b\")", - "CREATE EXTERNAL DATA SOURCE IF NOT EXISTS usEr WITH (a = \"b\");\n"}, - {"creAte oR rePlaCe exTernAl daTa SouRce usEr With (a = \"b\")", - "CREATE OR REPLACE EXTERNAL DATA SOURCE usEr WITH (a = \"b\");\n"}, - {"create external data source eds with (a=\"a\",b=\"b\",c = true)", - "CREATE EXTERNAL DATA SOURCE eds WITH (\n\ta = \"a\",\n\tb = \"b\",\n\tc = TRUE\n);\n"}, - {"alter external data source eds set a true, reset (b, c), set (x=y, z=false)", + "CREATE EXTERNAL DATA SOURCE usEr WITH (a = 'b');\n"}, + {"creAte exTernAl daTa SouRce if not exists usEr With (a = \"b\")", + "CREATE EXTERNAL DATA SOURCE IF NOT EXISTS usEr WITH (a = 'b');\n"}, + {"creAte oR rePlaCe exTernAl daTa SouRce usEr With (a = \"b\")", + "CREATE OR REPLACE EXTERNAL DATA SOURCE usEr WITH (a = 'b');\n"}, + {"create external data source eds with (a=\"a\",b=\"b\",c = true)", + "CREATE EXTERNAL DATA SOURCE eds WITH (\n\ta = 'a',\n\tb = 'b',\n\tc = TRUE\n);\n"}, + {"alter external data source eds set a true, reset (b, c), set (x=y, z=false)", "ALTER EXTERNAL DATA SOURCE eds\n\tSET a TRUE,\n\tRESET (b, c),\n\tSET (x = y, z = FALSE)\n;\n"}, - {"alter external data source eds reset (a), set (x=y)", + {"alter external data source eds reset (a), set (x=y)", "ALTER EXTERNAL DATA SOURCE eds\n\tRESET (a),\n\tSET (x = y)\n;\n"}, {"dRop exTerNal Data SouRce usEr", "DROP EXTERNAL DATA SOURCE usEr;\n"}, - {"dRop exTerNal Data SouRce if exists usEr", + {"dRop exTerNal Data SouRce if exists usEr", "DROP EXTERNAL DATA SOURCE IF EXISTS usEr;\n"}, }; @@ -369,13 +369,13 @@ Y_UNIT_TEST(AsyncReplication) { Y_UNIT_TEST(ExternalTableOperations) { TCases cases = { {"creAte exTernAl TabLe usEr (a int) With (a = \"b\")", - "CREATE EXTERNAL TABLE usEr (\n\ta int\n)\nWITH (a = \"b\");\n"}, + "CREATE EXTERNAL TABLE usEr (\n\ta int\n)\nWITH (a = 'b');\n"}, {"creAte oR rePlaCe exTernAl TabLe usEr (a int) With (a = \"b\")", - "CREATE OR REPLACE EXTERNAL TABLE usEr (\n\ta int\n)\nWITH (a = \"b\");\n"}, + "CREATE OR REPLACE EXTERNAL TABLE usEr (\n\ta int\n)\nWITH (a = 'b');\n"}, {"creAte exTernAl TabLe iF NOt Exists usEr (a int) With (a = \"b\")", - "CREATE EXTERNAL TABLE IF NOT EXISTS usEr (\n\ta int\n)\nWITH (a = \"b\");\n"}, + "CREATE EXTERNAL TABLE IF NOT EXISTS usEr (\n\ta int\n)\nWITH (a = 'b');\n"}, {"create external table user (a int) with (a=\"b\",c=\"d\")", - "CREATE EXTERNAL TABLE user (\n\ta int\n)\nWITH (\n\ta = \"b\",\n\tc = \"d\"\n);\n"}, + "CREATE EXTERNAL TABLE user (\n\ta int\n)\nWITH (\n\ta = 'b',\n\tc = 'd'\n);\n"}, {"alter external table user add column col1 int32, drop column col2, reset(prop), set (prop2 = 42, x=y), set a true", "ALTER EXTERNAL TABLE user\n\tADD COLUMN col1 int32,\n\tDROP COLUMN col2,\n\tRESET (prop),\n\tSET (prop2 = 42, x = y),\n\tSET a TRUE\n;\n"}, {"dRop exTerNal taBlE usEr", @@ -455,13 +455,13 @@ Y_UNIT_TEST(AlterTable) { {"alter table user add changefeed user with (initial_scan = FaLsE)", "ALTER TABLE user\n\tADD CHANGEFEED user WITH (initial_scan = FALSE)\n;\n"}, {"alter table user add changefeed user with (retention_period = Interval(\"P1D\"))", - "ALTER TABLE user\n\tADD CHANGEFEED user WITH (retention_period = Interval(\"P1D\"))\n;\n"}, + "ALTER TABLE user\n\tADD CHANGEFEED user WITH (retention_period = Interval('P1D'))\n;\n"}, {"alter table user add changefeed user with (virtual_timestamps = TruE)", "ALTER TABLE user\n\tADD CHANGEFEED user WITH (virtual_timestamps = TRUE)\n;\n"}, {"alter table user add changefeed user with (virtual_timestamps = fAlSe)", "ALTER TABLE user\n\tADD CHANGEFEED user WITH (virtual_timestamps = FALSE)\n;\n"}, {"alter table user add changefeed user with (barriers_interval = Interval(\"PT1S\"))", - "ALTER TABLE user\n\tADD CHANGEFEED user WITH (barriers_interval = Interval(\"PT1S\"))\n;\n"}, + "ALTER TABLE user\n\tADD CHANGEFEED user WITH (barriers_interval = Interval('PT1S'))\n;\n"}, {"alter table user add changefeed user with (topic_min_active_partitions = 1)", "ALTER TABLE user\n\tADD CHANGEFEED user WITH (topic_min_active_partitions = 1)\n;\n"}, {"alter table user add changefeed user with (topic_auto_partitioning = 'ENABLED', topic_min_active_partitions = 1, topic_max_active_partitions = 7)", @@ -1394,7 +1394,7 @@ FROM Input MATCH_RECOGNIZE( DEFINE A as A, B as B ); )", -R"(PRAGMA FeatureR010 = "prototype"; +R"(PRAGMA FeatureR010 = 'prototype'; USE plato; @@ -1649,12 +1649,12 @@ Y_UNIT_TEST(DropView) { Y_UNIT_TEST(ResourcePoolOperations) { TCases cases = { {"creAte reSourCe poOl naMe With (a = \"b\")", - "CREATE RESOURCE POOL naMe WITH (a = \"b\");\n"}, - {"create resource pool eds with (a=\"a\",b=\"b\",c = true)", - "CREATE RESOURCE POOL eds WITH (\n\ta = \"a\",\n\tb = \"b\",\n\tc = TRUE\n);\n"}, - {"alTer reSOurcE poOl naMe resEt (b, c), seT (x=y, z=false)", + "CREATE RESOURCE POOL naMe WITH (a = 'b');\n"}, + {"create resource pool eds with (a=\"a\",b=\"b\",c = true)", + "CREATE RESOURCE POOL eds WITH (\n\ta = 'a',\n\tb = 'b',\n\tc = TRUE\n);\n"}, + {"alTer reSOurcE poOl naMe resEt (b, c), seT (x=y, z=false)", "ALTER RESOURCE POOL naMe\n\tRESET (b, c),\n\tSET (x = y, z = FALSE)\n;\n"}, - {"alter resource pool eds reset (a), set (x=y)", + {"alter resource pool eds reset (a), set (x=y)", "ALTER RESOURCE POOL eds\n\tRESET (a),\n\tSET (x = y)\n;\n"}, {"dRop reSourCe poOl naMe", "DROP RESOURCE POOL naMe;\n"}, @@ -1667,11 +1667,11 @@ Y_UNIT_TEST(ResourcePoolOperations) { Y_UNIT_TEST(BackupCollectionOperations) { TCases cases = { {"creAte BackuP colLection `-naMe` wIth (a = \"b\")", - "CREATE BACKUP COLLECTION `-naMe` WITH (a = \"b\");\n"}, - {"creAte BackuP colLection `-naMe` DATabase wIth (a = \"b\")", - "CREATE BACKUP COLLECTION `-naMe` DATABASE WITH (a = \"b\");\n"}, + "CREATE BACKUP COLLECTION `-naMe` WITH (a = 'b');\n"}, + {"creAte BackuP colLection `-naMe` DATabase wIth (a = 'b')", + "CREATE BACKUP COLLECTION `-naMe` DATABASE WITH (a = 'b');\n"}, {"creAte BackuP colLection `-naMe` ( tabLe `tbl1` , TablE `tbl2`) wIth (a = \"b\")", - "CREATE BACKUP COLLECTION `-naMe` (TABLE `tbl1`, TABLE `tbl2`) WITH (a = \"b\");\n"}, + "CREATE BACKUP COLLECTION `-naMe` (TABLE `tbl1`, TABLE `tbl2`) WITH (a = 'b');\n"}, {"alTer bACKuP coLLECTION naMe resEt (b, c), seT (x=y, z=false)", "ALTER BACKUP COLLECTION naMe\n\tRESET (b, c),\n\tSET (x = y, z = FALSE)\n;\n"}, {"alTer bACKuP coLLECTION naMe aDD DATAbase", @@ -1692,7 +1692,7 @@ Y_UNIT_TEST(Analyze) { TCases cases = { {"analyze table (col1, col2, col3)", "ANALYZE table (col1, col2, col3);\n"}, - {"analyze table", + {"analyze table", "ANALYZE table;\n"} }; @@ -1703,12 +1703,12 @@ Y_UNIT_TEST(Analyze) { Y_UNIT_TEST(ResourcePoolClassifierOperations) { TCases cases = { {"creAte reSourCe poOl ClaSsiFIer naMe With (a = \"b\")", - "CREATE RESOURCE POOL CLASSIFIER naMe WITH (a = \"b\");\n"}, - {"create resource pool classifier eds with (a=\"a\",b=\"b\",c = true)", - "CREATE RESOURCE POOL CLASSIFIER eds WITH (\n\ta = \"a\",\n\tb = \"b\",\n\tc = TRUE\n);\n"}, - {"alTer reSOurcE poOl ClaSsiFIer naMe resEt (b, c), seT (x=y, z=false)", + "CREATE RESOURCE POOL CLASSIFIER naMe WITH (a = 'b');\n"}, + {"create resource pool classifier eds with (a=\"a\",b=\"b\",c = true)", + "CREATE RESOURCE POOL CLASSIFIER eds WITH (\n\ta = 'a',\n\tb = 'b',\n\tc = TRUE\n);\n"}, + {"alTer reSOurcE poOl ClaSsiFIer naMe resEt (b, c), seT (x=y, z=false)", "ALTER RESOURCE POOL CLASSIFIER naMe\n\tRESET (b, c),\n\tSET (x = y, z = FALSE)\n;\n"}, - {"alter resource pool classifier eds reset (a), set (x=y)", + {"alter resource pool classifier eds reset (a), set (x=y)", "ALTER RESOURCE POOL CLASSIFIER eds\n\tRESET (a),\n\tSET (x = y)\n;\n"}, {"dRop reSourCe poOl ClaSsiFIer naMe", "DROP RESOURCE POOL CLASSIFIER naMe;\n"}, |
