diff options
author | vityaman <[email protected]> | 2025-05-12 21:05:25 +0300 |
---|---|---|
committer | robot-piglet <[email protected]> | 2025-05-12 21:16:38 +0300 |
commit | 53b15a5b87b078a27ee071b8ab93458f1a3bcd81 (patch) | |
tree | 6fb88295e8bf4ee279d06a9fed992bfcec9a9b56 | |
parent | b336ad5ec16dd1f541c55b7944fc9e6b5bba57a2 (diff) |
YQL-19747: Complete camel case type names
---
- Related to `YQL-19747`
- Related to https://github.com/vityaman/ydb/issues/8
---
Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1268
commit_hash:76e4e2c8b225994cc842c1ee00a0ec8e6eed5c05
-rw-r--r-- | yql/essentials/sql/v1/complete/sql_complete_ut.cpp | 66 | ||||
-rw-r--r-- | yql/essentials/sql/v1/complete/syntax/format.cpp | 39 |
2 files changed, 69 insertions, 36 deletions
diff --git a/yql/essentials/sql/v1/complete/sql_complete_ut.cpp b/yql/essentials/sql/v1/complete/sql_complete_ut.cpp index 10afd08f827..dd083c5a301 100644 --- a/yql/essentials/sql/v1/complete/sql_complete_ut.cpp +++ b/yql/essentials/sql/v1/complete/sql_complete_ut.cpp @@ -452,28 +452,28 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { {Keyword, "CURRENT_DATE"}, {Keyword, "CURRENT_TIME"}, {Keyword, "CURRENT_TIMESTAMP"}, - {Keyword, "DICT<"}, + {Keyword, "Dict<"}, {Keyword, "DISTINCT"}, {FunctionName, "DateTime::Split("}, {Keyword, "EMPTY_ACTION"}, {Keyword, "ENUM"}, {Keyword, "EXISTS("}, {Keyword, "FALSE"}, - {Keyword, "FLOW<"}, + {Keyword, "Flow<"}, {Keyword, "JSON_EXISTS("}, {Keyword, "JSON_QUERY("}, {Keyword, "JSON_VALUE("}, - {Keyword, "LIST<"}, + {Keyword, "List<"}, {Keyword, "NOT"}, {Keyword, "NULL"}, - {Keyword, "OPTIONAL<"}, + {Keyword, "Optional<"}, {FunctionName, "Python::__private("}, - {Keyword, "RESOURCE<"}, - {Keyword, "SET<"}, + {Keyword, "Resource<"}, + {Keyword, "Set<"}, {Keyword, "STREAM"}, {Keyword, "STRUCT"}, {FunctionName, "StartsWith("}, - {Keyword, "TAGGED<"}, + {Keyword, "Tagged<"}, {Keyword, "TRUE"}, {Keyword, "TUPLE"}, {Keyword, "VARIANT"}, @@ -628,27 +628,27 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { {Keyword, "CURRENT_DATE"}, {Keyword, "CURRENT_TIME"}, {Keyword, "CURRENT_TIMESTAMP"}, - {Keyword, "DICT<"}, + {Keyword, "Dict<"}, {FunctionName, "DateTime::Split("}, {Keyword, "EMPTY_ACTION"}, {Keyword, "ENUM"}, {Keyword, "EXISTS("}, {Keyword, "FALSE"}, - {Keyword, "FLOW<"}, + {Keyword, "Flow<"}, {Keyword, "JSON_EXISTS("}, {Keyword, "JSON_QUERY("}, {Keyword, "JSON_VALUE("}, - {Keyword, "LIST<"}, + {Keyword, "List<"}, {Keyword, "NOT"}, {Keyword, "NULL"}, - {Keyword, "OPTIONAL<"}, + {Keyword, "Optional<"}, {FunctionName, "Python::__private("}, - {Keyword, "RESOURCE<"}, - {Keyword, "SET<"}, - {Keyword, "STREAM<"}, + {Keyword, "Resource<"}, + {Keyword, "Set<"}, + {Keyword, "Stream<"}, {Keyword, "STRUCT"}, {FunctionName, "StartsWith("}, - {Keyword, "TAGGED<"}, + {Keyword, "Tagged<"}, {Keyword, "TRUE"}, {Keyword, "TUPLE"}, {Keyword, "VARIANT"}, @@ -692,28 +692,28 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { Y_UNIT_TEST(TypeName) { TVector<TCandidate> expected = { - {Keyword, "CALLABLE<("}, - {Keyword, "DECIMAL("}, - {Keyword, "DICT<"}, - {Keyword, "ENUM<"}, - {Keyword, "FLOW<"}, - {Keyword, "LIST<"}, - {Keyword, "OPTIONAL<"}, - {Keyword, "RESOURCE<"}, - {Keyword, "SET<"}, - {Keyword, "STREAM<"}, + {Keyword, "Callable<("}, + {Keyword, "Decimal("}, + {Keyword, "Dict<"}, + {Keyword, "Enum<"}, + {Keyword, "Flow<"}, + {Keyword, "List<"}, + {Keyword, "Optional<"}, + {Keyword, "Resource<"}, + {Keyword, "Set<"}, + {Keyword, "Stream<"}, {Keyword, "STRUCT"}, - {Keyword, "TAGGED<"}, + {Keyword, "Tagged<"}, {Keyword, "TUPLE"}, {TypeName, "Uint64"}, - {Keyword, "VARIANT<"}, + {Keyword, "Variant<"}, }; auto engine = MakeSqlCompletionEngineUT(); UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "CREATE TABLE table (id "), expected); UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT CAST (1 AS "), expected); - UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT OPTIONAL<"), expected); - UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT OPTIONAL<#>"), expected); + UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT Optional<"), expected); + UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT Optional<#>"), expected); } Y_UNIT_TEST(TypeNameAsArgument) { @@ -726,7 +726,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { } { TVector<TCandidate> expected = { - {Keyword, "OPTIONAL<"}, + {Keyword, "Optional<"}, }; UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT Nothing(Option"), expected); } @@ -985,7 +985,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { {TypeName, "Unit"}, {TypeName, "Uint16"}, }; - UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT OPTIONAL<U"), expected); + UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT Optional<U"), expected); } { TVector<TCandidate> expected = { @@ -1009,7 +1009,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { auto service = MakeIntrusive<TFailingNameService>(); auto engine = MakeSqlCompletionEngine(MakePureLexerSupplier(), std::move(service)); UNIT_ASSERT_EXCEPTION(Complete(engine, ""), TDummyException); - UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT OPTIONAL<U"), TDummyException); + UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT Optional<U"), TDummyException); UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT CAST (1 AS ").size(), TDummyException); } @@ -1077,7 +1077,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) { {TypeName, "Int16"}, {TypeName, "Int8"}, }; - UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT OPTIONAL<I"), expected); + UNIT_ASSERT_VALUES_EQUAL(Complete(engine, "SELECT Optional<I"), expected); } { TVector<TCandidate> expected = { diff --git a/yql/essentials/sql/v1/complete/syntax/format.cpp b/yql/essentials/sql/v1/complete/syntax/format.cpp index 43c36aea9dd..19c7c9d2148 100644 --- a/yql/essentials/sql/v1/complete/syntax/format.cpp +++ b/yql/essentials/sql/v1/complete/syntax/format.cpp @@ -5,10 +5,12 @@ #include <yql/essentials/sql/v1/complete/antlr4/vocabulary.h> #include <util/generic/hash_set.h> +#include <util/charset/utf8.h> namespace NSQLComplete { - TString FormatKeywords(const TVector<TString>& seq) { + namespace { + static const THashSet<std::string> Keywords = [] { const auto& grammar = GetSqlGrammar(); const auto& vocabulary = grammar.GetVocabulary(); @@ -20,18 +22,49 @@ namespace NSQLComplete { return keywords; }(); + static const THashSet<TString> TypeConstructors = { + "DECIMAL", + "OPTIONAL", + "TUPLE", + "STRUCT", + "VARIANT", + "LIST", + "STREAM", + "FLOW", + "DICT", + "SET", + "ENUM", + "RESOURCE", + "TAGGED", + "CALLABLE", + }; + + } // namespace + + TString FormatKeywords(const TVector<TString>& seq) { if (seq.empty()) { return ""; } - TString text = seq[0]; - for (size_t i = 1; i < seq.size(); ++i) { + size_t i = 0; + TString text = seq[i++]; + + if (2 <= seq.size() && + TypeConstructors.contains(text) && + (seq[i] == "<" || seq[i] == "(")) { + text.to_title(); + text.append(seq[i]); + i += 1; + } + + for (; i < seq.size(); ++i) { const auto& token = seq[i]; if (Keywords.contains(token)) { text += " "; } text += token; } + return text; } |