Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -4817,14 +4817,18 @@ func (e *EngineExpr) String() string {
if e.Params != nil {
builder.WriteString(e.Params.String())
}
if e.PrimaryKey != nil {
if e.OrderBy != nil {
builder.WriteString(" ")
builder.WriteString(e.PrimaryKey.String())
builder.WriteString(e.OrderBy.String())
}
if e.PartitionBy != nil {
builder.WriteString(" ")
builder.WriteString(e.PartitionBy.String())
}
if e.PrimaryKey != nil {
builder.WriteString(" ")
builder.WriteString(e.PrimaryKey.String())
}
if e.SampleBy != nil {
builder.WriteString(" ")
builder.WriteString(e.SampleBy.String())
Expand All @@ -4837,10 +4841,6 @@ func (e *EngineExpr) String() string {
builder.WriteString(" ")
builder.WriteString(e.Settings.String())
}
if e.OrderBy != nil {
builder.WriteString(" ")
builder.WriteString(e.OrderBy.String())
}
return builder.String()
}

Expand Down
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/attach_table_basic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ PARTITION BY toYYYYMMDD(f3)
ORDER BY (f0,f1,f2);

-- Format SQL:
CREATE TABLE IF NOT EXISTS test.events_local ON CLUSTER 'default_cluster' (f0 String, f1 String, f2 String, f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Datetime DEFAULT now()) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/test/events_local', '{replica}') PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH ORDER BY (f0, f1, f2);
CREATE TABLE IF NOT EXISTS test.events_local ON CLUSTER 'default_cluster' (f0 String, f1 String, f2 String, f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Datetime DEFAULT now()) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/test/events_local', '{replica}') ORDER BY (f0, f1, f2) PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH;
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ from
where rn = 1;

-- Format SQL:
CREATE MATERIALIZED VIEW test.t0 ON CLUSTER default_cluster ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/{layer}-{shard}/test/t0', '{replica}') PARTITION BY toYYYYMM(f0) ORDER BY (f0) POPULATE AS SELECT f0, f1, f2, coalesce(f0, f1) AS f333 FROM (SELECT f0, f1, f2, ROW_NUMBER() OVER (PARTITION BY f0 ORDER BY coalesce(f1, f2)) AS rn FROM test.t WHERE f3 IN ('foo', 'bar', 'test') AND env = 'test') AS tmp WHERE rn = 1;
CREATE MATERIALIZED VIEW test.t0 ON CLUSTER default_cluster ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/{layer}-{shard}/test/t0', '{replica}') ORDER BY (f0) PARTITION BY toYYYYMM(f0) POPULATE AS SELECT f0, f1, f2, coalesce(f0, f1) AS f333 FROM (SELECT f0, f1, f2, ROW_NUMBER() OVER (PARTITION BY f0 ORDER BY coalesce(f1, f2)) AS rn FROM test.t WHERE f3 IN ('foo', 'bar', 'test') AND env = 'test') AS tmp WHERE rn = 1;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_mv_with_order_by.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ AS
SELECT * FROM test_table;

-- Format SQL:
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv ENGINE = ReplacingMergeTree() PRIMARY KEY (id) ORDER BY (id) AS SELECT * FROM test_table;
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv ENGINE = ReplacingMergeTree() ORDER BY (id) PRIMARY KEY (id) AS SELECT * FROM test_table;
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv ENGINE = ReplacingMergeTree() PRIMARY KEY (id) AS SELECT * FROM test_table;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_or_replace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ FROM
CREATE OR REPLACE FUNCTION IF NOT EXISTS my_function AS (x, y) -> x + y;

-- Format SQL:
CREATE OR REPLACE TABLE IF NOT EXISTS test.events_local (f0 String, f1 String CODEC(ZSTD(1)), f2 VARCHAR(255)) ENGINE = MergeTree PRIMARY KEY (f0, f1, f2) PARTITION BY toYYYYMMDD(f1) TTL f1 + INTERVAL 6 MONTH ORDER BY (f1, f2) COMMENT 'Comment for table';
CREATE OR REPLACE TABLE IF NOT EXISTS test.events_local (f0 String, f1 String CODEC(ZSTD(1)), f2 VARCHAR(255)) ENGINE = MergeTree ORDER BY (f1, f2) PARTITION BY toYYYYMMDD(f1) PRIMARY KEY (f0, f1, f2) TTL f1 + INTERVAL 6 MONTH COMMENT 'Comment for table';
CREATE OR REPLACE VIEW IF NOT EXISTS my_view (col1 String, col2 String) AS SELECT id, name FROM my_table;
CREATE OR REPLACE FUNCTION IF NOT EXISTS my_function AS (x, y) -> x + y;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_table_basic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ ORDER BY (f1,f2,f3)
COMMENT 'Comment for table';

-- Format SQL:
CREATE TABLE IF NOT EXISTS test.events_local (f0 String, f1 String CODEC(ZSTD(1)), f2 VARCHAR(255), f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Nested(f70 UInt32, f71 UInt32, f72 DateTime, f73 Int64, f74 Int64, f75 String), f8 Datetime DEFAULT now(), f9 String MATERIALIZED toString(f7['f70']), f10 String ALIAS f11, f12 JSON(max_dynamic_types=10, max_dynamic_paths=3, SKIP a, SKIP a.b.c, SKIP REGEXP 'hello')) ENGINE = MergeTree PRIMARY KEY (f0, f1, f2) PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH ORDER BY (f1, f2, f3) COMMENT 'Comment for table';
CREATE TABLE IF NOT EXISTS test.events_local (f0 String, f1 String CODEC(ZSTD(1)), f2 VARCHAR(255), f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Nested(f70 UInt32, f71 UInt32, f72 DateTime, f73 Int64, f74 Int64, f75 String), f8 Datetime DEFAULT now(), f9 String MATERIALIZED toString(f7['f70']), f10 String ALIAS f11, f12 JSON(max_dynamic_types=10, max_dynamic_paths=3, SKIP a, SKIP a.b.c, SKIP REGEXP 'hello')) ENGINE = MergeTree ORDER BY (f1, f2, f3) PARTITION BY toYYYYMMDD(f3) PRIMARY KEY (f0, f1, f2) TTL f3 + INTERVAL 6 MONTH COMMENT 'Comment for table';
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ SETTINGS execute_merges_on_single_replica_time_threshold=1200, index_granularity


-- Format SQL:
CREATE TABLE IF NOT EXISTS test_local (`id` UInt64 CODEC(Delta, ZSTD(1)), `api_id` UInt64 CODEC(ZSTD(1)), `app_id` UInt64 CODEC(Delta(9), ZSTD(1)), `device_id` UInt64 CODEC(DoubleDelta, ZSTD(1)), `guage` Float64 CODEC(Gorilla, LZ4), `value` UInt64 CODEC(T64, LZ4), `timestamp` DateTime64(9) CODEC(ZSTD(1)), INDEX timestamp_index(timestamp) TYPE minmax GRANULARITY 4) 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`);
CREATE TABLE IF NOT EXISTS test_local (`id` UInt64 CODEC(Delta, ZSTD(1)), `api_id` UInt64 CODEC(ZSTD(1)), `app_id` UInt64 CODEC(Delta(9), ZSTD(1)), `device_id` UInt64 CODEC(DoubleDelta, ZSTD(1)), `guage` Float64 CODEC(Gorilla, LZ4), `value` UInt64 CODEC(T64, LZ4), `timestamp` DateTime64(9) CODEC(ZSTD(1)), INDEX timestamp_index(timestamp) TYPE minmax GRANULARITY 4) ENGINE = ReplicatedMergeTree('/root/test_local', '{replica}') ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`) 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;
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ TTL toDate(timestamp) + toIntervalDay(3)
SETTINGS index_granularity = 8192;

-- Format SQL:
CREATE TABLE t0 ON CLUSTER default_cluster (`method` Enum8('GET'=1, 'POST'=2, 'HEAD'=3, 'PUT'=4, 'PATCH'=5, 'DELETE'=6, 'CONNECT'=7, 'OPTIONS'=8, 'TRACE'=9) CODEC(ZSTD(1)), `timestamp` DateTime64(3) CODEC(DoubleDelta, ZSTD)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}', '{replica}') PARTITION BY toDate(timestamp) TTL toDate(timestamp) + toIntervalDay(3) SETTINGS index_granularity=8192 ORDER BY (method, timestamp);
CREATE TABLE t0 ON CLUSTER default_cluster (`method` Enum8('GET'=1, 'POST'=2, 'HEAD'=3, 'PUT'=4, 'PATCH'=5, 'DELETE'=6, 'CONNECT'=7, 'OPTIONS'=8, 'TRACE'=9) CODEC(ZSTD(1)), `timestamp` DateTime64(3) CODEC(DoubleDelta, ZSTD)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}', '{replica}') ORDER BY (method, timestamp) PARTITION BY toDate(timestamp) TTL toDate(timestamp) + toIntervalDay(3) SETTINGS index_granularity=8192;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_table_with_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ SETTINGS execute_merges_on_single_replica_time_threshold=1200, index_granularity


-- Format SQL:
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`);
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}') ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`) 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;
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ CREATE TABLE test.events_local UUID 'dad17568-b070-49d0-9ad1-7568b07029d0' (
SETTINGS index_granularity = 8192;

-- Format SQL:
CREATE TABLE test.events_local UUID 'dad17568-b070-49d0-9ad1-7568b07029d0' (`date` Date, `f1` String, `f2` String, `f3` UInt64) ENGINE = ReplacingMergeTree PARTITION BY date SETTINGS index_granularity=8192 ORDER BY (f1, f2);
CREATE TABLE test.events_local UUID 'dad17568-b070-49d0-9ad1-7568b07029d0' (`date` Date, `f1` String, `f2` String, `f3` UInt64) ENGINE = ReplacingMergeTree ORDER BY (f1, f2) PARTITION BY date SETTINGS index_granularity=8192;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_table_with_nullable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ SETTINGS index_granularity = 8192;


-- Format SQL:
CREATE TABLE test.`.inner.752391fb-44cc-4dd5-b523-91fb44cc9dd5` UUID '27673372-7973-44f5-a767-33727973c4f5' (`f0` String, `f1` String, `f2` LowCardinality(String), `f3` LowCardinality(String), `f4` DateTime64(3), `f5` Nullable(DateTime64(3)), `succeed_at` Nullable(DateTime64(3))) ENGINE = MergeTree PARTITION BY xxHash32(tag_id) % 20 SETTINGS index_granularity=8192 ORDER BY label_id;
CREATE TABLE test.`.inner.752391fb-44cc-4dd5-b523-91fb44cc9dd5` UUID '27673372-7973-44f5-a767-33727973c4f5' (`f0` String, `f1` String, `f2` LowCardinality(String), `f3` LowCardinality(String), `f4` DateTime64(3), `f5` Nullable(DateTime64(3)), `succeed_at` Nullable(DateTime64(3))) ENGINE = MergeTree ORDER BY label_id PARTITION BY xxHash32(tag_id) % 20 SETTINGS index_granularity=8192;
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ PARTITION BY toYYYYMMDD(f3)
ORDER BY (f0,f1,f2);

-- Format SQL:
CREATE TABLE IF NOT EXISTS test.events_local ON CLUSTER 'default_cluster' (f0 String, f1 String, f2 String, f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Datetime DEFAULT now()) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/test/events_local', '{replica}') PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH ORDER BY (f0, f1, f2);
CREATE TABLE IF NOT EXISTS test.events_local ON CLUSTER 'default_cluster' (f0 String, f1 String, f2 String, f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Datetime DEFAULT now()) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/test/events_local', '{replica}') ORDER BY (f0, f1, f2) PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_table_with_sample_by.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ SAMPLE BY userid
SETTINGS index_granularity = 8192;

-- Format SQL:
CREATE TABLE default.test UUID '87887901-e33c-497e-8788-7901e33c997e' (`f0` DateTime, `f1` UInt32, `f3` UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}/{shard}/default/test', '{replica}') PARTITION BY toYYYYMM(timestamp) SAMPLE BY userid SETTINGS index_granularity=8192 ORDER BY (contractid, toDate(timestamp), userid);
CREATE TABLE default.test UUID '87887901-e33c-497e-8788-7901e33c997e' (`f0` DateTime, `f1` UInt32, `f3` UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}/{shard}/default/test', '{replica}') ORDER BY (contractid, toDate(timestamp), userid) PARTITION BY toYYYYMM(timestamp) SAMPLE BY userid SETTINGS index_granularity=8192;
6 changes: 3 additions & 3 deletions parser/testdata/ddl/format/create_table_with_ttl_policy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ SETTINGS min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0;


-- Format SQL:
CREATE TABLE tab (d DateTime, a Int) ENGINE = MergeTree PARTITION BY toYYYYMM(d) TTL d + INTERVAL 1 MONTH DELETE, d + INTERVAL 1 WEEK TO VOLUME 'aaa', d + INTERVAL 2 WEEK TO DISK 'bbb' ORDER BY d;
CREATE TABLE table_with_where (d DateTime, a Int) ENGINE = MergeTree PARTITION BY toYYYYMM(d) TTL d + INTERVAL 1 MONTH DELETE WHERE toDayOfWeek(d) = 1 ORDER BY d;
CREATE TABLE table_for_recompression (d DateTime, key UInt64, value String) ENGINE = MergeTree() PARTITION BY key TTL d + INTERVAL 1 MONTH RECOMPRESS CODEC(ZSTD(17)), d + INTERVAL 1 YEAR RECOMPRESS CODEC(LZ4HC(10)) SETTINGS min_rows_for_wide_part=0, min_bytes_for_wide_part=0 ORDER BY tuple();
CREATE TABLE tab (d DateTime, a Int) ENGINE = MergeTree ORDER BY d PARTITION BY toYYYYMM(d) TTL d + INTERVAL 1 MONTH DELETE, d + INTERVAL 1 WEEK TO VOLUME 'aaa', d + INTERVAL 2 WEEK TO DISK 'bbb';
CREATE TABLE table_with_where (d DateTime, a Int) ENGINE = MergeTree ORDER BY d PARTITION BY toYYYYMM(d) TTL d + INTERVAL 1 MONTH DELETE WHERE toDayOfWeek(d) = 1;
CREATE TABLE table_for_recompression (d DateTime, key UInt64, value String) ENGINE = MergeTree() ORDER BY tuple() PARTITION BY key TTL d + INTERVAL 1 MONTH RECOMPRESS CODEC(ZSTD(17)), d + INTERVAL 1 YEAR RECOMPRESS CODEC(LZ4HC(10)) SETTINGS min_rows_for_wide_part=0, min_bytes_for_wide_part=0;
2 changes: 1 addition & 1 deletion parser/testdata/ddl/format/create_table_with_uuid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ PARTITION BY toYYYYMMDD(f3)
ORDER BY (f0,f1,f2);

-- Format SQL:
CREATE TABLE IF NOT EXISTS test.events_local UUID '1234' ON CLUSTER 'default_cluster' (f0 String, f1 String, f2 String, f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Datetime DEFAULT now()) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/test/events_local', '{replica}') PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH ORDER BY (f0, f1, f2);
CREATE TABLE IF NOT EXISTS test.events_local UUID '1234' ON CLUSTER 'default_cluster' (f0 String, f1 String, f2 String, f3 Datetime, f4 Datetime, f5 Map(String, String), f6 String, f7 Datetime DEFAULT now()) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/test/events_local', '{replica}') ORDER BY (f0, f1, f2) PARTITION BY toYYYYMMDD(f3) TTL f3 + INTERVAL 6 MONTH;