blob: a58ce0ff1e531affb71aa3e2865593fc14742c04 [file] [log] [blame]
Michael Blow82464fb2017-03-28 18:48:13 -04001//
2// Licensed to the Apache Software Foundation (ASF) under one
3// or more contributor license agreements. See the NOTICE file
4// distributed with this work for additional information
5// regarding copyright ownership. The ASF licenses this file
6// to you under the Apache License, Version 2.0 (the
7// "License"); you may not use this file except in compliance
8// with the License. You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing,
13// software distributed under the License is distributed on an
14// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15// KIND, either express or implied. See the License for the
16// specific language governing permissions and limitations
17// under the License.
18//
Yingyi Bu391f09e2015-10-29 13:49:39 -070019options {
20
21
22 STATIC = false;
23
24}
25
26
27PARSER_BEGIN(SQLPPParser)
28
29package org.apache.asterix.lang.sqlpp.parser;
30
31// For SQL++ ParserTokenManager
Till Westmanne9b2adf2016-10-15 12:39:01 -070032import java.util.ArrayDeque;
Yingyi Bu391f09e2015-10-29 13:49:39 -070033
34import java.io.BufferedReader;
35import java.io.File;
36import java.io.FileInputStream;
37import java.io.FileNotFoundException;
38import java.io.IOException;
39import java.io.InputStreamReader;
40import java.io.Reader;
41import java.io.StringReader;
42import java.util.ArrayList;
Yingyi Budaa549c2016-06-28 22:30:52 -070043import java.util.Collections;
Yingyi Bu391f09e2015-10-29 13:49:39 -070044import java.util.HashMap;
45import java.util.Iterator;
46import java.util.LinkedHashMap;
47import java.util.List;
48import java.util.Map;
49
50import org.apache.asterix.common.annotations.AutoDataGen;
51import org.apache.asterix.common.annotations.DateBetweenYearsDataGen;
52import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen;
53import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen;
54import org.apache.asterix.common.annotations.FieldIntervalDataGen;
55import org.apache.asterix.common.annotations.FieldValFileDataGen;
56import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen;
57import org.apache.asterix.common.annotations.IRecordFieldDataGen;
58import org.apache.asterix.common.annotations.InsertRandIntDataGen;
59import org.apache.asterix.common.annotations.ListDataGen;
60import org.apache.asterix.common.annotations.ListValFileDataGen;
61import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
62import org.apache.asterix.common.annotations.TypeDataGen;
63import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
64import org.apache.asterix.common.config.DatasetConfig.DatasetType;
65import org.apache.asterix.common.config.DatasetConfig.IndexType;
Taewoo Kime65e6ca2017-01-14 17:53:28 -080066import org.apache.asterix.common.exceptions.CompilationException;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -080067import org.apache.asterix.common.functions.FunctionConstants;
Yingyi Bu391f09e2015-10-29 13:49:39 -070068import org.apache.asterix.common.functions.FunctionSignature;
69import org.apache.asterix.lang.common.base.Expression;
70import org.apache.asterix.lang.common.base.Literal;
71import org.apache.asterix.lang.common.base.IParser;
72import org.apache.asterix.lang.common.base.Statement;
73import org.apache.asterix.lang.common.clause.GroupbyClause;
74import org.apache.asterix.lang.common.clause.LetClause;
75import org.apache.asterix.lang.common.clause.LimitClause;
76import org.apache.asterix.lang.common.clause.OrderbyClause;
77import org.apache.asterix.lang.common.clause.UpdateClause;
78import org.apache.asterix.lang.common.clause.WhereClause;
79import org.apache.asterix.lang.common.context.RootScopeFactory;
80import org.apache.asterix.lang.common.context.Scope;
81import org.apache.asterix.lang.common.expression.AbstractAccessor;
82import org.apache.asterix.lang.common.expression.CallExpr;
83import org.apache.asterix.lang.common.expression.FieldAccessor;
84import org.apache.asterix.lang.common.expression.FieldBinding;
85import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
86import org.apache.asterix.lang.common.expression.IfExpr;
87import org.apache.asterix.lang.common.expression.IndexAccessor;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -070088import org.apache.asterix.lang.common.expression.IndexedTypeExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -070089import org.apache.asterix.lang.common.expression.ListConstructor;
90import org.apache.asterix.lang.common.expression.LiteralExpr;
91import org.apache.asterix.lang.common.expression.OperatorExpr;
92import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
93import org.apache.asterix.lang.common.expression.QuantifiedExpression;
94import org.apache.asterix.lang.common.expression.RecordConstructor;
95import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
96import org.apache.asterix.lang.common.expression.TypeExpression;
97import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
98import org.apache.asterix.lang.common.expression.UnaryExpr;
Yingyi Bu391f09e2015-10-29 13:49:39 -070099import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
100import org.apache.asterix.lang.common.expression.VariableExpr;
101import org.apache.asterix.lang.common.literal.DoubleLiteral;
102import org.apache.asterix.lang.common.literal.FalseLiteral;
103import org.apache.asterix.lang.common.literal.FloatLiteral;
104import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
Yingyi Bu535d86b2016-05-23 16:44:25 -0700105import org.apache.asterix.lang.common.literal.MissingLiteral;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700106import org.apache.asterix.lang.common.literal.NullLiteral;
107import org.apache.asterix.lang.common.literal.StringLiteral;
108import org.apache.asterix.lang.common.literal.TrueLiteral;
109import org.apache.asterix.lang.common.parser.ScopeChecker;
110import org.apache.asterix.lang.common.statement.CompactStatement;
111import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800112import org.apache.asterix.lang.common.statement.StartFeedStatement;
113import org.apache.asterix.lang.common.statement.StopFeedStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700114import org.apache.asterix.lang.common.statement.CreateDataverseStatement;
115import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement;
116import org.apache.asterix.lang.common.statement.CreateFeedStatement;
117import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
118import org.apache.asterix.lang.common.statement.CreateIndexStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700119import org.apache.asterix.lang.common.statement.DatasetDecl;
120import org.apache.asterix.lang.common.statement.DataverseDecl;
121import org.apache.asterix.lang.common.statement.DataverseDropStatement;
122import org.apache.asterix.lang.common.statement.DeleteStatement;
123import org.apache.asterix.lang.common.statement.DisconnectFeedStatement;
Yingyi Buab817482016-08-19 21:29:31 -0700124import org.apache.asterix.lang.common.statement.DropDatasetStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700125import org.apache.asterix.lang.common.statement.ExternalDetailsDecl;
126import org.apache.asterix.lang.common.statement.FeedDropStatement;
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300127import org.apache.asterix.lang.common.statement.FeedPolicyDropStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700128import org.apache.asterix.lang.common.statement.FunctionDecl;
129import org.apache.asterix.lang.common.statement.FunctionDropStatement;
130import org.apache.asterix.lang.common.statement.IndexDropStatement;
131import org.apache.asterix.lang.common.statement.InsertStatement;
132import org.apache.asterix.lang.common.statement.InternalDetailsDecl;
133import org.apache.asterix.lang.common.statement.LoadStatement;
134import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
135import org.apache.asterix.lang.common.statement.NodegroupDecl;
136import org.apache.asterix.lang.common.statement.Query;
137import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement;
138import org.apache.asterix.lang.common.statement.RunStatement;
139import org.apache.asterix.lang.common.statement.SetStatement;
140import org.apache.asterix.lang.common.statement.TypeDecl;
141import org.apache.asterix.lang.common.statement.TypeDropStatement;
142import org.apache.asterix.lang.common.statement.UpdateStatement;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800143import org.apache.asterix.lang.common.statement.UpsertStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700144import org.apache.asterix.lang.common.statement.WriteStatement;
145import org.apache.asterix.lang.common.struct.Identifier;
146import org.apache.asterix.lang.common.struct.QuantifiedPair;
147import org.apache.asterix.lang.common.struct.VarIdentifier;
148import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
149import org.apache.asterix.lang.sqlpp.clause.FromClause;
150import org.apache.asterix.lang.sqlpp.clause.FromTerm;
151import org.apache.asterix.lang.sqlpp.clause.HavingClause;
152import org.apache.asterix.lang.sqlpp.clause.JoinClause;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700153import org.apache.asterix.lang.sqlpp.clause.Projection;
154import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
155import org.apache.asterix.lang.sqlpp.clause.SelectClause;
156import org.apache.asterix.lang.sqlpp.clause.SelectElement;
157import org.apache.asterix.lang.sqlpp.clause.SelectRegular;
158import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
159import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
Yingyi Buc8c067c2016-07-25 23:37:19 -0700160import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700161import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
162import org.apache.asterix.lang.sqlpp.optype.JoinType;
163import org.apache.asterix.lang.sqlpp.optype.SetOpType;
164import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
165import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
Yingyi Bu9e3f9be2016-07-01 10:07:37 -0700166import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil;
Xikui Wang96fd4022017-04-10 14:23:31 -0700167import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
Yingyi Buacc12a92016-03-26 17:25:05 -0700168import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -0800169import org.apache.asterix.om.functions.BuiltinFunctions;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700170import org.apache.hyracks.algebricks.common.utils.Pair;
171import org.apache.hyracks.algebricks.common.utils.Triple;
172import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
173import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
174import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
175
Yingyi Bucaea8f02015-11-16 15:12:15 -0800176class SQLPPParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700177
178 // optimizer hints
179 private static final String AUTO_HINT = "auto";
180 private static final String BROADCAST_JOIN_HINT = "bcast";
181 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
182 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
183 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
184 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
185 private static final String HASH_GROUP_BY_HINT = "hash";
186 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
187 private static final String INMEMORY_HINT = "inmem";
188 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
189 private static final String INTERVAL_HINT = "interval";
190 private static final String LIST_HINT = "list";
191 private static final String LIST_VAL_FILE_HINT = "list-val-file";
192 private static final String RANGE_HINT = "range";
193 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
194 private static final String VAL_FILE_HINT = "val-files";
195 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
196
197 private static final String GEN_FIELDS_HINT = "gen-fields";
198
199 // data generator hints
200 private static final String DGEN_HINT = "dgen";
201
Till Westmann7199a562016-09-17 16:07:32 -0700202 // error configuration
203 protected static final boolean REPORT_EXPECTED_TOKENS = false;
204
Yingyi Bu391f09e2015-10-29 13:49:39 -0700205 private static class IndexParams {
206 public IndexType type;
207 public int gramLength;
208
209 public IndexParams(IndexType type, int gramLength) {
210 this.type = type;
211 this.gramLength = gramLength;
212 }
213 };
214
215 private static class FunctionName {
216 public String dataverse = null;
217 public String library = null;
218 public String function = null;
219 public String hint = null;
220 }
221
222 private static String getHint(Token t) {
223 if (t.specialToken == null) {
224 return null;
225 }
226 String s = t.specialToken.image;
227 int n = s.length();
228 if (n < 2) {
229 return null;
230 }
231 return s.substring(1).trim();
232 }
233
234 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
235 IRecordFieldDataGen rfdg = null;
236 String splits[] = hint.split(" +");
237 if (splits[0].equals(VAL_FILE_HINT)) {
238 File[] valFiles = new File[splits.length - 1];
239 for (int k=1; k<splits.length; k++) {
240 valFiles[k-1] = new File(splits[k]);
241 }
242 rfdg = new FieldValFileDataGen(valFiles);
243 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
244 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
245 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
246 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
247 } else if (splits[0].equals(LIST_HINT)) {
248 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
249 } else if (splits[0].equals(INTERVAL_HINT)) {
250 FieldIntervalDataGen.ValueType vt;
251 if (splits[1].equals("int")) {
252 vt = FieldIntervalDataGen.ValueType.INT;
253 } else if (splits[1].equals("long")) {
254 vt = FieldIntervalDataGen.ValueType.LONG;
255 } else if (splits[1].equals("float")) {
256 vt = FieldIntervalDataGen.ValueType.FLOAT;
257 } else if (splits[1].equals("double")) {
258 vt = FieldIntervalDataGen.ValueType.DOUBLE;
259 } else {
260 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
261 }
262 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
263 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
264 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
265 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
266 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
267 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
268 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
269 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
270 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
271 } else if (splits[0].equals(AUTO_HINT)) {
272 rfdg = new AutoDataGen(splits[1]);
273 }
274 return rfdg;
275 }
276
Till Westmann7199a562016-09-17 16:07:32 -0700277 public SQLPPParser(String s) {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700278 this(new StringReader(s));
279 super.setInput(s);
280 }
281
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800282 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700283 File file = new File(args[0]);
284 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
285 SQLPPParser parser = new SQLPPParser(fis);
286 List<Statement> st = parser.parse();
287 //st.accept(new SQLPPPrintVisitor(), 0);
288 }
289
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800290 public List<Statement> parse() throws CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700291 try {
292 return Statement();
293 } catch (Error e) {
294 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
295 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
Till Westmann60f89982017-08-11 18:14:20 -0700296 final String msg = e.getClass().getSimpleName() + (e.getMessage() != null ? ": " + e.getMessage() : "");
297 throw new CompilationException(new ParseException(msg));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700298 } catch (ParseException e) {
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800299 throw new CompilationException("Syntax error: " + getMessage(e));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700300 }
301 }
Till Westmann7199a562016-09-17 16:07:32 -0700302
303 protected String getMessage(ParseException pe) {
304 Token currentToken = pe.currentToken;
305 if (currentToken == null) {
306 return pe.getMessage();
307 }
308 int[][] expectedTokenSequences = pe.expectedTokenSequences;
309 String[] tokenImage = pe.tokenImage;
310 String sep = REPORT_EXPECTED_TOKENS ? eol : " ";
311 StringBuilder expected = REPORT_EXPECTED_TOKENS ? new StringBuilder() : null;
312 int maxSize = appendExpected(expected, expectedTokenSequences, tokenImage);
313 Token tok = currentToken.next;
314 int line = tok.beginLine;
315 String message = "In line " + line + " >>" + getLine(line) + "<<" + sep + "Encountered ";
316 for (int i = 0; i < maxSize; i++) {
317 if (i != 0) {
318 message += " ";
319 }
320 if (tok.kind == 0) {
321 message += fixQuotes(tokenImage[0]);
322 break;
323 }
Till Westmanne3c9f272016-10-09 11:09:26 -0700324 final String fixedTokenImage = tokenImage[tok.kind];
325 if (! tok.image.equalsIgnoreCase(stripQuotes(fixedTokenImage))) {
326 message += fixQuotes(fixedTokenImage) + " ";
327 }
Till Westmann7199a562016-09-17 16:07:32 -0700328 message += quot + addEscapes(tok.image) + quot;
329 tok = tok.next;
330 }
331 message += " at column " + currentToken.next.beginColumn + "." + sep;
332 if (REPORT_EXPECTED_TOKENS) {
333 if (expectedTokenSequences.length == 1) {
334 message += "Was expecting:" + sep + " ";
335 } else {
336 message += "Was expecting one of:" + sep + " ";
337 }
338 message += expected.toString();
339 }
340 return message;
341 }
342
Yingyi Bu391f09e2015-10-29 13:49:39 -0700343}
344
345PARSER_END(SQLPPParser)
346
347
348List<Statement> Statement() throws ParseException:
349{
350 scopeStack.push(RootScopeFactory.createRootScope(this));
351 List<Statement> decls = new ArrayList<Statement>();
352 Statement stmt = null;
353}
354{
Murtadha Hubaildc775222017-08-21 15:22:45 +0300355 (
356 (stmt = SingleStatement()
357 {
358 decls.add(stmt);
359 }
360 )?
361 (<SEMICOLON>)+
Yingyi Bu391f09e2015-10-29 13:49:39 -0700362 )*
363 <EOF>
364 {
365 return decls;
366 }
367}
368
369Statement SingleStatement() throws ParseException:
370{
371 Statement stmt = null;
372}
373{
374 (
375 stmt = DataverseDeclaration()
376 | stmt = FunctionDeclaration()
377 | stmt = CreateStatement()
378 | stmt = LoadStatement()
379 | stmt = DropStatement()
380 | stmt = WriteStatement()
381 | stmt = SetStatement()
382 | stmt = InsertStatement()
383 | stmt = DeleteStatement()
384 | stmt = UpdateStatement()
Yingyi Bucb5bf332017-01-02 22:19:50 -0800385 | stmt = UpsertStatement()
Yingyi Buab817482016-08-19 21:29:31 -0700386 | stmt = ConnectionStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700387 | stmt = CompactStatement()
Till Westmannef3f0272016-07-27 18:34:01 -0700388 | stmt = ExplainStatement()
Murtadha Hubaildc775222017-08-21 15:22:45 +0300389 | stmt = Query(false)
Yingyi Bu391f09e2015-10-29 13:49:39 -0700390 | stmt = RefreshExternalDatasetStatement()
391 | stmt = RunStatement()
392 )
393 {
394 return stmt;
395 }
396}
397
398DataverseDecl DataverseDeclaration() throws ParseException:
399{
400 String dvName = null;
401}
402{
403 <USE> dvName = Identifier()
404 {
405 defaultDataverse = dvName;
406 return new DataverseDecl(new Identifier(dvName));
407 }
408}
409
410Statement CreateStatement() throws ParseException:
411{
412 String hint = null;
413 boolean dgen = false;
414 Statement stmt = null;
415}
416{
417 <CREATE>
418 (
419 {
420 hint = getHint(token);
421 if (hint != null && hint.startsWith(DGEN_HINT)) {
422 dgen = true;
423 }
424 }
425 stmt = TypeSpecification(hint, dgen)
426 | stmt = NodegroupSpecification()
427 | stmt = DatasetSpecification()
428 | stmt = IndexSpecification()
429 | stmt = DataverseSpecification()
430 | stmt = FunctionSpecification()
431 | stmt = FeedSpecification()
432 | stmt = FeedPolicySpecification()
433 )
434 {
435 return stmt;
436 }
437}
438
439TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
440{
441 Pair<Identifier,Identifier> nameComponents = null;
442 boolean ifNotExists = false;
443 TypeExpression typeExpr = null;
444}
445{
446 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmannf6028272016-09-30 14:34:42 -0700447 <AS> typeExpr = RecordTypeDef()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700448 {
449 long numValues = -1;
450 String filename = null;
451 if (dgen) {
452 String splits[] = hint.split(" +");
453 if (splits.length != 3) {
454 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
455 }
456 filename = splits[1];
457 numValues = Long.parseLong(splits[2]);
458 }
459 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
460 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
461 }
462}
463
464
465NodegroupDecl NodegroupSpecification() throws ParseException:
466{
467 String name = null;
468 String tmp = null;
469 boolean ifNotExists = false;
470 List<Identifier>ncNames = null;
471}
472{
473 <NODEGROUP> name = Identifier()
474 ifNotExists = IfNotExists() <ON> tmp = Identifier()
475 {
476 ncNames = new ArrayList<Identifier>();
477 ncNames.add(new Identifier(tmp));
478 }
479 ( <COMMA> tmp = Identifier()
480 {
481 ncNames.add(new Identifier(tmp));
482 }
483 )*
484 {
485 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
486 }
487}
488
489DatasetDecl DatasetSpecification() throws ParseException:
490{
491 Pair<Identifier,Identifier> nameComponents = null;
492 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800493 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700494 String adapterName = null;
495 Map<String,String> properties = null;
496 Map<String,String> compactionPolicyProperties = null;
497 FunctionSignature appliedFunction = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800498 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700499 String nodeGroupName = null;
500 Map<String,String> hints = new HashMap<String,String>();
501 DatasetDecl dsetDecl = null;
502 boolean autogenerated = false;
503 String compactionPolicy = null;
504 boolean temp = false;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800505 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800506 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700507}
508{
509 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700510 <EXTERNAL> Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800511 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700512 ifNotExists = IfNotExists()
513 <USING> adapterName = AdapterName() properties = Configuration()
514 (<ON> nodeGroupName = Identifier() )?
515 ( <HINTS> hints = Properties() )?
516 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )?
517 {
518 ExternalDetailsDecl edd = new ExternalDetailsDecl();
519 edd.setAdapter(adapterName);
520 edd.setProperties(properties);
521 dsetDecl = new DatasetDecl(nameComponents.first,
522 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800523 typeComponents.first,
524 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800525 metaTypeComponents.first,
526 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700527 nodeGroupName != null? new Identifier(nodeGroupName): null,
528 compactionPolicy,
529 compactionPolicyProperties,
530 hints,
531 DatasetType.EXTERNAL,
532 edd,
533 ifNotExists);
534 }
535
Yingyi Bub9169b62016-02-26 21:21:49 -0800536 | (<INTERNAL> | <TEMPORARY> { temp = true; })?
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700537 Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800538 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800539 (
540 { String name; }
541 <WITH>
542 name = Identifier()
543 {
544 if(!name.toLowerCase().equals("meta")){
545 throw new ParseException("We can only support one additional associated field called \"meta\".");
546 }
547 }
548 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
549 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700550 ifNotExists = IfNotExists()
551 primaryKeyFields = PrimaryKey()
552 (<AUTOGENERATED> { autogenerated = true; } )?
553 (<ON> nodeGroupName = Identifier() )?
554 ( <HINTS> hints = Properties() )?
555 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )?
556 ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
557 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800558 if(filterField!=null && filterField.first!=0){
559 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
560 }
561 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
562 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700563 autogenerated,
Yingyi Buc9bfe252016-03-01 00:02:40 -0800564 filterField == null? null : filterField.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700565 temp);
566 dsetDecl = new DatasetDecl(nameComponents.first,
567 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800568 typeComponents.first,
569 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800570 metaTypeComponents.first,
571 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700572 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
573 compactionPolicy,
574 compactionPolicyProperties,
575 hints,
576 DatasetType.INTERNAL,
577 idd,
578 ifNotExists);
579 }
580 )
581 {
582 return dsetDecl;
583 }
584}
585
586RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
587{
588 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
589 Pair<Identifier,Identifier> nameComponents = null;
590 String datasetName = null;
591}
592{
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700593 <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700594 {
595 redss.setDataverseName(nameComponents.first);
596 redss.setDatasetName(nameComponents.second);
597 return redss;
598 }
599}
600
601RunStatement RunStatement() throws ParseException:
602{
603 String system = null;
604 String tmp;
605 ArrayList<String> parameters = new ArrayList<String>();
606 Pair<Identifier,Identifier> nameComponentsFrom = null;
607 Pair<Identifier,Identifier> nameComponentsTo = null;
608}
609{
610 <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
611 {
612 parameters.add(tmp);
613 }
614 )*<RIGHTPAREN>
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700615 <FROM> Dataset() nameComponentsFrom = QualifiedName()
616 <TO> Dataset() nameComponentsTo = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700617 {
618 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
619 }
620}
621
622CreateIndexStatement IndexSpecification() throws ParseException:
623{
624 CreateIndexStatement cis = new CreateIndexStatement();
625 String indexName = null;
626 boolean ifNotExists = false;
627 Pair<Identifier,Identifier> nameComponents = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -0700628 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700629 IndexParams indexType = null;
630 boolean enforced = false;
Ali Alsuliman8351d252017-09-24 00:43:15 -0700631 boolean isPrimaryIdx = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700632}
633{
Ali Alsuliman8351d252017-09-24 00:43:15 -0700634 (
635 (<INDEX> indexName = Identifier()
636 ifNotExists = IfNotExists()
637 <ON> nameComponents = QualifiedName()
638 <LEFTPAREN> ( fieldPair = OpenField()
639 {
640 cis.addFieldExprPair(fieldPair.second);
641 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700642 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700643 ) (<COMMA> fieldPair = OpenField()
644 {
645 cis.addFieldExprPair(fieldPair.second);
646 cis.addFieldIndexIndicator(fieldPair.first);
647 }
648 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
649 |
650 (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
651 (
652 (indexName = Identifier())? ifNotExists = IfNotExists()
653 )
654 <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
655 )
656 )
657 {
658 if (isPrimaryIdx && indexName == null) {
659 indexName = "primary_idx_" + nameComponents.second;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700660 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700661 cis.setIndexName(new Identifier(indexName));
662 cis.setIfNotExists(ifNotExists);
663 cis.setDataverseName(nameComponents.first);
664 cis.setDatasetName(nameComponents.second);
665 if (indexType != null) {
666 cis.setIndexType(indexType.type);
667 cis.setGramLength(indexType.gramLength);
668 }
669 cis.setEnforced(enforced);
670 return cis;
671 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700672}
673
674String CompactionPolicy() throws ParseException :
675{
676 String compactionPolicy = null;
677}
678{
679 compactionPolicy = Identifier()
680 {
681 return compactionPolicy;
682 }
683}
684
685String FilterField() throws ParseException :
686{
687 String filterField = null;
688}
689{
690 filterField = Identifier()
691 {
692 return filterField;
693 }
694}
695
696IndexParams IndexType() throws ParseException:
697{
698 IndexType type = null;
699 int gramLength = 0;
700}
701{
702 (<BTREE>
703 {
704 type = IndexType.BTREE;
705 }
706 | <RTREE>
707 {
708 type = IndexType.RTREE;
709 }
710 | <KEYWORD>
711 {
712 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
713 }
Taewoo Kimc49405a2017-01-04 00:30:43 -0800714 |<FULLTEXT>
715 {
716 type = IndexType.SINGLE_PARTITION_WORD_INVIX;
717 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700718 | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
719 {
720 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
721 gramLength = Integer.valueOf(token.image);
722 }
723 <RIGHTPAREN>)
724 {
725 return new IndexParams(type, gramLength);
726 }
727}
728
729CreateDataverseStatement DataverseSpecification() throws ParseException :
730{
731 String dvName = null;
732 boolean ifNotExists = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700733}
734{
735 <DATAVERSE> dvName = Identifier()
736 ifNotExists = IfNotExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700737 {
Till Westmannf6028272016-09-30 14:34:42 -0700738 return new CreateDataverseStatement(new Identifier(dvName), null, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700739 }
740}
741
742CreateFunctionStatement FunctionSpecification() throws ParseException:
743{
744 FunctionSignature signature;
745 boolean ifNotExists = false;
746 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
747 String functionBody;
748 VarIdentifier var = null;
749 Expression functionBodyExpr;
750 Token beginPos;
751 Token endPos;
752 FunctionName fctName = null;
753
754 createNewScope();
755}
756{
757 <FUNCTION> fctName = FunctionName()
758 ifNotExists = IfNotExists()
759 paramList = ParameterList()
760 <LEFTBRACE>
761 {
762 beginPos = token;
763 }
764 functionBodyExpr = Expression() <RIGHTBRACE>
765 {
766 endPos = token;
767 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
768 // TODO use fctName.library
769 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
770 getCurrentScope().addFunctionDescriptor(signature, false);
771 removeCurrentScope();
772 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
773 }
774}
775
776CreateFeedStatement FeedSpecification() throws ParseException:
777{
778 Pair<Identifier,Identifier> nameComponents = null;
779 boolean ifNotExists = false;
780 String adapterName = null;
781 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700782 CreateFeedStatement cfs = null;
783 Pair<Identifier,Identifier> sourceNameComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700784}
785{
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800786 <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
787 <USING> adapterName = AdapterName() properties = Configuration()
788 {
789 cfs = new CreateFeedStatement(nameComponents, adapterName, properties, ifNotExists);
790 return cfs;
791 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700792}
793
794CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
795{
Michael Blowd6cf6412016-06-30 02:44:35 -0400796 String policyName = null;
797 String basePolicyName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700798 String sourcePolicyFile = null;
799 String definition = null;
800 boolean ifNotExists = false;
801 Map<String,String> properties = null;
802 CreateFeedPolicyStatement cfps = null;
803}
804{
805 (
806 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
Yingyi Bu6d57e492016-06-06 21:24:42 -0700807 <FROM>
808 (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700809 {
810 cfps = new CreateFeedPolicyStatement(policyName,
811 basePolicyName, properties, definition, ifNotExists);
812 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300813 | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700814 {
815 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
816 }
Yingyi Bu6d57e492016-06-06 21:24:42 -0700817 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700818 )
819 {
820 return cfps;
821 }
822}
823
824
825
826List<VarIdentifier> ParameterList() throws ParseException:
827{
828 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
829 VarIdentifier var = null;
830}
831{
832 <LEFTPAREN> (<IDENTIFIER>
833 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700834 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700835 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700836 }
837 (<COMMA> <IDENTIFIER>
838 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700839 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700840 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700841 }
842 )*)? <RIGHTPAREN>
843 {
844 return paramList;
845 }
846}
847
848boolean IfNotExists() throws ParseException:
849{
850}
851{
Yingyi Budaa549c2016-06-28 22:30:52 -0700852 ( LOOKAHEAD(1) <IF> <NOT> <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700853 {
854 return true;
855 }
856 )?
857 {
858 return false;
859 }
860}
861
Xikui Wang9d63f622017-05-18 17:50:44 -0700862void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700863{
864 FunctionName functioName = null;
Xikui Wang261dc6d2017-03-29 21:23:15 -0700865 String fqFunctionName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700866}
867{
868 <APPLY> <FUNCTION> functioName = FunctionName()
869 {
Xikui Wang261dc6d2017-03-29 21:23:15 -0700870 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
871 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
872 }
873 (
874 <COMMA> functioName = FunctionName()
875 {
876 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
877 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
878 }
879 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -0700880}
881
882String GetPolicy() throws ParseException:
883{
884 String policy = null;
885}
886{
887 <USING> <POLICY> policy = Identifier()
888 {
889 return policy;
890 }
891
892}
893
894FunctionSignature FunctionSignature() throws ParseException:
895{
896 FunctionName fctName = null;
897 int arity = 0;
898}
899{
900 fctName = FunctionName() <ATT> <INTEGER_LITERAL>
901 {
902 arity = new Integer(token.image);
903 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
904 throw new ParseException(" invalid arity:" + arity);
905 }
906
907 // TODO use fctName.library
908 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
909 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
910 }
911}
912
Yingyi Buc9bfe252016-03-01 00:02:40 -0800913Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700914{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800915 Pair<Integer, List<String>> tmp = null;
916 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700917 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
918}
919{
920 <PRIMARY> <KEY> tmp = NestedField()
921 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800922 keyFieldSourceIndicators.add(tmp.first);
923 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700924 }
925 ( <COMMA> tmp = NestedField()
926 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800927 keyFieldSourceIndicators.add(tmp.first);
928 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700929 }
930 )*
931 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800932 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700933 }
934}
935
936Statement DropStatement() throws ParseException:
937{
938 String id = null;
939 Pair<Identifier,Identifier> pairId = null;
940 Triple<Identifier,Identifier,Identifier> tripleId = null;
941 FunctionSignature funcSig = null;
942 boolean ifExists = false;
943 Statement stmt = null;
944}
945{
946 <DROP>
947 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700948 Dataset() pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700949 {
Yingyi Buab817482016-08-19 21:29:31 -0700950 stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700951 }
952 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
953 {
954 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
955 }
956 | <NODEGROUP> id = Identifier() ifExists = IfExists()
957 {
958 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
959 }
960 | <TYPE> pairId = TypeName() ifExists = IfExists()
961 {
962 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
963 }
964 | <DATAVERSE> id = Identifier() ifExists = IfExists()
965 {
966 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
967 }
968 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
969 {
970 stmt = new FunctionDropStatement(funcSig, ifExists);
971 }
972 | <FEED> pairId = QualifiedName() ifExists = IfExists()
973 {
974 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
975 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300976 | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
977 {
978 stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
979 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700980 )
981 {
982 return stmt;
983 }
984}
985
986boolean IfExists() throws ParseException :
987{
988}
989{
990 ( LOOKAHEAD(1) <IF> <EXISTS>
991 {
992 return true;
993 }
994 )?
995 {
996 return false;
997 }
998}
999
1000InsertStatement InsertStatement() throws ParseException:
1001{
1002 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Bucb5bf332017-01-02 22:19:50 -08001003 VariableExpr var = null;
1004 Query query = null;
1005 Expression returnExpression = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001006}
1007{
Yingyi Bucb5bf332017-01-02 22:19:50 -08001008 <INSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
1009 query = Query(false)
1010 ( <RETURNING> returnExpression = Expression())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001011 {
Yingyi Bucb5bf332017-01-02 22:19:50 -08001012 if (returnExpression != null && var == null) {
1013 var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
1014 }
Yingyi Bucaea8f02015-11-16 15:12:15 -08001015 query.setTopLevel(true);
Yingyi Bucb5bf332017-01-02 22:19:50 -08001016 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1017 returnExpression);
1018 }
1019}
1020
1021UpsertStatement UpsertStatement() throws ParseException:
1022{
1023 Pair<Identifier,Identifier> nameComponents = null;
1024 VariableExpr var = null;
1025 Query query = null;
1026 Expression returnExpression = null;
1027}
1028{
1029 <UPSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
1030 query = Query(false)
1031 ( <RETURNING> returnExpression = Expression())?
1032 {
1033 if (returnExpression != null && var == null) {
1034 var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
1035 }
1036 query.setTopLevel(true);
1037 return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1038 returnExpression);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001039 }
1040}
1041
1042DeleteStatement DeleteStatement() throws ParseException:
1043{
Yingyi Bu20e085b2016-07-06 12:57:27 -07001044 VariableExpr varExpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001045 Expression condition = null;
1046 Pair<Identifier, Identifier> nameComponents;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001047}
1048{
Yingyi Bu20e085b2016-07-06 12:57:27 -07001049 <DELETE>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001050 <FROM> nameComponents = QualifiedName()
Yingyi Bu20e085b2016-07-06 12:57:27 -07001051 ((<AS>)? varExpr = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001052 (<WHERE> condition = Expression())?
Yingyi Bu20e085b2016-07-06 12:57:27 -07001053 {
Yingyi Bu20e085b2016-07-06 12:57:27 -07001054 if(varExpr == null){
1055 varExpr = new VariableExpr();
1056 VarIdentifier var = SqlppVariableUtil.toInternalVariableIdentifier(nameComponents.second.getValue());
1057 varExpr.setVar(var);
1058 }
1059 return new DeleteStatement(varExpr, nameComponents.first, nameComponents.second,
Abdullah Alamoudi6eb01752017-04-01 21:51:19 -07001060 condition, getVarCounter());
Yingyi Bu20e085b2016-07-06 12:57:27 -07001061 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001062}
1063
1064UpdateStatement UpdateStatement() throws ParseException:
1065{
1066 VariableExpr vars;
1067 Expression target;
1068 Expression condition;
1069 UpdateClause uc;
1070 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
1071}
1072{
1073 <UPDATE> vars = Variable() <IN> target = Expression()
1074 <WHERE> condition = Expression()
1075 <LEFTPAREN> (uc = UpdateClause()
1076 {
1077 ucs.add(uc);
1078 }
1079 (<COMMA> uc = UpdateClause()
1080 {
1081 ucs.add(uc);
1082 }
1083 )*) <RIGHTPAREN>
1084 {
1085 return new UpdateStatement(vars, target, condition, ucs);
1086 }
1087}
1088
1089UpdateClause UpdateClause() throws ParseException:
1090{
1091 Expression target = null;
1092 Expression value = null ;
1093 InsertStatement is = null;
1094 DeleteStatement ds = null;
1095 UpdateStatement us = null;
1096 Expression condition = null;
1097 UpdateClause ifbranch = null;
1098 UpdateClause elsebranch = null;
1099}
1100{
1101 (<SET> target = Expression() <EQ> value = Expression()
1102 | is = InsertStatement()
1103 | ds = DeleteStatement()
1104 | us = UpdateStatement()
1105 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
1106 <THEN> ifbranch = UpdateClause()
1107 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1108 {
1109 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1110 }
1111 )
1112}
1113
1114Statement SetStatement() throws ParseException:
1115{
1116 String pn = null;
1117 String pv = null;
1118}
1119{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001120 <SET> pn = Identifier() pv = ConstantString()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001121 {
1122 return new SetStatement(pn, pv);
1123 }
1124}
1125
1126Statement WriteStatement() throws ParseException:
1127{
1128 String nodeName = null;
1129 String fileName = null;
1130 Query query;
1131 String writerClass = null;
1132 Pair<Identifier,Identifier> nameComponents = null;
1133}
1134{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001135 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString()
1136 ( <USING> writerClass = ConstantString() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001137 {
1138 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1139 }
1140}
1141
1142LoadStatement LoadStatement() throws ParseException:
1143{
1144 Identifier dataverseName = null;
1145 Identifier datasetName = null;
1146 boolean alreadySorted = false;
1147 String adapterName;
1148 Map<String,String> properties;
1149 Pair<Identifier,Identifier> nameComponents = null;
1150}
1151{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001152 <LOAD> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001153 {
1154 dataverseName = nameComponents.first;
1155 datasetName = nameComponents.second;
1156 }
1157 <USING> adapterName = AdapterName() properties = Configuration()
1158 (<PRESORTED>
1159 {
1160 alreadySorted = true;
1161 }
1162 )?
1163 {
1164 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1165 }
1166}
1167
1168
1169String AdapterName() throws ParseException :
1170{
1171 String adapterName = null;
1172}
1173{
1174 adapterName = Identifier()
1175 {
1176 return adapterName;
1177 }
1178}
1179
1180Statement CompactStatement() throws ParseException:
1181{
1182 Pair<Identifier,Identifier> nameComponents = null;
1183 Statement stmt = null;
1184}
1185{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001186 <COMPACT> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001187 {
1188 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1189 }
1190 {
1191 return stmt;
1192 }
1193}
1194
Yingyi Buab817482016-08-19 21:29:31 -07001195Statement ConnectionStatement() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001196{
1197 Pair<Identifier,Identifier> feedNameComponents = null;
1198 Pair<Identifier,Identifier> datasetNameComponents = null;
1199
1200 Map<String,String> configuration = null;
1201 Statement stmt = null;
1202 String policy = null;
1203}
1204{
1205 (
Yingyi Buab817482016-08-19 21:29:31 -07001206 <CONNECT> stmt = ConnectStatement()
1207 | <DISCONNECT> stmt = DisconnectStatement()
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001208 | <START> stmt = StartStatement()
1209 | <STOP> stmt = StopStatement()
Yingyi Buab817482016-08-19 21:29:31 -07001210 )
1211 {
1212 return stmt;
1213 }
1214}
1215
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001216Statement StartStatement() throws ParseException:
1217{
1218 Pair<Identifier,Identifier> feedNameComponents = null;
1219
1220 Statement stmt = null;
1221}
1222{
1223 <FEED> feedNameComponents = QualifiedName()
1224 {
1225 stmt = new StartFeedStatement (feedNameComponents);
1226 return stmt;
1227 }
1228}
1229
1230Statement StopStatement () throws ParseException:
1231{
1232 Pair<Identifier,Identifier> feedNameComponents = null;
1233
1234 Statement stmt = null;
1235}
1236{
1237 <FEED> feedNameComponents = QualifiedName()
1238 {
1239 stmt = new StopFeedStatement (feedNameComponents);
1240 return stmt;
1241 }
1242}
1243
1244
Yingyi Buab817482016-08-19 21:29:31 -07001245Statement DisconnectStatement() throws ParseException:
1246{
1247 Pair<Identifier,Identifier> feedNameComponents = null;
1248 Pair<Identifier,Identifier> datasetNameComponents = null;
1249
1250 Map<String,String> configuration = null;
1251 Statement stmt = null;
1252 String policy = null;
1253}
1254{
1255 (
1256 <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001257 {
1258 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1259 }
1260 )
Yingyi Buab817482016-08-19 21:29:31 -07001261 {
1262 return stmt;
1263 }
1264}
1265
1266Statement ConnectStatement() throws ParseException:
1267{
1268 Pair<Identifier,Identifier> feedNameComponents = null;
1269 Pair<Identifier,Identifier> datasetNameComponents = null;
1270
1271 Map<String,String> configuration = null;
Xikui Wang9d63f622017-05-18 17:50:44 -07001272 List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
Yingyi Buab817482016-08-19 21:29:31 -07001273 Statement stmt = null;
1274 String policy = null;
1275}
1276{
1277 (
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001278 <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName()
Xikui Wang9d63f622017-05-18 17:50:44 -07001279 (ApplyFunction(appliedFunctions))? (policy = GetPolicy())?
Yingyi Buab817482016-08-19 21:29:31 -07001280 {
Xikui Wang261dc6d2017-03-29 21:23:15 -07001281 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions,
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001282 policy, getVarCounter());
Yingyi Buab817482016-08-19 21:29:31 -07001283 }
1284 )
1285 {
1286 return stmt;
1287 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001288}
1289
1290Map<String,String> Configuration() throws ParseException :
1291{
1292 Map<String,String> configuration = new LinkedHashMap<String,String>();
1293 Pair<String, String> keyValuePair = null;
1294}
1295{
1296 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1297 {
1298 configuration.put(keyValuePair.first, keyValuePair.second);
1299 }
1300 ( <COMMA> keyValuePair = KeyValuePair()
1301 {
1302 configuration.put(keyValuePair.first, keyValuePair.second);
1303 }
1304 )* )? <RIGHTPAREN>
1305 {
1306 return configuration;
1307 }
1308}
1309
1310Pair<String, String> KeyValuePair() throws ParseException:
1311{
1312 String key;
1313 String value;
1314}
1315{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001316 <LEFTPAREN> key = ConstantString() <EQ> value = ConstantString() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001317 {
1318 return new Pair<String, String>(key, value);
1319 }
1320}
1321
1322Map<String,String> Properties() throws ParseException:
1323{
1324 Map<String,String> properties = new HashMap<String,String>();
1325 Pair<String, String> property;
1326}
1327{
1328 (LOOKAHEAD(1) <LEFTPAREN> property = Property()
1329 {
1330 properties.put(property.first, property.second);
1331 }
1332 ( <COMMA> property = Property()
1333 {
1334 properties.put(property.first, property.second);
1335 }
1336 )* <RIGHTPAREN> )?
1337 {
1338 return properties;
1339 }
1340}
1341
1342Pair<String, String> Property() throws ParseException:
1343{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001344 String key = null;
1345 String value = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001346}
1347{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001348 (key = Identifier() | key = StringLiteral())
1349 <EQ>
1350 ( value = ConstantString() | <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001351 {
1352 try {
1353 value = "" + Long.valueOf(token.image);
1354 } catch (NumberFormatException nfe) {
1355 throw new ParseException("inapproriate value: " + token.image);
1356 }
1357 }
1358 )
1359 {
1360 return new Pair<String, String>(key.toUpperCase(), value);
1361 }
1362}
1363
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001364IndexedTypeExpression IndexedTypeExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001365{
1366 TypeExpression typeExpr = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001367 boolean isUnknownable = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001368}
1369{
1370 (
1371 typeExpr = TypeReference()
1372 | typeExpr = OrderedListTypeDef()
1373 | typeExpr = UnorderedListTypeDef()
1374 )
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001375 ( <QUES> { isUnknownable = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001376 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001377 return new IndexedTypeExpression(typeExpr, isUnknownable);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001378 }
1379}
1380
1381TypeExpression TypeExpr() throws ParseException:
1382{
1383 TypeExpression typeExpr = null;
1384}
1385{
1386 (
1387 typeExpr = RecordTypeDef()
1388 | typeExpr = TypeReference()
1389 | typeExpr = OrderedListTypeDef()
1390 | typeExpr = UnorderedListTypeDef()
1391 )
1392 {
1393 return typeExpr;
1394 }
1395}
1396
1397RecordTypeDefinition RecordTypeDef() throws ParseException:
1398{
1399 RecordTypeDefinition recType = new RecordTypeDefinition();
1400 RecordTypeDefinition.RecordKind recordKind = null;
1401}
1402{
1403 ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1404 | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1405 <LEFTBRACE>
1406 {
1407 String hint = getHint(token);
1408 if (hint != null) {
1409 String splits[] = hint.split(" +");
1410 if (splits[0].equals(GEN_FIELDS_HINT)) {
1411 if (splits.length != 5) {
1412 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1413 }
1414 if (!splits[1].equals("int")) {
1415 throw new ParseException("The only supported type for gen-fields is int.");
1416 }
1417 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1418 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1419 recType.setUndeclaredFieldsDataGen(ufdg);
1420 }
1421 }
1422
1423 }
1424 (
1425 RecordField(recType)
1426 ( <COMMA> RecordField(recType) )*
1427 )?
1428 <RIGHTBRACE>
1429 {
1430 if (recordKind == null) {
1431 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1432 }
1433 recType.setRecordKind(recordKind);
1434 return recType;
1435 }
1436}
1437
1438void RecordField(RecordTypeDefinition recType) throws ParseException:
1439{
1440 String fieldName;
1441 TypeExpression type = null;
1442 boolean nullable = false;
1443}
1444{
1445 fieldName = Identifier()
1446 {
1447 String hint = getHint(token);
1448 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1449 }
1450 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1451 {
1452 recType.addField(fieldName, type, nullable, rfdg);
1453 }
1454}
1455
1456TypeReferenceExpression TypeReference() throws ParseException:
1457{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001458 Pair<Identifier,Identifier> id = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001459}
1460{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001461 id = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001462 {
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001463 if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
1464 id.second.setValue("int64");
Yingyi Bu391f09e2015-10-29 13:49:39 -07001465 }
1466
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001467 return new TypeReferenceExpression(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001468 }
1469}
1470
1471OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1472{
1473 TypeExpression type = null;
1474}
1475{
1476 <LEFTBRACKET>
1477 ( type = TypeExpr() )
1478 <RIGHTBRACKET>
1479 {
1480 return new OrderedListTypeDefinition(type);
1481 }
1482}
1483
1484
1485UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1486{
1487 TypeExpression type = null;
1488}
1489{
1490 <LEFTDBLBRACE>
1491 ( type = TypeExpr() )
1492 <RIGHTDBLBRACE>
1493 {
1494 return new UnorderedListTypeDefinition(type);
1495 }
1496}
1497
1498FunctionName FunctionName() throws ParseException:
1499{
1500 String first = null;
1501 String second = null;
1502 String third = null;
1503 boolean secondAfterDot = false;
1504}
1505{
Michael Blowd6cf6412016-06-30 02:44:35 -04001506 first = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001507 {
1508 FunctionName result = new FunctionName();
1509 result.hint = getHint(token);
Michael Blowd6cf6412016-06-30 02:44:35 -04001510 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001511 ( <DOT> second = Identifier()
1512 {
1513 secondAfterDot = true;
1514 }
1515 (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )?
1516 {
1517 if (second == null) {
1518 result.dataverse = defaultDataverse;
1519 result.library = null;
1520 result.function = first;
1521 } else if (third == null) {
1522 if (secondAfterDot) {
1523 result.dataverse = first;
1524 result.library = null;
1525 result.function = second;
1526 } else {
1527 result.dataverse = defaultDataverse;
1528 result.library = first;
1529 result.function = second;
1530 }
1531 } else {
1532 result.dataverse = first;
1533 result.library = second;
1534 result.function = third;
1535 }
1536
1537 if (result.function.equalsIgnoreCase("int")) {
1538 result.function = "int64";
1539 }
1540 return result;
1541 }
1542}
1543
1544Pair<Identifier,Identifier> TypeName() throws ParseException:
1545{
1546 Pair<Identifier,Identifier> name = null;
1547}
1548{
1549 name = QualifiedName()
1550 {
1551 if (name.first == null) {
1552 name.first = new Identifier(defaultDataverse);
1553 }
1554 return name;
1555 }
1556}
1557
1558String Identifier() throws ParseException:
1559{
1560 String lit = null;
1561}
1562{
1563 (<IDENTIFIER>
1564 {
1565 return token.image;
1566 }
1567 | lit = QuotedString()
1568 {
1569 return lit;
1570 }
1571 )
1572}
1573
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001574void Dataset() throws ParseException:
1575{
1576}
1577{
1578 (<DATASET>|<COLLECTION>)
1579}
1580
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001581Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001582{
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001583 IndexedTypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001584 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001585}
1586{
1587 fieldList = NestedField()
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001588 ( <COLON> fieldType = IndexedTypeExpr() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001589 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001590 return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
1591 (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001592 }
1593}
1594
Yingyi Buc9bfe252016-03-01 00:02:40 -08001595Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001596{
1597 List<String> exprList = new ArrayList<String>();
1598 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001599 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001600}
1601{
1602 lit = Identifier()
1603 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001604 boolean meetParens = false;
1605 }
1606 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001607 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001608 <LEFTPAREN><RIGHTPAREN>
1609 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001610 if(!lit.toLowerCase().equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001611 throw new ParseException("The string before () has to be \"meta\".");
1612 }
1613 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001614 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001615 }
1616 )?
1617 {
1618 if(!meetParens){
1619 exprList.add(lit);
1620 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001621 }
1622 (<DOT>
1623 lit = Identifier()
1624 {
1625 exprList.add(lit);
1626 }
1627 )*
1628 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001629 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001630 }
1631}
1632
Yingyi Bu6d57e492016-06-06 21:24:42 -07001633String ConstantString() throws ParseException:
1634{
1635 String value = null;
1636}
1637{
1638 (value = QuotedString() | value = StringLiteral())
1639 {
1640 return value;
1641 }
1642}
1643
Yingyi Bu391f09e2015-10-29 13:49:39 -07001644
1645String QuotedString() throws ParseException:
1646{
1647}
1648{
1649 <QUOTED_STRING>
1650 {
1651 return removeQuotesAndEscapes(token.image);
1652 }
1653}
1654
1655
1656String StringLiteral() throws ParseException:
1657{
1658}
1659{
1660 <STRING_LITERAL>
1661 {
1662 return removeQuotesAndEscapes(token.image);
1663 }
1664}
1665
1666Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1667{
1668 String first = null;
1669 String second = null;
1670}
1671{
1672 first = Identifier() (<DOT> second = Identifier())?
1673 {
1674 Identifier id1 = null;
1675 Identifier id2 = null;
1676 if (second == null) {
1677 id2 = new Identifier(first);
1678 } else
1679 {
1680 id1 = new Identifier(first);
1681 id2 = new Identifier(second);
1682 }
1683 return new Pair<Identifier,Identifier>(id1, id2);
1684 }
1685}
1686
1687Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1688{
1689 String first = null;
1690 String second = null;
1691 String third = null;
1692}
1693{
1694 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1695 {
1696 Identifier id1 = null;
1697 Identifier id2 = null;
1698 Identifier id3 = null;
1699 if (third == null) {
1700 id2 = new Identifier(first);
1701 id3 = new Identifier(second);
1702 } else {
1703 id1 = new Identifier(first);
1704 id2 = new Identifier(second);
1705 id3 = new Identifier(third);
1706 }
1707 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1708 }
1709}
1710
1711FunctionDecl FunctionDeclaration() throws ParseException:
1712{
1713 FunctionDecl funcDecl;
1714 FunctionSignature signature;
1715 String functionName;
1716 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1717 Expression funcBody;
1718 createNewScope();
1719}
1720{
1721 <DECLARE> <FUNCTION> functionName = Identifier()
1722 paramList = ParameterList()
1723 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1724 {
1725 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1726 getCurrentScope().addFunctionDescriptor(signature, false);
1727 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1728 removeCurrentScope();
1729 return funcDecl;
1730 }
1731}
1732
Till Westmannef3f0272016-07-27 18:34:01 -07001733Query ExplainStatement() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001734{
Till Westmannef3f0272016-07-27 18:34:01 -07001735 Query query;
1736}
1737{
Till Westmann516d1a82016-08-02 14:45:53 -07001738 <EXPLAIN> query = Query(true)
Till Westmannef3f0272016-07-27 18:34:01 -07001739 {
1740 return query;
1741 }
1742}
1743
1744Query Query(boolean explain) throws ParseException:
1745{
1746 Query query = new Query(explain);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001747 Expression expr;
1748}
1749{
1750 (
1751 expr = Expression()
1752 |
1753 expr = SelectExpression(false)
1754 )
1755 {
1756 query.setBody(expr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001757 return query;
1758 }
1759}
1760
1761
1762
1763Expression Expression():
1764{
1765 Expression expr = null;
1766 Expression exprP = null;
1767}
1768{
1769(
1770 LOOKAHEAD(2)
1771 expr = OperatorExpr()
Yingyi Buc8c067c2016-07-25 23:37:19 -07001772 | expr = CaseExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001773 | expr = QuantifiedExpression()
1774)
1775 {
1776 return (exprP==null) ? expr : exprP;
1777 }
1778}
1779
1780
1781
1782Expression OperatorExpr()throws ParseException:
1783{
1784 OperatorExpr op = null;
1785 Expression operand = null;
1786}
1787{
1788 operand = AndExpr()
1789 (
1790
1791 <OR>
1792 {
1793 if (op == null) {
1794 op = new OperatorExpr();
1795 op.addOperand(operand);
1796 op.setCurrentop(true);
1797 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001798 try{
1799 op.addOperator(token.image.toLowerCase());
1800 } catch (Exception e){
1801 throw new ParseException(e.getMessage());
1802 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001803 }
1804
1805 operand = AndExpr()
1806 {
1807 op.addOperand(operand);
1808 }
1809
1810 )*
1811
1812 {
1813 return op==null? operand: op;
1814 }
1815}
1816
1817Expression AndExpr()throws ParseException:
1818{
1819 OperatorExpr op = null;
1820 Expression operand = null;
1821}
1822{
Yingyi Bu196db5d2016-07-15 19:07:20 -07001823 operand = NotExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001824 (
1825
1826 <AND>
1827 {
1828 if (op == null) {
1829 op = new OperatorExpr();
1830 op.addOperand(operand);
Yingyi Bu196db5d2016-07-15 19:07:20 -07001831 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001832 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001833 try{
1834 op.addOperator(token.image.toLowerCase());
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001835 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001836 throw new ParseException(e.getMessage());
1837 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001838 }
1839
Yingyi Bu196db5d2016-07-15 19:07:20 -07001840 operand = NotExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001841 {
1842 op.addOperand(operand);
1843 }
1844
1845 )*
1846
1847 {
1848 return op==null? operand: op;
1849 }
1850}
1851
Yingyi Bu196db5d2016-07-15 19:07:20 -07001852Expression NotExpr()throws ParseException:
1853{
1854 Expression inputExpr;
1855 boolean not = false;
1856}
1857{
1858 (<NOT> { not = true; } )? inputExpr = RelExpr()
1859 {
1860 if(not){
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001861 FunctionSignature signature = new FunctionSignature(BuiltinFunctions.NOT);
Yingyi Bu196db5d2016-07-15 19:07:20 -07001862 return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
1863 } else {
1864 return inputExpr;
1865 }
1866 }
1867}
Yingyi Bu391f09e2015-10-29 13:49:39 -07001868
1869Expression RelExpr()throws ParseException:
1870{
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001871 boolean not = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001872 OperatorExpr op = null;
1873 Expression operand = null;
1874 boolean broadcast = false;
1875 IExpressionAnnotation annotation = null;
1876}
1877{
Yingyi Bu6c638342016-09-02 17:54:34 -07001878 operand = BetweenExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001879
1880 (
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001881 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? <IN>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001882 {
1883 String mhint = getHint(token);
1884 if (mhint != null) {
1885 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001886 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1887 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1888 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
Yingyi Buea4ec722016-11-04 01:26:16 -07001889 } else if (mhint.equals(BROADCAST_JOIN_HINT)) {
1890 broadcast = true;
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001891 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001892 }
Yingyi Buea4ec722016-11-04 01:26:16 -07001893
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001894 String operator = token.image.toLowerCase();
Yingyi Bu4a4b8962016-09-16 12:09:11 -07001895 if (operator.equals("<>")){
1896 operator = "!=";
1897 }
1898 if (not) {
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001899 operator = "not_" + operator;
1900 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001901 if (op == null) {
1902 op = new OperatorExpr();
Yingyi Buea4ec722016-11-04 01:26:16 -07001903 op.addOperand(operand, false); // broadcast is always for the right branch
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001904 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001905 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001906 try{
1907 op.addOperator(operator);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001908 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001909 throw new ParseException(e.getMessage());
1910 }
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001911 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001912
Yingyi Bu6c638342016-09-02 17:54:34 -07001913 operand = BetweenExpr()
Yingyi Buea4ec722016-11-04 01:26:16 -07001914 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001915 op.addOperand(operand, broadcast);
Yingyi Buea4ec722016-11-04 01:26:16 -07001916 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001917 )?
1918
1919 {
1920 if (annotation != null) {
1921 op.addHint(annotation);
1922 }
1923 return op==null? operand: op;
1924 }
1925}
1926
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001927
Yingyi Bu6c638342016-09-02 17:54:34 -07001928Expression BetweenExpr()throws ParseException:
1929{
1930 boolean not = false;
1931 OperatorExpr op = null;
1932 Expression operand = null;
1933 IExpressionAnnotation annotation = null;
1934}
1935{
1936 operand = IsExpr()
1937 (
1938 LOOKAHEAD(2)
1939 (<NOT> { not = true; })? <BETWEEN>
1940 {
1941 String mhint = getHint(token);
1942 if (mhint != null) {
1943 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1944 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1945 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1946 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1947 }
1948 }
1949 String operator = token.image.toLowerCase();
1950 if(not){
1951 operator = "not_" + operator;
1952 }
1953 if (op == null) {
1954 op = new OperatorExpr();
1955 op.addOperand(operand);
1956 op.setCurrentop(true);
1957 }
1958 try{
1959 op.addOperator(operator);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001960 } catch (CompilationException e){
Yingyi Bu6c638342016-09-02 17:54:34 -07001961 throw new ParseException(e.getMessage());
1962 }
1963 }
1964
1965 operand = IsExpr()
1966 {
1967 op.addOperand(operand);
1968 }
1969
1970 <AND>
1971 operand = IsExpr()
1972 {
1973 op.addOperand(operand);
1974 }
1975 )?
1976
1977 {
1978 if (annotation != null) {
1979 op.addHint(annotation);
1980 }
1981 return op==null? operand: op;
1982 }
1983}
1984
Yingyi Budaa549c2016-06-28 22:30:52 -07001985Expression IsExpr() throws ParseException:
1986{
1987 Expression expr = null;
1988 Expression operand = null;
1989 boolean not = false;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001990 FunctionIdentifier fn = null;
Yingyi Budaa549c2016-06-28 22:30:52 -07001991}
1992{
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001993 operand = LikeExpr()
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001994 ( <IS>
1995 (<NOT> { not = true; })?
1996 (
1997 <NULL> { fn = BuiltinFunctions.IS_NULL; } |
1998 <MISSING> { fn = BuiltinFunctions.IS_MISSING; } |
Dmitry Lychagin8b6578a2017-11-08 15:04:35 -08001999 <UNKNOWN> { fn = BuiltinFunctions.IS_UNKNOWN; }
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002000 )
Yingyi Budaa549c2016-06-28 22:30:52 -07002001 {
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002002 FunctionSignature signature = new FunctionSignature(fn);
Yingyi Budaa549c2016-06-28 22:30:52 -07002003 expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand)));
2004 if(not) {
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002005 FunctionSignature notSignature = new FunctionSignature(BuiltinFunctions.NOT);
Yingyi Budaa549c2016-06-28 22:30:52 -07002006 expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr)));
2007 }
2008 }
2009 )?
2010 {
2011 return expr = expr==null? operand : expr;
2012 }
2013}
2014
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08002015
2016Expression LikeExpr()throws ParseException:
2017{
2018 boolean not = false;
2019 OperatorExpr op = null;
2020 Expression operand = null;
2021}
2022{
2023 operand = ConcatExpr()
2024 (
2025 LOOKAHEAD(2)
2026 (<NOT> { not = true; })? <LIKE>
2027 {
2028 op = new OperatorExpr();
2029 op.addOperand(operand);
2030 op.setCurrentop(true);
2031
2032 String operator = token.image.toLowerCase();
2033 if (not) {
2034 operator = "not_" + operator;
2035 }
2036 try{
2037 op.addOperator(operator);
2038 } catch (CompilationException e){
2039 throw new ParseException(e.getMessage());
2040 }
2041 }
2042
2043 operand = ConcatExpr()
2044 {
2045 op.addOperand(operand);
2046 }
2047 )?
2048
2049 {
2050 return op == null ? operand : op;
2051 }
2052}
2053
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002054Expression ConcatExpr()throws ParseException:
2055{
2056 OperatorExpr op = null;
2057 Expression operand = null;
2058}
2059{
2060 operand = AddExpr()
2061 (
2062 LOOKAHEAD(1)
2063 (<CONCAT>)
2064 {
2065 if (op == null) {
2066 op = new OperatorExpr();
2067 op.addOperand(operand);
2068 op.setCurrentop(true);
2069 }
2070 try{
2071 ((OperatorExpr)op).addOperator(token.image);
2072 } catch (Exception e){
2073 throw new ParseException(e.getMessage());
2074 }
2075 }
2076 operand = AddExpr()
2077 {
2078 op.addOperand(operand);
2079 }
2080 )*
2081
2082 {
2083 return op==null? operand: op;
2084 }
2085}
Yingyi Budaa549c2016-06-28 22:30:52 -07002086
Yingyi Bu391f09e2015-10-29 13:49:39 -07002087Expression AddExpr()throws ParseException:
2088{
2089 OperatorExpr op = null;
2090 Expression operand = null;
2091}
2092{
2093 operand = MultExpr()
Yingyi Budaa549c2016-06-28 22:30:52 -07002094 (
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002095 LOOKAHEAD(1)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002096 (<PLUS> | <MINUS>)
2097 {
2098 if (op == null) {
2099 op = new OperatorExpr();
2100 op.addOperand(operand);
2101 op.setCurrentop(true);
2102 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07002103 try{
2104 ((OperatorExpr)op).addOperator(token.image);
2105 } catch (Exception e){
2106 throw new ParseException(e.getMessage());
2107 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002108 }
2109
2110 operand = MultExpr()
2111 {
2112 op.addOperand(operand);
2113 }
2114 )*
2115
2116 {
2117 return op==null? operand: op;
2118 }
2119}
2120
2121Expression MultExpr()throws ParseException:
2122{
2123 OperatorExpr op = null;
2124 Expression operand = null;
2125}
2126{
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002127 operand = ExponentExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07002128
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002129 (( <MUL> | <DIV> | <MOD> | <IDIV>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002130 {
2131 if (op == null) {
2132 op = new OperatorExpr();
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002133 op.addOperand(operand);
2134 op.setCurrentop(true);
2135 }
2136 try{
2137 op.addOperator(token.image);
2138 } catch (Exception e){
2139 throw new ParseException(e.getMessage());
2140 }
2141 }
2142 operand = ExponentExpr()
2143 {
2144 op.addOperand(operand);
2145 }
2146 )*
2147
2148 {
2149 return op==null?operand:op;
2150 }
2151}
2152
2153Expression ExponentExpr()throws ParseException:
2154{
2155 OperatorExpr op = null;
2156 Expression operand = null;
2157}
2158{
2159 operand = UnaryExpr()
2160 (<CARET>
2161 {
2162 if (op == null) {
2163 op = new OperatorExpr();
2164 op.addOperand(operand);
2165 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002166 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07002167 try{
2168 op.addOperator(token.image);
2169 } catch (Exception e){
2170 throw new ParseException(e.getMessage());
2171 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002172 }
2173 operand = UnaryExpr()
2174 {
2175 op.addOperand(operand);
2176 }
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002177 )?
2178 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002179 return op==null?operand:op;
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002180 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002181}
2182
2183Expression UnaryExpr() throws ParseException:
2184{
Yingyi Bu196db5d2016-07-15 19:07:20 -07002185 boolean not = false;
2186 UnaryExpr uexpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002187 Expression expr = null;
2188}
Yingyi Budaa549c2016-06-28 22:30:52 -07002189{
Yingyi Bu196db5d2016-07-15 19:07:20 -07002190 ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> )
Yingyi Bu391f09e2015-10-29 13:49:39 -07002191 {
Yingyi Bu196db5d2016-07-15 19:07:20 -07002192 String exprType = token.image.toLowerCase();
2193 if(not){
2194 exprType = "not_" + exprType;
2195 }
2196 uexpr = new UnaryExpr();
2197 try{
2198 uexpr.setExprType(exprType);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08002199 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07002200 throw new ParseException(e.getMessage());
Yingyi Budaa549c2016-06-28 22:30:52 -07002201 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002202 }
2203 )?
2204
2205 expr = ValueExpr()
2206 {
Yingyi Bu196db5d2016-07-15 19:07:20 -07002207 if(uexpr==null){
Yingyi Bu391f09e2015-10-29 13:49:39 -07002208 return expr;
Yingyi Bu196db5d2016-07-15 19:07:20 -07002209 }
2210 uexpr.setExpr(expr);
2211 return uexpr;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002212 }
2213}
2214
2215Expression ValueExpr()throws ParseException:
2216{
2217 Expression expr = null;
2218 Identifier ident = null;
2219 AbstractAccessor fa = null;
2220 Expression indexExpr = null;
2221}
2222{
2223 expr = PrimaryExpr() (
2224 ident = Field()
2225 {
2226 fa = (fa == null ? new FieldAccessor(expr, ident)
2227 : new FieldAccessor(fa, ident));
2228 }
2229 | indexExpr = Index()
2230 {
2231 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
2232 : new IndexAccessor(fa, indexExpr));
2233 }
2234 )*
2235 {
2236 return fa == null ? expr : fa;
2237 }
2238}
2239
2240Identifier Field() throws ParseException:
2241{
2242 String ident = null;
2243}
2244{
2245 <DOT> ident = Identifier()
2246 {
2247 return new Identifier(ident);
2248 }
2249}
2250
2251Expression Index() throws ParseException:
2252{
2253 Expression expr = null;
2254}
2255{
2256 <LEFTBRACKET> ( expr = Expression()
2257 {
2258 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
2259 {
2260 Literal lit = ((LiteralExpr)expr).getValue();
2261 if(lit.getLiteralType() != Literal.Type.INTEGER &&
2262 lit.getLiteralType() != Literal.Type.LONG) {
2263 throw new ParseException("Index should be an INTEGER");
2264 }
2265 }
2266 }
2267
2268 | <QUES> // ANY
2269
2270 )
2271
2272 <RIGHTBRACKET>
2273 {
2274 return expr;
2275 }
2276}
2277
2278
2279Expression PrimaryExpr()throws ParseException:
2280{
2281 Expression expr = null;
2282}
2283{
2284 ( LOOKAHEAD(4)
2285 expr = FunctionCallExpr()
2286 | expr = Literal()
2287 | expr = VariableRef()
2288 | expr = ListConstructor()
2289 | expr = RecordConstructor()
2290 | expr = ParenthesizedExpression()
2291 )
2292 {
2293 return expr;
2294 }
2295}
2296
2297Expression Literal() throws ParseException:
2298{
2299 LiteralExpr lit = new LiteralExpr();
2300 String str = null;
2301}
2302{
2303 ( str = StringLiteral()
2304 {
2305 lit.setValue(new StringLiteral(str));
2306 }
2307 | <INTEGER_LITERAL>
2308 {
Till Westmann68c6a992016-09-30 00:19:12 -07002309 try {
2310 lit.setValue(new LongIntegerLiteral(Long.valueOf(token.image)));
2311 } catch (NumberFormatException e) {
2312 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2313 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002314 }
2315 | <FLOAT_LITERAL>
2316 {
Till Westmann68c6a992016-09-30 00:19:12 -07002317 try {
2318 lit.setValue(new FloatLiteral(Float.valueOf(token.image)));
2319 } catch (NumberFormatException e) {
2320 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2321 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002322 }
2323 | <DOUBLE_LITERAL>
2324 {
Till Westmann68c6a992016-09-30 00:19:12 -07002325 try {
2326 lit.setValue(new DoubleLiteral(Double.valueOf(token.image)));
2327 } catch (NumberFormatException e) {
2328 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2329 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002330 }
Yingyi Bu535d86b2016-05-23 16:44:25 -07002331 | <MISSING>
2332 {
2333 lit.setValue(MissingLiteral.INSTANCE);
2334 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002335 | <NULL>
2336 {
2337 lit.setValue(NullLiteral.INSTANCE);
2338 }
2339 | <TRUE>
2340 {
2341 lit.setValue(TrueLiteral.INSTANCE);
2342 }
2343 | <FALSE>
2344 {
2345 lit.setValue(FalseLiteral.INSTANCE);
2346 }
2347 )
2348 {
2349 return lit;
2350 }
2351}
2352
2353
2354VariableExpr VariableRef() throws ParseException:
2355{
2356 VariableExpr varExp = new VariableExpr();
2357 VarIdentifier var = new VarIdentifier();
2358}
2359{
2360 { String id = null; }
2361 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
2362 {
Yingyi Buacc12a92016-03-26 17:25:05 -07002363 id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$"
Yingyi Bu391f09e2015-10-29 13:49:39 -07002364 Identifier ident = lookupSymbol(id);
2365 if (isInForbiddenScopes(id)) {
2366 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.");
2367 }
2368 if(ident != null) { // exist such ident
Yingyi Bu391f09e2015-10-29 13:49:39 -07002369 varExp.setVar((VarIdentifier)ident);
2370 } else {
2371 varExp.setVar(var);
Yingyi Buacc12a92016-03-26 17:25:05 -07002372 varExp.setIsNewVar(false);
2373 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002374 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002375 return varExp;
2376 }
2377}
2378
2379
2380VariableExpr Variable() throws ParseException:
2381{
2382 VariableExpr varExp = new VariableExpr();
2383 VarIdentifier var = new VarIdentifier();
2384}
2385{
2386 { String id = null; }
2387 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
2388 {
Yingyi Buacc12a92016-03-26 17:25:05 -07002389 id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$".
Yingyi Bu391f09e2015-10-29 13:49:39 -07002390 Identifier ident = lookupSymbol(id);
2391 if(ident != null) { // exist such ident
2392 varExp.setIsNewVar(false);
2393 }
2394 varExp.setVar(var);
Yingyi Bucaea8f02015-11-16 15:12:15 -08002395 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002396 return varExp;
2397 }
2398}
2399
2400Expression ListConstructor() throws ParseException:
2401{
2402 Expression expr = null;
2403}
2404{
2405 (
2406 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
2407 )
2408
2409 {
2410 return expr;
2411 }
2412}
2413
2414
2415ListConstructor OrderedListConstructor() throws ParseException:
2416{
2417 ListConstructor expr = new ListConstructor();
2418 List<Expression> exprList = null;
2419 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
2420}
2421{
2422 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
2423 {
2424 expr.setExprList(exprList);
2425 return expr;
2426 }
2427}
2428
2429ListConstructor UnorderedListConstructor() throws ParseException:
2430{
2431 ListConstructor expr = new ListConstructor();
2432 List<Expression> exprList = null;
2433 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2434}
2435{
2436 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2437 {
2438 expr.setExprList(exprList);
2439 return expr;
2440 }
2441}
2442
2443List<Expression> ExpressionList() throws ParseException:
2444{
2445 Expression expr = null;
2446 List<Expression> list = null;
2447 List<Expression> exprList = new ArrayList<Expression>();
2448}
2449{
2450 (
Till Westmann60f89982017-08-11 18:14:20 -07002451 expr = Expression()
2452 {
2453 exprList.add(expr);
2454 }
2455 ( <COMMA> expr = Expression()
2456 {
2457 exprList.add(expr);
2458 }
2459 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -07002460 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002461 {
Till Westmann60f89982017-08-11 18:14:20 -07002462 return exprList;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002463 }
2464}
2465
Yingyi Bu391f09e2015-10-29 13:49:39 -07002466RecordConstructor RecordConstructor() throws ParseException:
2467{
2468 RecordConstructor expr = new RecordConstructor();
2469 FieldBinding tmp = null;
2470 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2471}
2472{
2473 <LEFTBRACE> (tmp = FieldBinding()
2474 {
2475 fbList.add(tmp);
2476 }
2477 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2478 {
2479 expr.setFbList(fbList);
2480 return expr;
2481 }
2482}
2483
2484FieldBinding FieldBinding() throws ParseException:
2485{
2486 FieldBinding fb = new FieldBinding();
2487 Expression left, right;
2488}
2489{
2490 left = Expression() <COLON> right = Expression()
2491 {
2492 fb.setLeftExpr(left);
2493 fb.setRightExpr(right);
2494 return fb;
2495 }
2496}
2497
2498
2499Expression FunctionCallExpr() throws ParseException:
2500{
2501 CallExpr callExpr;
2502 List<Expression> argList = new ArrayList<Expression>();
Yingyi Buf4d09842016-08-26 00:03:52 -07002503 Expression tmp = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002504 int arity = 0;
2505 FunctionName funcName = null;
2506 String hint = null;
Yingyi Buf4d09842016-08-26 00:03:52 -07002507 boolean star = false;
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002508 boolean distinct = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002509}
2510{
2511 funcName = FunctionName()
2512 {
2513 hint = funcName.hint;
2514 }
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002515 <LEFTPAREN> (
2516 ( <DISTINCT> { distinct = true; } )?
2517 ( tmp = Expression() | <MUL> { star = true; } )
Yingyi Bu391f09e2015-10-29 13:49:39 -07002518 {
Yingyi Buf4d09842016-08-26 00:03:52 -07002519 if(star){
2520 if(!funcName.function.toLowerCase().equals("count")){
2521 throw new ParseException("The parameter * can only be used in COUNT().");
2522 }
2523 argList.add(new LiteralExpr(new LongIntegerLiteral(1L)));
2524 } else {
2525 argList.add(tmp);
2526 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002527 arity ++;
2528 }
2529 (<COMMA> tmp = Expression()
2530 {
2531 argList.add(tmp);
2532 arity++;
2533 }
2534 )*)? <RIGHTPAREN>
2535 {
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002536 String name = funcName.function;
2537 if (distinct) {
2538 name += "-distinct";
2539 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002540 // TODO use funcName.library
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002541 String fqFunctionName = funcName.library == null ? name : funcName.library + "#" + name;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002542 FunctionSignature signature
2543 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2544 if (signature == null) {
2545 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2546 }
Xikui Wang96fd4022017-04-10 14:23:31 -07002547 callExpr = FunctionMapUtil.normalizedListInputFunctions(new CallExpr(signature,argList));
Yingyi Bu391f09e2015-10-29 13:49:39 -07002548 if (hint != null) {
2549 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2550 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2551 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2552 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2553 }
2554 }
2555 return callExpr;
2556 }
2557}
2558
2559Expression ParenthesizedExpression() throws ParseException:
2560{
2561 Expression expr;
2562}
2563{
2564 (
2565 LOOKAHEAD(2)
2566 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2567 |
2568 expr = Subquery()
2569 )
2570 {
2571 return expr;
2572 }
2573}
2574
Yingyi Buc8c067c2016-07-25 23:37:19 -07002575
2576Expression CaseExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07002577{
Yingyi Buc8c067c2016-07-25 23:37:19 -07002578 Expression conditionExpr = new LiteralExpr(TrueLiteral.INSTANCE);
2579 List<Expression> whenExprs = new ArrayList<Expression>();
2580 List<Expression> thenExprs = new ArrayList<Expression>();
2581 Expression elseExpr = null;
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002582
Yingyi Buc8c067c2016-07-25 23:37:19 -07002583 Expression whenExpr = null;
2584 Expression thenExpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002585}
2586{
Yingyi Buc8c067c2016-07-25 23:37:19 -07002587 <CASE> ( conditionExpr = Expression() )?
2588 (
2589 <WHEN> whenExpr = Expression()
2590 {
2591 whenExprs.add(whenExpr);
2592 }
2593 <THEN> thenExpr = Expression()
2594 {
2595 thenExprs.add(thenExpr);
2596 }
2597 )*
2598 (<ELSE> elseExpr = Expression() )?
2599 <END>
2600 {
2601 return new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr);
2602 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002603}
2604
Yingyi Buab817482016-08-19 21:29:31 -07002605SelectExpression SelectExpression(boolean subquery) throws ParseException:
2606{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002607 List<LetClause> letClauses = new ArrayList<LetClause>();
2608 SelectSetOperation selectSetOperation;
2609 OrderbyClause orderbyClause = null;
2610 LimitClause limitClause = null;
2611 createNewScope();
Yingyi Buab817482016-08-19 21:29:31 -07002612}
2613{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002614 ( letClauses = LetClause() )?
2615 selectSetOperation = SelectSetOperation()
2616 (orderbyClause = OrderbyClause() {})?
2617 (limitClause = LimitClause() {})?
2618 {
2619 return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
2620 }
2621}
2622
Yingyi Buab817482016-08-19 21:29:31 -07002623SelectSetOperation SelectSetOperation() throws ParseException:
2624{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002625 SetOperationInput setOperationInputLeft;
2626 List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>();
2627}
2628{
2629 {
2630 SelectBlock selectBlockLeft = null;
2631 SelectExpression subqueryLeft = null;
2632 Expression expr = null;
2633 }
2634 selectBlockLeft = SelectBlock()
2635 {
2636 setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft);
2637 }
2638 (
2639 {
2640 SetOpType opType = SetOpType.UNION;
2641 boolean setSemantics = true;
2642 SelectBlock selectBlockRight = null;
2643 SelectExpression subqueryRight = null;
2644 }
2645 (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )?
2646 (selectBlockRight = SelectBlock()| subqueryRight = Subquery())
2647 {
2648 setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight)));
2649 }
2650 )*
2651 {
2652 return new SelectSetOperation(setOperationInputLeft, setOperationRights);
2653 }
2654}
2655
Yingyi Buab817482016-08-19 21:29:31 -07002656SelectExpression Subquery() throws ParseException:
2657{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002658 SelectExpression selectExpr = null;
2659}
2660{
2661 <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN>
2662 {
2663 return selectExpr;
2664 }
2665}
2666
Yingyi Buab817482016-08-19 21:29:31 -07002667SelectBlock SelectBlock() throws ParseException:
2668{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002669 SelectClause selectClause = null;
2670 FromClause fromClause = null;
2671 List<LetClause> fromLetClauses = null;
2672 WhereClause whereClause = null;
2673 GroupbyClause groupbyClause = null;
2674 List<LetClause> gbyLetClauses = null;
2675 HavingClause havingClause = null;
2676}
2677{
2678 (
2679 selectClause = SelectClause()
2680 (
2681 LOOKAHEAD(1)
2682 fromClause = FromClause()
2683 (
2684 LOOKAHEAD(1)
2685 fromLetClauses = LetClause()
2686 )?
2687 )?
2688 (whereClause = WhereClause())?
2689 (
2690 groupbyClause = GroupbyClause()
2691 (
2692 LOOKAHEAD(1)
2693 gbyLetClauses = LetClause()
2694 )?
2695 (havingClause = HavingClause())?
2696 )?
2697 |
2698 fromClause = FromClause()
2699 (
2700 LOOKAHEAD(1)
2701 fromLetClauses = LetClause()
2702 )?
2703 (whereClause = WhereClause())?
2704 (
2705 groupbyClause = GroupbyClause()
2706 (
2707 gbyLetClauses = LetClause()
2708 )?
2709 (havingClause = HavingClause())?
2710 )?
2711 selectClause = SelectClause()
2712 )
2713 {
2714 return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
2715 }
2716}
2717
Yingyi Buab817482016-08-19 21:29:31 -07002718SelectClause SelectClause() throws ParseException:
2719{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002720 SelectRegular selectRegular = null;
2721 SelectElement selectElement = null;
2722 boolean distinct = false;
2723}
2724{
Michael Blowd6cf6412016-06-30 02:44:35 -04002725 <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002726 (
2727 selectRegular = SelectRegular()
Michael Blowd6cf6412016-06-30 02:44:35 -04002728 |
Yingyi Bu391f09e2015-10-29 13:49:39 -07002729 selectElement = SelectElement()
Yingyi Bua89fae62016-07-06 07:58:55 -07002730 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002731 {
Yingyi Bua89fae62016-07-06 07:58:55 -07002732 if(selectRegular == null && selectElement == null){
2733 Projection projection = new Projection(null, null, true, false);
2734 List<Projection> projections = new ArrayList<Projection>();
2735 projections.add(projection);
2736 selectRegular = new SelectRegular(projections);
2737 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002738 return new SelectClause(selectElement, selectRegular, distinct);
2739 }
2740}
2741
Yingyi Buab817482016-08-19 21:29:31 -07002742SelectRegular SelectRegular() throws ParseException:
2743{
Michael Blowd6cf6412016-06-30 02:44:35 -04002744 List<Projection> projections = new ArrayList<Projection>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002745}
2746{
2747 {
2748 Projection projection = null;
2749 }
Michael Blowd6cf6412016-06-30 02:44:35 -04002750 projection = Projection() { projections.add(projection); }
Yingyi Bua89fae62016-07-06 07:58:55 -07002751 ( LOOKAHEAD(2) <COMMA>
2752 projection = Projection() {projections.add(projection);}
2753 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -07002754 {
2755 return new SelectRegular(projections);
2756 }
2757}
2758
Yingyi Buab817482016-08-19 21:29:31 -07002759SelectElement SelectElement() throws ParseException:
2760{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002761 Expression expr = null;
2762 String name = null;
2763}
2764{
2765 (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
2766 {
2767 return new SelectElement(expr);
2768 }
2769}
2770
Yingyi Buab817482016-08-19 21:29:31 -07002771Projection Projection() throws ParseException :
2772{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002773 Expression expr = null;
2774 Identifier identifier = null;
2775 String name = null;
2776 boolean star = false;
2777 boolean exprStar = false;
2778}
2779{
2780 (
2781 LOOKAHEAD(2)
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002782 expr = Expression() ((<AS>)? name = Identifier())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002783 | expr = Expression() <DOT> <MUL> {exprStar = true; }
2784 | <MUL> {star = true; }
2785 )
2786 {
Yingyi Bua89fae62016-07-06 07:58:55 -07002787 if(!star && name == null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002788 String generatedColumnIdentifier = ExpressionToVariableUtil.getGeneratedIdentifier(expr, false);
2789 if(generatedColumnIdentifier != null){
2790 name = SqlppVariableUtil.toUserDefinedName(generatedColumnIdentifier);
2791 }
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002792 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002793 return new Projection(expr, name, star, exprStar);
2794 }
2795}
2796
2797FromClause FromClause() throws ParseException :
2798{
2799 List<FromTerm> fromTerms = new ArrayList<FromTerm>();
2800 extendCurrentScope();
2801}
2802{
2803 {
2804 FromTerm fromTerm = null;
2805 }
Michael Blowd6cf6412016-06-30 02:44:35 -04002806 <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002807 (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
2808 {
2809 return new FromClause(fromTerms);
2810 }
2811}
2812
2813FromTerm FromTerm() throws ParseException :
2814{
2815 Expression leftExpr = null;
Michael Blowd6cf6412016-06-30 02:44:35 -04002816 VariableExpr leftVar = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002817 VariableExpr posVar = null;
2818 List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
2819}
2820{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002821 leftExpr = Expression() ((<AS>)? leftVar = Variable())? (<AT> posVar = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002822 (
2823 {JoinType joinType = JoinType.INNER; }
2824 (joinType = JoinType())?
2825 {
2826 AbstractBinaryCorrelateClause correlateClause = null;
2827 }
2828 (correlateClause = JoinClause(joinType)
Yingyi Bu6d999ed2016-07-13 11:59:06 -07002829 | correlateClause = UnnestClause(joinType)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002830 )
2831 {
2832 correlateClauses.add(correlateClause);
2833 }
2834 )*
2835 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002836 if(leftVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002837 leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002838 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002839 return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
2840 }
2841}
2842
2843JoinClause JoinClause(JoinType joinType) throws ParseException :
2844{
2845 Expression rightExpr = null;
2846 VariableExpr rightVar = null;
2847 VariableExpr posVar = null;
2848 Expression conditionExpr = null;
2849}
2850{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002851 <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07002852 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002853 if(rightVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002854 rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002855 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002856 return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2857 }
2858}
2859
Yingyi Bu391f09e2015-10-29 13:49:39 -07002860UnnestClause UnnestClause(JoinType joinType) throws ParseException :
2861{
2862 Expression rightExpr;
2863 VariableExpr rightVar;
2864 VariableExpr posVar = null;
2865}
2866{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002867 (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002868 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002869 if(rightVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002870 rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002871 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002872 return new UnnestClause(joinType, rightExpr, rightVar, posVar);
2873 }
2874}
2875
2876
2877JoinType JoinType() throws ParseException :
2878{
2879 JoinType joinType = JoinType.INNER;
2880}
2881{
2882 (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; })
2883 {
2884 return joinType;
2885 }
2886}
2887
2888List<LetClause> LetClause() throws ParseException:
2889{
2890 List<LetClause> letList = new ArrayList<LetClause>();
2891 LetClause letClause;
2892}
2893{
2894 (
2895 (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })*
2896 |
2897 <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })*
2898 )
2899 {
2900 return letList;
2901 }
2902}
2903
2904WhereClause WhereClause()throws ParseException :
2905{
2906 WhereClause wc = new WhereClause();
2907 Expression whereExpr;
2908}
2909{
2910 <WHERE> whereExpr = Expression()
2911 {
2912 wc.setWhereExpr(whereExpr);
2913 return wc;
2914 }
2915}
2916
2917OrderbyClause OrderbyClause()throws ParseException :
2918{
2919 OrderbyClause oc = new OrderbyClause();
2920 Expression orderbyExpr;
2921 List<Expression> orderbyList = new ArrayList<Expression>();
2922 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2923 int numOfOrderby = 0;
2924}
2925{
2926 <ORDER>
2927 {
2928 String hint = getHint(token);
2929 if (hint != null) {
2930 if (hint.startsWith(INMEMORY_HINT)) {
2931 String splits[] = hint.split(" +");
2932 int numFrames = Integer.parseInt(splits[1]);
2933 int numTuples = Integer.parseInt(splits[2]);
2934 oc.setNumFrames(numFrames);
2935 oc.setNumTuples(numTuples);
2936 }
2937 }
2938 }
2939 <BY> orderbyExpr = Expression()
2940 {
2941 orderbyList.add(orderbyExpr);
2942 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2943 }
2944 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2945 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2946 {
2947 modifierList.add(modif);
2948 }
2949
2950 (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression()
2951 {
2952 orderbyList.add(orderbyExpr);
2953 modif = OrderbyClause.OrderModifier.ASC;
2954 }
2955 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2956 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2957 {
2958 modifierList.add(modif);
2959 }
2960 )*
2961
2962 {
2963 oc.setModifierList(modifierList);
2964 oc.setOrderbyList(orderbyList);
2965 return oc;
2966 }
2967}
2968
2969GroupbyClause GroupbyClause()throws ParseException :
2970{
2971 GroupbyClause gbc = new GroupbyClause();
2972 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2973 VariableExpr var = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002974 Expression expr = null;
2975 VariableExpr decorVar = null;
2976 Expression decorExpr = null;
Yingyi Buacc12a92016-03-26 17:25:05 -07002977
2978 VariableExpr groupVar = null;
2979 List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<Pair<Expression, Identifier>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002980}
2981{
2982 {
2983 Scope newScope = extendCurrentScopeNoPush(true);
2984 // extendCurrentScope(true);
2985 }
2986 <GROUP>
2987 {
2988 String hint = getHint(token);
2989 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2990 gbc.setHashGroupByHint(true);
2991 }
2992 }
2993 <BY> (
2994 expr = Expression()
2995 (LOOKAHEAD(1) (<AS>)?
2996 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002997 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002998 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002999 if(var==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07003000 var = ExpressionToVariableUtil.getGeneratedVariable(expr, false);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003001 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003002 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
3003 vePairList.add(pair1);
3004 }
3005 ( LOOKAHEAD(1) <COMMA>
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003006 {
3007 var = null;
3008 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003009 expr = Expression()
3010 (LOOKAHEAD(1) (<AS>)?
3011 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08003012 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003013 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003014 if(var==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07003015 var = ExpressionToVariableUtil.getGeneratedVariable(expr, false);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003016 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003017 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
3018 vePairList.add(pair2);
3019 }
3020 )*
3021 )
Yingyi Buacc12a92016-03-26 17:25:05 -07003022 (<GROUP> <AS> groupVar = Variable()
3023 ( LOOKAHEAD(1)
3024 {
3025 VariableExpr fieldVarExpr = null;
3026 String fieldIdentifierStr = null;
3027 }
3028 <LEFTPAREN>
3029 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
3030 {
3031 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
3032 }
3033 (<COMMA>
3034 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
3035 {
3036 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
3037 }
3038 )*
3039 <RIGHTPAREN>
3040 )?
3041 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003042 {
3043 gbc.setGbyPairList(vePairList);
3044 gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07003045 gbc.setWithVarMap(new HashMap<Expression, VariableExpr>());
Yingyi Buacc12a92016-03-26 17:25:05 -07003046 gbc.setGroupVar(groupVar);
3047 gbc.setGroupFieldList(groupFieldList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003048 replaceCurrentScope(newScope);
3049 return gbc;
3050 }
3051}
3052
3053HavingClause HavingClause() throws ParseException:
3054{
3055 Expression filterExpr = null;
3056}
3057{
3058 <HAVING> filterExpr = Expression()
3059 {
3060 return new HavingClause(filterExpr);
3061 }
3062}
3063
3064LimitClause LimitClause() throws ParseException:
3065{
3066 LimitClause lc = new LimitClause();
3067 Expression expr;
3068 pushForbiddenScope(getCurrentScope());
3069}
3070{
3071 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
3072 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
3073
3074 {
3075 popForbiddenScope();
3076 return lc;
3077 }
3078}
3079
3080QuantifiedExpression QuantifiedExpression()throws ParseException:
3081{
3082 QuantifiedExpression qc = new QuantifiedExpression();
3083 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
3084 Expression satisfiesExpr;
3085 VariableExpr var;
3086 Expression inExpr;
3087 QuantifiedPair pair;
3088}
3089{
3090 {
3091 createNewScope();
3092 }
3093
Yingyi Bu8aac7242016-09-13 23:14:09 -07003094 ( ((<ANY>|<SOME>) { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Michael Blowd6cf6412016-06-30 02:44:35 -04003095 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
Yingyi Bu391f09e2015-10-29 13:49:39 -07003096 var = Variable() <IN> inExpr = Expression()
3097 {
3098 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003099 quantifiedList.add(pair);
3100 }
3101 (
3102 <COMMA> var = Variable() <IN> inExpr = Expression()
3103 {
3104 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003105 quantifiedList.add(pair);
3106 }
3107 )*
Yingyi Bu858efae2016-10-13 17:31:57 -07003108 <SATISFIES> satisfiesExpr = Expression() (<END>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003109 {
3110 qc.setSatisfiesExpr(satisfiesExpr);
3111 qc.setQuantifiedList(quantifiedList);
3112 removeCurrentScope();
3113 return qc;
3114 }
3115}
3116
3117LetClause LetElement() throws ParseException:
3118{
3119 LetClause lc = new LetClause();
3120 VariableExpr varExp;
3121 Expression beExp;
3122 extendCurrentScope();
3123}
3124{
3125 varExp = Variable() <EQ> beExp = Expression()
3126 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07003127 lc.setVarExpr(varExp);
3128 lc.setBindingExpr(beExp);
3129 return lc;
3130 }
3131}
3132
3133LetClause WithElement() throws ParseException:
3134{
3135 LetClause lc = new LetClause();
3136 VariableExpr varExp;
3137 Expression beExp;
3138 extendCurrentScope();
3139}
3140{
3141 varExp = Variable() <AS> beExp = Expression()
3142 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07003143 lc.setVarExpr(varExp);
3144 lc.setBindingExpr(beExp);
3145 return lc;
3146 }
3147}
3148
3149TOKEN_MGR_DECLS:
3150{
3151 public int commentDepth = 0;
Till Westmanne9b2adf2016-10-15 12:39:01 -07003152 public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07003153
3154 public void pushState() {
3155 lexerStateStack.push( curLexState );
3156 }
3157
3158 public void popState(String token) {
3159 if (lexerStateStack.size() > 0) {
3160 SwitchTo( lexerStateStack.pop() );
3161 } else {
3162 int errorLine = input_stream.getEndLine();
3163 int errorColumn = input_stream.getEndColumn();
3164 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
3165 + "\" but state stack is empty.";
3166 throw new TokenMgrError(msg, -1);
3167 }
3168 }
3169}
3170
3171<DEFAULT,IN_DBL_BRACE>
3172TOKEN [IGNORE_CASE]:
3173{
3174 <ALL : "all">
3175 | <AND : "and">
Yingyi Bu8aac7242016-09-13 23:14:09 -07003176 | <ANY : "any">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003177 | <APPLY : "apply">
3178 | <AS : "as">
3179 | <ASC : "asc">
3180 | <AT : "at">
3181 | <AUTOGENERATED : "autogenerated">
Yingyi Bua8baf6d2016-07-05 21:40:44 -07003182 | <BETWEEN : "between">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003183 | <BTREE : "btree">
3184 | <BY : "by">
3185 | <CASE : "case">
3186 | <CLOSED : "closed">
3187 | <CREATE : "create">
3188 | <COMPACTION : "compaction">
3189 | <COMPACT : "compact">
3190 | <CONNECT : "connect">
3191 | <CORRELATE : "correlate">
Yingyi Bud56ff032016-08-01 10:26:57 -07003192 | <DATASET : "dataset">
Yingyi Bu1c0fff52016-03-25 20:23:30 -07003193 | <COLLECTION : "collection">
Yingyi Bud56ff032016-08-01 10:26:57 -07003194 | <DATAVERSE : "dataverse">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003195 | <DECLARE : "declare">
3196 | <DEFINITION : "definition">
3197 | <DELETE : "delete">
3198 | <DESC : "desc">
3199 | <DISCONNECT : "disconnect">
3200 | <DISTINCT : "distinct">
3201 | <DROP : "drop">
3202 | <ELEMENT : "element">
Till Westmann516d1a82016-08-02 14:45:53 -07003203 | <EXPLAIN : "explain">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003204 | <ELSE : "else">
3205 | <ENFORCED : "enforced">
Yingyi Buc8c067c2016-07-25 23:37:19 -07003206 | <END : "end">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003207 | <EVERY : "every">
3208 | <EXCEPT : "except">
3209 | <EXISTS : "exists">
3210 | <EXTERNAL : "external">
3211 | <FEED : "feed">
3212 | <FILTER : "filter">
3213 | <FLATTEN : "flatten">
3214 | <FOR : "for">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003215 | <FROM : "from">
3216 | <FULL : "full">
Taewoo Kimc49405a2017-01-04 00:30:43 -08003217 | <FULLTEXT : "fulltext">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003218 | <FUNCTION : "function">
3219 | <GROUP : "group">
3220 | <HAVING : "having">
3221 | <HINTS : "hints">
3222 | <IF : "if">
3223 | <INTO : "into">
3224 | <IN : "in">
3225 | <INDEX : "index">
3226 | <INGESTION : "ingestion">
3227 | <INNER : "inner">
3228 | <INSERT : "insert">
3229 | <INTERNAL : "internal">
3230 | <INTERSECT : "intersect">
Yingyi Budaa549c2016-06-28 22:30:52 -07003231 | <IS : "is">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003232 | <JOIN : "join">
3233 | <KEYWORD : "keyword">
3234 | <KEY : "key">
3235 | <LEFT : "left">
3236 | <LETTING : "letting">
3237 | <LET : "let">
Yingyi Bua8baf6d2016-07-05 21:40:44 -07003238 | <LIKE : "like">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003239 | <LIMIT : "limit">
3240 | <LOAD : "load">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003241 | <NODEGROUP : "nodegroup">
3242 | <NGRAM : "ngram">
Yingyi Budaa549c2016-06-28 22:30:52 -07003243 | <NOT : "not">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003244 | <OFFSET : "offset">
3245 | <ON : "on">
3246 | <OPEN : "open">
3247 | <OR : "or">
3248 | <ORDER : "order">
3249 | <OUTER : "outer">
3250 | <OUTPUT : "output">
3251 | <PATH : "path">
3252 | <POLICY : "policy">
3253 | <PRESORTED : "pre-sorted">
3254 | <PRIMARY : "primary">
3255 | <RAW : "raw">
3256 | <REFRESH : "refresh">
3257 | <RETURN : "return">
Yingyi Bucb5bf332017-01-02 22:19:50 -08003258 | <RETURNING : "returning">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003259 | <RTREE : "rtree">
3260 | <RUN : "run">
3261 | <SATISFIES : "satisfies">
3262 | <SECONDARY : "secondary">
3263 | <SELECT : "select">
3264 | <SET : "set">
3265 | <SOME : "some">
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08003266 | <START : "start">
3267 | <STOP : "stop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003268 | <TEMPORARY : "temporary">
3269 | <THEN : "then">
3270 | <TYPE : "type">
3271 | <TO : "to">
3272 | <UNION : "union">
Dmitry Lychagin8b6578a2017-11-08 15:04:35 -08003273 | <UNKNOWN : "unknown">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003274 | <UNNEST : "unnest">
Yingyi Budaa549c2016-06-28 22:30:52 -07003275 | <UPDATE : "update">
Yingyi Bucb5bf332017-01-02 22:19:50 -08003276 | <UPSERT : "upsert">
Yingyi Budaa549c2016-06-28 22:30:52 -07003277 | <USE : "use">
3278 | <USING : "using">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003279 | <VALUE : "value">
3280 | <WHEN : "when">
3281 | <WHERE : "where">
3282 | <WITH : "with">
3283 | <WRITE : "write">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003284}
3285
3286<DEFAULT,IN_DBL_BRACE>
3287TOKEN :
3288{
3289 <CARET : "^">
Yingyi Bufdc71eb2016-08-24 22:41:57 -07003290 | <CONCAT : "||">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003291 | <DIV : "/">
3292 | <IDIV : "idiv">
3293 | <MINUS : "-">
3294 | <MOD : "%">
3295 | <MUL : "*">
3296 | <PLUS : "+">
3297
3298 | <LEFTPAREN : "(">
3299 | <RIGHTPAREN : ")">
3300 | <LEFTBRACKET : "[">
3301 | <RIGHTBRACKET : "]">
3302
3303 | <ATT : "@">
3304 | <COLON : ":">
3305 | <COMMA : ",">
3306 | <DOT : ".">
3307 | <QUES : "?">
3308 | <SEMICOLON : ";">
3309 | <SHARP : "#">
3310
3311 | <LT : "<">
3312 | <GT : ">">
3313 | <LE : "<=">
3314 | <GE : ">=">
3315 | <EQ : "=">
3316 | <NE : "!=">
Yingyi Bu4a4b8962016-09-16 12:09:11 -07003317 | <LG : "<>">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003318 | <SIMILAR : "~=">
3319}
3320
3321<DEFAULT,IN_DBL_BRACE>
3322TOKEN :
3323{
3324 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
3325}
3326
3327<DEFAULT>
3328TOKEN :
3329{
3330 <RIGHTBRACE : "}"> { popState("}"); }
3331}
3332
3333<DEFAULT,IN_DBL_BRACE>
3334TOKEN :
3335{
3336 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
3337}
3338
3339<IN_DBL_BRACE>
3340TOKEN :
3341{
3342 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
3343}
3344
3345<DEFAULT,IN_DBL_BRACE>
3346TOKEN :
3347{
3348 <INTEGER_LITERAL : (<DIGIT>)+ >
3349}
3350
3351<DEFAULT,IN_DBL_BRACE>
Yingyi Bue311a632016-06-07 18:23:16 -07003352TOKEN [IGNORE_CASE]:
Yingyi Bu391f09e2015-10-29 13:49:39 -07003353{
Yingyi Bu535d86b2016-05-23 16:44:25 -07003354 <MISSING : "missing">
3355 | <NULL : "null">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003356 | <TRUE : "true">
3357 | <FALSE : "false">
3358}
3359
3360<DEFAULT,IN_DBL_BRACE>
3361TOKEN :
3362{
3363 <#DIGIT : ["0" - "9"]>
3364}
3365
3366<DEFAULT,IN_DBL_BRACE>
3367TOKEN:
3368{
Yingyi Bu144453b2017-05-24 14:34:46 -07003369 < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("-")? <DIGITS>)?
3370 | <DIGITS> (("e"|"E") ("-")? <DIGITS>)
3371 | "." <DIGITS> (("e"|"E") ("-")? <DIGITS>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003372 >
Yingyi Bue4d919e2016-10-30 10:47:03 -07003373 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
3374 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
3375 | "." <DIGITS> ( "f" | "F" )
Yingyi Bu391f09e2015-10-29 13:49:39 -07003376 >
3377 | <DIGITS : (<DIGIT>)+ >
3378}
3379
3380<DEFAULT,IN_DBL_BRACE>
3381TOKEN :
3382{
3383 <#LETTER : ["A" - "Z", "a" - "z"]>
3384 | <SPECIALCHARS : ["$", "_"]>
3385}
3386
3387<DEFAULT,IN_DBL_BRACE>
3388TOKEN :
3389{
3390 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
Yingyi Bu6d57e492016-06-06 21:24:42 -07003391 <QUOTED_STRING : "`" (
Yingyi Bu391f09e2015-10-29 13:49:39 -07003392 <EscapeQuot>
3393 | <EscapeBslash>
3394 | <EscapeSlash>
3395 | <EscapeBspace>
3396 | <EscapeFormf>
3397 | <EscapeNl>
3398 | <EscapeCr>
3399 | <EscapeTab>
Yingyi Bu6d57e492016-06-06 21:24:42 -07003400 | ~["`","\\"])* "`">
3401 | <STRING_LITERAL : ("\"" (
Yingyi Bu391f09e2015-10-29 13:49:39 -07003402 <EscapeQuot>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003403 | <EscapeBslash>
3404 | <EscapeSlash>
3405 | <EscapeBspace>
3406 | <EscapeFormf>
3407 | <EscapeNl>
3408 | <EscapeCr>
3409 | <EscapeTab>
Yingyi Bu6d57e492016-06-06 21:24:42 -07003410 | ~["\"","\\"])* "\"")
3411 | ("\'"(
3412 <EscapeApos>
3413 | <EscapeBslash>
3414 | <EscapeSlash>
3415 | <EscapeBspace>
3416 | <EscapeFormf>
3417 | <EscapeNl>
3418 | <EscapeCr>
3419 | <EscapeTab>
3420 | ~["\'","\\"])* "\'")>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003421 | < #EscapeQuot: "\\\"" >
3422 | < #EscapeApos: "\\\'" >
3423 | < #EscapeBslash: "\\\\" >
3424 | < #EscapeSlash: "\\/" >
3425 | < #EscapeBspace: "\\b" >
3426 | < #EscapeFormf: "\\f" >
3427 | < #EscapeNl: "\\n" >
3428 | < #EscapeCr: "\\r" >
3429 | < #EscapeTab: "\\t" >
3430}
3431
3432<DEFAULT,IN_DBL_BRACE>
3433TOKEN :
3434{
3435 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
3436}
3437
3438<DEFAULT,IN_DBL_BRACE>
3439SKIP:
3440{
3441 " "
3442 | "\t"
3443 | "\r"
3444 | "\n"
3445}
3446
3447<DEFAULT,IN_DBL_BRACE>
3448SKIP:
3449{
3450 <"//" (~["\n"])* "\n">
3451}
3452
3453<DEFAULT,IN_DBL_BRACE>
3454SKIP:
3455{
3456 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
3457}
3458
3459<DEFAULT,IN_DBL_BRACE>
3460SKIP:
3461{
Yingyi Bu93846a72016-09-13 16:30:39 -07003462 <"--" (~["\n"])* "\n">
3463}
3464
3465
3466<DEFAULT,IN_DBL_BRACE>
3467SKIP:
3468{
3469 <"--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
3470}
3471
3472<DEFAULT,IN_DBL_BRACE>
3473SKIP:
3474{
Yingyi Bu391f09e2015-10-29 13:49:39 -07003475 <"/*"> { pushState(); } : INSIDE_COMMENT
3476}
3477
3478<INSIDE_COMMENT>
3479SPECIAL_TOKEN:
3480{
3481 <"+"(" ")*(~["*"])*>
3482}
3483
3484<INSIDE_COMMENT>
3485SKIP:
3486{
3487 <"/*"> { pushState(); }
3488}
3489
3490<INSIDE_COMMENT>
3491SKIP:
3492{
3493 <"*/"> { popState("*/"); }
3494 | <~[]>
3495}