Skip to content

Commit b5e4778

Browse files
Address review: do not treat structure = ... as a named schema in positional-only table functions
In `values`, `format`, `input`, `null` and `generateRandom` an argument of the form `structure = '...'` is an ordinary comparison, for example a row of `values` that refers to a `WITH` alias. Materializing `uuid_type_version` into a persisted query rewrote its right-hand side as a columns list and changed the result. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 0c05603 commit b5e4778

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎src/Parsers/ASTDataType.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,21 @@ std::vector<ASTPtr *> getTableFunctionStructureArguments(ASTFunction & table_fun
245245
auto & arguments = table_function.arguments->children;
246246
const auto argument_at = [&arguments](size_t index) -> ASTPtr * { return index < arguments.size() ? &arguments[index] : nullptr; };
247247

248+
/// These table functions have only positional arguments. An argument of the form `structure = ...` is an ordinary
249+
/// comparison there (for example, a row of `values` that refers to a `WITH` alias named `structure`), not a schema.
250+
const bool has_only_positional_arguments = equalsCaseInsensitiveString(table_function.name, "values")
251+
|| equalsCaseInsensitiveString(table_function.name, "format") || equalsCaseInsensitiveString(table_function.name, "input")
252+
|| equalsCaseInsensitiveString(table_function.name, "null")
253+
|| equalsCaseInsensitiveString(table_function.name, "generateRandom");
254+
248255
/// Named arguments override a positional structure slot. This also covers the object-storage table-function
249256
/// family, whose positional signatures differ according to credentials, but all share `structure = ...`.
250257
for (auto & argument : arguments)
251258
{
259+
if (has_only_positional_arguments)
260+
break;
261+
262+
252263
auto * equals = argument->as<ASTFunction>();
253264
if (!equals || !equalsCaseInsensitiveString(equals->name, "equals") || !equals->arguments
254265
|| equals->arguments->children.size() != 2)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
direct
2+
1
3+
table
4+
1
5+
view
6+
1
7+
schema
8+
UUID2 00000000-0000-0000-0000-000000000001
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- In the `values` table function, `structure = '...'` is an ordinary comparison (here with a `WITH` alias),
2+
-- not a named schema argument. Materializing `uuid_type_version` into a persisted query must not rewrite it.
3+
4+
SET uuid_type_version = 2;
5+
6+
DROP TABLE IF EXISTS t_values_structure;
7+
DROP VIEW IF EXISTS v_values_structure;
8+
9+
SELECT 'direct';
10+
WITH 'id UUID' AS structure SELECT * FROM values('x UInt8', structure = 'id UUID');
11+
12+
CREATE TABLE t_values_structure ENGINE = Memory AS
13+
WITH 'id UUID' AS structure SELECT * FROM values('x UInt8', structure = 'id UUID');
14+
SELECT 'table';
15+
SELECT * FROM t_values_structure;
16+
17+
CREATE VIEW v_values_structure AS
18+
WITH 'id UUID' AS structure SELECT * FROM values('x UInt8', structure = 'id UUID');
19+
SELECT 'view';
20+
SELECT * FROM v_values_structure;
21+
22+
-- The schema of `values` is still materialized.
23+
DROP VIEW v_values_structure;
24+
CREATE VIEW v_values_structure AS SELECT * FROM values('id UUID', '00000000-0000-0000-0000-000000000001');
25+
SELECT 'schema';
26+
SELECT toTypeName(id), id FROM v_values_structure;
27+
28+
DROP VIEW v_values_structure;
29+
DROP TABLE t_values_structure;

0 commit comments

Comments
 (0)