diff options
author | vityaman <vityaman.dev@yandex.ru> | 2025-05-12 21:05:25 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2025-05-12 21:16:38 +0300 |
commit | 53b15a5b87b078a27ee071b8ab93458f1a3bcd81 (patch) | |
tree | 6fb88295e8bf4ee279d06a9fed992bfcec9a9b56 /yql/essentials/sql/v1/complete/syntax/format.cpp | |
parent | b336ad5ec16dd1f541c55b7944fc9e6b5bba57a2 (diff) | |
download | ydb-53b15a5b87b078a27ee071b8ab93458f1a3bcd81.tar.gz |
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
Diffstat (limited to 'yql/essentials/sql/v1/complete/syntax/format.cpp')
-rw-r--r-- | yql/essentials/sql/v1/complete/syntax/format.cpp | 39 |
1 files changed, 36 insertions, 3 deletions
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; } |