Skip to content

ALTER / CREATE / DROP / RENAME queries fail when using ON CLUSTER #241

@jspeedz

Description

@jspeedz

In version 1.5.2 and later, write() will add FORMAT JSON to the end of some queries when it should not.

For example:
CREATE USER OR REPLACE {user} ON CLUSTER some_cluster IDENTIFIED WITH sha256_password BY \'{password}\'.

It will change this query to:

CREATE USER OR REPLACE {user} ON CLUSTER some_cluster IDENTIFIED WITH sha256_password BY \'{password}\' FORMAT JSON, which will crash.

[22000] Code: 62. DB::Exception: Syntax error: failed at position 122 (FORMAT): FORMAT JSON. Expected one of: VALID UNTIL, token, Comma, HOST, SettingsProfileElements, SETTINGS, SETTING, PROFILES, PROFILE, DEFAULT ROLE, GRANTEES, DEFAULT DATABASE, IN, ParallelWithClause, PARALLEL WITH, end of query. (SYNTAX_ERROR) (version 25.9.3.48 (official build))

str_starts_with($sql, 'CREATE')

if (
    str_starts_with($sql, 'CREATE')
    || str_starts_with($sql, 'DROP')
    || str_starts_with($sql, 'ALTER')
    || str_starts_with($sql, 'RENAME')
) {
    $query->setFormat('JSON');
}

Should this logic not be inverted to:

if (
    !str_starts_with($sql, 'CREATE')
    && !str_starts_with($sql, 'DROP')
    && !str_starts_with($sql, 'ALTER')
    && !str_starts_with($sql, 'RENAME')
) {
    $query->setFormat('JSON');
}

Or am I missing something here?

Realtes to: #214

I am willing to create a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions