Skip to content

Commit fa2bec7

Browse files
authored
Handling Codec(Delta, ZSTD(1)) (#73)
1 parent 61b3867 commit fa2bec7

File tree

7 files changed

+588
-2
lines changed

7 files changed

+588
-2
lines changed

parser/ast.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func (a *AlterTableAddIndex) AlterType() string {
567567

568568
func (a *AlterTableAddIndex) String(level int) string {
569569
var builder strings.Builder
570-
builder.WriteString("ADD INDEX ")
570+
builder.WriteString("ADD ")
571571
builder.WriteString(a.Index.String(level))
572572
if a.IfNotExists {
573573
builder.WriteString("IF NOT EXISTS ")
@@ -1271,8 +1271,11 @@ func (a *TableIndex) End() Pos {
12711271

12721272
func (a *TableIndex) String(level int) string {
12731273
var builder strings.Builder
1274+
builder.WriteString("INDEX")
1275+
builder.WriteByte(' ')
12741276
builder.WriteString(a.Name.String(0))
12751277
builder.WriteString(a.ColumnExpr.String(level))
1278+
builder.WriteByte(' ')
12761279
builder.WriteString("TYPE")
12771280
builder.WriteByte(' ')
12781281
builder.WriteString(a.ColumnType.String(level))
@@ -3265,6 +3268,7 @@ func (n *NestedTypeExpr) Accept(visitor ASTVisitor) error {
32653268
type CompressionCodec struct {
32663269
CodecPos Pos
32673270
RightParenPos Pos
3271+
Type *Ident
32683272
Name *Ident
32693273
Level *NumberLiteral // compression level
32703274
}
@@ -3280,6 +3284,11 @@ func (c *CompressionCodec) End() Pos {
32803284
func (c *CompressionCodec) String(level int) string {
32813285
var builder strings.Builder
32823286
builder.WriteString("CODEC(")
3287+
if c.Type != nil {
3288+
builder.WriteString(c.Type.String(level))
3289+
builder.WriteByte(',')
3290+
builder.WriteByte(' ')
3291+
}
32833292
builder.WriteString(c.Name.String(level))
32843293
if c.Level != nil {
32853294
builder.WriteByte('(')

parser/parser_column.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,19 @@ func (p *Parser) tryParseCompressionCodecs(pos Pos) (*CompressionCodec, error) {
801801
if err != nil {
802802
return nil, err
803803
}
804+
// parse DELTA if CODEC(Delta, ZSTD(1))
805+
var codecType *Ident
806+
if strings.ToUpper(name.Name) == "DELTA" {
807+
codecType = name
808+
if _, err := p.consumeTokenKind(","); err != nil {
809+
return nil, err
810+
}
811+
name, err = p.parseIdent()
812+
if err != nil {
813+
return nil, err
814+
}
815+
}
816+
804817
var level *NumberLiteral
805818
// TODO: check if the codec name is valid
806819
switch strings.ToUpper(name.Name) {
@@ -819,6 +832,7 @@ func (p *Parser) tryParseCompressionCodecs(pos Pos) (*CompressionCodec, error) {
819832
return &CompressionCodec{
820833
CodecPos: pos,
821834
RightParenPos: rightParenPos,
835+
Type: codecType,
822836
Name: name,
823837
Level: level,
824838
}, nil
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE IF NOT EXISTS test_local
2+
(
3+
`id` UInt64 CODEC(Delta, ZSTD(1)),
4+
`api_id` UInt64 CODEC(ZSTD(1)),
5+
`timestamp` DateTime64(9) CODEC(ZSTD(1)),
6+
INDEX timestamp_index(timestamp) TYPE minmax GRANULARITY 4
7+
)
8+
ENGINE = ReplicatedMergeTree('/root/test_local', '{replica}')
9+
PARTITION BY toStartOfHour(`timestamp`)
10+
ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`)
11+
TTL toStartOfHour(`timestamp`) + INTERVAL 7 DAY,toStartOfHour(`timestamp`) + INTERVAL 2 DAY
12+
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;

parser/testdata/ddl/format/alter_table_add_index.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ALTER TABLE test.events_local ON CLUSTER 'default_cluster' ADD INDEX my_index(f0
55
-- Format SQL:
66
ALTER TABLE test.events_local
77
ON CLUSTER 'default_cluster'
8-
ADD INDEX my_index(f0)TYPE minmax GRANULARITY 1024;
8+
ADD INDEX my_index(f0) TYPE minmax GRANULARITY 1024;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Origin SQL:
2+
CREATE TABLE IF NOT EXISTS test_local
3+
(
4+
`id` UInt64 CODEC(Delta, ZSTD(1)),
5+
`api_id` UInt64 CODEC(ZSTD(1)),
6+
`timestamp` DateTime64(9) CODEC(ZSTD(1)),
7+
INDEX timestamp_index(timestamp) TYPE minmax GRANULARITY 4
8+
)
9+
ENGINE = ReplicatedMergeTree('/root/test_local', '{replica}')
10+
PARTITION BY toStartOfHour(`timestamp`)
11+
ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`)
12+
TTL toStartOfHour(`timestamp`) + INTERVAL 7 DAY,toStartOfHour(`timestamp`) + INTERVAL 2 DAY
13+
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;
14+
15+
16+
-- Format SQL:
17+
CREATE TABLE IF NOT EXISTS test_local
18+
(
19+
`id` UInt64 CODEC(Delta, ZSTD(1)),
20+
`api_id` UInt64 CODEC(ZSTD(1)),
21+
`timestamp` DateTime64(9) CODEC(ZSTD(1)),
22+
INDEX timestamp_index(timestamp) TYPE minmax GRANULARITY 4
23+
)
24+
ENGINE = ReplicatedMergeTree('/root/test_local', '{replica}')
25+
PARTITION BY toStartOfHour(`timestamp`)
26+
TTL toStartOfHour(`timestamp`) + INTERVAL 7 DAY,toStartOfHour(`timestamp`) + INTERVAL 2 DAY
27+
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
28+
ORDER BY (toUnixTimestamp64Nano(`timestamp`), `api_id`);

parser/testdata/ddl/output/create_table_basic.sql.golden.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"Codec": {
7878
"CodecPos": 198,
7979
"RightParenPos": 212,
80+
"Type": null,
8081
"Name": {
8182
"Name": "ZSTD",
8283
"QuoteType": 1,

0 commit comments

Comments
 (0)