Skip to content

Inconsistent query formatting with equals function in type argument #65055

@antaljanosbenjamin

Description

@antaljanosbenjamin

Describe what's wrong

Parsing of type arguments is not consistent with formatting. Operator functions (e.g.: equals) can be parsed as types, because Decimal(12,10) is the same as equals(1,2) from the parser perspective. However when outputting the AST, ASTFunction outputs 1 = 2 instead of equals(1,2), which cannot be parsed as a type. Thus formatQuery(formatQuery(<query with equals(1,2) as type>)) fails to parse the result of the inner formatQuery.

ip-10-2-3-206.eu-west-1.compute.internal :) SELECT formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))')

SELECT formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))')

Query id: 9455f2f0-5533-4c56-b48a-ef1ac05ea1ac

   ┌─formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))')─┐
1. │ ALTER TABLE src
    (MODIFY COLUMN `B` Nullable('test6' = toNullable(5)))                     │
   └──────────────────────────────────────────────────────────────────────────────────────────────┘

1 row in set. Elapsed: 0.019 sec. 

ip-10-2-3-206.eu-west-1.compute.internal :) SELECT formatQuery(formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))'))

SELECT formatQuery(formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))'))

Query id: 7a57b554-4c82-4f28-a40d-d31aff95441d


Elapsed: 0.025 sec. 

Received exception:
Code: 62. DB::Exception: Syntax error: failed at position 59 ('toNullable') (line 2, col 43): toNullable(5))). Expected one of: literal, NULL, NULL, number, Bool, TRUE, FALSE, string literal: In scope SELECT formatQuery(formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))')). (SYNTAX_ERROR)

ip-10-2-3-206.eu-west-1.compute.internal :) 

Found by fuzzer.

How to reproduce

Fiddle:

SELECT formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))');

SELECT formatQuery(formatQuery('ALTER TABLE src (MODIFY COLUMN `B` Nullable(equals(\'test6\',toNullable(5))))'));

Expected behavior

If the original query can be parsed, then the formatted query can also be parsed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fuzzProblem found by one of the fuzzers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions