Skip to content

Commit 0b8b2e3

Browse files
authored
Support QBit data type via simplified identifier handling (#207)
1 parent 5c0f9cc commit 0b8b2e3

File tree

5 files changed

+144
-4
lines changed

5 files changed

+144
-4
lines changed

parser/parser_column.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,13 @@ func (p *Parser) parseColumnType(_ Pos) (ColumnType, error) { // nolint:funlen
874874
if p.tryConsumeTokenKind(TokenKindLParen) != nil {
875875
switch {
876876
case p.matchTokenKind(TokenKindIdent):
877-
switch ident.Name {
878-
case "Nested":
877+
switch {
878+
case strings.EqualFold(ident.Name, "Nested"):
879879
return p.parseNestedType(ident, p.Pos())
880-
case "JSON":
880+
case strings.EqualFold(ident.Name, "JSON"):
881881
return p.parseJSONType(ident, p.Pos())
882+
case strings.EqualFold(ident.Name, "QBit"):
883+
return p.parseColumnTypeWithParams(ident, p.Pos())
882884
default:
883885
return p.parseComplexType(ident, p.Pos())
884886
}

parser/parser_common.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,13 @@ func (p *Parser) parseLiteral(pos Pos) (Literal, error) {
315315
return p.parseNumber(pos)
316316
case p.matchTokenKind(TokenKindString):
317317
return p.parseString(pos)
318+
case p.matchTokenKind(TokenKindIdent):
319+
return p.parseIdent()
318320
case p.matchKeyword(KeywordNull):
319321
// accept the NULL keyword
320322
return &NullLiteral{NullPos: pos}, nil
321323
default:
322-
return nil, fmt.Errorf("expected <int>, <string> or keyword <NULL>, but got %q", p.lastTokenKind())
324+
return nil, fmt.Errorf("expected <int>, <string>, <ident> or keyword <NULL>, but got %q", p.lastTokenKind())
323325
}
324326
}
325327

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TABLE test.qbit_example (
2+
id UInt32,
3+
vec QBit(Float32, 8)
4+
) ENGINE = Memory;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Origin SQL:
2+
CREATE TABLE test.qbit_example (
3+
id UInt32,
4+
vec QBit(Float32, 8)
5+
) ENGINE = Memory;
6+
7+
8+
-- Format SQL:
9+
CREATE TABLE test.qbit_example (id UInt32, vec QBit(Float32, 8)) ENGINE = Memory;
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
[
2+
{
3+
"CreatePos": 0,
4+
"StatementEnd": 90,
5+
"OrReplace": false,
6+
"Name": {
7+
"Database": {
8+
"Name": "test",
9+
"QuoteType": 1,
10+
"NamePos": 13,
11+
"NameEnd": 17
12+
},
13+
"Table": {
14+
"Name": "qbit_example",
15+
"QuoteType": 1,
16+
"NamePos": 18,
17+
"NameEnd": 30
18+
}
19+
},
20+
"IfNotExists": false,
21+
"UUID": null,
22+
"OnCluster": null,
23+
"TableSchema": {
24+
"SchemaPos": 31,
25+
"SchemaEnd": 73,
26+
"Columns": [
27+
{
28+
"NamePos": 37,
29+
"ColumnEnd": 46,
30+
"Name": {
31+
"Ident": {
32+
"Name": "id",
33+
"QuoteType": 1,
34+
"NamePos": 37,
35+
"NameEnd": 39
36+
},
37+
"DotIdent": null
38+
},
39+
"Type": {
40+
"Name": {
41+
"Name": "UInt32",
42+
"QuoteType": 1,
43+
"NamePos": 40,
44+
"NameEnd": 46
45+
}
46+
},
47+
"NotNull": null,
48+
"Nullable": null,
49+
"DefaultExpr": null,
50+
"MaterializedExpr": null,
51+
"AliasExpr": null,
52+
"Codec": null,
53+
"TTL": null,
54+
"Comment": null,
55+
"CompressionCodec": null
56+
},
57+
{
58+
"NamePos": 52,
59+
"ColumnEnd": 71,
60+
"Name": {
61+
"Ident": {
62+
"Name": "vec",
63+
"QuoteType": 1,
64+
"NamePos": 52,
65+
"NameEnd": 55
66+
},
67+
"DotIdent": null
68+
},
69+
"Type": {
70+
"LeftParenPos": 61,
71+
"RightParenPos": 71,
72+
"Name": {
73+
"Name": "QBit",
74+
"QuoteType": 1,
75+
"NamePos": 56,
76+
"NameEnd": 60
77+
},
78+
"Params": [
79+
{
80+
"Name": "Float32",
81+
"QuoteType": 1,
82+
"NamePos": 61,
83+
"NameEnd": 68
84+
},
85+
{
86+
"NumPos": 70,
87+
"NumEnd": 71,
88+
"Literal": "8",
89+
"Base": 10
90+
}
91+
]
92+
},
93+
"NotNull": null,
94+
"Nullable": null,
95+
"DefaultExpr": null,
96+
"MaterializedExpr": null,
97+
"AliasExpr": null,
98+
"Codec": null,
99+
"TTL": null,
100+
"Comment": null,
101+
"CompressionCodec": null
102+
}
103+
],
104+
"AliasTable": null,
105+
"TableFunction": null
106+
},
107+
"Engine": {
108+
"EnginePos": 75,
109+
"EngineEnd": 90,
110+
"Name": "Memory",
111+
"Params": null,
112+
"PrimaryKey": null,
113+
"PartitionBy": null,
114+
"SampleBy": null,
115+
"TTL": null,
116+
"Settings": null,
117+
"OrderBy": null
118+
},
119+
"SubQuery": null,
120+
"HasTemporary": false,
121+
"Comment": null
122+
}
123+
]

0 commit comments

Comments
 (0)