Skip to content

[jdbc-v2] parser doesn't recognize aliases that happen to be keywords #2427

@Gerrit-K

Description

@Gerrit-K

Description

@chernser: The real problem is in statements like:

SELECT [...] FROM some_database.some_table source
WHERE source.some_column = ? AND source.some_other_column = ?

We need to make sure that short form of alias do not break parameter detection.

-- original description
The JDBC-V2 parser doesn't seem to correctly parse statements where there are aliases that happen to be keywords. The examples below illustrate this issue.

Steps to reproduce

  1. Using source as an alias fails:
    PreparedStatement stmt = conn.prepareStatement("SELECT date, ? FROM system.one source WHERE ? = ?");
    conn.getParameterMetadata().getParameterCount(); // returns 1 instead of 3
  2. Prepending AS before the alias fixes the issue:
    PreparedStatement stmt = conn.prepareStatement("SELECT date, ? FROM system.one AS source WHERE ? = ?");
    conn.getParameterMetadata().getParameterCount(); // returns 3 as expected
  3. Using a different alias also fixes the issue:
    PreparedStatement stmt = conn.prepareStatement("SELECT date, ? FROM system.one _source WHERE ? = ?");
    conn.getParameterMetadata().getParameterCount(); // returns 3 as expected
    

Expected Behaviour

The example query without the AS before the alias should work as well, as it's valid ClickHouse syntax.

Code Example

see repro steps above

Environment

Running integration tests on v0.8.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions