Support SQL standard VALUES clause as a table expression#100143
Support SQL standard VALUES clause as a table expression#100143Avogar merged 26 commits intoClickHouse:masterfrom
Conversation
Adds support for the SQL standard `VALUES` clause syntax: `SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t(id, val)` This is rewritten internally to use the existing `values` table function, so all existing type inference and column naming logic is reused. Closes ClickHouse#99605 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Workflow [PR], commit [954d1d3] Summary: ❌
AI ReviewSummaryThis PR adds support for SQL-standard PR Metadata
Exact replacement:
Missing context
Findings
ClickHouse Rules
Final Verdict
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
The code looks good.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ix/issue-99704-v2
|
Hi @alexey-milovidov |
|
@Desel72, it shows that some additions to the docs are needed for a new feature. At least mention this feature in the docs in the appropriate place. |
…ix/issue-99704-v2
…House into fix/issue-99704-v2
…ix/issue-99704-v2 # Conflicts: # ci/jobs/scripts/check_style/aspell-ignore/en/aspell-dict.txt
…House into fix/issue-99704-v2 # Conflicts: # ci/jobs/scripts/check_style/aspell-ignore/en/aspell-dict.txt
…rd_values_clause` setting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…alSettings, fix aspell dict merge conflict
| -- https://github.com/ClickHouse/ClickHouse/issues/99605 | ||
|
|
||
| SET enable_analyzer = 1; | ||
| SET allow_experimental_sql_standard_values_clause = 1; |
There was a problem hiding this comment.
Please add targeted negative/regression coverage for the parser rewrite edge cases:
- A query that validates a first-row single-string literal is treated as row data (not as
valuesstructure), e.g.(VALUES ('x UInt8'), (2)). - A query that asserts the syntax is rejected when
allow_experimental_sql_standard_values_clause = 0.
Right now the test only covers happy-path enabled usage, so these two important failure modes can regress silently.
…ix/issue-99704-v2
…House into fix/issue-99704-v2
| DECLARE(Bool, allow_experimental_ytsaurus_dictionary_source, false, R"( | ||
| Experimental dictionary source for integration with YTsaurus. | ||
| )", EXPERIMENTAL) \ | ||
| DECLARE(Bool, allow_experimental_sql_standard_values_clause, false, R"( |
There was a problem hiding this comment.
The PR marks this as New Feature, but this syntax is explicitly gated by allow_experimental_sql_standard_values_clause. Please switch the PR template Changelog category to Experimental Feature to match ClickHouse rollout policy.
| DECLARE(Bool, allow_experimental_ytsaurus_dictionary_source, false, R"( | ||
| Experimental dictionary source for integration with YTsaurus. | ||
| )", EXPERIMENTAL) \ | ||
| DECLARE(Bool, allow_experimental_sql_standard_values_clause, false, R"( |
There was a problem hiding this comment.
I don't know why AI decided to ask you to put it under experimental setting. The feature is not that big and complex to do it. Let's remove the setting and allow this syntax out of the box. Ignore AI comments about experimental setting
There was a problem hiding this comment.
Please, remove this setting, as I said, it's not needed
…ix/issue-99704-v2
… and setting gate
| Experimental dictionary source for integration with YTsaurus. | ||
| )", EXPERIMENTAL) \ | ||
| DECLARE(Bool, allow_experimental_sql_standard_values_clause, false, R"( | ||
| Enables support for the SQL standard VALUES clause as a table expression in FROM, e.g. SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t(id, val). Internally rewritten to the existing values table function. |
There was a problem hiding this comment.
The setting description says the syntax is rewritten to the existing values table function, but this PR now rewrites to SQLStandardValues. Please update this text to match the actual implementation to avoid confusing users and future maintainers.
Suggested wording: "Internally rewritten to the internal SQLStandardValues table function."
| DECLARE(Bool, allow_experimental_ytsaurus_dictionary_source, false, R"( | ||
| Experimental dictionary source for integration with YTsaurus. | ||
| )", EXPERIMENTAL) \ | ||
| DECLARE(Bool, allow_experimental_sql_standard_values_clause, false, R"( |
There was a problem hiding this comment.
Please, remove this setting, as I said, it's not needed
| /// SQL standard VALUES clause: (VALUES (1, 'a'), (2, 'b')) | ||
| /// Rewritten by the parser to SQLStandardValues(tuple(1, 'a'), tuple(2, 'b')) | ||
| /// This checks the experimental setting and never interprets the first arg as schema. | ||
| class TableFunctionSQLStandardValues : public ITableFunction |
There was a problem hiding this comment.
We can avoid creating new class for this, just make TableFunctionValues template with a bool flag:
template <bool interpret_first_argument_as_structure>
class TableFunctionValues : public ITableFunction
And check this template argument in all appropriate places, also function name can depend on templat argument.
…put getTypesFromArgument in anonymous namespace
| ParserExpression expr_parser; | ||
|
|
||
| ASTPtr value_expr; | ||
| if (!expr_parser.parse(pos, value_expr, expected)) |
There was a problem hiding this comment.
ParserExpression here accepts any expression, so (VALUES 1, 2) is parsed successfully even though SQL-standard VALUES requires row constructors (expr, ...) per row.
This makes the new syntax less strict than documented and can introduce parsing ambiguities with future grammar extensions. Please require each item after VALUES to be a parenthesized row expression (or at minimum reject non-parenthesized items) before rewriting to SQLStandardValues.
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 97.18% (69/71, 0 noise lines excluded) |
|
@Avogar Thanks |
438e5c9
|
Thanks @Avogar |
Adds support for the SQL standard
VALUESclause syntax:SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t(id, val)This is rewritten internally to use the existing
valuestable function, so all existing type inference and column naming logic is reused.Closes #99605
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support SQL standard
VALUESclause as a table expression inFROM, e.g.SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t(id, val).Documentation entry for user-facing changes