diff options
| author | azevaykin <[email protected]> | 2026-07-07 11:48:39 +0300 |
|---|---|---|
| committer | azevaykin <[email protected]> | 2026-07-07 12:26:27 +0300 |
| commit | 65fbcdc91d53bb48efff3bb41c23732b6c4b32fc (patch) | |
| tree | 386abfc1246cca980ba9f9df5c1cd55c47bff3d6 /yql/essentials/sql/v1/sql_translation.cpp | |
| parent | 1540d7662ca2b227ab3fd14d6787ec662df0f31f (diff) | |
KIKIMR-25621: Introduce multi-column statistics
#### Introduce multi-column statistics support ✎
- Adds support for defining multi-column statistics in table schemas, allowing users to specify statistics for combinations of columns rather than individual columns
- Introduces new SQL syntax for CREATE TABLE and ALTER TABLE statements to declare statistics with optional type specifications
- Implements validation for statistics definitions, ensuring column references are valid and names are unique
- Extends the query processing pipeline to handle statistics declarations during table creation and modification operations
- Updates syntax highlighting and parsing rules to recognize the new statistics keyword and related constructs
- Adds comprehensive unit tests covering various statistics scenarios including multi-column definitions, type specifications, and validation rules
<a href="https://nda.ya.ru/t/qa0kX64r7DqvtN"><font size="2">Autodescription by Yandex Code Assistant</font></a>
commit_hash:5ca3f8721d3e3660f2bb890c1408e420cf7c3e81
Diffstat (limited to 'yql/essentials/sql/v1/sql_translation.cpp')
| -rw-r--r-- | yql/essentials/sql/v1/sql_translation.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/yql/essentials/sql/v1/sql_translation.cpp b/yql/essentials/sql/v1/sql_translation.cpp index b95e1c61b56..17596ab4d9c 100644 --- a/yql/essentials/sql/v1/sql_translation.cpp +++ b/yql/essentials/sql/v1/sql_translation.cpp @@ -790,6 +790,28 @@ bool TSqlTranslation::CreateTableIndex(const TRule_table_index& node, TVector<TI return true; } +bool TSqlTranslation::CreateTableStatistics(const TRule_table_statistics& node, TVector<TStatisticsDescription>& statistics) { + statistics.emplace_back(IdEx(node.GetRule_an_id2(), *this)); + auto& stat = statistics.back(); + + // ON (columns) + stat.Columns.emplace_back(IdEx(node.GetRule_an_id_schema5(), *this)); + for (const auto& block : node.GetBlock6()) { + stat.Columns.emplace_back(IdEx(block.GetRule_an_id_schema2(), *this)); + } + + // WITH (types) — optional; omission means "all supported statistic types" + if (node.HasBlock8()) { + const auto& withTypes = node.GetBlock8().GetRule_with_statistics_types1(); + stat.Types.emplace_back(IdEx(withTypes.GetRule_an_id_or_type3(), *this)); + for (const auto& block : withTypes.GetBlock4()) { + stat.Types.emplace_back(IdEx(block.GetRule_an_id_or_type2(), *this)); + } + } + + return true; +} + bool TSqlTranslation::ParseDatabaseSettings(const TRule_database_settings& in, THashMap<TString, TNodePtr>& out) { if (!ParseDatabaseSetting(in.GetRule_database_setting1(), out)) { return false; @@ -2156,6 +2178,14 @@ bool TSqlTranslation::CreateTableEntry(const TRule_create_table_entry& node, TCr params.Columns.push_back({.Pos = pos, .Name = name, .Nullable = true}); break; } + case TRule_create_table_entry::kAltCreateTableEntry7: { + // table_statistics + auto& table_statistics = node.GetAlt_create_table_entry7().GetRule_table_statistics1(); + if (!CreateTableStatistics(table_statistics, params.Statistics)) { + return false; + } + break; + } case NSQLv1Generated::TRule_create_table_entry::ALT_NOT_SET: YQL_ENSURE(false, "Unreachable"); } |
