forked from manticoresoftware/manticoresearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddl.y
461 lines (414 loc) · 11.2 KB
/
ddl.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
%{
#if _WIN32
#pragma warning(push,1)
#pragma warning(disable:4702) // unreachable code
#endif
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
%}
%lex-param { DdlParser_c * pParser }
%parse-param { DdlParser_c * pParser }
%pure-parser
%error-verbose
%token TOK_IDENT "identifier"
%token TOK_TABLEIDENT "tablename"
%token TOK_CONST_FLOAT "float"
%token TOK_CONST_INT "integer"
%token TOK_QUOTED_STRING "string"
%token TOK_ADD
%token TOK_ALTER
%token TOK_AS
%token TOK_AT
%token TOK_ATTRIBUTE
%token TOK_BIGINT
%token TOK_BIT
%token TOK_BOOL
%token TOK_CLUSTER
%token TOK_COLUMN
%token TOK_COLUMNAR
%token TOK_CREATE
%token TOK_DOUBLE
%token TOK_DROP
%token TOK_ENGINE
%token TOK_EXISTS
%token TOK_FAST_FETCH
%token TOK_FLOAT
%token TOK_FROM
%token TOK_FUNCTION
%token TOK_HASH
%token TOK_IF
%token TOK_IMPORT
%token TOK_INDEXED
%token TOK_INT
%token TOK_INTEGER
%token TOK_JOIN
%token TOK_JSON
%token TOK_KILLLIST_TARGET
%token TOK_LIKE
%token TOK_MULTI
%token TOK_MULTI64
%token TOK_NOT
%token TOK_PLUGIN
%token TOK_REBUILD
%token TOK_RECONFIGURE
%token TOK_RETURNS
%token TOK_RTINDEX
%token TOK_SECONDARY
%token TOK_SONAME
%token TOK_STORED
%token TOK_STRING
%token TOK_TABLE
%token TOK_TEXT
%token TOK_TIMESTAMP
%token TOK_TYPE
%token TOK_UINT
%token TOK_UPDATE
%%
request:
statement { pParser->PushQuery(); }
;
statement:
alter
| create_table
| create_table_like
| drop_table
| create_function
| drop_function
| create_plugin
| drop_plugin
| create_cluster
| join_cluster
| import_table
;
ident:
TOK_IDENT
| TOK_TABLEIDENT
| TOK_TYPE
;
tablename:
TOK_TABLEIDENT
;
text_or_string:
TOK_TEXT { $$.m_iType = ( DdlParser_c::FLAG_INDEXED | DdlParser_c::FLAG_STORED ); }
| TOK_STRING { $$.m_iType = DdlParser_c::FLAG_ATTRIBUTE; }
;
attribute_type:
TOK_INTEGER { $$.SetValueInt ( SPH_ATTR_INTEGER ); }
| TOK_BIGINT { $$.SetValueInt ( SPH_ATTR_BIGINT ); }
| TOK_FLOAT { $$.SetValueInt ( SPH_ATTR_FLOAT ); }
| TOK_BOOL { $$.SetValueInt ( SPH_ATTR_BOOL ); }
| TOK_MULTI { $$.SetValueInt ( SPH_ATTR_UINT32SET ); }
| TOK_MULTI64 { $$.SetValueInt ( SPH_ATTR_INT64SET ); }
| TOK_JSON { $$.SetValueInt ( SPH_ATTR_JSON ); }
| TOK_INT { $$.SetValueInt ( SPH_ATTR_INTEGER ); }
| TOK_UINT { $$.SetValueInt ( SPH_ATTR_INTEGER ); }
| TOK_TIMESTAMP { $$.SetValueInt ( SPH_ATTR_TIMESTAMP ); }
;
//////////////////////////////////////////////////////////////////////////
alter_col_type:
attribute_type
| text_or_string { $$.SetValueInt ( SPH_ATTR_STRING ); }
| text_or_string field_flag_list { $$.SetValueInt ( SPH_ATTR_STRING ); $$.m_iType = $2.m_iType; }
;
alter:
TOK_ALTER TOK_TABLE tablename TOK_ADD TOK_COLUMN ident alter_col_type item_option_list
{
if ( !pParser->SetupAlterTable ( $3, $6, $7 ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
| TOK_ALTER TOK_TABLE tablename TOK_ADD TOK_COLUMN ident TOK_BIT '(' TOK_CONST_INT ')' item_option_list
{
if ( !pParser->SetupAlterTable ( $3, $6, SPH_ATTR_INTEGER, 0, $9.GetValueInt() ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
| TOK_ALTER TOK_TABLE tablename TOK_DROP TOK_COLUMN ident
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_ALTER_DROP;
pParser->ToString ( tStmt.m_sIndex, $3 );
pParser->ToString ( tStmt.m_sAlterAttr, $6 );
}
| TOK_ALTER TOK_RTINDEX tablename TOK_RECONFIGURE
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_ALTER_RECONFIGURE;
pParser->ToString ( tStmt.m_sIndex, $3 );
}
| TOK_ALTER TOK_TABLE tablename TOK_RECONFIGURE
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_ALTER_RECONFIGURE;
pParser->ToString ( tStmt.m_sIndex, $3 );
}
| TOK_ALTER TOK_TABLE tablename TOK_KILLLIST_TARGET '=' TOK_QUOTED_STRING
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_ALTER_KLIST_TARGET;
pParser->ToString ( tStmt.m_sIndex, $3 );
pParser->ToString ( tStmt.m_sAlterOption, $6 ).Unquote();
}
| TOK_ALTER TOK_TABLE tablename create_table_option_list
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_ALTER_INDEX_SETTINGS;
pParser->ToString ( tStmt.m_sIndex, $3 );
}
| TOK_ALTER TOK_CLUSTER ident TOK_ADD tablename
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CLUSTER_ALTER_ADD;
pParser->ToString ( tStmt.m_sCluster, $3 );
pParser->ToString ( tStmt.m_sIndex, $5 );
}
| TOK_ALTER TOK_CLUSTER ident TOK_DROP tablename
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CLUSTER_ALTER_DROP;
pParser->ToString ( tStmt.m_sCluster, $3 );
pParser->ToString ( tStmt.m_sIndex, $5 );
}
| TOK_ALTER TOK_CLUSTER ident TOK_UPDATE tablename
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CLUSTER_ALTER_UPDATE;
pParser->ToString ( tStmt.m_sCluster, $3 );
pParser->ToString ( tStmt.m_sSetName, $5 );
}
| TOK_ALTER TOK_TABLE tablename TOK_REBUILD TOK_SECONDARY
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_ALTER_REBUILD_SI;
pParser->ToString ( tStmt.m_sIndex, $3 );
}
;
//////////////////////////////////////////////////////////////////////////
field_flag:
TOK_INDEXED { $$.m_iType = DdlParser_c::FLAG_INDEXED; }
| TOK_STORED { $$.m_iType = DdlParser_c::FLAG_STORED; }
| TOK_ATTRIBUTE { $$.m_iType = DdlParser_c::FLAG_ATTRIBUTE; }
;
field_flag_list:
field_flag
| field_flag_list field_flag { $$.m_iType |= $2.m_iType; }
;
item_option:
TOK_ENGINE '=' TOK_QUOTED_STRING
{
if ( !pParser->AddItemOptionEngine ( $3 ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
| TOK_HASH '=' TOK_QUOTED_STRING
{
if ( !pParser->AddItemOptionHash ( $3 ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
| TOK_FAST_FETCH '=' TOK_QUOTED_STRING
{
if ( !pParser->AddItemOptionFastFetch ( $3 ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
;
item_option_list:
// empty
| item_option_list item_option
;
create_table_item:
ident alter_col_type item_option_list
{
if ( !pParser->AddCreateTableCol ( $1, $2 ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
| ident item_option_list
{
if ( !pParser->AddCreateTableId ( $1 ) )
{
yyerror ( pParser, pParser->GetLastError() );
YYERROR;
}
}
| ident TOK_BIT '(' TOK_CONST_INT ')' item_option_list { pParser->AddCreateTableBitCol ( $1, $4.GetValueInt() ); }
;
create_table_item_list:
create_table_item
| create_table_item_list ',' create_table_item
;
create_table_items:
// empty
| '(' create_table_item_list ')'
;
create_table_option:
ident '=' TOK_QUOTED_STRING { pParser->AddCreateTableOption ( $1, $3 ); }
| TOK_ENGINE '=' TOK_QUOTED_STRING { pParser->AddCreateTableOption ( $1, $3 ); }
;
create_table_option_list:
// empty
| create_table_option_list create_table_option
;
_if_not_exists:
// empty
| TOK_IF TOK_NOT TOK_EXISTS { pParser->m_pStmt->m_tCreateTable.m_bIfNotExists = true; }
;
_if_exists:
// empty
| TOK_IF TOK_EXISTS { pParser->m_pStmt->m_bIfExists = true; }
;
create_table:
TOK_CREATE TOK_TABLE _if_not_exists tablename create_table_items create_table_option_list
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CREATE_TABLE;
pParser->ToString ( tStmt.m_sIndex, $4 );
tStmt.m_sIndex.ToLower();
}
;
create_table_like:
TOK_CREATE TOK_TABLE _if_not_exists tablename TOK_LIKE tablename
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CREATE_TABLE_LIKE;
pParser->ToString ( tStmt.m_sIndex, $4 );
pParser->ToString ( tStmt.m_tCreateTable.m_sLike, $6 );
tStmt.m_sIndex.ToLower();
tStmt.m_tCreateTable.m_sLike.ToLower();
}
;
drop_table:
TOK_DROP TOK_TABLE _if_exists tablename
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_DROP_TABLE;
pParser->ToString ( tStmt.m_sIndex, $4 );
tStmt.m_sIndex.ToLower();
}
;
//////////////////////////////////////////////////////////////////////////
create_function:
TOK_CREATE TOK_FUNCTION ident TOK_RETURNS udf_type TOK_SONAME TOK_QUOTED_STRING
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CREATE_FUNCTION;
pParser->ToString ( tStmt.m_sUdfName, $3 );
tStmt.m_sUdfLib = pParser->ToStringUnescape ( $7 );
tStmt.m_eUdfType = (ESphAttr) $5.GetValueInt();
}
;
udf_type:
TOK_INT { $$.SetValueInt ( SPH_ATTR_INTEGER ); }
| TOK_BIGINT { $$.SetValueInt ( SPH_ATTR_BIGINT ); }
| TOK_FLOAT { $$.SetValueInt ( SPH_ATTR_FLOAT ); }
| TOK_STRING { $$.SetValueInt ( SPH_ATTR_STRINGPTR ); }
| TOK_INTEGER { $$.SetValueInt ( SPH_ATTR_INTEGER ); }
;
drop_function:
TOK_DROP TOK_FUNCTION ident
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_DROP_FUNCTION;
pParser->ToString ( tStmt.m_sUdfName, $3 );
}
;
//////////////////////////////////////////////////////////////////////////
create_plugin:
TOK_CREATE TOK_PLUGIN ident TOK_TYPE TOK_QUOTED_STRING TOK_SONAME TOK_QUOTED_STRING
{
SqlStmt_t & s = *pParser->m_pStmt;
s.m_eStmt = STMT_CREATE_PLUGIN;
pParser->ToString ( s.m_sUdfName, $3 );
s.m_sStringParam = pParser->ToStringUnescape ( $5 );
s.m_sUdfLib = pParser->ToStringUnescape ( $7 );
}
;
drop_plugin:
TOK_DROP TOK_PLUGIN ident TOK_TYPE TOK_QUOTED_STRING
{
SqlStmt_t & s = *pParser->m_pStmt;
s.m_eStmt = STMT_DROP_PLUGIN;
pParser->ToString ( s.m_sUdfName, $3 );
s.m_sStringParam = pParser->ToStringUnescape ( $5 );
}
;
//////////////////////////////////////////////////////////////////////////
call_opts_list:
call_opt
{
assert ( pParser->m_pStmt->m_dCallOptNames.GetLength()==1 );
assert ( pParser->m_pStmt->m_dCallOptValues.GetLength()==1 );
}
| call_opts_list ',' call_opt
;
cluster_opts_list:
// empty
| call_opts_list
;
call_opt:
insert_val opt_as ident
{
pParser->ToString ( pParser->m_pStmt->m_dCallOptNames.Add(), $3 );
pParser->AddInsval ( pParser->m_pStmt->m_dCallOptValues, $1 );
}
;
opt_as:
// empty
| TOK_AS
;
insert_val:
TOK_CONST_INT { $$.m_iType = TOK_CONST_INT; $$.SetValueInt ( $1.GetValueInt() ); }
| TOK_CONST_FLOAT { $$.m_iType = TOK_CONST_FLOAT; $$.m_fValue = $1.m_fValue; }
| TOK_QUOTED_STRING { $$.m_iType = TOK_QUOTED_STRING; $$.m_iStart = $1.m_iStart; $$.m_iEnd = $1.m_iEnd; }
;
create_cluster:
TOK_CREATE TOK_CLUSTER ident cluster_opts_list
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_CLUSTER_CREATE;
pParser->ToString ( tStmt.m_sIndex, $3 );
}
;
join_cluster:
TOK_JOIN TOK_CLUSTER ident cluster_opts_list
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_JOIN_CLUSTER;
pParser->ToString ( tStmt.m_sIndex, $3 );
}
| TOK_JOIN TOK_CLUSTER ident TOK_AT TOK_QUOTED_STRING cluster_opts_list
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_JOIN_CLUSTER;
pParser->ToString ( tStmt.m_sIndex, $3 );
pParser->JoinClusterAt ( $5 );
}
;
import_table:
TOK_IMPORT TOK_TABLE tablename TOK_FROM TOK_QUOTED_STRING
{
SqlStmt_t & tStmt = *pParser->m_pStmt;
tStmt.m_eStmt = STMT_IMPORT_TABLE;
pParser->ToString ( tStmt.m_sIndex, $3 );
tStmt.m_sStringParam = pParser->ToStringUnescape ( $5 );
}
;
%%
#if _WIN32
#pragma warning(pop)
#endif