ClickHouse: clickhouse-format doesn't hilite some identifiers

Hey!

  1. In this query the identifier is not hilited — is it intended behaviour? I think it should either be hilited as an identifier, or an alias.
$ ./clickhouse-format --hilite --query "with identifier as (select * from table) select * from table"
WITH identifier AS
    (
        SELECT *
        FROM table
    )

https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTWithElement.cpp#L21

image

  1. And also there’s another identifier output without being hilited, but I cannot come up with the query which corresponds to this code - any help? https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTWithAlias.cpp#L23

  2. There seems to be an inconsistensy of manually applied hilite, as it’s never removed within this if: https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTFunction.cpp#L585

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 34 (34 by maintainers)

Most upvoted comments

clickhouse format --hilite --query "alter table tab add index index_name a + b type set GRANULARITY 1" clickhouse format --hilite --query "alter table tab drop index index_name"

image

ADD INDEX prints index_decl, DROP INDEX prints index, it looks more like a decision rather than an inconsistency. Moreover, my refactoring doesn’t automatically change this behaviour, so I’m keeping this as is.

https://github.com/ClickHouse/ClickHouse/blob/bbf94a2664be9b5ba3bdc5f10ccde150cae08f34/src/Parsers/ASTAlterQuery.cpp#L220

UPD It’s even consistent with something like CREATE TABLE name, which wouldn’t be hiliting name as identifier. The reasoning behind this could be: it’s an identifier-to-be, so let’s not hilite it just yep.

The one with SOURCE is listed above. I’ll investigate if there are overlapping bugs.

Thank you!

clickhouse format --hilite --query "alter table tab add index index_name a + b type set GRANULARITY 1" clickhouse format --hilite --query "alter table tab drop index index_name"

image

clickhouse format --hilite --query "create table t as (select 1) comment 'hello'"

image

@murfel I see it can be either TEST, SYNC, or ASYNC.

Hilite not taken off https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTKillQueryQuery.cpp#L31

UPD

KILL QUERY ON CLUSTER clustername WHERE user='username' SYNC

Matching parenthesis is not hilited https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTDictionary.cpp#L164

UPD

No parenthesis should be hilited in the first place.

CREATE DICTIONARY somename (`Name` ClickHouseDataType DEFAULT '' EXPRESSION rand64()) SOURCE(FILE(PATH 'path'))

Hilite not taken off x4 (4 cases) https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTDictionaryAttributeDeclaration.cpp#L59

UPD Oh boy does this query mess with your terminal!

CREATE DICTIONARY somename (
    Name ClickHouseDataType DEFAULT '' EXPRESSION rand64() HIERARCHICAL INJECTIVE IS_OBJECT_ID
)

The hilite hasn’t been taken off, thus the terminal remains hilited as a keyword.

This closing bracket should be hilited, just like its pairing opening bracket https://github.com/ClickHouse/ClickHouse/blob/master/src/Parsers/ASTCreateQuery.cpp#L436

UPD

Couldn’t find a query to contain both a select and a comment.

I checked documentation for creating table, database, and view here https://clickhouse.com/docs/en/sql-reference/statements/create/

UPD 2 See Nicolai Kochetov’s query below.

  1. clickhouse format --hilite --query "select a + 1 as b, a + 1 as b". image

Thanks! I will hilite the second b as an identifier, then.