blob: 3c81cff58e4836436a091e4364da76eb6c27aa0c [file] [log] [blame]
Yingyi Bu391f09e2015-10-29 13:49:39 -07001options {
2
3
4 STATIC = false;
5
6}
7
8
9PARSER_BEGIN(SQLPPParser)
10
11package org.apache.asterix.lang.sqlpp.parser;
12
13// For SQL++ ParserTokenManager
14import org.apache.xerces.util.IntStack;
15
16import java.io.BufferedReader;
17import java.io.File;
18import java.io.FileInputStream;
19import java.io.FileNotFoundException;
20import java.io.IOException;
21import java.io.InputStreamReader;
22import java.io.Reader;
23import java.io.StringReader;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.Iterator;
27import java.util.LinkedHashMap;
28import java.util.List;
29import java.util.Map;
30
31import org.apache.asterix.common.annotations.AutoDataGen;
32import org.apache.asterix.common.annotations.DateBetweenYearsDataGen;
33import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen;
34import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen;
35import org.apache.asterix.common.annotations.FieldIntervalDataGen;
36import org.apache.asterix.common.annotations.FieldValFileDataGen;
37import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen;
38import org.apache.asterix.common.annotations.IRecordFieldDataGen;
39import org.apache.asterix.common.annotations.InsertRandIntDataGen;
40import org.apache.asterix.common.annotations.ListDataGen;
41import org.apache.asterix.common.annotations.ListValFileDataGen;
42import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
43import org.apache.asterix.common.annotations.TypeDataGen;
44import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
45import org.apache.asterix.common.config.DatasetConfig.DatasetType;
46import org.apache.asterix.common.config.DatasetConfig.IndexType;
Abdullah Alamoudie800e6d2016-01-14 11:20:55 +030047import org.apache.asterix.common.config.MetadataConstants;
Yingyi Bu391f09e2015-10-29 13:49:39 -070048import org.apache.asterix.common.exceptions.AsterixException;
49import org.apache.asterix.common.functions.FunctionSignature;
50import org.apache.asterix.lang.common.base.Expression;
51import org.apache.asterix.lang.common.base.Literal;
52import org.apache.asterix.lang.common.base.IParser;
53import org.apache.asterix.lang.common.base.Statement;
54import org.apache.asterix.lang.common.clause.GroupbyClause;
55import org.apache.asterix.lang.common.clause.LetClause;
56import org.apache.asterix.lang.common.clause.LimitClause;
57import org.apache.asterix.lang.common.clause.OrderbyClause;
58import org.apache.asterix.lang.common.clause.UpdateClause;
59import org.apache.asterix.lang.common.clause.WhereClause;
60import org.apache.asterix.lang.common.context.RootScopeFactory;
61import org.apache.asterix.lang.common.context.Scope;
62import org.apache.asterix.lang.common.expression.AbstractAccessor;
63import org.apache.asterix.lang.common.expression.CallExpr;
64import org.apache.asterix.lang.common.expression.FieldAccessor;
65import org.apache.asterix.lang.common.expression.FieldBinding;
66import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
67import org.apache.asterix.lang.common.expression.IfExpr;
68import org.apache.asterix.lang.common.expression.IndexAccessor;
69import org.apache.asterix.lang.common.expression.ListConstructor;
70import org.apache.asterix.lang.common.expression.LiteralExpr;
71import org.apache.asterix.lang.common.expression.OperatorExpr;
72import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
73import org.apache.asterix.lang.common.expression.QuantifiedExpression;
74import org.apache.asterix.lang.common.expression.RecordConstructor;
75import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
76import org.apache.asterix.lang.common.expression.TypeExpression;
77import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
78import org.apache.asterix.lang.common.expression.UnaryExpr;
79import org.apache.asterix.lang.common.expression.UnaryExpr.Sign;
80import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
81import org.apache.asterix.lang.common.expression.VariableExpr;
82import org.apache.asterix.lang.common.literal.DoubleLiteral;
83import org.apache.asterix.lang.common.literal.FalseLiteral;
84import org.apache.asterix.lang.common.literal.FloatLiteral;
85import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
86import org.apache.asterix.lang.common.literal.NullLiteral;
87import org.apache.asterix.lang.common.literal.StringLiteral;
88import org.apache.asterix.lang.common.literal.TrueLiteral;
89import org.apache.asterix.lang.common.parser.ScopeChecker;
90import org.apache.asterix.lang.common.statement.CompactStatement;
91import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
92import org.apache.asterix.lang.common.statement.CreateDataverseStatement;
93import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement;
94import org.apache.asterix.lang.common.statement.CreateFeedStatement;
95import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
96import org.apache.asterix.lang.common.statement.CreateIndexStatement;
97import org.apache.asterix.lang.common.statement.CreatePrimaryFeedStatement;
98import org.apache.asterix.lang.common.statement.CreateSecondaryFeedStatement;
99import org.apache.asterix.lang.common.statement.DatasetDecl;
100import org.apache.asterix.lang.common.statement.DataverseDecl;
101import org.apache.asterix.lang.common.statement.DataverseDropStatement;
102import org.apache.asterix.lang.common.statement.DeleteStatement;
103import org.apache.asterix.lang.common.statement.DisconnectFeedStatement;
104import org.apache.asterix.lang.common.statement.DropStatement;
105import org.apache.asterix.lang.common.statement.ExternalDetailsDecl;
106import org.apache.asterix.lang.common.statement.FeedDropStatement;
107import org.apache.asterix.lang.common.statement.FunctionDecl;
108import org.apache.asterix.lang.common.statement.FunctionDropStatement;
109import org.apache.asterix.lang.common.statement.IndexDropStatement;
110import org.apache.asterix.lang.common.statement.InsertStatement;
111import org.apache.asterix.lang.common.statement.InternalDetailsDecl;
112import org.apache.asterix.lang.common.statement.LoadStatement;
113import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
114import org.apache.asterix.lang.common.statement.NodegroupDecl;
115import org.apache.asterix.lang.common.statement.Query;
116import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement;
117import org.apache.asterix.lang.common.statement.RunStatement;
118import org.apache.asterix.lang.common.statement.SetStatement;
119import org.apache.asterix.lang.common.statement.TypeDecl;
120import org.apache.asterix.lang.common.statement.TypeDropStatement;
121import org.apache.asterix.lang.common.statement.UpdateStatement;
122import org.apache.asterix.lang.common.statement.WriteStatement;
123import org.apache.asterix.lang.common.struct.Identifier;
124import org.apache.asterix.lang.common.struct.QuantifiedPair;
125import org.apache.asterix.lang.common.struct.VarIdentifier;
126import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
127import org.apache.asterix.lang.sqlpp.clause.FromClause;
128import org.apache.asterix.lang.sqlpp.clause.FromTerm;
129import org.apache.asterix.lang.sqlpp.clause.HavingClause;
130import org.apache.asterix.lang.sqlpp.clause.JoinClause;
131import org.apache.asterix.lang.sqlpp.clause.NestClause;
132import org.apache.asterix.lang.sqlpp.clause.Projection;
133import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
134import org.apache.asterix.lang.sqlpp.clause.SelectClause;
135import org.apache.asterix.lang.sqlpp.clause.SelectElement;
136import org.apache.asterix.lang.sqlpp.clause.SelectRegular;
137import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
138import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
139import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
140import org.apache.asterix.lang.sqlpp.optype.JoinType;
141import org.apache.asterix.lang.sqlpp.optype.SetOpType;
142import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
143import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
Yingyi Buacc12a92016-03-26 17:25:05 -0700144import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700145import org.apache.hyracks.algebricks.common.utils.Pair;
146import org.apache.hyracks.algebricks.common.utils.Triple;
147import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
148import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
149import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
150
151
152
Yingyi Bucaea8f02015-11-16 15:12:15 -0800153class SQLPPParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700154
155 // optimizer hints
156 private static final String AUTO_HINT = "auto";
157 private static final String BROADCAST_JOIN_HINT = "bcast";
158 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
159 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
160 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
161 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
162 private static final String HASH_GROUP_BY_HINT = "hash";
163 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
164 private static final String INMEMORY_HINT = "inmem";
165 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
166 private static final String INTERVAL_HINT = "interval";
167 private static final String LIST_HINT = "list";
168 private static final String LIST_VAL_FILE_HINT = "list-val-file";
169 private static final String RANGE_HINT = "range";
170 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
171 private static final String VAL_FILE_HINT = "val-files";
172 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
173
174 private static final String GEN_FIELDS_HINT = "gen-fields";
175
176 // data generator hints
177 private static final String DGEN_HINT = "dgen";
178
179 private static class IndexParams {
180 public IndexType type;
181 public int gramLength;
182
183 public IndexParams(IndexType type, int gramLength) {
184 this.type = type;
185 this.gramLength = gramLength;
186 }
187 };
188
189 private static class FunctionName {
190 public String dataverse = null;
191 public String library = null;
192 public String function = null;
193 public String hint = null;
194 }
195
196 private static String getHint(Token t) {
197 if (t.specialToken == null) {
198 return null;
199 }
200 String s = t.specialToken.image;
201 int n = s.length();
202 if (n < 2) {
203 return null;
204 }
205 return s.substring(1).trim();
206 }
207
208 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
209 IRecordFieldDataGen rfdg = null;
210 String splits[] = hint.split(" +");
211 if (splits[0].equals(VAL_FILE_HINT)) {
212 File[] valFiles = new File[splits.length - 1];
213 for (int k=1; k<splits.length; k++) {
214 valFiles[k-1] = new File(splits[k]);
215 }
216 rfdg = new FieldValFileDataGen(valFiles);
217 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
218 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
219 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
220 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
221 } else if (splits[0].equals(LIST_HINT)) {
222 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
223 } else if (splits[0].equals(INTERVAL_HINT)) {
224 FieldIntervalDataGen.ValueType vt;
225 if (splits[1].equals("int")) {
226 vt = FieldIntervalDataGen.ValueType.INT;
227 } else if (splits[1].equals("long")) {
228 vt = FieldIntervalDataGen.ValueType.LONG;
229 } else if (splits[1].equals("float")) {
230 vt = FieldIntervalDataGen.ValueType.FLOAT;
231 } else if (splits[1].equals("double")) {
232 vt = FieldIntervalDataGen.ValueType.DOUBLE;
233 } else {
234 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
235 }
236 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
237 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
238 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
239 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
240 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
241 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
242 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
243 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
244 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
245 } else if (splits[0].equals(AUTO_HINT)) {
246 rfdg = new AutoDataGen(splits[1]);
247 }
248 return rfdg;
249 }
250
251 public SQLPPParser(String s){
252 this(new StringReader(s));
253 super.setInput(s);
254 }
255
256 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
257 File file = new File(args[0]);
258 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
259 SQLPPParser parser = new SQLPPParser(fis);
260 List<Statement> st = parser.parse();
261 //st.accept(new SQLPPPrintVisitor(), 0);
262 }
263
264 public List<Statement> parse() throws AsterixException {
265 try {
266 return Statement();
267 } catch (Error e) {
268 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
269 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
270 throw new AsterixException(new ParseException(e.getMessage()));
271 } catch (ParseException e) {
272 throw new AsterixException(e.getMessage());
273 }
274 }
275}
276
277PARSER_END(SQLPPParser)
278
279
280List<Statement> Statement() throws ParseException:
281{
282 scopeStack.push(RootScopeFactory.createRootScope(this));
283 List<Statement> decls = new ArrayList<Statement>();
284 Statement stmt = null;
285}
286{
287 ( stmt = SingleStatement() (<SEMICOLON>)*
288 {
289 decls.add(stmt);
290 }
291 )*
292 <EOF>
293 {
294 return decls;
295 }
296}
297
298Statement SingleStatement() throws ParseException:
299{
300 Statement stmt = null;
301}
302{
303 (
304 stmt = DataverseDeclaration()
305 | stmt = FunctionDeclaration()
306 | stmt = CreateStatement()
307 | stmt = LoadStatement()
308 | stmt = DropStatement()
309 | stmt = WriteStatement()
310 | stmt = SetStatement()
311 | stmt = InsertStatement()
312 | stmt = DeleteStatement()
313 | stmt = UpdateStatement()
314 | stmt = FeedStatement()
315 | stmt = CompactStatement()
316 | stmt = Query() <SEMICOLON>
317 | stmt = RefreshExternalDatasetStatement()
318 | stmt = RunStatement()
319 )
320 {
321 return stmt;
322 }
323}
324
325DataverseDecl DataverseDeclaration() throws ParseException:
326{
327 String dvName = null;
328}
329{
330 <USE> dvName = Identifier()
331 {
332 defaultDataverse = dvName;
333 return new DataverseDecl(new Identifier(dvName));
334 }
335}
336
337Statement CreateStatement() throws ParseException:
338{
339 String hint = null;
340 boolean dgen = false;
341 Statement stmt = null;
342}
343{
344 <CREATE>
345 (
346 {
347 hint = getHint(token);
348 if (hint != null && hint.startsWith(DGEN_HINT)) {
349 dgen = true;
350 }
351 }
352 stmt = TypeSpecification(hint, dgen)
353 | stmt = NodegroupSpecification()
354 | stmt = DatasetSpecification()
355 | stmt = IndexSpecification()
356 | stmt = DataverseSpecification()
357 | stmt = FunctionSpecification()
358 | stmt = FeedSpecification()
359 | stmt = FeedPolicySpecification()
360 )
361 {
362 return stmt;
363 }
364}
365
366TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
367{
368 Pair<Identifier,Identifier> nameComponents = null;
369 boolean ifNotExists = false;
370 TypeExpression typeExpr = null;
371}
372{
373 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
374 <AS> typeExpr = TypeExpr()
375 {
376 long numValues = -1;
377 String filename = null;
378 if (dgen) {
379 String splits[] = hint.split(" +");
380 if (splits.length != 3) {
381 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
382 }
383 filename = splits[1];
384 numValues = Long.parseLong(splits[2]);
385 }
386 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
387 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
388 }
389}
390
391
392NodegroupDecl NodegroupSpecification() throws ParseException:
393{
394 String name = null;
395 String tmp = null;
396 boolean ifNotExists = false;
397 List<Identifier>ncNames = null;
398}
399{
400 <NODEGROUP> name = Identifier()
401 ifNotExists = IfNotExists() <ON> tmp = Identifier()
402 {
403 ncNames = new ArrayList<Identifier>();
404 ncNames.add(new Identifier(tmp));
405 }
406 ( <COMMA> tmp = Identifier()
407 {
408 ncNames.add(new Identifier(tmp));
409 }
410 )*
411 {
412 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
413 }
414}
415
416DatasetDecl DatasetSpecification() throws ParseException:
417{
418 Pair<Identifier,Identifier> nameComponents = null;
419 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800420 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700421 String adapterName = null;
422 Map<String,String> properties = null;
423 Map<String,String> compactionPolicyProperties = null;
424 FunctionSignature appliedFunction = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800425 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700426 String nodeGroupName = null;
427 Map<String,String> hints = new HashMap<String,String>();
428 DatasetDecl dsetDecl = null;
429 boolean autogenerated = false;
430 String compactionPolicy = null;
431 boolean temp = false;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800432 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800433 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700434}
435{
436 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700437 <EXTERNAL> Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800438 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700439 ifNotExists = IfNotExists()
440 <USING> adapterName = AdapterName() properties = Configuration()
441 (<ON> nodeGroupName = Identifier() )?
442 ( <HINTS> hints = Properties() )?
443 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )?
444 {
445 ExternalDetailsDecl edd = new ExternalDetailsDecl();
446 edd.setAdapter(adapterName);
447 edd.setProperties(properties);
448 dsetDecl = new DatasetDecl(nameComponents.first,
449 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800450 typeComponents.first,
451 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800452 metaTypeComponents.first,
453 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700454 nodeGroupName != null? new Identifier(nodeGroupName): null,
455 compactionPolicy,
456 compactionPolicyProperties,
457 hints,
458 DatasetType.EXTERNAL,
459 edd,
460 ifNotExists);
461 }
462
Yingyi Bub9169b62016-02-26 21:21:49 -0800463 | (<INTERNAL> | <TEMPORARY> { temp = true; })?
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700464 Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800465 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800466 (
467 { String name; }
468 <WITH>
469 name = Identifier()
470 {
471 if(!name.toLowerCase().equals("meta")){
472 throw new ParseException("We can only support one additional associated field called \"meta\".");
473 }
474 }
475 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
476 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700477 ifNotExists = IfNotExists()
478 primaryKeyFields = PrimaryKey()
479 (<AUTOGENERATED> { autogenerated = true; } )?
480 (<ON> nodeGroupName = Identifier() )?
481 ( <HINTS> hints = Properties() )?
482 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )?
483 ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
484 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800485 if(filterField!=null && filterField.first!=0){
486 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
487 }
488 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
489 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700490 autogenerated,
Yingyi Buc9bfe252016-03-01 00:02:40 -0800491 filterField == null? null : filterField.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700492 temp);
493 dsetDecl = new DatasetDecl(nameComponents.first,
494 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800495 typeComponents.first,
496 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800497 metaTypeComponents.first,
498 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700499 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
500 compactionPolicy,
501 compactionPolicyProperties,
502 hints,
503 DatasetType.INTERNAL,
504 idd,
505 ifNotExists);
506 }
507 )
508 {
509 return dsetDecl;
510 }
511}
512
513RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
514{
515 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
516 Pair<Identifier,Identifier> nameComponents = null;
517 String datasetName = null;
518}
519{
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700520 <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700521 {
522 redss.setDataverseName(nameComponents.first);
523 redss.setDatasetName(nameComponents.second);
524 return redss;
525 }
526}
527
528RunStatement RunStatement() throws ParseException:
529{
530 String system = null;
531 String tmp;
532 ArrayList<String> parameters = new ArrayList<String>();
533 Pair<Identifier,Identifier> nameComponentsFrom = null;
534 Pair<Identifier,Identifier> nameComponentsTo = null;
535}
536{
537 <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
538 {
539 parameters.add(tmp);
540 }
541 )*<RIGHTPAREN>
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700542 <FROM> Dataset() nameComponentsFrom = QualifiedName()
543 <TO> Dataset() nameComponentsTo = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700544 {
545 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
546 }
547}
548
549CreateIndexStatement IndexSpecification() throws ParseException:
550{
551 CreateIndexStatement cis = new CreateIndexStatement();
552 String indexName = null;
553 boolean ifNotExists = false;
554 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800555 Pair<Integer, Pair<List<String>, TypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700556 IndexParams indexType = null;
557 boolean enforced = false;
558}
559{
560 <INDEX> indexName = Identifier()
561 ifNotExists = IfNotExists()
562 <ON> nameComponents = QualifiedName()
563 <LEFTPAREN> ( fieldPair = OpenField()
564 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800565 cis.addFieldExprPair(fieldPair.second);
566 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700567 }
568 ) (<COMMA> fieldPair = OpenField()
569 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800570 cis.addFieldExprPair(fieldPair.second);
571 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700572 }
573 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?
574 {
575 cis.setIndexName(new Identifier(indexName));
576 cis.setIfNotExists(ifNotExists);
577 cis.setDataverseName(nameComponents.first);
578 cis.setDatasetName(nameComponents.second);
579 if (indexType != null) {
580 cis.setIndexType(indexType.type);
581 cis.setGramLength(indexType.gramLength);
582 }
583 cis.setEnforced(enforced);
584 return cis;
585 }
586}
587
588String CompactionPolicy() throws ParseException :
589{
590 String compactionPolicy = null;
591}
592{
593 compactionPolicy = Identifier()
594 {
595 return compactionPolicy;
596 }
597}
598
599String FilterField() throws ParseException :
600{
601 String filterField = null;
602}
603{
604 filterField = Identifier()
605 {
606 return filterField;
607 }
608}
609
610IndexParams IndexType() throws ParseException:
611{
612 IndexType type = null;
613 int gramLength = 0;
614}
615{
616 (<BTREE>
617 {
618 type = IndexType.BTREE;
619 }
620 | <RTREE>
621 {
622 type = IndexType.RTREE;
623 }
624 | <KEYWORD>
625 {
626 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
627 }
628 | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
629 {
630 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
631 gramLength = Integer.valueOf(token.image);
632 }
633 <RIGHTPAREN>)
634 {
635 return new IndexParams(type, gramLength);
636 }
637}
638
639CreateDataverseStatement DataverseSpecification() throws ParseException :
640{
641 String dvName = null;
642 boolean ifNotExists = false;
643 String format = null;
644}
645{
646 <DATAVERSE> dvName = Identifier()
647 ifNotExists = IfNotExists()
648 ( LOOKAHEAD(1) <WITH> <FORMAT> format = QuotedString() )?
649 {
650 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
651 }
652}
653
654CreateFunctionStatement FunctionSpecification() throws ParseException:
655{
656 FunctionSignature signature;
657 boolean ifNotExists = false;
658 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
659 String functionBody;
660 VarIdentifier var = null;
661 Expression functionBodyExpr;
662 Token beginPos;
663 Token endPos;
664 FunctionName fctName = null;
665
666 createNewScope();
667}
668{
669 <FUNCTION> fctName = FunctionName()
670 ifNotExists = IfNotExists()
671 paramList = ParameterList()
672 <LEFTBRACE>
673 {
674 beginPos = token;
675 }
676 functionBodyExpr = Expression() <RIGHTBRACE>
677 {
678 endPos = token;
679 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
680 // TODO use fctName.library
681 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
682 getCurrentScope().addFunctionDescriptor(signature, false);
683 removeCurrentScope();
684 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
685 }
686}
687
688CreateFeedStatement FeedSpecification() throws ParseException:
689{
690 Pair<Identifier,Identifier> nameComponents = null;
691 boolean ifNotExists = false;
692 String adapterName = null;
693 Map<String,String> properties = null;
694 FunctionSignature appliedFunction = null;
695 CreateFeedStatement cfs = null;
696 Pair<Identifier,Identifier> sourceNameComponents = null;
697
698}
699{
700 (
701 <SECONDARY> <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
702 <FROM> <FEED> sourceNameComponents = QualifiedName() (appliedFunction = ApplyFunction())?
703 {
704 cfs = new CreateSecondaryFeedStatement(nameComponents,
705 sourceNameComponents, appliedFunction, ifNotExists);
706 }
707 |
708 (<PRIMARY>)? <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
709 <USING> adapterName = AdapterName() properties = Configuration() (appliedFunction = ApplyFunction())?
710 {
711 cfs = new CreatePrimaryFeedStatement(nameComponents,
712 adapterName, properties, appliedFunction, ifNotExists);
713 }
714 )
715 {
716 return cfs;
717 }
718}
719
720CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
721{
722 String policyName = null;
723 String basePolicyName = null;
724 String sourcePolicyFile = null;
725 String definition = null;
726 boolean ifNotExists = false;
727 Map<String,String> properties = null;
728 CreateFeedPolicyStatement cfps = null;
729}
730{
731 (
732 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
733 <FROM>
734 (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = QuotedString())?
735 {
736 cfps = new CreateFeedPolicyStatement(policyName,
737 basePolicyName, properties, definition, ifNotExists);
738 }
739 | <PATH> sourcePolicyFile = Identifier() (<DEFINITION> definition = QuotedString())?
740 {
741 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
742 }
743 )
744
745 )
746 {
747 return cfps;
748 }
749}
750
751
752
753List<VarIdentifier> ParameterList() throws ParseException:
754{
755 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
756 VarIdentifier var = null;
757}
758{
759 <LEFTPAREN> (<IDENTIFIER>
760 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700761 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700762 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700763 }
764 (<COMMA> <IDENTIFIER>
765 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700766 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700767 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700768 }
769 )*)? <RIGHTPAREN>
770 {
771 return paramList;
772 }
773}
774
775boolean IfNotExists() throws ParseException:
776{
777}
778{
779 ( LOOKAHEAD(1) <IF> ("not exists"|"NOT EXISTS")
780 {
781 return true;
782 }
783 )?
784 {
785 return false;
786 }
787}
788
789FunctionSignature ApplyFunction() throws ParseException:
790{
791 FunctionName functioName = null;
792 FunctionSignature funcSig = null;
793}
794{
795 <APPLY> <FUNCTION> functioName = FunctionName()
796 {
797 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
798 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
799 }
800}
801
802String GetPolicy() throws ParseException:
803{
804 String policy = null;
805}
806{
807 <USING> <POLICY> policy = Identifier()
808 {
809 return policy;
810 }
811
812}
813
814FunctionSignature FunctionSignature() throws ParseException:
815{
816 FunctionName fctName = null;
817 int arity = 0;
818}
819{
820 fctName = FunctionName() <ATT> <INTEGER_LITERAL>
821 {
822 arity = new Integer(token.image);
823 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
824 throw new ParseException(" invalid arity:" + arity);
825 }
826
827 // TODO use fctName.library
828 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
829 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
830 }
831}
832
Yingyi Buc9bfe252016-03-01 00:02:40 -0800833Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700834{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800835 Pair<Integer, List<String>> tmp = null;
836 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700837 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
838}
839{
840 <PRIMARY> <KEY> tmp = NestedField()
841 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800842 keyFieldSourceIndicators.add(tmp.first);
843 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700844 }
845 ( <COMMA> tmp = NestedField()
846 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800847 keyFieldSourceIndicators.add(tmp.first);
848 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700849 }
850 )*
851 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800852 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700853 }
854}
855
856Statement DropStatement() throws ParseException:
857{
858 String id = null;
859 Pair<Identifier,Identifier> pairId = null;
860 Triple<Identifier,Identifier,Identifier> tripleId = null;
861 FunctionSignature funcSig = null;
862 boolean ifExists = false;
863 Statement stmt = null;
864}
865{
866 <DROP>
867 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700868 Dataset() pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700869 {
870 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
871 }
872 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
873 {
874 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
875 }
876 | <NODEGROUP> id = Identifier() ifExists = IfExists()
877 {
878 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
879 }
880 | <TYPE> pairId = TypeName() ifExists = IfExists()
881 {
882 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
883 }
884 | <DATAVERSE> id = Identifier() ifExists = IfExists()
885 {
886 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
887 }
888 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
889 {
890 stmt = new FunctionDropStatement(funcSig, ifExists);
891 }
892 | <FEED> pairId = QualifiedName() ifExists = IfExists()
893 {
894 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
895 }
896 )
897 {
898 return stmt;
899 }
900}
901
902boolean IfExists() throws ParseException :
903{
904}
905{
906 ( LOOKAHEAD(1) <IF> <EXISTS>
907 {
908 return true;
909 }
910 )?
911 {
912 return false;
913 }
914}
915
916InsertStatement InsertStatement() throws ParseException:
917{
918 Pair<Identifier,Identifier> nameComponents = null;
919 Query query;
920}
921{
922 <INSERT> <INTO> nameComponents = QualifiedName() query = Query()
923 {
Yingyi Bucaea8f02015-11-16 15:12:15 -0800924 query.setTopLevel(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700925 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
926 }
927}
928
929DeleteStatement DeleteStatement() throws ParseException:
930{
931 VariableExpr var = null;
932 Expression condition = null;
933 Pair<Identifier, Identifier> nameComponents;
934 // This is related to the new metadata lock management
935 setDataverses(new ArrayList<String>());
936 setDatasets(new ArrayList<String>());
937
938}
939{
940 <DELETE> var = Variable()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700941 <FROM> nameComponents = QualifiedName()
942 (<WHERE> condition = Expression())?
943 {
944 // First we get the dataverses and datasets that we want to lock
945 List<String> dataverses = getDataverses();
946 List<String> datasets = getDatasets();
947 // we remove the pointer to the dataverses and datasets
948 setDataverses(null);
949 setDatasets(null);
950 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
951 condition, getVarCounter(), dataverses, datasets);
952 }
953}
954
955UpdateStatement UpdateStatement() throws ParseException:
956{
957 VariableExpr vars;
958 Expression target;
959 Expression condition;
960 UpdateClause uc;
961 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
962}
963{
964 <UPDATE> vars = Variable() <IN> target = Expression()
965 <WHERE> condition = Expression()
966 <LEFTPAREN> (uc = UpdateClause()
967 {
968 ucs.add(uc);
969 }
970 (<COMMA> uc = UpdateClause()
971 {
972 ucs.add(uc);
973 }
974 )*) <RIGHTPAREN>
975 {
976 return new UpdateStatement(vars, target, condition, ucs);
977 }
978}
979
980UpdateClause UpdateClause() throws ParseException:
981{
982 Expression target = null;
983 Expression value = null ;
984 InsertStatement is = null;
985 DeleteStatement ds = null;
986 UpdateStatement us = null;
987 Expression condition = null;
988 UpdateClause ifbranch = null;
989 UpdateClause elsebranch = null;
990}
991{
992 (<SET> target = Expression() <EQ> value = Expression()
993 | is = InsertStatement()
994 | ds = DeleteStatement()
995 | us = UpdateStatement()
996 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
997 <THEN> ifbranch = UpdateClause()
998 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
999 {
1000 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1001 }
1002 )
1003}
1004
1005Statement SetStatement() throws ParseException:
1006{
1007 String pn = null;
1008 String pv = null;
1009}
1010{
1011 <SET> pn = Identifier() pv = QuotedString()
1012 {
1013 return new SetStatement(pn, pv);
1014 }
1015}
1016
1017Statement WriteStatement() throws ParseException:
1018{
1019 String nodeName = null;
1020 String fileName = null;
1021 Query query;
1022 String writerClass = null;
1023 Pair<Identifier,Identifier> nameComponents = null;
1024}
1025{
1026 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = QuotedString()
1027 ( <USING> writerClass = QuotedString() )?
1028 {
1029 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1030 }
1031}
1032
1033LoadStatement LoadStatement() throws ParseException:
1034{
1035 Identifier dataverseName = null;
1036 Identifier datasetName = null;
1037 boolean alreadySorted = false;
1038 String adapterName;
1039 Map<String,String> properties;
1040 Pair<Identifier,Identifier> nameComponents = null;
1041}
1042{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001043 <LOAD> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001044 {
1045 dataverseName = nameComponents.first;
1046 datasetName = nameComponents.second;
1047 }
1048 <USING> adapterName = AdapterName() properties = Configuration()
1049 (<PRESORTED>
1050 {
1051 alreadySorted = true;
1052 }
1053 )?
1054 {
1055 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1056 }
1057}
1058
1059
1060String AdapterName() throws ParseException :
1061{
1062 String adapterName = null;
1063}
1064{
1065 adapterName = Identifier()
1066 {
1067 return adapterName;
1068 }
1069}
1070
1071Statement CompactStatement() throws ParseException:
1072{
1073 Pair<Identifier,Identifier> nameComponents = null;
1074 Statement stmt = null;
1075}
1076{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001077 <COMPACT> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001078 {
1079 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1080 }
1081 {
1082 return stmt;
1083 }
1084}
1085
1086Statement FeedStatement() throws ParseException:
1087{
1088 Pair<Identifier,Identifier> feedNameComponents = null;
1089 Pair<Identifier,Identifier> datasetNameComponents = null;
1090
1091 Map<String,String> configuration = null;
1092 Statement stmt = null;
1093 String policy = null;
1094}
1095{
1096 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001097 <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001098 {
1099 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
1100 }
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001101 | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001102 {
1103 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1104 }
1105 )
1106 {
1107 return stmt;
1108 }
1109}
1110
1111Map<String,String> Configuration() throws ParseException :
1112{
1113 Map<String,String> configuration = new LinkedHashMap<String,String>();
1114 Pair<String, String> keyValuePair = null;
1115}
1116{
1117 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1118 {
1119 configuration.put(keyValuePair.first, keyValuePair.second);
1120 }
1121 ( <COMMA> keyValuePair = KeyValuePair()
1122 {
1123 configuration.put(keyValuePair.first, keyValuePair.second);
1124 }
1125 )* )? <RIGHTPAREN>
1126 {
1127 return configuration;
1128 }
1129}
1130
1131Pair<String, String> KeyValuePair() throws ParseException:
1132{
1133 String key;
1134 String value;
1135}
1136{
1137 <LEFTPAREN> key = QuotedString() <EQ> value = QuotedString() <RIGHTPAREN>
1138 {
1139 return new Pair<String, String>(key, value);
1140 }
1141}
1142
1143Map<String,String> Properties() throws ParseException:
1144{
1145 Map<String,String> properties = new HashMap<String,String>();
1146 Pair<String, String> property;
1147}
1148{
1149 (LOOKAHEAD(1) <LEFTPAREN> property = Property()
1150 {
1151 properties.put(property.first, property.second);
1152 }
1153 ( <COMMA> property = Property()
1154 {
1155 properties.put(property.first, property.second);
1156 }
1157 )* <RIGHTPAREN> )?
1158 {
1159 return properties;
1160 }
1161}
1162
1163Pair<String, String> Property() throws ParseException:
1164{
1165 String key;
1166 String value;
1167}
1168{
1169 key = Identifier() <EQ> ( value = QuotedString() | <INTEGER_LITERAL>
1170 {
1171 try {
1172 value = "" + Long.valueOf(token.image);
1173 } catch (NumberFormatException nfe) {
1174 throw new ParseException("inapproriate value: " + token.image);
1175 }
1176 }
1177 )
1178 {
1179 return new Pair<String, String>(key.toUpperCase(), value);
1180 }
1181}
1182
1183TypeExpression IndexedTypeExpr() throws ParseException:
1184{
1185 TypeExpression typeExpr = null;
1186}
1187{
1188 (
1189 typeExpr = TypeReference()
1190 | typeExpr = OrderedListTypeDef()
1191 | typeExpr = UnorderedListTypeDef()
1192 )
1193 {
1194 return typeExpr;
1195 }
1196}
1197
1198TypeExpression TypeExpr() throws ParseException:
1199{
1200 TypeExpression typeExpr = null;
1201}
1202{
1203 (
1204 typeExpr = RecordTypeDef()
1205 | typeExpr = TypeReference()
1206 | typeExpr = OrderedListTypeDef()
1207 | typeExpr = UnorderedListTypeDef()
1208 )
1209 {
1210 return typeExpr;
1211 }
1212}
1213
1214RecordTypeDefinition RecordTypeDef() throws ParseException:
1215{
1216 RecordTypeDefinition recType = new RecordTypeDefinition();
1217 RecordTypeDefinition.RecordKind recordKind = null;
1218}
1219{
1220 ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1221 | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1222 <LEFTBRACE>
1223 {
1224 String hint = getHint(token);
1225 if (hint != null) {
1226 String splits[] = hint.split(" +");
1227 if (splits[0].equals(GEN_FIELDS_HINT)) {
1228 if (splits.length != 5) {
1229 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1230 }
1231 if (!splits[1].equals("int")) {
1232 throw new ParseException("The only supported type for gen-fields is int.");
1233 }
1234 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1235 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1236 recType.setUndeclaredFieldsDataGen(ufdg);
1237 }
1238 }
1239
1240 }
1241 (
1242 RecordField(recType)
1243 ( <COMMA> RecordField(recType) )*
1244 )?
1245 <RIGHTBRACE>
1246 {
1247 if (recordKind == null) {
1248 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1249 }
1250 recType.setRecordKind(recordKind);
1251 return recType;
1252 }
1253}
1254
1255void RecordField(RecordTypeDefinition recType) throws ParseException:
1256{
1257 String fieldName;
1258 TypeExpression type = null;
1259 boolean nullable = false;
1260}
1261{
1262 fieldName = Identifier()
1263 {
1264 String hint = getHint(token);
1265 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1266 }
1267 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1268 {
1269 recType.addField(fieldName, type, nullable, rfdg);
1270 }
1271}
1272
1273TypeReferenceExpression TypeReference() throws ParseException:
1274{
1275 String id = null;
1276}
1277{
1278 id = Identifier()
1279 {
1280 if (id.equalsIgnoreCase("int")) {
1281 id = "int64";
1282 }
1283
1284 return new TypeReferenceExpression(new Identifier(id));
1285 }
1286}
1287
1288OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1289{
1290 TypeExpression type = null;
1291}
1292{
1293 <LEFTBRACKET>
1294 ( type = TypeExpr() )
1295 <RIGHTBRACKET>
1296 {
1297 return new OrderedListTypeDefinition(type);
1298 }
1299}
1300
1301
1302UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1303{
1304 TypeExpression type = null;
1305}
1306{
1307 <LEFTDBLBRACE>
1308 ( type = TypeExpr() )
1309 <RIGHTDBLBRACE>
1310 {
1311 return new UnorderedListTypeDefinition(type);
1312 }
1313}
1314
1315FunctionName FunctionName() throws ParseException:
1316{
1317 String first = null;
1318 String second = null;
1319 String third = null;
1320 boolean secondAfterDot = false;
1321}
1322{
1323 first = Identifier()
1324 {
1325 FunctionName result = new FunctionName();
1326 result.hint = getHint(token);
1327 }
1328 ( <DOT> second = Identifier()
1329 {
1330 secondAfterDot = true;
1331 }
1332 (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )?
1333 {
1334 if (second == null) {
1335 result.dataverse = defaultDataverse;
1336 result.library = null;
1337 result.function = first;
1338 } else if (third == null) {
1339 if (secondAfterDot) {
1340 result.dataverse = first;
1341 result.library = null;
1342 result.function = second;
1343 } else {
1344 result.dataverse = defaultDataverse;
1345 result.library = first;
1346 result.function = second;
1347 }
1348 } else {
1349 result.dataverse = first;
1350 result.library = second;
1351 result.function = third;
1352 }
1353
1354 if (result.function.equalsIgnoreCase("int")) {
1355 result.function = "int64";
1356 }
1357 return result;
1358 }
1359}
1360
1361Pair<Identifier,Identifier> TypeName() throws ParseException:
1362{
1363 Pair<Identifier,Identifier> name = null;
1364}
1365{
1366 name = QualifiedName()
1367 {
1368 if (name.first == null) {
1369 name.first = new Identifier(defaultDataverse);
1370 }
1371 return name;
1372 }
1373}
1374
1375String Identifier() throws ParseException:
1376{
1377 String lit = null;
1378}
1379{
1380 (<IDENTIFIER>
1381 {
1382 return token.image;
1383 }
1384 | lit = QuotedString()
1385 {
1386 return lit;
1387 }
1388 )
1389}
1390
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001391void Dataset() throws ParseException:
1392{
1393}
1394{
1395 (<DATASET>|<COLLECTION>)
1396}
1397
Yingyi Buc9bfe252016-03-01 00:02:40 -08001398Pair<Integer, Pair<List<String>, TypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001399{
1400 TypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001401 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001402}
1403{
1404 fieldList = NestedField()
1405 ( <COLON> fieldType = IndexedTypeExpr() )?
1406 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001407 return new Pair<Integer, Pair<List<String>, TypeExpression>>
1408 (fieldList.first, new Pair<List<String>, TypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001409 }
1410}
1411
Yingyi Buc9bfe252016-03-01 00:02:40 -08001412Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001413{
1414 List<String> exprList = new ArrayList<String>();
1415 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001416 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001417}
1418{
1419 lit = Identifier()
1420 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001421 boolean meetParens = false;
1422 }
1423 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001424 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001425 <LEFTPAREN><RIGHTPAREN>
1426 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001427 if(!lit.toLowerCase().equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001428 throw new ParseException("The string before () has to be \"meta\".");
1429 }
1430 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001431 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001432 }
1433 )?
1434 {
1435 if(!meetParens){
1436 exprList.add(lit);
1437 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001438 }
1439 (<DOT>
1440 lit = Identifier()
1441 {
1442 exprList.add(lit);
1443 }
1444 )*
1445 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001446 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001447 }
1448}
1449
1450
1451String QuotedString() throws ParseException:
1452{
1453}
1454{
1455 <QUOTED_STRING>
1456 {
1457 return removeQuotesAndEscapes(token.image);
1458 }
1459}
1460
1461
1462String StringLiteral() throws ParseException:
1463{
1464}
1465{
1466 <STRING_LITERAL>
1467 {
1468 return removeQuotesAndEscapes(token.image);
1469 }
1470}
1471
1472Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1473{
1474 String first = null;
1475 String second = null;
1476}
1477{
1478 first = Identifier() (<DOT> second = Identifier())?
1479 {
1480 Identifier id1 = null;
1481 Identifier id2 = null;
1482 if (second == null) {
1483 id2 = new Identifier(first);
1484 } else
1485 {
1486 id1 = new Identifier(first);
1487 id2 = new Identifier(second);
1488 }
1489 return new Pair<Identifier,Identifier>(id1, id2);
1490 }
1491}
1492
1493Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1494{
1495 String first = null;
1496 String second = null;
1497 String third = null;
1498}
1499{
1500 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1501 {
1502 Identifier id1 = null;
1503 Identifier id2 = null;
1504 Identifier id3 = null;
1505 if (third == null) {
1506 id2 = new Identifier(first);
1507 id3 = new Identifier(second);
1508 } else {
1509 id1 = new Identifier(first);
1510 id2 = new Identifier(second);
1511 id3 = new Identifier(third);
1512 }
1513 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1514 }
1515}
1516
1517FunctionDecl FunctionDeclaration() throws ParseException:
1518{
1519 FunctionDecl funcDecl;
1520 FunctionSignature signature;
1521 String functionName;
1522 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1523 Expression funcBody;
1524 createNewScope();
1525}
1526{
1527 <DECLARE> <FUNCTION> functionName = Identifier()
1528 paramList = ParameterList()
1529 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1530 {
1531 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1532 getCurrentScope().addFunctionDescriptor(signature, false);
1533 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1534 removeCurrentScope();
1535 return funcDecl;
1536 }
1537}
1538
1539
1540Query Query() throws ParseException:
1541{
1542 Query query = new Query();
1543 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1544 setDataverses(query.getDataverses());
1545 setDatasets(query.getDatasets());
1546 Expression expr;
1547}
1548{
1549 (
1550 expr = Expression()
1551 |
1552 expr = SelectExpression(false)
1553 )
1554 {
1555 query.setBody(expr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001556 // we remove the pointers to the locked entities before we return the query object
1557 setDataverses(null);
1558 setDatasets(null);
1559 return query;
1560 }
1561}
1562
1563
1564
1565Expression Expression():
1566{
1567 Expression expr = null;
1568 Expression exprP = null;
1569}
1570{
1571(
1572 LOOKAHEAD(2)
1573 expr = OperatorExpr()
1574 | expr = IfThenElse()
1575 | expr = QuantifiedExpression()
1576)
1577 {
1578 return (exprP==null) ? expr : exprP;
1579 }
1580}
1581
1582
1583
1584Expression OperatorExpr()throws ParseException:
1585{
1586 OperatorExpr op = null;
1587 Expression operand = null;
1588}
1589{
1590 operand = AndExpr()
1591 (
1592
1593 <OR>
1594 {
1595 if (op == null) {
1596 op = new OperatorExpr();
1597 op.addOperand(operand);
1598 op.setCurrentop(true);
1599 }
Yingyi Buacc12a92016-03-26 17:25:05 -07001600 op.addOperator(token.image.toLowerCase());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001601 }
1602
1603 operand = AndExpr()
1604 {
1605 op.addOperand(operand);
1606 }
1607
1608 )*
1609
1610 {
1611 return op==null? operand: op;
1612 }
1613}
1614
1615Expression AndExpr()throws ParseException:
1616{
1617 OperatorExpr op = null;
1618 Expression operand = null;
1619}
1620{
1621 operand = RelExpr()
1622 (
1623
1624 <AND>
1625 {
1626 if (op == null) {
1627 op = new OperatorExpr();
1628 op.addOperand(operand);
1629 op.setCurrentop(true);
1630 }
Yingyi Buacc12a92016-03-26 17:25:05 -07001631 op.addOperator(token.image.toLowerCase());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001632 }
1633
1634 operand = RelExpr()
1635 {
1636 op.addOperand(operand);
1637 }
1638
1639 )*
1640
1641 {
1642 return op==null? operand: op;
1643 }
1644}
1645
1646
1647
1648Expression RelExpr()throws ParseException:
1649{
1650 OperatorExpr op = null;
1651 Expression operand = null;
1652 boolean broadcast = false;
1653 IExpressionAnnotation annotation = null;
1654}
1655{
1656 operand = AddExpr()
1657 {
1658 if (operand instanceof VariableExpr) {
1659 String hint = getHint(token);
1660 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1661 broadcast = true;
1662 }
1663 }
1664 }
1665
1666 (
1667 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
1668 {
1669 String mhint = getHint(token);
1670 if (mhint != null) {
1671 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1672 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1673 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1674 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1675 }
1676 }
1677 if (op == null) {
1678 op = new OperatorExpr();
1679 op.addOperand(operand, broadcast);
1680 op.setCurrentop(true);
1681 broadcast = false;
1682 }
1683 op.addOperator(token.image);
1684 }
1685
1686 operand = AddExpr()
1687 {
1688 broadcast = false;
1689 if (operand instanceof VariableExpr) {
1690 String hint = getHint(token);
1691 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1692 broadcast = true;
1693 }
1694 }
1695 op.addOperand(operand, broadcast);
1696 }
1697 )?
1698
1699 {
1700 if (annotation != null) {
1701 op.addHint(annotation);
1702 }
1703 return op==null? operand: op;
1704 }
1705}
1706
1707Expression AddExpr()throws ParseException:
1708{
1709 OperatorExpr op = null;
1710 Expression operand = null;
1711}
1712{
1713 operand = MultExpr()
1714 (
1715 LOOKAHEAD(1)
1716 (<PLUS> | <MINUS>)
1717 {
1718 if (op == null) {
1719 op = new OperatorExpr();
1720 op.addOperand(operand);
1721 op.setCurrentop(true);
1722 }
1723 ((OperatorExpr)op).addOperator(token.image);
1724 }
1725
1726 operand = MultExpr()
1727 {
1728 op.addOperand(operand);
1729 }
1730 )*
1731
1732 {
1733 return op==null? operand: op;
1734 }
1735}
1736
1737Expression MultExpr()throws ParseException:
1738{
1739 OperatorExpr op = null;
1740 Expression operand = null;
1741}
1742{
1743 operand = UnaryExpr()
1744
1745 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1746 {
1747 if (op == null) {
1748 op = new OperatorExpr();
1749 op.addOperand(operand);
1750 op.setCurrentop(true);
1751 }
1752 op.addOperator(token.image);
1753 }
1754 operand = UnaryExpr()
1755 {
1756 op.addOperand(operand);
1757 }
1758 )*
1759
1760 {
1761 return op==null?operand:op;
1762 }
1763}
1764
1765Expression UnaryExpr() throws ParseException:
1766{
1767 Expression uexpr = null;
1768 Expression expr = null;
1769}
1770{
1771 ( (<PLUS> | <MINUS>)
1772 {
1773 uexpr = new UnaryExpr();
1774 if("+".equals(token.image))
1775 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1776 else if("-".equals(token.image))
1777 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1778 else
1779 throw new ParseException();
1780 }
1781 )?
1782
1783 expr = ValueExpr()
1784 {
1785 if(uexpr!=null){
1786 ((UnaryExpr)uexpr).setExpr(expr);
1787 return uexpr;
1788 }
1789 else{
1790 return expr;
1791 }
1792 }
1793}
1794
1795Expression ValueExpr()throws ParseException:
1796{
1797 Expression expr = null;
1798 Identifier ident = null;
1799 AbstractAccessor fa = null;
1800 Expression indexExpr = null;
1801}
1802{
1803 expr = PrimaryExpr() (
1804 ident = Field()
1805 {
1806 fa = (fa == null ? new FieldAccessor(expr, ident)
1807 : new FieldAccessor(fa, ident));
1808 }
1809 | indexExpr = Index()
1810 {
1811 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1812 : new IndexAccessor(fa, indexExpr));
1813 }
1814 )*
1815 {
1816 return fa == null ? expr : fa;
1817 }
1818}
1819
1820Identifier Field() throws ParseException:
1821{
1822 String ident = null;
1823}
1824{
1825 <DOT> ident = Identifier()
1826 {
1827 return new Identifier(ident);
1828 }
1829}
1830
1831Expression Index() throws ParseException:
1832{
1833 Expression expr = null;
1834}
1835{
1836 <LEFTBRACKET> ( expr = Expression()
1837 {
1838 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1839 {
1840 Literal lit = ((LiteralExpr)expr).getValue();
1841 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1842 lit.getLiteralType() != Literal.Type.LONG) {
1843 throw new ParseException("Index should be an INTEGER");
1844 }
1845 }
1846 }
1847
1848 | <QUES> // ANY
1849
1850 )
1851
1852 <RIGHTBRACKET>
1853 {
1854 return expr;
1855 }
1856}
1857
1858
1859Expression PrimaryExpr()throws ParseException:
1860{
1861 Expression expr = null;
1862}
1863{
1864 ( LOOKAHEAD(4)
1865 expr = FunctionCallExpr()
1866 | expr = Literal()
1867 | expr = VariableRef()
1868 | expr = ListConstructor()
1869 | expr = RecordConstructor()
1870 | expr = ParenthesizedExpression()
1871 )
1872 {
1873 return expr;
1874 }
1875}
1876
1877Expression Literal() throws ParseException:
1878{
1879 LiteralExpr lit = new LiteralExpr();
1880 String str = null;
1881}
1882{
1883 ( str = StringLiteral()
1884 {
1885 lit.setValue(new StringLiteral(str));
1886 }
1887 | <INTEGER_LITERAL>
1888 {
1889 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1890 }
1891 | <FLOAT_LITERAL>
1892 {
1893 lit.setValue(new FloatLiteral(new Float(token.image)));
1894 }
1895 | <DOUBLE_LITERAL>
1896 {
1897 lit.setValue(new DoubleLiteral(new Double(token.image)));
1898 }
1899 | <NULL>
1900 {
1901 lit.setValue(NullLiteral.INSTANCE);
1902 }
1903 | <TRUE>
1904 {
1905 lit.setValue(TrueLiteral.INSTANCE);
1906 }
1907 | <FALSE>
1908 {
1909 lit.setValue(FalseLiteral.INSTANCE);
1910 }
1911 )
1912 {
1913 return lit;
1914 }
1915}
1916
1917
1918VariableExpr VariableRef() throws ParseException:
1919{
1920 VariableExpr varExp = new VariableExpr();
1921 VarIdentifier var = new VarIdentifier();
1922}
1923{
1924 { String id = null; }
1925 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
1926 {
Yingyi Buacc12a92016-03-26 17:25:05 -07001927 id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$"
Yingyi Bu391f09e2015-10-29 13:49:39 -07001928 Identifier ident = lookupSymbol(id);
1929 if (isInForbiddenScopes(id)) {
1930 throw new ParseException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
1931 }
1932 if(ident != null) { // exist such ident
Yingyi Bu391f09e2015-10-29 13:49:39 -07001933 varExp.setVar((VarIdentifier)ident);
1934 } else {
1935 varExp.setVar(var);
Yingyi Buacc12a92016-03-26 17:25:05 -07001936 varExp.setIsNewVar(false);
1937 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001938 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001939 return varExp;
1940 }
1941}
1942
1943
1944VariableExpr Variable() throws ParseException:
1945{
1946 VariableExpr varExp = new VariableExpr();
1947 VarIdentifier var = new VarIdentifier();
1948}
1949{
1950 { String id = null; }
1951 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
1952 {
Yingyi Buacc12a92016-03-26 17:25:05 -07001953 id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$".
Yingyi Bu391f09e2015-10-29 13:49:39 -07001954 Identifier ident = lookupSymbol(id);
1955 if(ident != null) { // exist such ident
1956 varExp.setIsNewVar(false);
1957 }
1958 varExp.setVar(var);
Yingyi Bucaea8f02015-11-16 15:12:15 -08001959 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001960 return varExp;
1961 }
1962}
1963
1964Expression ListConstructor() throws ParseException:
1965{
1966 Expression expr = null;
1967}
1968{
1969 (
1970 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1971 )
1972
1973 {
1974 return expr;
1975 }
1976}
1977
1978
1979ListConstructor OrderedListConstructor() throws ParseException:
1980{
1981 ListConstructor expr = new ListConstructor();
1982 List<Expression> exprList = null;
1983 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1984}
1985{
1986 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
1987 {
1988 expr.setExprList(exprList);
1989 return expr;
1990 }
1991}
1992
1993ListConstructor UnorderedListConstructor() throws ParseException:
1994{
1995 ListConstructor expr = new ListConstructor();
1996 List<Expression> exprList = null;
1997 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1998}
1999{
2000 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2001 {
2002 expr.setExprList(exprList);
2003 return expr;
2004 }
2005}
2006
2007List<Expression> ExpressionList() throws ParseException:
2008{
2009 Expression expr = null;
2010 List<Expression> list = null;
2011 List<Expression> exprList = new ArrayList<Expression>();
2012}
2013{
2014 (
2015 expr = Expression() { exprList.add(expr); }
2016 (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
2017 )?
2018 (LOOKAHEAD(1) Comma())?
2019 {
2020 return exprList;
2021 }
2022}
2023
2024void Comma():
2025{}
2026{
2027 <COMMA>
2028}
2029
2030RecordConstructor RecordConstructor() throws ParseException:
2031{
2032 RecordConstructor expr = new RecordConstructor();
2033 FieldBinding tmp = null;
2034 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2035}
2036{
2037 <LEFTBRACE> (tmp = FieldBinding()
2038 {
2039 fbList.add(tmp);
2040 }
2041 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2042 {
2043 expr.setFbList(fbList);
2044 return expr;
2045 }
2046}
2047
2048FieldBinding FieldBinding() throws ParseException:
2049{
2050 FieldBinding fb = new FieldBinding();
2051 Expression left, right;
2052}
2053{
2054 left = Expression() <COLON> right = Expression()
2055 {
2056 fb.setLeftExpr(left);
2057 fb.setRightExpr(right);
2058 return fb;
2059 }
2060}
2061
2062
2063Expression FunctionCallExpr() throws ParseException:
2064{
2065 CallExpr callExpr;
2066 List<Expression> argList = new ArrayList<Expression>();
2067 Expression tmp;
2068 int arity = 0;
2069 FunctionName funcName = null;
2070 String hint = null;
2071}
2072{
2073 funcName = FunctionName()
2074 {
2075 hint = funcName.hint;
2076 }
2077 <LEFTPAREN> (tmp = Expression()
2078 {
2079 argList.add(tmp);
2080 arity ++;
2081 }
2082 (<COMMA> tmp = Expression()
2083 {
2084 argList.add(tmp);
2085 arity++;
2086 }
2087 )*)? <RIGHTPAREN>
2088 {
2089 // TODO use funcName.library
2090 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
2091 FunctionSignature signature
2092 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2093 if (signature == null) {
2094 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2095 }
2096 callExpr = new CallExpr(signature,argList);
2097 if (hint != null) {
2098 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2099 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2100 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2101 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2102 }
2103 }
2104 return callExpr;
2105 }
2106}
2107
2108Expression ParenthesizedExpression() throws ParseException:
2109{
2110 Expression expr;
2111}
2112{
2113 (
2114 LOOKAHEAD(2)
2115 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2116 |
2117 expr = Subquery()
2118 )
2119 {
2120 return expr;
2121 }
2122}
2123
2124Expression IfThenElse() throws ParseException:
2125{
2126 Expression condExpr;
2127 Expression thenExpr;
2128 Expression elseExpr;
2129 IfExpr ifExpr = new IfExpr();
2130}
2131{
2132 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
2133
2134 {
2135 ifExpr.setCondExpr(condExpr);
2136 ifExpr.setThenExpr(thenExpr);
2137 ifExpr.setElseExpr(elseExpr);
2138 return ifExpr;
2139 }
2140}
2141
2142SelectExpression SelectExpression(boolean subquery) throws ParseException: {
2143 List<LetClause> letClauses = new ArrayList<LetClause>();
2144 SelectSetOperation selectSetOperation;
2145 OrderbyClause orderbyClause = null;
2146 LimitClause limitClause = null;
2147 createNewScope();
2148} {
2149 ( letClauses = LetClause() )?
2150 selectSetOperation = SelectSetOperation()
2151 (orderbyClause = OrderbyClause() {})?
2152 (limitClause = LimitClause() {})?
2153 {
2154 return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
2155 }
2156}
2157
2158SelectSetOperation SelectSetOperation() throws ParseException: {
2159 SetOperationInput setOperationInputLeft;
2160 List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>();
2161}
2162{
2163 {
2164 SelectBlock selectBlockLeft = null;
2165 SelectExpression subqueryLeft = null;
2166 Expression expr = null;
2167 }
2168 selectBlockLeft = SelectBlock()
2169 {
2170 setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft);
2171 }
2172 (
2173 {
2174 SetOpType opType = SetOpType.UNION;
2175 boolean setSemantics = true;
2176 SelectBlock selectBlockRight = null;
2177 SelectExpression subqueryRight = null;
2178 }
2179 (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )?
2180 (selectBlockRight = SelectBlock()| subqueryRight = Subquery())
2181 {
2182 setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight)));
2183 }
2184 )*
2185 {
2186 return new SelectSetOperation(setOperationInputLeft, setOperationRights);
2187 }
2188}
2189
2190SelectExpression Subquery() throws ParseException: {
2191 SelectExpression selectExpr = null;
2192}
2193{
2194 <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN>
2195 {
2196 return selectExpr;
2197 }
2198}
2199
2200SelectBlock SelectBlock() throws ParseException: {
2201 SelectClause selectClause = null;
2202 FromClause fromClause = null;
2203 List<LetClause> fromLetClauses = null;
2204 WhereClause whereClause = null;
2205 GroupbyClause groupbyClause = null;
2206 List<LetClause> gbyLetClauses = null;
2207 HavingClause havingClause = null;
2208}
2209{
2210 (
2211 selectClause = SelectClause()
2212 (
2213 LOOKAHEAD(1)
2214 fromClause = FromClause()
2215 (
2216 LOOKAHEAD(1)
2217 fromLetClauses = LetClause()
2218 )?
2219 )?
2220 (whereClause = WhereClause())?
2221 (
2222 groupbyClause = GroupbyClause()
2223 (
2224 LOOKAHEAD(1)
2225 gbyLetClauses = LetClause()
2226 )?
2227 (havingClause = HavingClause())?
2228 )?
2229 |
2230 fromClause = FromClause()
2231 (
2232 LOOKAHEAD(1)
2233 fromLetClauses = LetClause()
2234 )?
2235 (whereClause = WhereClause())?
2236 (
2237 groupbyClause = GroupbyClause()
2238 (
2239 gbyLetClauses = LetClause()
2240 )?
2241 (havingClause = HavingClause())?
2242 )?
2243 selectClause = SelectClause()
2244 )
2245 {
2246 return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
2247 }
2248}
2249
2250SelectClause SelectClause() throws ParseException: {
2251 SelectRegular selectRegular = null;
2252 SelectElement selectElement = null;
2253 boolean distinct = false;
2254}
2255{
2256 <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
2257 (
2258 selectRegular = SelectRegular()
2259 |
2260 selectElement = SelectElement()
2261 )
2262 {
2263 return new SelectClause(selectElement, selectRegular, distinct);
2264 }
2265}
2266
2267SelectRegular SelectRegular() throws ParseException: {
2268 List<Projection> projections = new ArrayList<Projection>();
2269}
2270{
2271 {
2272 Projection projection = null;
2273 }
2274 projection = Projection() { projections.add(projection); }
2275 ( LOOKAHEAD(2) <COMMA>
2276 projection = Projection() {projections.add(projection);}
2277 )*
2278 {
2279 return new SelectRegular(projections);
2280 }
2281}
2282
2283SelectElement SelectElement() throws ParseException: {
2284 Expression expr = null;
2285 String name = null;
2286}
2287{
2288 (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
2289 {
2290 return new SelectElement(expr);
2291 }
2292}
2293
2294Projection Projection() throws ParseException: {
2295 Expression expr = null;
2296 Identifier identifier = null;
2297 String name = null;
2298 boolean star = false;
2299 boolean exprStar = false;
2300}
2301{
2302 (
2303 LOOKAHEAD(2)
2304 expr= Expression() (<AS>)? name = Identifier()
2305 | expr = Expression() <DOT> <MUL> {exprStar = true; }
2306 | <MUL> {star = true; }
2307 )
2308 {
2309 return new Projection(expr, name, star, exprStar);
2310 }
2311}
2312
2313FromClause FromClause() throws ParseException :
2314{
2315 List<FromTerm> fromTerms = new ArrayList<FromTerm>();
2316 extendCurrentScope();
2317}
2318{
2319 {
2320 FromTerm fromTerm = null;
2321 }
2322 <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
2323 (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
2324 {
2325 return new FromClause(fromTerms);
2326 }
2327}
2328
2329FromTerm FromTerm() throws ParseException :
2330{
2331 Expression leftExpr = null;
2332 VariableExpr leftVar = null;
2333 VariableExpr posVar = null;
2334 List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
2335}
2336{
2337 leftExpr = Expression() (<AS>)? leftVar = Variable() (<AT> posVar = Variable())?
2338 (
2339 {JoinType joinType = JoinType.INNER; }
2340 (joinType = JoinType())?
2341 {
2342 AbstractBinaryCorrelateClause correlateClause = null;
2343 }
2344 (correlateClause = JoinClause(joinType)
2345 |
2346 correlateClause = NestClause(joinType)
2347 |
2348 correlateClause = UnnestClause(joinType)
2349 )
2350 {
2351 correlateClauses.add(correlateClause);
2352 }
2353 )*
2354 {
2355 return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
2356 }
2357}
2358
2359JoinClause JoinClause(JoinType joinType) throws ParseException :
2360{
2361 Expression rightExpr = null;
2362 VariableExpr rightVar = null;
2363 VariableExpr posVar = null;
2364 Expression conditionExpr = null;
2365}
2366{
2367 <JOIN> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
2368 {
2369 return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2370 }
2371}
2372
2373NestClause NestClause(JoinType joinType) throws ParseException :
2374{
2375 Expression rightExpr = null;
2376 VariableExpr rightVar = null;
2377 VariableExpr posVar = null;
2378 Expression conditionExpr = null;
2379}
2380{
2381 <NEST> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
2382 {
2383 return new NestClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2384 }
2385}
2386
2387UnnestClause UnnestClause(JoinType joinType) throws ParseException :
2388{
2389 Expression rightExpr;
2390 VariableExpr rightVar;
2391 VariableExpr posVar = null;
2392}
2393{
2394 (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())?
2395 {
2396 return new UnnestClause(joinType, rightExpr, rightVar, posVar);
2397 }
2398}
2399
2400
2401JoinType JoinType() throws ParseException :
2402{
2403 JoinType joinType = JoinType.INNER;
2404}
2405{
2406 (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; })
2407 {
2408 return joinType;
2409 }
2410}
2411
2412List<LetClause> LetClause() throws ParseException:
2413{
2414 List<LetClause> letList = new ArrayList<LetClause>();
2415 LetClause letClause;
2416}
2417{
2418 (
2419 (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })*
2420 |
2421 <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })*
2422 )
2423 {
2424 return letList;
2425 }
2426}
2427
2428WhereClause WhereClause()throws ParseException :
2429{
2430 WhereClause wc = new WhereClause();
2431 Expression whereExpr;
2432}
2433{
2434 <WHERE> whereExpr = Expression()
2435 {
2436 wc.setWhereExpr(whereExpr);
2437 return wc;
2438 }
2439}
2440
2441OrderbyClause OrderbyClause()throws ParseException :
2442{
2443 OrderbyClause oc = new OrderbyClause();
2444 Expression orderbyExpr;
2445 List<Expression> orderbyList = new ArrayList<Expression>();
2446 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2447 int numOfOrderby = 0;
2448}
2449{
2450 <ORDER>
2451 {
2452 String hint = getHint(token);
2453 if (hint != null) {
2454 if (hint.startsWith(INMEMORY_HINT)) {
2455 String splits[] = hint.split(" +");
2456 int numFrames = Integer.parseInt(splits[1]);
2457 int numTuples = Integer.parseInt(splits[2]);
2458 oc.setNumFrames(numFrames);
2459 oc.setNumTuples(numTuples);
2460 }
2461 }
2462 }
2463 <BY> orderbyExpr = Expression()
2464 {
2465 orderbyList.add(orderbyExpr);
2466 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2467 }
2468 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2469 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2470 {
2471 modifierList.add(modif);
2472 }
2473
2474 (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression()
2475 {
2476 orderbyList.add(orderbyExpr);
2477 modif = OrderbyClause.OrderModifier.ASC;
2478 }
2479 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2480 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2481 {
2482 modifierList.add(modif);
2483 }
2484 )*
2485
2486 {
2487 oc.setModifierList(modifierList);
2488 oc.setOrderbyList(orderbyList);
2489 return oc;
2490 }
2491}
2492
2493GroupbyClause GroupbyClause()throws ParseException :
2494{
2495 GroupbyClause gbc = new GroupbyClause();
2496 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2497 VariableExpr var = null;
2498 VariableExpr withVar = null;
2499 Expression expr = null;
2500 VariableExpr decorVar = null;
2501 Expression decorExpr = null;
Yingyi Buacc12a92016-03-26 17:25:05 -07002502
2503 VariableExpr groupVar = null;
2504 List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<Pair<Expression, Identifier>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002505}
2506{
2507 {
2508 Scope newScope = extendCurrentScopeNoPush(true);
2509 // extendCurrentScope(true);
2510 }
2511 <GROUP>
2512 {
2513 String hint = getHint(token);
2514 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2515 gbc.setHashGroupByHint(true);
2516 }
2517 }
2518 <BY> (
2519 expr = Expression()
2520 (LOOKAHEAD(1) (<AS>)?
2521 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002522 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002523 {
2524 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2525 vePairList.add(pair1);
2526 }
2527 ( LOOKAHEAD(1) <COMMA>
2528 expr = Expression()
2529 (LOOKAHEAD(1) (<AS>)?
2530 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002531 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002532 {
2533 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2534 vePairList.add(pair2);
2535 }
2536 )*
2537 )
Yingyi Buacc12a92016-03-26 17:25:05 -07002538 (<GROUP> <AS> groupVar = Variable()
2539 ( LOOKAHEAD(1)
2540 {
2541 VariableExpr fieldVarExpr = null;
2542 String fieldIdentifierStr = null;
2543 }
2544 <LEFTPAREN>
2545 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
2546 {
2547 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
2548 }
2549 (<COMMA>
2550 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
2551 {
2552 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
2553 }
2554 )*
2555 <RIGHTPAREN>
2556 )?
2557 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002558 {
2559 gbc.setGbyPairList(vePairList);
2560 gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>());
2561 gbc.setWithVarList(new ArrayList<VariableExpr>());
Yingyi Buacc12a92016-03-26 17:25:05 -07002562 gbc.setGroupVar(groupVar);
2563 gbc.setGroupFieldList(groupFieldList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002564 replaceCurrentScope(newScope);
2565 return gbc;
2566 }
2567}
2568
2569HavingClause HavingClause() throws ParseException:
2570{
2571 Expression filterExpr = null;
2572}
2573{
2574 <HAVING> filterExpr = Expression()
2575 {
2576 return new HavingClause(filterExpr);
2577 }
2578}
2579
2580LimitClause LimitClause() throws ParseException:
2581{
2582 LimitClause lc = new LimitClause();
2583 Expression expr;
2584 pushForbiddenScope(getCurrentScope());
2585}
2586{
2587 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2588 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
2589
2590 {
2591 popForbiddenScope();
2592 return lc;
2593 }
2594}
2595
2596QuantifiedExpression QuantifiedExpression()throws ParseException:
2597{
2598 QuantifiedExpression qc = new QuantifiedExpression();
2599 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2600 Expression satisfiesExpr;
2601 VariableExpr var;
2602 Expression inExpr;
2603 QuantifiedPair pair;
2604}
2605{
2606 {
2607 createNewScope();
2608 }
2609
2610 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2611 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2612 var = Variable() <IN> inExpr = Expression()
2613 {
2614 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002615 quantifiedList.add(pair);
2616 }
2617 (
2618 <COMMA> var = Variable() <IN> inExpr = Expression()
2619 {
2620 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002621 quantifiedList.add(pair);
2622 }
2623 )*
2624 <SATISFIES> satisfiesExpr = Expression()
2625 {
2626 qc.setSatisfiesExpr(satisfiesExpr);
2627 qc.setQuantifiedList(quantifiedList);
2628 removeCurrentScope();
2629 return qc;
2630 }
2631}
2632
2633LetClause LetElement() throws ParseException:
2634{
2635 LetClause lc = new LetClause();
2636 VariableExpr varExp;
2637 Expression beExp;
2638 extendCurrentScope();
2639}
2640{
2641 varExp = Variable() <EQ> beExp = Expression()
2642 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002643 lc.setVarExpr(varExp);
2644 lc.setBindingExpr(beExp);
2645 return lc;
2646 }
2647}
2648
2649LetClause WithElement() throws ParseException:
2650{
2651 LetClause lc = new LetClause();
2652 VariableExpr varExp;
2653 Expression beExp;
2654 extendCurrentScope();
2655}
2656{
2657 varExp = Variable() <AS> beExp = Expression()
2658 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002659 lc.setVarExpr(varExp);
2660 lc.setBindingExpr(beExp);
2661 return lc;
2662 }
2663}
2664
2665TOKEN_MGR_DECLS:
2666{
2667 public int commentDepth = 0;
2668 public IntStack lexerStateStack = new IntStack();
2669
2670 public void pushState() {
2671 lexerStateStack.push( curLexState );
2672 }
2673
2674 public void popState(String token) {
2675 if (lexerStateStack.size() > 0) {
2676 SwitchTo( lexerStateStack.pop() );
2677 } else {
2678 int errorLine = input_stream.getEndLine();
2679 int errorColumn = input_stream.getEndColumn();
2680 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2681 + "\" but state stack is empty.";
2682 throw new TokenMgrError(msg, -1);
2683 }
2684 }
2685}
2686
2687<DEFAULT,IN_DBL_BRACE>
2688TOKEN [IGNORE_CASE]:
2689{
2690 <ALL : "all">
2691 | <AND : "and">
2692 | <APPLY : "apply">
2693 | <AS : "as">
2694 | <ASC : "asc">
2695 | <AT : "at">
2696 | <AUTOGENERATED : "autogenerated">
2697 | <BTREE : "btree">
2698 | <BY : "by">
2699 | <CASE : "case">
2700 | <CLOSED : "closed">
2701 | <CREATE : "create">
2702 | <COMPACTION : "compaction">
2703 | <COMPACT : "compact">
2704 | <CONNECT : "connect">
2705 | <CORRELATE : "correlate">
2706 | <DATASET : "table">
Yingyi Bu1c0fff52016-03-25 20:23:30 -07002707 | <COLLECTION : "collection">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002708 | <DATAVERSE : "database">
2709 | <DECLARE : "declare">
2710 | <DEFINITION : "definition">
2711 | <DELETE : "delete">
2712 | <DESC : "desc">
2713 | <DISCONNECT : "disconnect">
2714 | <DISTINCT : "distinct">
2715 | <DROP : "drop">
2716 | <ELEMENT : "element">
2717 | <ELSE : "else">
2718 | <ENFORCED : "enforced">
2719 | <EVERY : "every">
2720 | <EXCEPT : "except">
2721 | <EXISTS : "exists">
2722 | <EXTERNAL : "external">
2723 | <FEED : "feed">
2724 | <FILTER : "filter">
2725 | <FLATTEN : "flatten">
2726 | <FOR : "for">
2727 | <FORMAT : "format">
2728 | <FROM : "from">
2729 | <FULL : "full">
2730 | <FUNCTION : "function">
2731 | <GROUP : "group">
2732 | <HAVING : "having">
2733 | <HINTS : "hints">
2734 | <IF : "if">
2735 | <INTO : "into">
2736 | <IN : "in">
2737 | <INDEX : "index">
2738 | <INGESTION : "ingestion">
2739 | <INNER : "inner">
2740 | <INSERT : "insert">
2741 | <INTERNAL : "internal">
2742 | <INTERSECT : "intersect">
2743 | <JOIN : "join">
2744 | <KEYWORD : "keyword">
2745 | <KEY : "key">
2746 | <LEFT : "left">
2747 | <LETTING : "letting">
2748 | <LET : "let">
2749 | <LIMIT : "limit">
2750 | <LOAD : "load">
2751 | <NEST : "nest">
2752 | <NODEGROUP : "nodegroup">
2753 | <NGRAM : "ngram">
2754 | <OFFSET : "offset">
2755 | <ON : "on">
2756 | <OPEN : "open">
2757 | <OR : "or">
2758 | <ORDER : "order">
2759 | <OUTER : "outer">
2760 | <OUTPUT : "output">
2761 | <PATH : "path">
2762 | <POLICY : "policy">
2763 | <PRESORTED : "pre-sorted">
2764 | <PRIMARY : "primary">
2765 | <RAW : "raw">
2766 | <REFRESH : "refresh">
2767 | <RETURN : "return">
2768 | <RTREE : "rtree">
2769 | <RUN : "run">
2770 | <SATISFIES : "satisfies">
2771 | <SECONDARY : "secondary">
2772 | <SELECT : "select">
2773 | <SET : "set">
2774 | <SOME : "some">
2775 | <TEMPORARY : "temporary">
2776 | <THEN : "then">
2777 | <TYPE : "type">
2778 | <TO : "to">
2779 | <UNION : "union">
2780 | <UNNEST : "unnest">
2781 | <VALUE : "value">
2782 | <WHEN : "when">
2783 | <WHERE : "where">
2784 | <WITH : "with">
2785 | <WRITE : "write">
2786 | <UPDATE : "update">
2787 | <USE : "use">
2788 | <USING : "using">
2789}
2790
2791<DEFAULT,IN_DBL_BRACE>
2792TOKEN :
2793{
2794 <CARET : "^">
2795 | <DIV : "/">
2796 | <IDIV : "idiv">
2797 | <MINUS : "-">
2798 | <MOD : "%">
2799 | <MUL : "*">
2800 | <PLUS : "+">
2801
2802 | <LEFTPAREN : "(">
2803 | <RIGHTPAREN : ")">
2804 | <LEFTBRACKET : "[">
2805 | <RIGHTBRACKET : "]">
2806
2807 | <ATT : "@">
2808 | <COLON : ":">
2809 | <COMMA : ",">
2810 | <DOT : ".">
2811 | <QUES : "?">
2812 | <SEMICOLON : ";">
2813 | <SHARP : "#">
2814
2815 | <LT : "<">
2816 | <GT : ">">
2817 | <LE : "<=">
2818 | <GE : ">=">
2819 | <EQ : "=">
2820 | <NE : "!=">
2821 | <SIMILAR : "~=">
2822}
2823
2824<DEFAULT,IN_DBL_BRACE>
2825TOKEN :
2826{
2827 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2828}
2829
2830<DEFAULT>
2831TOKEN :
2832{
2833 <RIGHTBRACE : "}"> { popState("}"); }
2834}
2835
2836<DEFAULT,IN_DBL_BRACE>
2837TOKEN :
2838{
2839 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2840}
2841
2842<IN_DBL_BRACE>
2843TOKEN :
2844{
2845 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
2846}
2847
2848<DEFAULT,IN_DBL_BRACE>
2849TOKEN :
2850{
2851 <INTEGER_LITERAL : (<DIGIT>)+ >
2852}
2853
2854<DEFAULT,IN_DBL_BRACE>
2855TOKEN :
2856{
2857 <NULL : "null">
2858 | <TRUE : "true">
2859 | <FALSE : "false">
2860}
2861
2862<DEFAULT,IN_DBL_BRACE>
2863TOKEN :
2864{
2865 <#DIGIT : ["0" - "9"]>
2866}
2867
2868<DEFAULT,IN_DBL_BRACE>
2869TOKEN:
2870{
2871 < DOUBLE_LITERAL: <DIGITS>
2872 | <DIGITS> ( "." <DIGITS> )?
2873 | "." <DIGITS>
2874 >
2875 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2876 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2877 | "." <DIGITS> ( "f" | "F" )
2878 >
2879 | <DIGITS : (<DIGIT>)+ >
2880}
2881
2882<DEFAULT,IN_DBL_BRACE>
2883TOKEN :
2884{
2885 <#LETTER : ["A" - "Z", "a" - "z"]>
2886 | <SPECIALCHARS : ["$", "_"]>
2887}
2888
2889<DEFAULT,IN_DBL_BRACE>
2890TOKEN :
2891{
2892 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2893 <QUOTED_STRING : "\"" (
2894 <EscapeQuot>
2895 | <EscapeBslash>
2896 | <EscapeSlash>
2897 | <EscapeBspace>
2898 | <EscapeFormf>
2899 | <EscapeNl>
2900 | <EscapeCr>
2901 | <EscapeTab>
2902 | ~["\"","\\"])* "\"">
2903 | <STRING_LITERAL : "\'" (
2904 <EscapeQuot>
2905 | <EscapeApos>
2906 | <EscapeBslash>
2907 | <EscapeSlash>
2908 | <EscapeBspace>
2909 | <EscapeFormf>
2910 | <EscapeNl>
2911 | <EscapeCr>
2912 | <EscapeTab>
2913 | ~["\'","\\"])* "\'">
2914 | < #EscapeQuot: "\\\"" >
2915 | < #EscapeApos: "\\\'" >
2916 | < #EscapeBslash: "\\\\" >
2917 | < #EscapeSlash: "\\/" >
2918 | < #EscapeBspace: "\\b" >
2919 | < #EscapeFormf: "\\f" >
2920 | < #EscapeNl: "\\n" >
2921 | < #EscapeCr: "\\r" >
2922 | < #EscapeTab: "\\t" >
2923}
2924
2925<DEFAULT,IN_DBL_BRACE>
2926TOKEN :
2927{
2928 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2929}
2930
2931<DEFAULT,IN_DBL_BRACE>
2932SKIP:
2933{
2934 " "
2935 | "\t"
2936 | "\r"
2937 | "\n"
2938}
2939
2940<DEFAULT,IN_DBL_BRACE>
2941SKIP:
2942{
2943 <"//" (~["\n"])* "\n">
2944}
2945
2946<DEFAULT,IN_DBL_BRACE>
2947SKIP:
2948{
2949 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2950}
2951
2952<DEFAULT,IN_DBL_BRACE>
2953SKIP:
2954{
2955 <"/*"> { pushState(); } : INSIDE_COMMENT
2956}
2957
2958<INSIDE_COMMENT>
2959SPECIAL_TOKEN:
2960{
2961 <"+"(" ")*(~["*"])*>
2962}
2963
2964<INSIDE_COMMENT>
2965SKIP:
2966{
2967 <"/*"> { pushState(); }
2968}
2969
2970<INSIDE_COMMENT>
2971SKIP:
2972{
2973 <"*/"> { popState("*/"); }
2974 | <~[]>
2975}