Skip to content

Commit 171c3e8

Browse files
authored
Fix INDEX column spacing bug (#186)
--------- Signed-off-by: Sharad Gaur <[email protected]>
1 parent bf74993 commit 171c3e8

File tree

5 files changed

+330
-225
lines changed

5 files changed

+330
-225
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ jobs:
5353
- name: Send coverage
5454
env:
5555
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56-
run: goveralls -coverprofile=coverage.out -service=github
56+
run: goveralls -coverprofile=coverage.out -service=github

parser/ast.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,12 +1494,12 @@ func (a *TableIndex) String() string {
14941494
builder.WriteString("INDEX")
14951495
builder.WriteByte(' ')
14961496
builder.WriteString(a.Name.String())
1497-
// a.ColumnDef = *Name --- e.g. INDEX idx column TYPE ...
1498-
// a.ColumnDef = *ParamExprList --- e.g. INDEX idx(column) TYPE ...
1499-
if _, ok := a.ColumnExpr.Expr.(*Ident); ok {
1497+
// Add space only if column expression doesn't start with '('
1498+
columnExprStr := a.ColumnExpr.String()
1499+
if len(columnExprStr) > 0 && columnExprStr[0] != '(' {
15001500
builder.WriteByte(' ')
15011501
}
1502-
builder.WriteString(a.ColumnExpr.String())
1502+
builder.WriteString(columnExprStr)
15031503
builder.WriteByte(' ')
15041504
builder.WriteString("TYPE")
15051505
builder.WriteByte(' ')

parser/testdata/ddl/create_table_with_index.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
CREATE TABLE IF NOT EXISTS test_local
22
(
3+
`common.id` String CODEC(ZSTD(1)),
34
`id` UInt64 CODEC(Delta, ZSTD(1)),
45
`api_id` UInt64 CODEC(ZSTD(1)),
56
`arr` Array(Int64),
67
`content` String CODEC(ZSTD(1)),
78
`output` String,
9+
INDEX id_common_id_bloom_filter common.id TYPE bloom_filter(0.001) GRANULARITY 1,
810
INDEX id_idx id TYPE minmax GRANULARITY 10,
911
INDEX api_id_idx api_id TYPE set(100) GRANULARITY 2,
1012
INDEX arr_idx arr TYPE bloom_filter(0.01) GRANULARITY 3,

parser/testdata/ddl/format/create_table_with_index.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
-- Origin SQL:
22
CREATE TABLE IF NOT EXISTS test_local
33
(
4+
`common.id` String CODEC(ZSTD(1)),
45
`id` UInt64 CODEC(Delta, ZSTD(1)),
56
`api_id` UInt64 CODEC(ZSTD(1)),
67
`arr` Array(Int64),
78
`content` String CODEC(ZSTD(1)),
89
`output` String,
10+
INDEX id_common_id_bloom_filter common.id TYPE bloom_filter(0.001) GRANULARITY 1,
911
INDEX id_idx id TYPE minmax GRANULARITY 10,
1012
INDEX api_id_idx api_id TYPE set(100) GRANULARITY 2,
1113
INDEX arr_idx arr TYPE bloom_filter(0.01) GRANULARITY 3,
@@ -20,4 +22,4 @@ SETTINGS execute_merges_on_single_replica_time_threshold=1200, index_granularity
2022

2123

2224
-- Format SQL:
23-
CREATE TABLE IF NOT EXISTS test_local (`id` UInt64 CODEC(Delta, ZSTD(1)), `api_id` UInt64 CODEC(ZSTD(1)), `arr` Array(Int64), `content` String CODEC(ZSTD(1)), `output` String, INDEX id_idx id TYPE minmax GRANULARITY 10, INDEX api_id_idx api_id TYPE set(100) GRANULARITY 2, INDEX arr_idx arr TYPE bloom_filter(0.01) GRANULARITY 3, INDEX content_idx content TYPE tokenbf_v1(30720, 2, 0) GRANULARITY 1, INDEX output_idx output TYPE ngrambf_v1(3, 10000, 2, 1) GRANULARITY 2) ENGINE = ReplicatedMergeTree('/root/test_local', '{replica}') PARTITION BY toStartOfHour(`timestamp`) TTL toStartOfHour(`timestamp`) + INTERVAL 7 DAY, toStartOfHour(`timestamp`) + INTERVAL 2 DAY SETTINGS execute_merges_on_single_replica_time_threshold=1200, index_granularity=16384, max_bytes_to_merge_at_max_space_in_pool=64424509440, storage_policy='main', ttl_only_drop_parts=1 ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`);
25+
CREATE TABLE IF NOT EXISTS test_local (`common.id` String CODEC(ZSTD(1)), `id` UInt64 CODEC(Delta, ZSTD(1)), `api_id` UInt64 CODEC(ZSTD(1)), `arr` Array(Int64), `content` String CODEC(ZSTD(1)), `output` String, INDEX id_common_id_bloom_filter common.id TYPE bloom_filter(0.001) GRANULARITY 1, INDEX id_idx id TYPE minmax GRANULARITY 10, INDEX api_id_idx api_id TYPE set(100) GRANULARITY 2, INDEX arr_idx arr TYPE bloom_filter(0.01) GRANULARITY 3, INDEX content_idx content TYPE tokenbf_v1(30720, 2, 0) GRANULARITY 1, INDEX output_idx output TYPE ngrambf_v1(3, 10000, 2, 1) GRANULARITY 2) ENGINE = ReplicatedMergeTree('/root/test_local', '{replica}') PARTITION BY toStartOfHour(`timestamp`) TTL toStartOfHour(`timestamp`) + INTERVAL 7 DAY, toStartOfHour(`timestamp`) + INTERVAL 2 DAY SETTINGS execute_merges_on_single_replica_time_threshold=1200, index_granularity=16384, max_bytes_to_merge_at_max_space_in_pool=64424509440, storage_policy='main', ttl_only_drop_parts=1 ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`);

0 commit comments

Comments
 (0)