blob: 2bf84e0e3788551562f4bd6aa4a92cf7657cb4cb [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;
Dmitry Lychaginef1719e2017-12-15 08:33:07 -0800146import org.apache.asterix.lang.common.struct.OperatorType;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700147import org.apache.asterix.lang.common.struct.QuantifiedPair;
148import org.apache.asterix.lang.common.struct.VarIdentifier;
149import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
150import org.apache.asterix.lang.sqlpp.clause.FromClause;
151import org.apache.asterix.lang.sqlpp.clause.FromTerm;
152import org.apache.asterix.lang.sqlpp.clause.HavingClause;
153import org.apache.asterix.lang.sqlpp.clause.JoinClause;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700154import org.apache.asterix.lang.sqlpp.clause.Projection;
155import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
156import org.apache.asterix.lang.sqlpp.clause.SelectClause;
157import org.apache.asterix.lang.sqlpp.clause.SelectElement;
158import org.apache.asterix.lang.sqlpp.clause.SelectRegular;
159import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
160import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
Yingyi Buc8c067c2016-07-25 23:37:19 -0700161import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700162import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
163import org.apache.asterix.lang.sqlpp.optype.JoinType;
164import org.apache.asterix.lang.sqlpp.optype.SetOpType;
165import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
166import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
Yingyi Bu9e3f9be2016-07-01 10:07:37 -0700167import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil;
Xikui Wang96fd4022017-04-10 14:23:31 -0700168import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
Yingyi Buacc12a92016-03-26 17:25:05 -0700169import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -0800170import org.apache.asterix.om.functions.BuiltinFunctions;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700171import org.apache.hyracks.algebricks.common.utils.Pair;
172import org.apache.hyracks.algebricks.common.utils.Triple;
173import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
174import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
175import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
176
Yingyi Bucaea8f02015-11-16 15:12:15 -0800177class SQLPPParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700178
179 // optimizer hints
180 private static final String AUTO_HINT = "auto";
181 private static final String BROADCAST_JOIN_HINT = "bcast";
182 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
183 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
184 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
185 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
186 private static final String HASH_GROUP_BY_HINT = "hash";
187 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
188 private static final String INMEMORY_HINT = "inmem";
189 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
190 private static final String INTERVAL_HINT = "interval";
191 private static final String LIST_HINT = "list";
192 private static final String LIST_VAL_FILE_HINT = "list-val-file";
193 private static final String RANGE_HINT = "range";
194 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
195 private static final String VAL_FILE_HINT = "val-files";
196 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
197
198 private static final String GEN_FIELDS_HINT = "gen-fields";
199
200 // data generator hints
201 private static final String DGEN_HINT = "dgen";
202
Till Westmann7199a562016-09-17 16:07:32 -0700203 // error configuration
204 protected static final boolean REPORT_EXPECTED_TOKENS = false;
205
Yingyi Bu391f09e2015-10-29 13:49:39 -0700206 private static class IndexParams {
207 public IndexType type;
208 public int gramLength;
209
210 public IndexParams(IndexType type, int gramLength) {
211 this.type = type;
212 this.gramLength = gramLength;
213 }
214 };
215
216 private static class FunctionName {
217 public String dataverse = null;
218 public String library = null;
219 public String function = null;
220 public String hint = null;
221 }
222
223 private static String getHint(Token t) {
224 if (t.specialToken == null) {
225 return null;
226 }
227 String s = t.specialToken.image;
228 int n = s.length();
229 if (n < 2) {
230 return null;
231 }
232 return s.substring(1).trim();
233 }
234
235 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
236 IRecordFieldDataGen rfdg = null;
237 String splits[] = hint.split(" +");
238 if (splits[0].equals(VAL_FILE_HINT)) {
239 File[] valFiles = new File[splits.length - 1];
240 for (int k=1; k<splits.length; k++) {
241 valFiles[k-1] = new File(splits[k]);
242 }
243 rfdg = new FieldValFileDataGen(valFiles);
244 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
245 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
246 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
247 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
248 } else if (splits[0].equals(LIST_HINT)) {
249 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
250 } else if (splits[0].equals(INTERVAL_HINT)) {
251 FieldIntervalDataGen.ValueType vt;
252 if (splits[1].equals("int")) {
253 vt = FieldIntervalDataGen.ValueType.INT;
254 } else if (splits[1].equals("long")) {
255 vt = FieldIntervalDataGen.ValueType.LONG;
256 } else if (splits[1].equals("float")) {
257 vt = FieldIntervalDataGen.ValueType.FLOAT;
258 } else if (splits[1].equals("double")) {
259 vt = FieldIntervalDataGen.ValueType.DOUBLE;
260 } else {
261 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
262 }
263 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
264 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
265 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
266 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
267 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
268 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
269 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
270 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
271 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
272 } else if (splits[0].equals(AUTO_HINT)) {
273 rfdg = new AutoDataGen(splits[1]);
274 }
275 return rfdg;
276 }
277
Till Westmann7199a562016-09-17 16:07:32 -0700278 public SQLPPParser(String s) {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700279 this(new StringReader(s));
280 super.setInput(s);
281 }
282
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800283 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700284 File file = new File(args[0]);
285 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
286 SQLPPParser parser = new SQLPPParser(fis);
287 List<Statement> st = parser.parse();
288 //st.accept(new SQLPPPrintVisitor(), 0);
289 }
290
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800291 public List<Statement> parse() throws CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700292 try {
293 return Statement();
294 } catch (Error e) {
295 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
296 // 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 -0700297 final String msg = e.getClass().getSimpleName() + (e.getMessage() != null ? ": " + e.getMessage() : "");
298 throw new CompilationException(new ParseException(msg));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700299 } catch (ParseException e) {
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800300 throw new CompilationException("Syntax error: " + getMessage(e));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700301 }
302 }
Till Westmann7199a562016-09-17 16:07:32 -0700303
304 protected String getMessage(ParseException pe) {
305 Token currentToken = pe.currentToken;
306 if (currentToken == null) {
307 return pe.getMessage();
308 }
309 int[][] expectedTokenSequences = pe.expectedTokenSequences;
310 String[] tokenImage = pe.tokenImage;
311 String sep = REPORT_EXPECTED_TOKENS ? eol : " ";
312 StringBuilder expected = REPORT_EXPECTED_TOKENS ? new StringBuilder() : null;
313 int maxSize = appendExpected(expected, expectedTokenSequences, tokenImage);
314 Token tok = currentToken.next;
315 int line = tok.beginLine;
316 String message = "In line " + line + " >>" + getLine(line) + "<<" + sep + "Encountered ";
317 for (int i = 0; i < maxSize; i++) {
318 if (i != 0) {
319 message += " ";
320 }
321 if (tok.kind == 0) {
322 message += fixQuotes(tokenImage[0]);
323 break;
324 }
Till Westmanne3c9f272016-10-09 11:09:26 -0700325 final String fixedTokenImage = tokenImage[tok.kind];
326 if (! tok.image.equalsIgnoreCase(stripQuotes(fixedTokenImage))) {
327 message += fixQuotes(fixedTokenImage) + " ";
328 }
Till Westmann7199a562016-09-17 16:07:32 -0700329 message += quot + addEscapes(tok.image) + quot;
330 tok = tok.next;
331 }
332 message += " at column " + currentToken.next.beginColumn + "." + sep;
333 if (REPORT_EXPECTED_TOKENS) {
334 if (expectedTokenSequences.length == 1) {
335 message += "Was expecting:" + sep + " ";
336 } else {
337 message += "Was expecting one of:" + sep + " ";
338 }
339 message += expected.toString();
340 }
341 return message;
342 }
343
Yingyi Bu391f09e2015-10-29 13:49:39 -0700344}
345
346PARSER_END(SQLPPParser)
347
348
349List<Statement> Statement() throws ParseException:
350{
351 scopeStack.push(RootScopeFactory.createRootScope(this));
352 List<Statement> decls = new ArrayList<Statement>();
353 Statement stmt = null;
354}
355{
Murtadha Hubaildc775222017-08-21 15:22:45 +0300356 (
357 (stmt = SingleStatement()
358 {
359 decls.add(stmt);
360 }
361 )?
362 (<SEMICOLON>)+
Yingyi Bu391f09e2015-10-29 13:49:39 -0700363 )*
364 <EOF>
365 {
366 return decls;
367 }
368}
369
370Statement SingleStatement() throws ParseException:
371{
372 Statement stmt = null;
373}
374{
375 (
376 stmt = DataverseDeclaration()
377 | stmt = FunctionDeclaration()
378 | stmt = CreateStatement()
379 | stmt = LoadStatement()
380 | stmt = DropStatement()
381 | stmt = WriteStatement()
382 | stmt = SetStatement()
383 | stmt = InsertStatement()
384 | stmt = DeleteStatement()
385 | stmt = UpdateStatement()
Yingyi Bucb5bf332017-01-02 22:19:50 -0800386 | stmt = UpsertStatement()
Yingyi Buab817482016-08-19 21:29:31 -0700387 | stmt = ConnectionStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700388 | stmt = CompactStatement()
Till Westmannef3f0272016-07-27 18:34:01 -0700389 | stmt = ExplainStatement()
Murtadha Hubaildc775222017-08-21 15:22:45 +0300390 | stmt = Query(false)
Yingyi Bu391f09e2015-10-29 13:49:39 -0700391 | stmt = RefreshExternalDatasetStatement()
392 | stmt = RunStatement()
393 )
394 {
395 return stmt;
396 }
397}
398
399DataverseDecl DataverseDeclaration() throws ParseException:
400{
401 String dvName = null;
402}
403{
404 <USE> dvName = Identifier()
405 {
406 defaultDataverse = dvName;
407 return new DataverseDecl(new Identifier(dvName));
408 }
409}
410
411Statement CreateStatement() throws ParseException:
412{
413 String hint = null;
414 boolean dgen = false;
415 Statement stmt = null;
416}
417{
418 <CREATE>
419 (
420 {
421 hint = getHint(token);
422 if (hint != null && hint.startsWith(DGEN_HINT)) {
423 dgen = true;
424 }
425 }
426 stmt = TypeSpecification(hint, dgen)
427 | stmt = NodegroupSpecification()
428 | stmt = DatasetSpecification()
429 | stmt = IndexSpecification()
430 | stmt = DataverseSpecification()
431 | stmt = FunctionSpecification()
432 | stmt = FeedSpecification()
433 | stmt = FeedPolicySpecification()
434 )
435 {
436 return stmt;
437 }
438}
439
440TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
441{
442 Pair<Identifier,Identifier> nameComponents = null;
443 boolean ifNotExists = false;
444 TypeExpression typeExpr = null;
445}
446{
447 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmannf6028272016-09-30 14:34:42 -0700448 <AS> typeExpr = RecordTypeDef()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700449 {
450 long numValues = -1;
451 String filename = null;
452 if (dgen) {
453 String splits[] = hint.split(" +");
454 if (splits.length != 3) {
455 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
456 }
457 filename = splits[1];
458 numValues = Long.parseLong(splits[2]);
459 }
460 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
461 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
462 }
463}
464
465
466NodegroupDecl NodegroupSpecification() throws ParseException:
467{
468 String name = null;
469 String tmp = null;
470 boolean ifNotExists = false;
471 List<Identifier>ncNames = null;
472}
473{
474 <NODEGROUP> name = Identifier()
475 ifNotExists = IfNotExists() <ON> tmp = Identifier()
476 {
477 ncNames = new ArrayList<Identifier>();
478 ncNames.add(new Identifier(tmp));
479 }
480 ( <COMMA> tmp = Identifier()
481 {
482 ncNames.add(new Identifier(tmp));
483 }
484 )*
485 {
486 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
487 }
488}
489
490DatasetDecl DatasetSpecification() throws ParseException:
491{
492 Pair<Identifier,Identifier> nameComponents = null;
493 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800494 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700495 String adapterName = null;
496 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700497 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;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800503 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800504 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800505 RecordConstructor withRecord = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700506}
507{
508 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700509 <EXTERNAL> Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800510 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700511 ifNotExists = IfNotExists()
512 <USING> adapterName = AdapterName() properties = Configuration()
Till Westmannf3aa19f2017-12-01 17:42:35 -0800513 ( <ON> nodeGroupName = Identifier() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700514 ( <HINTS> hints = Properties() )?
Till Westmannf3aa19f2017-12-01 17:42:35 -0800515 ( <WITH> withRecord = RecordConstructor() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700516 {
517 ExternalDetailsDecl edd = new ExternalDetailsDecl();
518 edd.setAdapter(adapterName);
519 edd.setProperties(properties);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800520 try{
Yingyi Bu391f09e2015-10-29 13:49:39 -0700521 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,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700528 hints,
529 DatasetType.EXTERNAL,
530 edd,
Till Westmannf3aa19f2017-12-01 17:42:35 -0800531 withRecord,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700532 ifNotExists);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800533 } catch (CompilationException e){
534 throw new ParseException(e.getMessage());
535 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700536 }
537
Murtadha Hubail2c04ae02017-11-21 15:58:01 +0300538 | ( <INTERNAL> )?
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700539 Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800540 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800541 (
542 { String name; }
543 <WITH>
544 name = Identifier()
545 {
546 if(!name.toLowerCase().equals("meta")){
547 throw new ParseException("We can only support one additional associated field called \"meta\".");
548 }
549 }
550 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
551 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700552 ifNotExists = IfNotExists()
553 primaryKeyFields = PrimaryKey()
554 (<AUTOGENERATED> { autogenerated = true; } )?
555 (<ON> nodeGroupName = Identifier() )?
556 ( <HINTS> hints = Properties() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700557 ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
Till Westmannf3aa19f2017-12-01 17:42:35 -0800558 ( <WITH> withRecord = RecordConstructor() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700559 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800560 if(filterField!=null && filterField.first!=0){
561 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
562 }
563 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
564 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700565 autogenerated,
Murtadha Hubail2c04ae02017-11-21 15:58:01 +0300566 filterField == null? null : filterField.second);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800567 try{
Yingyi Bu391f09e2015-10-29 13:49:39 -0700568 dsetDecl = new DatasetDecl(nameComponents.first,
569 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800570 typeComponents.first,
571 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800572 metaTypeComponents.first,
573 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700574 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700575 hints,
576 DatasetType.INTERNAL,
577 idd,
Till Westmannf3aa19f2017-12-01 17:42:35 -0800578 withRecord,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700579 ifNotExists);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800580 } catch (CompilationException e){
581 throw new ParseException(e.getMessage());
582 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700583 }
584 )
585 {
586 return dsetDecl;
587 }
588}
589
590RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
591{
592 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
593 Pair<Identifier,Identifier> nameComponents = null;
594 String datasetName = null;
595}
596{
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700597 <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700598 {
599 redss.setDataverseName(nameComponents.first);
600 redss.setDatasetName(nameComponents.second);
601 return redss;
602 }
603}
604
605RunStatement RunStatement() throws ParseException:
606{
607 String system = null;
608 String tmp;
609 ArrayList<String> parameters = new ArrayList<String>();
610 Pair<Identifier,Identifier> nameComponentsFrom = null;
611 Pair<Identifier,Identifier> nameComponentsTo = null;
612}
613{
614 <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
615 {
616 parameters.add(tmp);
617 }
618 )*<RIGHTPAREN>
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700619 <FROM> Dataset() nameComponentsFrom = QualifiedName()
620 <TO> Dataset() nameComponentsTo = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700621 {
622 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
623 }
624}
625
626CreateIndexStatement IndexSpecification() throws ParseException:
627{
628 CreateIndexStatement cis = new CreateIndexStatement();
629 String indexName = null;
630 boolean ifNotExists = false;
631 Pair<Identifier,Identifier> nameComponents = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -0700632 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700633 IndexParams indexType = null;
634 boolean enforced = false;
Ali Alsuliman8351d252017-09-24 00:43:15 -0700635 boolean isPrimaryIdx = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700636}
637{
Ali Alsuliman8351d252017-09-24 00:43:15 -0700638 (
639 (<INDEX> indexName = Identifier()
640 ifNotExists = IfNotExists()
641 <ON> nameComponents = QualifiedName()
642 <LEFTPAREN> ( fieldPair = OpenField()
643 {
644 cis.addFieldExprPair(fieldPair.second);
645 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700646 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700647 ) (<COMMA> fieldPair = OpenField()
648 {
649 cis.addFieldExprPair(fieldPair.second);
650 cis.addFieldIndexIndicator(fieldPair.first);
651 }
652 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
653 |
654 (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
655 (
656 (indexName = Identifier())? ifNotExists = IfNotExists()
657 )
658 <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
659 )
660 )
661 {
662 if (isPrimaryIdx && indexName == null) {
663 indexName = "primary_idx_" + nameComponents.second;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700664 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700665 cis.setIndexName(new Identifier(indexName));
666 cis.setIfNotExists(ifNotExists);
667 cis.setDataverseName(nameComponents.first);
668 cis.setDatasetName(nameComponents.second);
669 if (indexType != null) {
670 cis.setIndexType(indexType.type);
671 cis.setGramLength(indexType.gramLength);
672 }
673 cis.setEnforced(enforced);
674 return cis;
675 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700676}
677
678String CompactionPolicy() throws ParseException :
679{
680 String compactionPolicy = null;
681}
682{
683 compactionPolicy = Identifier()
684 {
685 return compactionPolicy;
686 }
687}
688
689String FilterField() throws ParseException :
690{
691 String filterField = null;
692}
693{
694 filterField = Identifier()
695 {
696 return filterField;
697 }
698}
699
700IndexParams IndexType() throws ParseException:
701{
702 IndexType type = null;
703 int gramLength = 0;
704}
705{
706 (<BTREE>
707 {
708 type = IndexType.BTREE;
709 }
710 | <RTREE>
711 {
712 type = IndexType.RTREE;
713 }
714 | <KEYWORD>
715 {
716 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
717 }
Taewoo Kimc49405a2017-01-04 00:30:43 -0800718 |<FULLTEXT>
719 {
720 type = IndexType.SINGLE_PARTITION_WORD_INVIX;
721 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700722 | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
723 {
724 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
725 gramLength = Integer.valueOf(token.image);
726 }
727 <RIGHTPAREN>)
728 {
729 return new IndexParams(type, gramLength);
730 }
731}
732
733CreateDataverseStatement DataverseSpecification() throws ParseException :
734{
735 String dvName = null;
736 boolean ifNotExists = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700737}
738{
739 <DATAVERSE> dvName = Identifier()
740 ifNotExists = IfNotExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700741 {
Till Westmannf6028272016-09-30 14:34:42 -0700742 return new CreateDataverseStatement(new Identifier(dvName), null, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700743 }
744}
745
746CreateFunctionStatement FunctionSpecification() throws ParseException:
747{
748 FunctionSignature signature;
749 boolean ifNotExists = false;
750 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
751 String functionBody;
752 VarIdentifier var = null;
753 Expression functionBodyExpr;
754 Token beginPos;
755 Token endPos;
756 FunctionName fctName = null;
757
758 createNewScope();
759}
760{
761 <FUNCTION> fctName = FunctionName()
762 ifNotExists = IfNotExists()
763 paramList = ParameterList()
764 <LEFTBRACE>
765 {
766 beginPos = token;
767 }
768 functionBodyExpr = Expression() <RIGHTBRACE>
769 {
770 endPos = token;
771 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
772 // TODO use fctName.library
773 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
774 getCurrentScope().addFunctionDescriptor(signature, false);
775 removeCurrentScope();
776 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
777 }
778}
779
780CreateFeedStatement FeedSpecification() throws ParseException:
781{
782 Pair<Identifier,Identifier> nameComponents = null;
783 boolean ifNotExists = false;
784 String adapterName = null;
785 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700786 CreateFeedStatement cfs = null;
787 Pair<Identifier,Identifier> sourceNameComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700788}
789{
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800790 <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
791 <USING> adapterName = AdapterName() properties = Configuration()
792 {
793 cfs = new CreateFeedStatement(nameComponents, adapterName, properties, ifNotExists);
794 return cfs;
795 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700796}
797
798CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
799{
Michael Blowd6cf6412016-06-30 02:44:35 -0400800 String policyName = null;
801 String basePolicyName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700802 String sourcePolicyFile = null;
803 String definition = null;
804 boolean ifNotExists = false;
805 Map<String,String> properties = null;
806 CreateFeedPolicyStatement cfps = null;
807}
808{
809 (
810 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
Yingyi Bu6d57e492016-06-06 21:24:42 -0700811 <FROM>
812 (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700813 {
814 cfps = new CreateFeedPolicyStatement(policyName,
815 basePolicyName, properties, definition, ifNotExists);
816 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300817 | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700818 {
819 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
820 }
Yingyi Bu6d57e492016-06-06 21:24:42 -0700821 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700822 )
823 {
824 return cfps;
825 }
826}
827
828
829
830List<VarIdentifier> ParameterList() throws ParseException:
831{
832 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
833 VarIdentifier var = null;
834}
835{
836 <LEFTPAREN> (<IDENTIFIER>
837 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700838 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700839 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700840 }
841 (<COMMA> <IDENTIFIER>
842 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700843 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700844 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700845 }
846 )*)? <RIGHTPAREN>
847 {
848 return paramList;
849 }
850}
851
852boolean IfNotExists() throws ParseException:
853{
854}
855{
Yingyi Budaa549c2016-06-28 22:30:52 -0700856 ( LOOKAHEAD(1) <IF> <NOT> <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700857 {
858 return true;
859 }
860 )?
861 {
862 return false;
863 }
864}
865
Xikui Wang9d63f622017-05-18 17:50:44 -0700866void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700867{
868 FunctionName functioName = null;
Xikui Wang261dc6d2017-03-29 21:23:15 -0700869 String fqFunctionName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700870}
871{
872 <APPLY> <FUNCTION> functioName = FunctionName()
873 {
Xikui Wang261dc6d2017-03-29 21:23:15 -0700874 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
875 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
876 }
877 (
878 <COMMA> functioName = FunctionName()
879 {
880 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
881 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
882 }
883 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -0700884}
885
886String GetPolicy() throws ParseException:
887{
888 String policy = null;
889}
890{
891 <USING> <POLICY> policy = Identifier()
892 {
893 return policy;
894 }
895
896}
897
898FunctionSignature FunctionSignature() throws ParseException:
899{
900 FunctionName fctName = null;
901 int arity = 0;
902}
903{
904 fctName = FunctionName() <ATT> <INTEGER_LITERAL>
905 {
906 arity = new Integer(token.image);
907 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
908 throw new ParseException(" invalid arity:" + arity);
909 }
910
911 // TODO use fctName.library
912 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
913 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
914 }
915}
916
Yingyi Buc9bfe252016-03-01 00:02:40 -0800917Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700918{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800919 Pair<Integer, List<String>> tmp = null;
920 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700921 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
922}
923{
924 <PRIMARY> <KEY> tmp = NestedField()
925 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800926 keyFieldSourceIndicators.add(tmp.first);
927 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700928 }
929 ( <COMMA> tmp = NestedField()
930 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800931 keyFieldSourceIndicators.add(tmp.first);
932 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700933 }
934 )*
935 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800936 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700937 }
938}
939
940Statement DropStatement() throws ParseException:
941{
942 String id = null;
943 Pair<Identifier,Identifier> pairId = null;
944 Triple<Identifier,Identifier,Identifier> tripleId = null;
945 FunctionSignature funcSig = null;
946 boolean ifExists = false;
947 Statement stmt = null;
948}
949{
950 <DROP>
951 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700952 Dataset() pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700953 {
Yingyi Buab817482016-08-19 21:29:31 -0700954 stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700955 }
956 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
957 {
958 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
959 }
960 | <NODEGROUP> id = Identifier() ifExists = IfExists()
961 {
962 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
963 }
964 | <TYPE> pairId = TypeName() ifExists = IfExists()
965 {
966 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
967 }
968 | <DATAVERSE> id = Identifier() ifExists = IfExists()
969 {
970 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
971 }
972 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
973 {
974 stmt = new FunctionDropStatement(funcSig, ifExists);
975 }
976 | <FEED> pairId = QualifiedName() ifExists = IfExists()
977 {
978 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
979 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300980 | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
981 {
982 stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
983 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700984 )
985 {
986 return stmt;
987 }
988}
989
990boolean IfExists() throws ParseException :
991{
992}
993{
994 ( LOOKAHEAD(1) <IF> <EXISTS>
995 {
996 return true;
997 }
998 )?
999 {
1000 return false;
1001 }
1002}
1003
1004InsertStatement InsertStatement() throws ParseException:
1005{
1006 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Bucb5bf332017-01-02 22:19:50 -08001007 VariableExpr var = null;
1008 Query query = null;
1009 Expression returnExpression = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001010}
1011{
Yingyi Bucb5bf332017-01-02 22:19:50 -08001012 <INSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
1013 query = Query(false)
1014 ( <RETURNING> returnExpression = Expression())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001015 {
Yingyi Bucb5bf332017-01-02 22:19:50 -08001016 if (returnExpression != null && var == null) {
1017 var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
1018 }
Yingyi Bucaea8f02015-11-16 15:12:15 -08001019 query.setTopLevel(true);
Yingyi Bucb5bf332017-01-02 22:19:50 -08001020 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1021 returnExpression);
1022 }
1023}
1024
1025UpsertStatement UpsertStatement() throws ParseException:
1026{
1027 Pair<Identifier,Identifier> nameComponents = null;
1028 VariableExpr var = null;
1029 Query query = null;
1030 Expression returnExpression = null;
1031}
1032{
1033 <UPSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
1034 query = Query(false)
1035 ( <RETURNING> returnExpression = Expression())?
1036 {
1037 if (returnExpression != null && var == null) {
1038 var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
1039 }
1040 query.setTopLevel(true);
1041 return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1042 returnExpression);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001043 }
1044}
1045
1046DeleteStatement DeleteStatement() throws ParseException:
1047{
Yingyi Bu20e085b2016-07-06 12:57:27 -07001048 VariableExpr varExpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001049 Expression condition = null;
1050 Pair<Identifier, Identifier> nameComponents;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001051}
1052{
Yingyi Bu20e085b2016-07-06 12:57:27 -07001053 <DELETE>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001054 <FROM> nameComponents = QualifiedName()
Yingyi Bu20e085b2016-07-06 12:57:27 -07001055 ((<AS>)? varExpr = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001056 (<WHERE> condition = Expression())?
Yingyi Bu20e085b2016-07-06 12:57:27 -07001057 {
Yingyi Bu20e085b2016-07-06 12:57:27 -07001058 if(varExpr == null){
1059 varExpr = new VariableExpr();
1060 VarIdentifier var = SqlppVariableUtil.toInternalVariableIdentifier(nameComponents.second.getValue());
1061 varExpr.setVar(var);
1062 }
1063 return new DeleteStatement(varExpr, nameComponents.first, nameComponents.second,
Abdullah Alamoudi6eb01752017-04-01 21:51:19 -07001064 condition, getVarCounter());
Yingyi Bu20e085b2016-07-06 12:57:27 -07001065 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001066}
1067
1068UpdateStatement UpdateStatement() throws ParseException:
1069{
1070 VariableExpr vars;
1071 Expression target;
1072 Expression condition;
1073 UpdateClause uc;
1074 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
1075}
1076{
1077 <UPDATE> vars = Variable() <IN> target = Expression()
1078 <WHERE> condition = Expression()
1079 <LEFTPAREN> (uc = UpdateClause()
1080 {
1081 ucs.add(uc);
1082 }
1083 (<COMMA> uc = UpdateClause()
1084 {
1085 ucs.add(uc);
1086 }
1087 )*) <RIGHTPAREN>
1088 {
1089 return new UpdateStatement(vars, target, condition, ucs);
1090 }
1091}
1092
1093UpdateClause UpdateClause() throws ParseException:
1094{
1095 Expression target = null;
1096 Expression value = null ;
1097 InsertStatement is = null;
1098 DeleteStatement ds = null;
1099 UpdateStatement us = null;
1100 Expression condition = null;
1101 UpdateClause ifbranch = null;
1102 UpdateClause elsebranch = null;
1103}
1104{
1105 (<SET> target = Expression() <EQ> value = Expression()
1106 | is = InsertStatement()
1107 | ds = DeleteStatement()
1108 | us = UpdateStatement()
1109 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
1110 <THEN> ifbranch = UpdateClause()
1111 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1112 {
1113 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1114 }
1115 )
1116}
1117
1118Statement SetStatement() throws ParseException:
1119{
1120 String pn = null;
1121 String pv = null;
1122}
1123{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001124 <SET> pn = Identifier() pv = ConstantString()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001125 {
1126 return new SetStatement(pn, pv);
1127 }
1128}
1129
1130Statement WriteStatement() throws ParseException:
1131{
1132 String nodeName = null;
1133 String fileName = null;
1134 Query query;
1135 String writerClass = null;
1136 Pair<Identifier,Identifier> nameComponents = null;
1137}
1138{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001139 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString()
1140 ( <USING> writerClass = ConstantString() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001141 {
1142 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1143 }
1144}
1145
1146LoadStatement LoadStatement() throws ParseException:
1147{
1148 Identifier dataverseName = null;
1149 Identifier datasetName = null;
1150 boolean alreadySorted = false;
1151 String adapterName;
1152 Map<String,String> properties;
1153 Pair<Identifier,Identifier> nameComponents = null;
1154}
1155{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001156 <LOAD> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001157 {
1158 dataverseName = nameComponents.first;
1159 datasetName = nameComponents.second;
1160 }
1161 <USING> adapterName = AdapterName() properties = Configuration()
1162 (<PRESORTED>
1163 {
1164 alreadySorted = true;
1165 }
1166 )?
1167 {
1168 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1169 }
1170}
1171
1172
1173String AdapterName() throws ParseException :
1174{
1175 String adapterName = null;
1176}
1177{
1178 adapterName = Identifier()
1179 {
1180 return adapterName;
1181 }
1182}
1183
1184Statement CompactStatement() throws ParseException:
1185{
1186 Pair<Identifier,Identifier> nameComponents = null;
1187 Statement stmt = null;
1188}
1189{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001190 <COMPACT> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001191 {
1192 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1193 }
1194 {
1195 return stmt;
1196 }
1197}
1198
Yingyi Buab817482016-08-19 21:29:31 -07001199Statement ConnectionStatement() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001200{
1201 Pair<Identifier,Identifier> feedNameComponents = null;
1202 Pair<Identifier,Identifier> datasetNameComponents = null;
1203
1204 Map<String,String> configuration = null;
1205 Statement stmt = null;
1206 String policy = null;
1207}
1208{
1209 (
Yingyi Buab817482016-08-19 21:29:31 -07001210 <CONNECT> stmt = ConnectStatement()
1211 | <DISCONNECT> stmt = DisconnectStatement()
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001212 | <START> stmt = StartStatement()
1213 | <STOP> stmt = StopStatement()
Yingyi Buab817482016-08-19 21:29:31 -07001214 )
1215 {
1216 return stmt;
1217 }
1218}
1219
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001220Statement StartStatement() throws ParseException:
1221{
1222 Pair<Identifier,Identifier> feedNameComponents = null;
1223
1224 Statement stmt = null;
1225}
1226{
1227 <FEED> feedNameComponents = QualifiedName()
1228 {
1229 stmt = new StartFeedStatement (feedNameComponents);
1230 return stmt;
1231 }
1232}
1233
1234Statement StopStatement () throws ParseException:
1235{
1236 Pair<Identifier,Identifier> feedNameComponents = null;
1237
1238 Statement stmt = null;
1239}
1240{
1241 <FEED> feedNameComponents = QualifiedName()
1242 {
1243 stmt = new StopFeedStatement (feedNameComponents);
1244 return stmt;
1245 }
1246}
1247
1248
Yingyi Buab817482016-08-19 21:29:31 -07001249Statement DisconnectStatement() throws ParseException:
1250{
1251 Pair<Identifier,Identifier> feedNameComponents = null;
1252 Pair<Identifier,Identifier> datasetNameComponents = null;
1253
1254 Map<String,String> configuration = null;
1255 Statement stmt = null;
1256 String policy = null;
1257}
1258{
1259 (
1260 <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001261 {
1262 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1263 }
1264 )
Yingyi Buab817482016-08-19 21:29:31 -07001265 {
1266 return stmt;
1267 }
1268}
1269
1270Statement ConnectStatement() throws ParseException:
1271{
1272 Pair<Identifier,Identifier> feedNameComponents = null;
1273 Pair<Identifier,Identifier> datasetNameComponents = null;
1274
1275 Map<String,String> configuration = null;
Xikui Wang9d63f622017-05-18 17:50:44 -07001276 List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
Yingyi Buab817482016-08-19 21:29:31 -07001277 Statement stmt = null;
1278 String policy = null;
1279}
1280{
1281 (
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001282 <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName()
Xikui Wang9d63f622017-05-18 17:50:44 -07001283 (ApplyFunction(appliedFunctions))? (policy = GetPolicy())?
Yingyi Buab817482016-08-19 21:29:31 -07001284 {
Xikui Wang261dc6d2017-03-29 21:23:15 -07001285 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions,
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001286 policy, getVarCounter());
Yingyi Buab817482016-08-19 21:29:31 -07001287 }
1288 )
1289 {
1290 return stmt;
1291 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001292}
1293
1294Map<String,String> Configuration() throws ParseException :
1295{
1296 Map<String,String> configuration = new LinkedHashMap<String,String>();
1297 Pair<String, String> keyValuePair = null;
1298}
1299{
1300 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1301 {
1302 configuration.put(keyValuePair.first, keyValuePair.second);
1303 }
1304 ( <COMMA> keyValuePair = KeyValuePair()
1305 {
1306 configuration.put(keyValuePair.first, keyValuePair.second);
1307 }
1308 )* )? <RIGHTPAREN>
1309 {
1310 return configuration;
1311 }
1312}
1313
1314Pair<String, String> KeyValuePair() throws ParseException:
1315{
1316 String key;
1317 String value;
1318}
1319{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001320 <LEFTPAREN> key = ConstantString() <EQ> value = ConstantString() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001321 {
1322 return new Pair<String, String>(key, value);
1323 }
1324}
1325
1326Map<String,String> Properties() throws ParseException:
1327{
1328 Map<String,String> properties = new HashMap<String,String>();
1329 Pair<String, String> property;
1330}
1331{
1332 (LOOKAHEAD(1) <LEFTPAREN> property = Property()
1333 {
1334 properties.put(property.first, property.second);
1335 }
1336 ( <COMMA> property = Property()
1337 {
1338 properties.put(property.first, property.second);
1339 }
1340 )* <RIGHTPAREN> )?
1341 {
1342 return properties;
1343 }
1344}
1345
1346Pair<String, String> Property() throws ParseException:
1347{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001348 String key = null;
1349 String value = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001350}
1351{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001352 (key = Identifier() | key = StringLiteral())
1353 <EQ>
1354 ( value = ConstantString() | <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001355 {
1356 try {
1357 value = "" + Long.valueOf(token.image);
1358 } catch (NumberFormatException nfe) {
1359 throw new ParseException("inapproriate value: " + token.image);
1360 }
1361 }
1362 )
1363 {
1364 return new Pair<String, String>(key.toUpperCase(), value);
1365 }
1366}
1367
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001368IndexedTypeExpression IndexedTypeExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001369{
1370 TypeExpression typeExpr = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001371 boolean isUnknownable = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001372}
1373{
1374 (
1375 typeExpr = TypeReference()
1376 | typeExpr = OrderedListTypeDef()
1377 | typeExpr = UnorderedListTypeDef()
1378 )
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001379 ( <QUES> { isUnknownable = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001380 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001381 return new IndexedTypeExpression(typeExpr, isUnknownable);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001382 }
1383}
1384
1385TypeExpression TypeExpr() throws ParseException:
1386{
1387 TypeExpression typeExpr = null;
1388}
1389{
1390 (
1391 typeExpr = RecordTypeDef()
1392 | typeExpr = TypeReference()
1393 | typeExpr = OrderedListTypeDef()
1394 | typeExpr = UnorderedListTypeDef()
1395 )
1396 {
1397 return typeExpr;
1398 }
1399}
1400
1401RecordTypeDefinition RecordTypeDef() throws ParseException:
1402{
1403 RecordTypeDefinition recType = new RecordTypeDefinition();
1404 RecordTypeDefinition.RecordKind recordKind = null;
1405}
1406{
1407 ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1408 | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1409 <LEFTBRACE>
1410 {
1411 String hint = getHint(token);
1412 if (hint != null) {
1413 String splits[] = hint.split(" +");
1414 if (splits[0].equals(GEN_FIELDS_HINT)) {
1415 if (splits.length != 5) {
1416 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1417 }
1418 if (!splits[1].equals("int")) {
1419 throw new ParseException("The only supported type for gen-fields is int.");
1420 }
1421 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1422 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1423 recType.setUndeclaredFieldsDataGen(ufdg);
1424 }
1425 }
1426
1427 }
1428 (
1429 RecordField(recType)
1430 ( <COMMA> RecordField(recType) )*
1431 )?
1432 <RIGHTBRACE>
1433 {
1434 if (recordKind == null) {
1435 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1436 }
1437 recType.setRecordKind(recordKind);
1438 return recType;
1439 }
1440}
1441
1442void RecordField(RecordTypeDefinition recType) throws ParseException:
1443{
1444 String fieldName;
1445 TypeExpression type = null;
1446 boolean nullable = false;
1447}
1448{
1449 fieldName = Identifier()
1450 {
1451 String hint = getHint(token);
1452 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1453 }
1454 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1455 {
1456 recType.addField(fieldName, type, nullable, rfdg);
1457 }
1458}
1459
1460TypeReferenceExpression TypeReference() throws ParseException:
1461{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001462 Pair<Identifier,Identifier> id = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001463}
1464{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001465 id = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001466 {
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001467 if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
1468 id.second.setValue("int64");
Yingyi Bu391f09e2015-10-29 13:49:39 -07001469 }
1470
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001471 return new TypeReferenceExpression(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001472 }
1473}
1474
1475OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1476{
1477 TypeExpression type = null;
1478}
1479{
1480 <LEFTBRACKET>
1481 ( type = TypeExpr() )
1482 <RIGHTBRACKET>
1483 {
1484 return new OrderedListTypeDefinition(type);
1485 }
1486}
1487
1488
1489UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1490{
1491 TypeExpression type = null;
1492}
1493{
1494 <LEFTDBLBRACE>
1495 ( type = TypeExpr() )
1496 <RIGHTDBLBRACE>
1497 {
1498 return new UnorderedListTypeDefinition(type);
1499 }
1500}
1501
1502FunctionName FunctionName() throws ParseException:
1503{
1504 String first = null;
1505 String second = null;
1506 String third = null;
1507 boolean secondAfterDot = false;
1508}
1509{
Michael Blowd6cf6412016-06-30 02:44:35 -04001510 first = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001511 {
1512 FunctionName result = new FunctionName();
1513 result.hint = getHint(token);
Michael Blowd6cf6412016-06-30 02:44:35 -04001514 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001515 ( <DOT> second = Identifier()
1516 {
1517 secondAfterDot = true;
1518 }
1519 (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )?
1520 {
1521 if (second == null) {
1522 result.dataverse = defaultDataverse;
1523 result.library = null;
1524 result.function = first;
1525 } else if (third == null) {
1526 if (secondAfterDot) {
1527 result.dataverse = first;
1528 result.library = null;
1529 result.function = second;
1530 } else {
1531 result.dataverse = defaultDataverse;
1532 result.library = first;
1533 result.function = second;
1534 }
1535 } else {
1536 result.dataverse = first;
1537 result.library = second;
1538 result.function = third;
1539 }
1540
1541 if (result.function.equalsIgnoreCase("int")) {
1542 result.function = "int64";
1543 }
1544 return result;
1545 }
1546}
1547
1548Pair<Identifier,Identifier> TypeName() throws ParseException:
1549{
1550 Pair<Identifier,Identifier> name = null;
1551}
1552{
1553 name = QualifiedName()
1554 {
1555 if (name.first == null) {
1556 name.first = new Identifier(defaultDataverse);
1557 }
1558 return name;
1559 }
1560}
1561
1562String Identifier() throws ParseException:
1563{
1564 String lit = null;
1565}
1566{
1567 (<IDENTIFIER>
1568 {
1569 return token.image;
1570 }
1571 | lit = QuotedString()
1572 {
1573 return lit;
1574 }
1575 )
1576}
1577
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001578void Dataset() throws ParseException:
1579{
1580}
1581{
1582 (<DATASET>|<COLLECTION>)
1583}
1584
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001585Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001586{
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001587 IndexedTypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001588 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001589}
1590{
1591 fieldList = NestedField()
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001592 ( <COLON> fieldType = IndexedTypeExpr() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001593 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001594 return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
1595 (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001596 }
1597}
1598
Yingyi Buc9bfe252016-03-01 00:02:40 -08001599Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001600{
1601 List<String> exprList = new ArrayList<String>();
1602 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001603 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001604}
1605{
1606 lit = Identifier()
1607 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001608 boolean meetParens = false;
1609 }
1610 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001611 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001612 <LEFTPAREN><RIGHTPAREN>
1613 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001614 if(!lit.toLowerCase().equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001615 throw new ParseException("The string before () has to be \"meta\".");
1616 }
1617 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001618 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001619 }
1620 )?
1621 {
1622 if(!meetParens){
1623 exprList.add(lit);
1624 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001625 }
1626 (<DOT>
1627 lit = Identifier()
1628 {
1629 exprList.add(lit);
1630 }
1631 )*
1632 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001633 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001634 }
1635}
1636
Yingyi Bu6d57e492016-06-06 21:24:42 -07001637String ConstantString() throws ParseException:
1638{
1639 String value = null;
1640}
1641{
1642 (value = QuotedString() | value = StringLiteral())
1643 {
1644 return value;
1645 }
1646}
1647
Yingyi Bu391f09e2015-10-29 13:49:39 -07001648
1649String QuotedString() throws ParseException:
1650{
1651}
1652{
1653 <QUOTED_STRING>
1654 {
1655 return removeQuotesAndEscapes(token.image);
1656 }
1657}
1658
1659
1660String StringLiteral() throws ParseException:
1661{
1662}
1663{
1664 <STRING_LITERAL>
1665 {
1666 return removeQuotesAndEscapes(token.image);
1667 }
1668}
1669
1670Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1671{
1672 String first = null;
1673 String second = null;
1674}
1675{
1676 first = Identifier() (<DOT> second = Identifier())?
1677 {
1678 Identifier id1 = null;
1679 Identifier id2 = null;
1680 if (second == null) {
1681 id2 = new Identifier(first);
1682 } else
1683 {
1684 id1 = new Identifier(first);
1685 id2 = new Identifier(second);
1686 }
1687 return new Pair<Identifier,Identifier>(id1, id2);
1688 }
1689}
1690
1691Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1692{
1693 String first = null;
1694 String second = null;
1695 String third = null;
1696}
1697{
1698 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1699 {
1700 Identifier id1 = null;
1701 Identifier id2 = null;
1702 Identifier id3 = null;
1703 if (third == null) {
1704 id2 = new Identifier(first);
1705 id3 = new Identifier(second);
1706 } else {
1707 id1 = new Identifier(first);
1708 id2 = new Identifier(second);
1709 id3 = new Identifier(third);
1710 }
1711 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1712 }
1713}
1714
1715FunctionDecl FunctionDeclaration() throws ParseException:
1716{
1717 FunctionDecl funcDecl;
1718 FunctionSignature signature;
1719 String functionName;
1720 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1721 Expression funcBody;
1722 createNewScope();
1723}
1724{
1725 <DECLARE> <FUNCTION> functionName = Identifier()
1726 paramList = ParameterList()
1727 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1728 {
1729 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1730 getCurrentScope().addFunctionDescriptor(signature, false);
1731 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1732 removeCurrentScope();
1733 return funcDecl;
1734 }
1735}
1736
Till Westmannef3f0272016-07-27 18:34:01 -07001737Query ExplainStatement() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001738{
Till Westmannef3f0272016-07-27 18:34:01 -07001739 Query query;
1740}
1741{
Till Westmann516d1a82016-08-02 14:45:53 -07001742 <EXPLAIN> query = Query(true)
Till Westmannef3f0272016-07-27 18:34:01 -07001743 {
1744 return query;
1745 }
1746}
1747
1748Query Query(boolean explain) throws ParseException:
1749{
1750 Query query = new Query(explain);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001751 Expression expr;
1752}
1753{
1754 (
1755 expr = Expression()
1756 |
1757 expr = SelectExpression(false)
1758 )
1759 {
1760 query.setBody(expr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001761 return query;
1762 }
1763}
1764
1765
1766
1767Expression Expression():
1768{
1769 Expression expr = null;
1770 Expression exprP = null;
1771}
1772{
1773(
1774 LOOKAHEAD(2)
1775 expr = OperatorExpr()
Yingyi Buc8c067c2016-07-25 23:37:19 -07001776 | expr = CaseExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001777 | expr = QuantifiedExpression()
1778)
1779 {
1780 return (exprP==null) ? expr : exprP;
1781 }
1782}
1783
1784
1785
1786Expression OperatorExpr()throws ParseException:
1787{
1788 OperatorExpr op = null;
1789 Expression operand = null;
1790}
1791{
1792 operand = AndExpr()
1793 (
1794
1795 <OR>
1796 {
1797 if (op == null) {
1798 op = new OperatorExpr();
1799 op.addOperand(operand);
1800 op.setCurrentop(true);
1801 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001802 try{
1803 op.addOperator(token.image.toLowerCase());
1804 } catch (Exception e){
1805 throw new ParseException(e.getMessage());
1806 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001807 }
1808
1809 operand = AndExpr()
1810 {
1811 op.addOperand(operand);
1812 }
1813
1814 )*
1815
1816 {
1817 return op==null? operand: op;
1818 }
1819}
1820
1821Expression AndExpr()throws ParseException:
1822{
1823 OperatorExpr op = null;
1824 Expression operand = null;
1825}
1826{
Yingyi Bu196db5d2016-07-15 19:07:20 -07001827 operand = NotExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001828 (
1829
1830 <AND>
1831 {
1832 if (op == null) {
1833 op = new OperatorExpr();
1834 op.addOperand(operand);
Yingyi Bu196db5d2016-07-15 19:07:20 -07001835 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001836 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001837 try{
1838 op.addOperator(token.image.toLowerCase());
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001839 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001840 throw new ParseException(e.getMessage());
1841 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001842 }
1843
Yingyi Bu196db5d2016-07-15 19:07:20 -07001844 operand = NotExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001845 {
1846 op.addOperand(operand);
1847 }
1848
1849 )*
1850
1851 {
1852 return op==null? operand: op;
1853 }
1854}
1855
Yingyi Bu196db5d2016-07-15 19:07:20 -07001856Expression NotExpr()throws ParseException:
1857{
1858 Expression inputExpr;
1859 boolean not = false;
1860}
1861{
1862 (<NOT> { not = true; } )? inputExpr = RelExpr()
1863 {
1864 if(not){
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001865 FunctionSignature signature = new FunctionSignature(BuiltinFunctions.NOT);
Yingyi Bu196db5d2016-07-15 19:07:20 -07001866 return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
1867 } else {
1868 return inputExpr;
1869 }
1870 }
1871}
Yingyi Bu391f09e2015-10-29 13:49:39 -07001872
1873Expression RelExpr()throws ParseException:
1874{
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001875 boolean not = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001876 OperatorExpr op = null;
1877 Expression operand = null;
1878 boolean broadcast = false;
1879 IExpressionAnnotation annotation = null;
1880}
1881{
Yingyi Bu6c638342016-09-02 17:54:34 -07001882 operand = BetweenExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001883
1884 (
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001885 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? <IN>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001886 {
1887 String mhint = getHint(token);
1888 if (mhint != null) {
1889 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001890 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1891 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1892 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
Yingyi Buea4ec722016-11-04 01:26:16 -07001893 } else if (mhint.equals(BROADCAST_JOIN_HINT)) {
1894 broadcast = true;
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001895 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001896 }
Yingyi Buea4ec722016-11-04 01:26:16 -07001897
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001898 String operator = token.image.toLowerCase();
Yingyi Bu4a4b8962016-09-16 12:09:11 -07001899 if (operator.equals("<>")){
1900 operator = "!=";
1901 }
1902 if (not) {
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001903 operator = "not_" + operator;
1904 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001905 if (op == null) {
1906 op = new OperatorExpr();
Yingyi Buea4ec722016-11-04 01:26:16 -07001907 op.addOperand(operand, false); // broadcast is always for the right branch
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001908 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001909 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001910 try{
1911 op.addOperator(operator);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001912 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001913 throw new ParseException(e.getMessage());
1914 }
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001915 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001916
Yingyi Bu6c638342016-09-02 17:54:34 -07001917 operand = BetweenExpr()
Yingyi Buea4ec722016-11-04 01:26:16 -07001918 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001919 op.addOperand(operand, broadcast);
Yingyi Buea4ec722016-11-04 01:26:16 -07001920 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001921 )?
1922
1923 {
1924 if (annotation != null) {
1925 op.addHint(annotation);
1926 }
1927 return op==null? operand: op;
1928 }
1929}
1930
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001931
Yingyi Bu6c638342016-09-02 17:54:34 -07001932Expression BetweenExpr()throws ParseException:
1933{
1934 boolean not = false;
1935 OperatorExpr op = null;
1936 Expression operand = null;
1937 IExpressionAnnotation annotation = null;
1938}
1939{
1940 operand = IsExpr()
1941 (
1942 LOOKAHEAD(2)
1943 (<NOT> { not = true; })? <BETWEEN>
1944 {
1945 String mhint = getHint(token);
1946 if (mhint != null) {
1947 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1948 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1949 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1950 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1951 }
1952 }
1953 String operator = token.image.toLowerCase();
1954 if(not){
1955 operator = "not_" + operator;
1956 }
1957 if (op == null) {
1958 op = new OperatorExpr();
1959 op.addOperand(operand);
1960 op.setCurrentop(true);
1961 }
1962 try{
1963 op.addOperator(operator);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001964 } catch (CompilationException e){
Yingyi Bu6c638342016-09-02 17:54:34 -07001965 throw new ParseException(e.getMessage());
1966 }
1967 }
1968
1969 operand = IsExpr()
1970 {
1971 op.addOperand(operand);
1972 }
1973
1974 <AND>
1975 operand = IsExpr()
1976 {
Dmitry Lychaginef1719e2017-12-15 08:33:07 -08001977 op.addOperator(OperatorType.AND);
Yingyi Bu6c638342016-09-02 17:54:34 -07001978 op.addOperand(operand);
1979 }
1980 )?
1981
1982 {
1983 if (annotation != null) {
1984 op.addHint(annotation);
1985 }
1986 return op==null? operand: op;
1987 }
1988}
1989
Yingyi Budaa549c2016-06-28 22:30:52 -07001990Expression IsExpr() throws ParseException:
1991{
1992 Expression expr = null;
1993 Expression operand = null;
1994 boolean not = false;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001995 FunctionIdentifier fn = null;
Yingyi Budaa549c2016-06-28 22:30:52 -07001996}
1997{
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001998 operand = LikeExpr()
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001999 ( <IS>
2000 (<NOT> { not = true; })?
2001 (
2002 <NULL> { fn = BuiltinFunctions.IS_NULL; } |
2003 <MISSING> { fn = BuiltinFunctions.IS_MISSING; } |
Dmitry Lychagin8b6578a2017-11-08 15:04:35 -08002004 <UNKNOWN> { fn = BuiltinFunctions.IS_UNKNOWN; }
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002005 )
Yingyi Budaa549c2016-06-28 22:30:52 -07002006 {
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002007 FunctionSignature signature = new FunctionSignature(fn);
Yingyi Budaa549c2016-06-28 22:30:52 -07002008 expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand)));
2009 if(not) {
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002010 FunctionSignature notSignature = new FunctionSignature(BuiltinFunctions.NOT);
Yingyi Budaa549c2016-06-28 22:30:52 -07002011 expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr)));
2012 }
2013 }
2014 )?
2015 {
2016 return expr = expr==null? operand : expr;
2017 }
2018}
2019
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08002020
2021Expression LikeExpr()throws ParseException:
2022{
2023 boolean not = false;
2024 OperatorExpr op = null;
2025 Expression operand = null;
2026}
2027{
2028 operand = ConcatExpr()
2029 (
2030 LOOKAHEAD(2)
2031 (<NOT> { not = true; })? <LIKE>
2032 {
2033 op = new OperatorExpr();
2034 op.addOperand(operand);
2035 op.setCurrentop(true);
2036
2037 String operator = token.image.toLowerCase();
2038 if (not) {
2039 operator = "not_" + operator;
2040 }
2041 try{
2042 op.addOperator(operator);
2043 } catch (CompilationException e){
2044 throw new ParseException(e.getMessage());
2045 }
2046 }
2047
2048 operand = ConcatExpr()
2049 {
2050 op.addOperand(operand);
2051 }
2052 )?
2053
2054 {
2055 return op == null ? operand : op;
2056 }
2057}
2058
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002059Expression ConcatExpr()throws ParseException:
2060{
2061 OperatorExpr op = null;
2062 Expression operand = null;
2063}
2064{
2065 operand = AddExpr()
2066 (
2067 LOOKAHEAD(1)
2068 (<CONCAT>)
2069 {
2070 if (op == null) {
2071 op = new OperatorExpr();
2072 op.addOperand(operand);
2073 op.setCurrentop(true);
2074 }
2075 try{
2076 ((OperatorExpr)op).addOperator(token.image);
2077 } catch (Exception e){
2078 throw new ParseException(e.getMessage());
2079 }
2080 }
2081 operand = AddExpr()
2082 {
2083 op.addOperand(operand);
2084 }
2085 )*
2086
2087 {
2088 return op==null? operand: op;
2089 }
2090}
Yingyi Budaa549c2016-06-28 22:30:52 -07002091
Yingyi Bu391f09e2015-10-29 13:49:39 -07002092Expression AddExpr()throws ParseException:
2093{
2094 OperatorExpr op = null;
2095 Expression operand = null;
2096}
2097{
2098 operand = MultExpr()
Yingyi Budaa549c2016-06-28 22:30:52 -07002099 (
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002100 LOOKAHEAD(1)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002101 (<PLUS> | <MINUS>)
2102 {
2103 if (op == null) {
2104 op = new OperatorExpr();
2105 op.addOperand(operand);
2106 op.setCurrentop(true);
2107 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07002108 try{
2109 ((OperatorExpr)op).addOperator(token.image);
2110 } catch (Exception e){
2111 throw new ParseException(e.getMessage());
2112 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002113 }
2114
2115 operand = MultExpr()
2116 {
2117 op.addOperand(operand);
2118 }
2119 )*
2120
2121 {
2122 return op==null? operand: op;
2123 }
2124}
2125
2126Expression MultExpr()throws ParseException:
2127{
2128 OperatorExpr op = null;
2129 Expression operand = null;
2130}
2131{
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002132 operand = ExponentExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07002133
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002134 (( <MUL> | <DIV> | <MOD> | <IDIV>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002135 {
2136 if (op == null) {
2137 op = new OperatorExpr();
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002138 op.addOperand(operand);
2139 op.setCurrentop(true);
2140 }
2141 try{
2142 op.addOperator(token.image);
2143 } catch (Exception e){
2144 throw new ParseException(e.getMessage());
2145 }
2146 }
2147 operand = ExponentExpr()
2148 {
2149 op.addOperand(operand);
2150 }
2151 )*
2152
2153 {
2154 return op==null?operand:op;
2155 }
2156}
2157
2158Expression ExponentExpr()throws ParseException:
2159{
2160 OperatorExpr op = null;
2161 Expression operand = null;
2162}
2163{
2164 operand = UnaryExpr()
2165 (<CARET>
2166 {
2167 if (op == null) {
2168 op = new OperatorExpr();
2169 op.addOperand(operand);
2170 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002171 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07002172 try{
2173 op.addOperator(token.image);
2174 } catch (Exception e){
2175 throw new ParseException(e.getMessage());
2176 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002177 }
2178 operand = UnaryExpr()
2179 {
2180 op.addOperand(operand);
2181 }
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002182 )?
2183 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002184 return op==null?operand:op;
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002185 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002186}
2187
2188Expression UnaryExpr() throws ParseException:
2189{
Yingyi Bu196db5d2016-07-15 19:07:20 -07002190 boolean not = false;
2191 UnaryExpr uexpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002192 Expression expr = null;
2193}
Yingyi Budaa549c2016-06-28 22:30:52 -07002194{
Yingyi Bu196db5d2016-07-15 19:07:20 -07002195 ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> )
Yingyi Bu391f09e2015-10-29 13:49:39 -07002196 {
Yingyi Bu196db5d2016-07-15 19:07:20 -07002197 String exprType = token.image.toLowerCase();
2198 if(not){
2199 exprType = "not_" + exprType;
2200 }
2201 uexpr = new UnaryExpr();
2202 try{
2203 uexpr.setExprType(exprType);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08002204 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07002205 throw new ParseException(e.getMessage());
Yingyi Budaa549c2016-06-28 22:30:52 -07002206 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002207 }
2208 )?
2209
2210 expr = ValueExpr()
2211 {
Yingyi Bu196db5d2016-07-15 19:07:20 -07002212 if(uexpr==null){
Yingyi Bu391f09e2015-10-29 13:49:39 -07002213 return expr;
Yingyi Bu196db5d2016-07-15 19:07:20 -07002214 }
2215 uexpr.setExpr(expr);
2216 return uexpr;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002217 }
2218}
2219
2220Expression ValueExpr()throws ParseException:
2221{
2222 Expression expr = null;
2223 Identifier ident = null;
2224 AbstractAccessor fa = null;
2225 Expression indexExpr = null;
2226}
2227{
2228 expr = PrimaryExpr() (
2229 ident = Field()
2230 {
2231 fa = (fa == null ? new FieldAccessor(expr, ident)
2232 : new FieldAccessor(fa, ident));
2233 }
2234 | indexExpr = Index()
2235 {
2236 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
2237 : new IndexAccessor(fa, indexExpr));
2238 }
2239 )*
2240 {
2241 return fa == null ? expr : fa;
2242 }
2243}
2244
2245Identifier Field() throws ParseException:
2246{
2247 String ident = null;
2248}
2249{
2250 <DOT> ident = Identifier()
2251 {
2252 return new Identifier(ident);
2253 }
2254}
2255
2256Expression Index() throws ParseException:
2257{
2258 Expression expr = null;
2259}
2260{
2261 <LEFTBRACKET> ( expr = Expression()
2262 {
2263 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
2264 {
2265 Literal lit = ((LiteralExpr)expr).getValue();
2266 if(lit.getLiteralType() != Literal.Type.INTEGER &&
2267 lit.getLiteralType() != Literal.Type.LONG) {
2268 throw new ParseException("Index should be an INTEGER");
2269 }
2270 }
2271 }
2272
2273 | <QUES> // ANY
2274
2275 )
2276
2277 <RIGHTBRACKET>
2278 {
2279 return expr;
2280 }
2281}
2282
2283
2284Expression PrimaryExpr()throws ParseException:
2285{
2286 Expression expr = null;
2287}
2288{
2289 ( LOOKAHEAD(4)
2290 expr = FunctionCallExpr()
2291 | expr = Literal()
2292 | expr = VariableRef()
2293 | expr = ListConstructor()
2294 | expr = RecordConstructor()
2295 | expr = ParenthesizedExpression()
2296 )
2297 {
2298 return expr;
2299 }
2300}
2301
2302Expression Literal() throws ParseException:
2303{
2304 LiteralExpr lit = new LiteralExpr();
2305 String str = null;
2306}
2307{
2308 ( str = StringLiteral()
2309 {
2310 lit.setValue(new StringLiteral(str));
2311 }
2312 | <INTEGER_LITERAL>
2313 {
Till Westmann68c6a992016-09-30 00:19:12 -07002314 try {
2315 lit.setValue(new LongIntegerLiteral(Long.valueOf(token.image)));
2316 } catch (NumberFormatException e) {
2317 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2318 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002319 }
2320 | <FLOAT_LITERAL>
2321 {
Till Westmann68c6a992016-09-30 00:19:12 -07002322 try {
2323 lit.setValue(new FloatLiteral(Float.valueOf(token.image)));
2324 } catch (NumberFormatException e) {
2325 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2326 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002327 }
2328 | <DOUBLE_LITERAL>
2329 {
Till Westmann68c6a992016-09-30 00:19:12 -07002330 try {
2331 lit.setValue(new DoubleLiteral(Double.valueOf(token.image)));
2332 } catch (NumberFormatException e) {
2333 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2334 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002335 }
Yingyi Bu535d86b2016-05-23 16:44:25 -07002336 | <MISSING>
2337 {
2338 lit.setValue(MissingLiteral.INSTANCE);
2339 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002340 | <NULL>
2341 {
2342 lit.setValue(NullLiteral.INSTANCE);
2343 }
2344 | <TRUE>
2345 {
2346 lit.setValue(TrueLiteral.INSTANCE);
2347 }
2348 | <FALSE>
2349 {
2350 lit.setValue(FalseLiteral.INSTANCE);
2351 }
2352 )
2353 {
2354 return lit;
2355 }
2356}
2357
2358
2359VariableExpr VariableRef() throws ParseException:
2360{
2361 VariableExpr varExp = new VariableExpr();
2362 VarIdentifier var = new VarIdentifier();
2363}
2364{
2365 { String id = null; }
2366 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
2367 {
Yingyi Buacc12a92016-03-26 17:25:05 -07002368 id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$"
Yingyi Bu391f09e2015-10-29 13:49:39 -07002369 Identifier ident = lookupSymbol(id);
2370 if (isInForbiddenScopes(id)) {
2371 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.");
2372 }
2373 if(ident != null) { // exist such ident
Yingyi Bu391f09e2015-10-29 13:49:39 -07002374 varExp.setVar((VarIdentifier)ident);
2375 } else {
2376 varExp.setVar(var);
Yingyi Buacc12a92016-03-26 17:25:05 -07002377 varExp.setIsNewVar(false);
2378 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002379 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002380 return varExp;
2381 }
2382}
2383
2384
2385VariableExpr Variable() throws ParseException:
2386{
2387 VariableExpr varExp = new VariableExpr();
2388 VarIdentifier var = new VarIdentifier();
2389}
2390{
2391 { String id = null; }
2392 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
2393 {
Yingyi Buacc12a92016-03-26 17:25:05 -07002394 id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$".
Yingyi Bu391f09e2015-10-29 13:49:39 -07002395 Identifier ident = lookupSymbol(id);
2396 if(ident != null) { // exist such ident
2397 varExp.setIsNewVar(false);
2398 }
2399 varExp.setVar(var);
Yingyi Bucaea8f02015-11-16 15:12:15 -08002400 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002401 return varExp;
2402 }
2403}
2404
2405Expression ListConstructor() throws ParseException:
2406{
2407 Expression expr = null;
2408}
2409{
2410 (
2411 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
2412 )
2413
2414 {
2415 return expr;
2416 }
2417}
2418
2419
2420ListConstructor OrderedListConstructor() throws ParseException:
2421{
2422 ListConstructor expr = new ListConstructor();
2423 List<Expression> exprList = null;
2424 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
2425}
2426{
2427 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
2428 {
2429 expr.setExprList(exprList);
2430 return expr;
2431 }
2432}
2433
2434ListConstructor UnorderedListConstructor() throws ParseException:
2435{
2436 ListConstructor expr = new ListConstructor();
2437 List<Expression> exprList = null;
2438 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2439}
2440{
2441 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2442 {
2443 expr.setExprList(exprList);
2444 return expr;
2445 }
2446}
2447
2448List<Expression> ExpressionList() throws ParseException:
2449{
2450 Expression expr = null;
2451 List<Expression> list = null;
2452 List<Expression> exprList = new ArrayList<Expression>();
2453}
2454{
2455 (
Till Westmann60f89982017-08-11 18:14:20 -07002456 expr = Expression()
2457 {
2458 exprList.add(expr);
2459 }
2460 ( <COMMA> expr = Expression()
2461 {
2462 exprList.add(expr);
2463 }
2464 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -07002465 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002466 {
Till Westmann60f89982017-08-11 18:14:20 -07002467 return exprList;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002468 }
2469}
2470
Yingyi Bu391f09e2015-10-29 13:49:39 -07002471RecordConstructor RecordConstructor() throws ParseException:
2472{
2473 RecordConstructor expr = new RecordConstructor();
2474 FieldBinding tmp = null;
2475 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2476}
2477{
2478 <LEFTBRACE> (tmp = FieldBinding()
2479 {
2480 fbList.add(tmp);
2481 }
2482 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2483 {
2484 expr.setFbList(fbList);
2485 return expr;
2486 }
2487}
2488
2489FieldBinding FieldBinding() throws ParseException:
2490{
2491 FieldBinding fb = new FieldBinding();
2492 Expression left, right;
2493}
2494{
2495 left = Expression() <COLON> right = Expression()
2496 {
2497 fb.setLeftExpr(left);
2498 fb.setRightExpr(right);
2499 return fb;
2500 }
2501}
2502
2503
2504Expression FunctionCallExpr() throws ParseException:
2505{
2506 CallExpr callExpr;
2507 List<Expression> argList = new ArrayList<Expression>();
Yingyi Buf4d09842016-08-26 00:03:52 -07002508 Expression tmp = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002509 int arity = 0;
2510 FunctionName funcName = null;
2511 String hint = null;
Yingyi Buf4d09842016-08-26 00:03:52 -07002512 boolean star = false;
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002513 boolean distinct = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002514}
2515{
2516 funcName = FunctionName()
2517 {
2518 hint = funcName.hint;
2519 }
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002520 <LEFTPAREN> (
2521 ( <DISTINCT> { distinct = true; } )?
2522 ( tmp = Expression() | <MUL> { star = true; } )
Yingyi Bu391f09e2015-10-29 13:49:39 -07002523 {
Yingyi Buf4d09842016-08-26 00:03:52 -07002524 if(star){
2525 if(!funcName.function.toLowerCase().equals("count")){
2526 throw new ParseException("The parameter * can only be used in COUNT().");
2527 }
2528 argList.add(new LiteralExpr(new LongIntegerLiteral(1L)));
2529 } else {
2530 argList.add(tmp);
2531 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002532 arity ++;
2533 }
2534 (<COMMA> tmp = Expression()
2535 {
2536 argList.add(tmp);
2537 arity++;
2538 }
2539 )*)? <RIGHTPAREN>
2540 {
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002541 String name = funcName.function;
2542 if (distinct) {
2543 name += "-distinct";
2544 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002545 // TODO use funcName.library
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002546 String fqFunctionName = funcName.library == null ? name : funcName.library + "#" + name;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002547 FunctionSignature signature
2548 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2549 if (signature == null) {
2550 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2551 }
Xikui Wang96fd4022017-04-10 14:23:31 -07002552 callExpr = FunctionMapUtil.normalizedListInputFunctions(new CallExpr(signature,argList));
Yingyi Bu391f09e2015-10-29 13:49:39 -07002553 if (hint != null) {
2554 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2555 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2556 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2557 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2558 }
2559 }
2560 return callExpr;
2561 }
2562}
2563
2564Expression ParenthesizedExpression() throws ParseException:
2565{
2566 Expression expr;
2567}
2568{
2569 (
2570 LOOKAHEAD(2)
2571 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2572 |
2573 expr = Subquery()
2574 )
2575 {
2576 return expr;
2577 }
2578}
2579
Yingyi Buc8c067c2016-07-25 23:37:19 -07002580
2581Expression CaseExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07002582{
Yingyi Buc8c067c2016-07-25 23:37:19 -07002583 Expression conditionExpr = new LiteralExpr(TrueLiteral.INSTANCE);
2584 List<Expression> whenExprs = new ArrayList<Expression>();
2585 List<Expression> thenExprs = new ArrayList<Expression>();
2586 Expression elseExpr = null;
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002587
Yingyi Buc8c067c2016-07-25 23:37:19 -07002588 Expression whenExpr = null;
2589 Expression thenExpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002590}
2591{
Yingyi Buc8c067c2016-07-25 23:37:19 -07002592 <CASE> ( conditionExpr = Expression() )?
2593 (
2594 <WHEN> whenExpr = Expression()
2595 {
2596 whenExprs.add(whenExpr);
2597 }
2598 <THEN> thenExpr = Expression()
2599 {
2600 thenExprs.add(thenExpr);
2601 }
2602 )*
2603 (<ELSE> elseExpr = Expression() )?
2604 <END>
2605 {
2606 return new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr);
2607 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002608}
2609
Yingyi Buab817482016-08-19 21:29:31 -07002610SelectExpression SelectExpression(boolean subquery) throws ParseException:
2611{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002612 List<LetClause> letClauses = new ArrayList<LetClause>();
2613 SelectSetOperation selectSetOperation;
2614 OrderbyClause orderbyClause = null;
2615 LimitClause limitClause = null;
2616 createNewScope();
Yingyi Buab817482016-08-19 21:29:31 -07002617}
2618{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002619 ( letClauses = LetClause() )?
2620 selectSetOperation = SelectSetOperation()
2621 (orderbyClause = OrderbyClause() {})?
2622 (limitClause = LimitClause() {})?
2623 {
2624 return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
2625 }
2626}
2627
Yingyi Buab817482016-08-19 21:29:31 -07002628SelectSetOperation SelectSetOperation() throws ParseException:
2629{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002630 SetOperationInput setOperationInputLeft;
2631 List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>();
2632}
2633{
2634 {
2635 SelectBlock selectBlockLeft = null;
2636 SelectExpression subqueryLeft = null;
2637 Expression expr = null;
2638 }
2639 selectBlockLeft = SelectBlock()
2640 {
2641 setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft);
2642 }
2643 (
2644 {
2645 SetOpType opType = SetOpType.UNION;
2646 boolean setSemantics = true;
2647 SelectBlock selectBlockRight = null;
2648 SelectExpression subqueryRight = null;
2649 }
2650 (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )?
2651 (selectBlockRight = SelectBlock()| subqueryRight = Subquery())
2652 {
2653 setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight)));
2654 }
2655 )*
2656 {
2657 return new SelectSetOperation(setOperationInputLeft, setOperationRights);
2658 }
2659}
2660
Yingyi Buab817482016-08-19 21:29:31 -07002661SelectExpression Subquery() throws ParseException:
2662{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002663 SelectExpression selectExpr = null;
2664}
2665{
2666 <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN>
2667 {
2668 return selectExpr;
2669 }
2670}
2671
Yingyi Buab817482016-08-19 21:29:31 -07002672SelectBlock SelectBlock() throws ParseException:
2673{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002674 SelectClause selectClause = null;
2675 FromClause fromClause = null;
2676 List<LetClause> fromLetClauses = null;
2677 WhereClause whereClause = null;
2678 GroupbyClause groupbyClause = null;
2679 List<LetClause> gbyLetClauses = null;
2680 HavingClause havingClause = null;
2681}
2682{
2683 (
2684 selectClause = SelectClause()
2685 (
2686 LOOKAHEAD(1)
2687 fromClause = FromClause()
2688 (
2689 LOOKAHEAD(1)
2690 fromLetClauses = LetClause()
2691 )?
2692 )?
2693 (whereClause = WhereClause())?
2694 (
2695 groupbyClause = GroupbyClause()
2696 (
2697 LOOKAHEAD(1)
2698 gbyLetClauses = LetClause()
2699 )?
2700 (havingClause = HavingClause())?
2701 )?
2702 |
2703 fromClause = FromClause()
2704 (
2705 LOOKAHEAD(1)
2706 fromLetClauses = LetClause()
2707 )?
2708 (whereClause = WhereClause())?
2709 (
2710 groupbyClause = GroupbyClause()
2711 (
2712 gbyLetClauses = LetClause()
2713 )?
2714 (havingClause = HavingClause())?
2715 )?
2716 selectClause = SelectClause()
2717 )
2718 {
2719 return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
2720 }
2721}
2722
Yingyi Buab817482016-08-19 21:29:31 -07002723SelectClause SelectClause() throws ParseException:
2724{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002725 SelectRegular selectRegular = null;
2726 SelectElement selectElement = null;
2727 boolean distinct = false;
2728}
2729{
Michael Blowd6cf6412016-06-30 02:44:35 -04002730 <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002731 (
2732 selectRegular = SelectRegular()
Michael Blowd6cf6412016-06-30 02:44:35 -04002733 |
Yingyi Bu391f09e2015-10-29 13:49:39 -07002734 selectElement = SelectElement()
Yingyi Bua89fae62016-07-06 07:58:55 -07002735 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002736 {
Yingyi Bua89fae62016-07-06 07:58:55 -07002737 if(selectRegular == null && selectElement == null){
2738 Projection projection = new Projection(null, null, true, false);
2739 List<Projection> projections = new ArrayList<Projection>();
2740 projections.add(projection);
2741 selectRegular = new SelectRegular(projections);
2742 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002743 return new SelectClause(selectElement, selectRegular, distinct);
2744 }
2745}
2746
Yingyi Buab817482016-08-19 21:29:31 -07002747SelectRegular SelectRegular() throws ParseException:
2748{
Michael Blowd6cf6412016-06-30 02:44:35 -04002749 List<Projection> projections = new ArrayList<Projection>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002750}
2751{
2752 {
2753 Projection projection = null;
2754 }
Michael Blowd6cf6412016-06-30 02:44:35 -04002755 projection = Projection() { projections.add(projection); }
Yingyi Bua89fae62016-07-06 07:58:55 -07002756 ( LOOKAHEAD(2) <COMMA>
2757 projection = Projection() {projections.add(projection);}
2758 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -07002759 {
2760 return new SelectRegular(projections);
2761 }
2762}
2763
Yingyi Buab817482016-08-19 21:29:31 -07002764SelectElement SelectElement() throws ParseException:
2765{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002766 Expression expr = null;
2767 String name = null;
2768}
2769{
2770 (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
2771 {
2772 return new SelectElement(expr);
2773 }
2774}
2775
Yingyi Buab817482016-08-19 21:29:31 -07002776Projection Projection() throws ParseException :
2777{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002778 Expression expr = null;
2779 Identifier identifier = null;
2780 String name = null;
2781 boolean star = false;
2782 boolean exprStar = false;
2783}
2784{
2785 (
2786 LOOKAHEAD(2)
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002787 expr = Expression() ((<AS>)? name = Identifier())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002788 | expr = Expression() <DOT> <MUL> {exprStar = true; }
2789 | <MUL> {star = true; }
2790 )
2791 {
Yingyi Bua89fae62016-07-06 07:58:55 -07002792 if(!star && name == null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002793 String generatedColumnIdentifier = ExpressionToVariableUtil.getGeneratedIdentifier(expr, false);
2794 if(generatedColumnIdentifier != null){
2795 name = SqlppVariableUtil.toUserDefinedName(generatedColumnIdentifier);
2796 }
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002797 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002798 return new Projection(expr, name, star, exprStar);
2799 }
2800}
2801
2802FromClause FromClause() throws ParseException :
2803{
2804 List<FromTerm> fromTerms = new ArrayList<FromTerm>();
2805 extendCurrentScope();
2806}
2807{
2808 {
2809 FromTerm fromTerm = null;
2810 }
Michael Blowd6cf6412016-06-30 02:44:35 -04002811 <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002812 (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
2813 {
2814 return new FromClause(fromTerms);
2815 }
2816}
2817
2818FromTerm FromTerm() throws ParseException :
2819{
2820 Expression leftExpr = null;
Michael Blowd6cf6412016-06-30 02:44:35 -04002821 VariableExpr leftVar = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002822 VariableExpr posVar = null;
2823 List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
2824}
2825{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002826 leftExpr = Expression() ((<AS>)? leftVar = Variable())? (<AT> posVar = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002827 (
2828 {JoinType joinType = JoinType.INNER; }
2829 (joinType = JoinType())?
2830 {
2831 AbstractBinaryCorrelateClause correlateClause = null;
2832 }
2833 (correlateClause = JoinClause(joinType)
Yingyi Bu6d999ed2016-07-13 11:59:06 -07002834 | correlateClause = UnnestClause(joinType)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002835 )
2836 {
2837 correlateClauses.add(correlateClause);
2838 }
2839 )*
2840 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002841 if(leftVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002842 leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002843 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002844 return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
2845 }
2846}
2847
2848JoinClause JoinClause(JoinType joinType) throws ParseException :
2849{
2850 Expression rightExpr = null;
2851 VariableExpr rightVar = null;
2852 VariableExpr posVar = null;
2853 Expression conditionExpr = null;
2854}
2855{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002856 <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07002857 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002858 if(rightVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002859 rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002860 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002861 return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2862 }
2863}
2864
Yingyi Bu391f09e2015-10-29 13:49:39 -07002865UnnestClause UnnestClause(JoinType joinType) throws ParseException :
2866{
2867 Expression rightExpr;
2868 VariableExpr rightVar;
2869 VariableExpr posVar = null;
2870}
2871{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002872 (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002873 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002874 if(rightVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002875 rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002876 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002877 return new UnnestClause(joinType, rightExpr, rightVar, posVar);
2878 }
2879}
2880
2881
2882JoinType JoinType() throws ParseException :
2883{
2884 JoinType joinType = JoinType.INNER;
2885}
2886{
2887 (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; })
2888 {
2889 return joinType;
2890 }
2891}
2892
2893List<LetClause> LetClause() throws ParseException:
2894{
2895 List<LetClause> letList = new ArrayList<LetClause>();
2896 LetClause letClause;
2897}
2898{
2899 (
2900 (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })*
2901 |
2902 <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })*
2903 )
2904 {
2905 return letList;
2906 }
2907}
2908
2909WhereClause WhereClause()throws ParseException :
2910{
2911 WhereClause wc = new WhereClause();
2912 Expression whereExpr;
2913}
2914{
2915 <WHERE> whereExpr = Expression()
2916 {
2917 wc.setWhereExpr(whereExpr);
2918 return wc;
2919 }
2920}
2921
2922OrderbyClause OrderbyClause()throws ParseException :
2923{
2924 OrderbyClause oc = new OrderbyClause();
2925 Expression orderbyExpr;
2926 List<Expression> orderbyList = new ArrayList<Expression>();
2927 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2928 int numOfOrderby = 0;
2929}
2930{
2931 <ORDER>
2932 {
2933 String hint = getHint(token);
2934 if (hint != null) {
2935 if (hint.startsWith(INMEMORY_HINT)) {
2936 String splits[] = hint.split(" +");
2937 int numFrames = Integer.parseInt(splits[1]);
2938 int numTuples = Integer.parseInt(splits[2]);
2939 oc.setNumFrames(numFrames);
2940 oc.setNumTuples(numTuples);
2941 }
2942 }
2943 }
2944 <BY> orderbyExpr = Expression()
2945 {
2946 orderbyList.add(orderbyExpr);
2947 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2948 }
2949 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2950 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2951 {
2952 modifierList.add(modif);
2953 }
2954
2955 (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression()
2956 {
2957 orderbyList.add(orderbyExpr);
2958 modif = OrderbyClause.OrderModifier.ASC;
2959 }
2960 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2961 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2962 {
2963 modifierList.add(modif);
2964 }
2965 )*
2966
2967 {
2968 oc.setModifierList(modifierList);
2969 oc.setOrderbyList(orderbyList);
2970 return oc;
2971 }
2972}
2973
2974GroupbyClause GroupbyClause()throws ParseException :
2975{
2976 GroupbyClause gbc = new GroupbyClause();
2977 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2978 VariableExpr var = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002979 Expression expr = null;
2980 VariableExpr decorVar = null;
2981 Expression decorExpr = null;
Yingyi Buacc12a92016-03-26 17:25:05 -07002982
2983 VariableExpr groupVar = null;
2984 List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<Pair<Expression, Identifier>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002985}
2986{
2987 {
2988 Scope newScope = extendCurrentScopeNoPush(true);
2989 // extendCurrentScope(true);
2990 }
2991 <GROUP>
2992 {
2993 String hint = getHint(token);
2994 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2995 gbc.setHashGroupByHint(true);
2996 }
2997 }
2998 <BY> (
2999 expr = Expression()
3000 (LOOKAHEAD(1) (<AS>)?
3001 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08003002 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003003 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003004 if(var==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07003005 var = ExpressionToVariableUtil.getGeneratedVariable(expr, false);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003006 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003007 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
3008 vePairList.add(pair1);
3009 }
3010 ( LOOKAHEAD(1) <COMMA>
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003011 {
3012 var = null;
3013 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003014 expr = Expression()
3015 (LOOKAHEAD(1) (<AS>)?
3016 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08003017 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003018 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003019 if(var==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07003020 var = ExpressionToVariableUtil.getGeneratedVariable(expr, false);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003021 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003022 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
3023 vePairList.add(pair2);
3024 }
3025 )*
3026 )
Yingyi Buacc12a92016-03-26 17:25:05 -07003027 (<GROUP> <AS> groupVar = Variable()
3028 ( LOOKAHEAD(1)
3029 {
3030 VariableExpr fieldVarExpr = null;
3031 String fieldIdentifierStr = null;
3032 }
3033 <LEFTPAREN>
3034 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
3035 {
3036 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
3037 }
3038 (<COMMA>
3039 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
3040 {
3041 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
3042 }
3043 )*
3044 <RIGHTPAREN>
3045 )?
3046 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003047 {
3048 gbc.setGbyPairList(vePairList);
3049 gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07003050 gbc.setWithVarMap(new HashMap<Expression, VariableExpr>());
Yingyi Buacc12a92016-03-26 17:25:05 -07003051 gbc.setGroupVar(groupVar);
3052 gbc.setGroupFieldList(groupFieldList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003053 replaceCurrentScope(newScope);
3054 return gbc;
3055 }
3056}
3057
3058HavingClause HavingClause() throws ParseException:
3059{
3060 Expression filterExpr = null;
3061}
3062{
3063 <HAVING> filterExpr = Expression()
3064 {
3065 return new HavingClause(filterExpr);
3066 }
3067}
3068
3069LimitClause LimitClause() throws ParseException:
3070{
3071 LimitClause lc = new LimitClause();
3072 Expression expr;
3073 pushForbiddenScope(getCurrentScope());
3074}
3075{
3076 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
3077 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
3078
3079 {
3080 popForbiddenScope();
3081 return lc;
3082 }
3083}
3084
3085QuantifiedExpression QuantifiedExpression()throws ParseException:
3086{
3087 QuantifiedExpression qc = new QuantifiedExpression();
3088 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
3089 Expression satisfiesExpr;
3090 VariableExpr var;
3091 Expression inExpr;
3092 QuantifiedPair pair;
3093}
3094{
3095 {
3096 createNewScope();
3097 }
3098
Yingyi Bu8aac7242016-09-13 23:14:09 -07003099 ( ((<ANY>|<SOME>) { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Michael Blowd6cf6412016-06-30 02:44:35 -04003100 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
Yingyi Bu391f09e2015-10-29 13:49:39 -07003101 var = Variable() <IN> inExpr = Expression()
3102 {
3103 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003104 quantifiedList.add(pair);
3105 }
3106 (
3107 <COMMA> var = Variable() <IN> inExpr = Expression()
3108 {
3109 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003110 quantifiedList.add(pair);
3111 }
3112 )*
Yingyi Bu858efae2016-10-13 17:31:57 -07003113 <SATISFIES> satisfiesExpr = Expression() (<END>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003114 {
3115 qc.setSatisfiesExpr(satisfiesExpr);
3116 qc.setQuantifiedList(quantifiedList);
3117 removeCurrentScope();
3118 return qc;
3119 }
3120}
3121
3122LetClause LetElement() throws ParseException:
3123{
3124 LetClause lc = new LetClause();
3125 VariableExpr varExp;
3126 Expression beExp;
3127 extendCurrentScope();
3128}
3129{
3130 varExp = Variable() <EQ> beExp = Expression()
3131 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07003132 lc.setVarExpr(varExp);
3133 lc.setBindingExpr(beExp);
3134 return lc;
3135 }
3136}
3137
3138LetClause WithElement() throws ParseException:
3139{
3140 LetClause lc = new LetClause();
3141 VariableExpr varExp;
3142 Expression beExp;
3143 extendCurrentScope();
3144}
3145{
3146 varExp = Variable() <AS> beExp = Expression()
3147 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07003148 lc.setVarExpr(varExp);
3149 lc.setBindingExpr(beExp);
3150 return lc;
3151 }
3152}
3153
3154TOKEN_MGR_DECLS:
3155{
3156 public int commentDepth = 0;
Till Westmanne9b2adf2016-10-15 12:39:01 -07003157 public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07003158
3159 public void pushState() {
3160 lexerStateStack.push( curLexState );
3161 }
3162
3163 public void popState(String token) {
3164 if (lexerStateStack.size() > 0) {
3165 SwitchTo( lexerStateStack.pop() );
3166 } else {
3167 int errorLine = input_stream.getEndLine();
3168 int errorColumn = input_stream.getEndColumn();
3169 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
3170 + "\" but state stack is empty.";
3171 throw new TokenMgrError(msg, -1);
3172 }
3173 }
3174}
3175
3176<DEFAULT,IN_DBL_BRACE>
3177TOKEN [IGNORE_CASE]:
3178{
3179 <ALL : "all">
3180 | <AND : "and">
Yingyi Bu8aac7242016-09-13 23:14:09 -07003181 | <ANY : "any">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003182 | <APPLY : "apply">
3183 | <AS : "as">
3184 | <ASC : "asc">
3185 | <AT : "at">
3186 | <AUTOGENERATED : "autogenerated">
Yingyi Bua8baf6d2016-07-05 21:40:44 -07003187 | <BETWEEN : "between">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003188 | <BTREE : "btree">
3189 | <BY : "by">
3190 | <CASE : "case">
3191 | <CLOSED : "closed">
3192 | <CREATE : "create">
3193 | <COMPACTION : "compaction">
3194 | <COMPACT : "compact">
3195 | <CONNECT : "connect">
3196 | <CORRELATE : "correlate">
Yingyi Bud56ff032016-08-01 10:26:57 -07003197 | <DATASET : "dataset">
Yingyi Bu1c0fff52016-03-25 20:23:30 -07003198 | <COLLECTION : "collection">
Yingyi Bud56ff032016-08-01 10:26:57 -07003199 | <DATAVERSE : "dataverse">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003200 | <DECLARE : "declare">
3201 | <DEFINITION : "definition">
3202 | <DELETE : "delete">
3203 | <DESC : "desc">
3204 | <DISCONNECT : "disconnect">
3205 | <DISTINCT : "distinct">
3206 | <DROP : "drop">
3207 | <ELEMENT : "element">
Till Westmann516d1a82016-08-02 14:45:53 -07003208 | <EXPLAIN : "explain">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003209 | <ELSE : "else">
3210 | <ENFORCED : "enforced">
Yingyi Buc8c067c2016-07-25 23:37:19 -07003211 | <END : "end">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003212 | <EVERY : "every">
3213 | <EXCEPT : "except">
3214 | <EXISTS : "exists">
3215 | <EXTERNAL : "external">
3216 | <FEED : "feed">
3217 | <FILTER : "filter">
3218 | <FLATTEN : "flatten">
3219 | <FOR : "for">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003220 | <FROM : "from">
3221 | <FULL : "full">
Taewoo Kimc49405a2017-01-04 00:30:43 -08003222 | <FULLTEXT : "fulltext">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003223 | <FUNCTION : "function">
3224 | <GROUP : "group">
3225 | <HAVING : "having">
3226 | <HINTS : "hints">
3227 | <IF : "if">
3228 | <INTO : "into">
3229 | <IN : "in">
3230 | <INDEX : "index">
3231 | <INGESTION : "ingestion">
3232 | <INNER : "inner">
3233 | <INSERT : "insert">
3234 | <INTERNAL : "internal">
3235 | <INTERSECT : "intersect">
Yingyi Budaa549c2016-06-28 22:30:52 -07003236 | <IS : "is">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003237 | <JOIN : "join">
3238 | <KEYWORD : "keyword">
3239 | <KEY : "key">
3240 | <LEFT : "left">
3241 | <LETTING : "letting">
3242 | <LET : "let">
Yingyi Bua8baf6d2016-07-05 21:40:44 -07003243 | <LIKE : "like">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003244 | <LIMIT : "limit">
3245 | <LOAD : "load">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003246 | <NODEGROUP : "nodegroup">
3247 | <NGRAM : "ngram">
Yingyi Budaa549c2016-06-28 22:30:52 -07003248 | <NOT : "not">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003249 | <OFFSET : "offset">
3250 | <ON : "on">
3251 | <OPEN : "open">
3252 | <OR : "or">
3253 | <ORDER : "order">
3254 | <OUTER : "outer">
3255 | <OUTPUT : "output">
3256 | <PATH : "path">
3257 | <POLICY : "policy">
3258 | <PRESORTED : "pre-sorted">
3259 | <PRIMARY : "primary">
3260 | <RAW : "raw">
3261 | <REFRESH : "refresh">
3262 | <RETURN : "return">
Yingyi Bucb5bf332017-01-02 22:19:50 -08003263 | <RETURNING : "returning">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003264 | <RTREE : "rtree">
3265 | <RUN : "run">
3266 | <SATISFIES : "satisfies">
3267 | <SECONDARY : "secondary">
3268 | <SELECT : "select">
3269 | <SET : "set">
3270 | <SOME : "some">
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08003271 | <START : "start">
3272 | <STOP : "stop">
Murtadha Hubail2c04ae02017-11-21 15:58:01 +03003273 | <TEMPORARY : "temporary"> // intentionally not used but reserved for future usage
Yingyi Bu391f09e2015-10-29 13:49:39 -07003274 | <THEN : "then">
3275 | <TYPE : "type">
3276 | <TO : "to">
3277 | <UNION : "union">
Dmitry Lychagin8b6578a2017-11-08 15:04:35 -08003278 | <UNKNOWN : "unknown">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003279 | <UNNEST : "unnest">
Yingyi Budaa549c2016-06-28 22:30:52 -07003280 | <UPDATE : "update">
Yingyi Bucb5bf332017-01-02 22:19:50 -08003281 | <UPSERT : "upsert">
Yingyi Budaa549c2016-06-28 22:30:52 -07003282 | <USE : "use">
3283 | <USING : "using">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003284 | <VALUE : "value">
3285 | <WHEN : "when">
3286 | <WHERE : "where">
3287 | <WITH : "with">
3288 | <WRITE : "write">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003289}
3290
3291<DEFAULT,IN_DBL_BRACE>
3292TOKEN :
3293{
3294 <CARET : "^">
Yingyi Bufdc71eb2016-08-24 22:41:57 -07003295 | <CONCAT : "||">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003296 | <DIV : "/">
3297 | <IDIV : "idiv">
3298 | <MINUS : "-">
3299 | <MOD : "%">
3300 | <MUL : "*">
3301 | <PLUS : "+">
3302
3303 | <LEFTPAREN : "(">
3304 | <RIGHTPAREN : ")">
3305 | <LEFTBRACKET : "[">
3306 | <RIGHTBRACKET : "]">
3307
3308 | <ATT : "@">
3309 | <COLON : ":">
3310 | <COMMA : ",">
3311 | <DOT : ".">
3312 | <QUES : "?">
3313 | <SEMICOLON : ";">
3314 | <SHARP : "#">
3315
3316 | <LT : "<">
3317 | <GT : ">">
3318 | <LE : "<=">
3319 | <GE : ">=">
3320 | <EQ : "=">
3321 | <NE : "!=">
Yingyi Bu4a4b8962016-09-16 12:09:11 -07003322 | <LG : "<>">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003323 | <SIMILAR : "~=">
3324}
3325
3326<DEFAULT,IN_DBL_BRACE>
3327TOKEN :
3328{
3329 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
3330}
3331
3332<DEFAULT>
3333TOKEN :
3334{
3335 <RIGHTBRACE : "}"> { popState("}"); }
3336}
3337
3338<DEFAULT,IN_DBL_BRACE>
3339TOKEN :
3340{
3341 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
3342}
3343
3344<IN_DBL_BRACE>
3345TOKEN :
3346{
3347 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
3348}
3349
3350<DEFAULT,IN_DBL_BRACE>
3351TOKEN :
3352{
3353 <INTEGER_LITERAL : (<DIGIT>)+ >
3354}
3355
3356<DEFAULT,IN_DBL_BRACE>
Yingyi Bue311a632016-06-07 18:23:16 -07003357TOKEN [IGNORE_CASE]:
Yingyi Bu391f09e2015-10-29 13:49:39 -07003358{
Yingyi Bu535d86b2016-05-23 16:44:25 -07003359 <MISSING : "missing">
3360 | <NULL : "null">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003361 | <TRUE : "true">
3362 | <FALSE : "false">
3363}
3364
3365<DEFAULT,IN_DBL_BRACE>
3366TOKEN :
3367{
3368 <#DIGIT : ["0" - "9"]>
3369}
3370
3371<DEFAULT,IN_DBL_BRACE>
3372TOKEN:
3373{
Yingyi Bu144453b2017-05-24 14:34:46 -07003374 < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("-")? <DIGITS>)?
3375 | <DIGITS> (("e"|"E") ("-")? <DIGITS>)
3376 | "." <DIGITS> (("e"|"E") ("-")? <DIGITS>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003377 >
Yingyi Bue4d919e2016-10-30 10:47:03 -07003378 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
3379 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
3380 | "." <DIGITS> ( "f" | "F" )
Yingyi Bu391f09e2015-10-29 13:49:39 -07003381 >
3382 | <DIGITS : (<DIGIT>)+ >
3383}
3384
3385<DEFAULT,IN_DBL_BRACE>
3386TOKEN :
3387{
3388 <#LETTER : ["A" - "Z", "a" - "z"]>
3389 | <SPECIALCHARS : ["$", "_"]>
3390}
3391
3392<DEFAULT,IN_DBL_BRACE>
3393TOKEN :
3394{
3395 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
Yingyi Bu6d57e492016-06-06 21:24:42 -07003396 <QUOTED_STRING : "`" (
Yingyi Bu391f09e2015-10-29 13:49:39 -07003397 <EscapeQuot>
3398 | <EscapeBslash>
3399 | <EscapeSlash>
3400 | <EscapeBspace>
3401 | <EscapeFormf>
3402 | <EscapeNl>
3403 | <EscapeCr>
3404 | <EscapeTab>
Yingyi Bu6d57e492016-06-06 21:24:42 -07003405 | ~["`","\\"])* "`">
3406 | <STRING_LITERAL : ("\"" (
Yingyi Bu391f09e2015-10-29 13:49:39 -07003407 <EscapeQuot>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003408 | <EscapeBslash>
3409 | <EscapeSlash>
3410 | <EscapeBspace>
3411 | <EscapeFormf>
3412 | <EscapeNl>
3413 | <EscapeCr>
3414 | <EscapeTab>
Yingyi Bu6d57e492016-06-06 21:24:42 -07003415 | ~["\"","\\"])* "\"")
3416 | ("\'"(
3417 <EscapeApos>
3418 | <EscapeBslash>
3419 | <EscapeSlash>
3420 | <EscapeBspace>
3421 | <EscapeFormf>
3422 | <EscapeNl>
3423 | <EscapeCr>
3424 | <EscapeTab>
3425 | ~["\'","\\"])* "\'")>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003426 | < #EscapeQuot: "\\\"" >
3427 | < #EscapeApos: "\\\'" >
3428 | < #EscapeBslash: "\\\\" >
3429 | < #EscapeSlash: "\\/" >
3430 | < #EscapeBspace: "\\b" >
3431 | < #EscapeFormf: "\\f" >
3432 | < #EscapeNl: "\\n" >
3433 | < #EscapeCr: "\\r" >
3434 | < #EscapeTab: "\\t" >
3435}
3436
3437<DEFAULT,IN_DBL_BRACE>
3438TOKEN :
3439{
3440 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
3441}
3442
3443<DEFAULT,IN_DBL_BRACE>
3444SKIP:
3445{
3446 " "
3447 | "\t"
3448 | "\r"
3449 | "\n"
3450}
3451
3452<DEFAULT,IN_DBL_BRACE>
3453SKIP:
3454{
3455 <"//" (~["\n"])* "\n">
3456}
3457
3458<DEFAULT,IN_DBL_BRACE>
3459SKIP:
3460{
3461 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
3462}
3463
3464<DEFAULT,IN_DBL_BRACE>
3465SKIP:
3466{
Yingyi Bu93846a72016-09-13 16:30:39 -07003467 <"--" (~["\n"])* "\n">
3468}
3469
3470
3471<DEFAULT,IN_DBL_BRACE>
3472SKIP:
3473{
3474 <"--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
3475}
3476
3477<DEFAULT,IN_DBL_BRACE>
3478SKIP:
3479{
Yingyi Bu391f09e2015-10-29 13:49:39 -07003480 <"/*"> { pushState(); } : INSIDE_COMMENT
3481}
3482
3483<INSIDE_COMMENT>
3484SPECIAL_TOKEN:
3485{
3486 <"+"(" ")*(~["*"])*>
3487}
3488
3489<INSIDE_COMMENT>
3490SKIP:
3491{
3492 <"/*"> { pushState(); }
3493}
3494
3495<INSIDE_COMMENT>
3496SKIP:
3497{
3498 <"*/"> { popState("*/"); }
3499 | <~[]>
3500}