Skip to content

Commit c10b43a

Browse files
authored
Support JSON parameter for max_dynamic_paths and max_dynamic_types (#164)
1 parent 746f0b7 commit c10b43a

File tree

5 files changed

+141
-71
lines changed

5 files changed

+141
-71
lines changed

parser/ast.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,8 +3716,10 @@ func (j *JSONPath) String() string {
37163716
}
37173717

37183718
type JSONOption struct {
3719-
SkipPath *JSONPath
3720-
SkipRegex *StringLiteral
3719+
SkipPath *JSONPath
3720+
SkipRegex *StringLiteral
3721+
MaxDynamicPaths *NumberLiteral
3722+
MaxDynamicTypes *NumberLiteral
37213723
}
37223724

37233725
func (j *JSONOption) String() string {
@@ -3730,6 +3732,16 @@ func (j *JSONOption) String() string {
37303732
builder.WriteString(" SKIP REGEXP ")
37313733
builder.WriteString(j.SkipRegex.String())
37323734
}
3735+
if j.MaxDynamicPaths != nil {
3736+
builder.WriteString("max_dynamic_paths")
3737+
builder.WriteByte('=')
3738+
builder.WriteString(j.MaxDynamicPaths.String())
3739+
}
3740+
if j.MaxDynamicTypes != nil {
3741+
builder.WriteString("max_dynamic_types")
3742+
builder.WriteByte('=')
3743+
builder.WriteString(j.MaxDynamicTypes.String())
3744+
}
37333745
return builder.String()
37343746
}
37353747

parser/parser_column.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,34 @@ func (p *Parser) parseJSONPath() (*JSONPath, error) {
964964
}, nil
965965
}
966966

967+
func (p *Parser) parseJSONMaxDynamicOptions(pos Pos) (*JSONOption, error) {
968+
ident, err := p.parseIdent()
969+
if err != nil {
970+
return nil, err
971+
}
972+
973+
if err := p.expectTokenKind(TokenKindSingleEQ); err != nil {
974+
return nil, err
975+
}
976+
977+
switch ident.Name {
978+
case "max_dynamic_types":
979+
number, err := p.parseNumber(pos)
980+
if err != nil {
981+
return nil, err
982+
}
983+
return &JSONOption{MaxDynamicTypes: number}, nil
984+
case "max_dynamic_paths":
985+
number, err := p.parseNumber(pos)
986+
if err != nil {
987+
return nil, err
988+
}
989+
return &JSONOption{MaxDynamicPaths: number}, nil
990+
default:
991+
return nil, fmt.Errorf("unexpected token kind: %s", p.lastTokenKind())
992+
}
993+
}
994+
967995
func (p *Parser) parseJSONOption() (*JSONOption, error) {
968996
switch {
969997
case p.tryConsumeKeywords(KeywordSkip):
@@ -983,6 +1011,8 @@ func (p *Parser) parseJSONOption() (*JSONOption, error) {
9831011
return &JSONOption{
9841012
SkipPath: jsonPath,
9851013
}, nil
1014+
case p.matchTokenKind(TokenKindIdent):
1015+
return p.parseJSONMaxDynamicOptions(p.Pos())
9861016
default:
9871017
return nil, fmt.Errorf("unexpected token kind: %s", p.lastTokenKind())
9881018
}

parser/testdata/ddl/create_table_basic.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS test.events_local (
2222
f8 Datetime DEFAULT now(),
2323
f9 String MATERIALIZED toString(f7['f70']),
2424
f10 String ALIAS f11,
25-
f12 JSON(SKIP a, SKIP a.b.c, SKIP REGEXP 'hello'),
25+
f12 JSON(max_dynamic_types=10, max_dynamic_paths=3, SKIP a, SKIP a.b.c, SKIP REGEXP 'hello'),
2626
) ENGINE = MergeTree
2727
PRIMARY KEY (f0, f1, f2)
2828
PARTITION BY toYYYYMMDD(f3)

parser/testdata/ddl/format/create_table_basic.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS test.events_local (
2323
f8 Datetime DEFAULT now(),
2424
f9 String MATERIALIZED toString(f7['f70']),
2525
f10 String ALIAS f11,
26-
f12 JSON(SKIP a, SKIP a.b.c, SKIP REGEXP 'hello'),
26+
f12 JSON(max_dynamic_types=10, max_dynamic_paths=3, SKIP a, SKIP a.b.c, SKIP REGEXP 'hello'),
2727
) ENGINE = MergeTree
2828
PRIMARY KEY (f0, f1, f2)
2929
PARTITION BY toYYYYMMDD(f3)
@@ -32,4 +32,4 @@ ORDER BY (f1,f2,f3)
3232
COMMENT 'Comment for table';
3333

3434
-- Format SQL:
35-
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(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';
35+
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';

0 commit comments

Comments
 (0)