blob: b8b7622efe1bcccc1d4ebaaa64f4327faf872a56 [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 Lychagin85142c02018-04-05 17:27:36 -070067import org.apache.asterix.common.exceptions.ErrorCode;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -080068import org.apache.asterix.common.functions.FunctionConstants;
Yingyi Bu391f09e2015-10-29 13:49:39 -070069import org.apache.asterix.common.functions.FunctionSignature;
70import org.apache.asterix.lang.common.base.Expression;
71import org.apache.asterix.lang.common.base.Literal;
72import org.apache.asterix.lang.common.base.IParser;
73import org.apache.asterix.lang.common.base.Statement;
74import org.apache.asterix.lang.common.clause.GroupbyClause;
75import org.apache.asterix.lang.common.clause.LetClause;
76import org.apache.asterix.lang.common.clause.LimitClause;
77import org.apache.asterix.lang.common.clause.OrderbyClause;
78import org.apache.asterix.lang.common.clause.UpdateClause;
79import org.apache.asterix.lang.common.clause.WhereClause;
80import org.apache.asterix.lang.common.context.RootScopeFactory;
81import org.apache.asterix.lang.common.context.Scope;
82import org.apache.asterix.lang.common.expression.AbstractAccessor;
83import org.apache.asterix.lang.common.expression.CallExpr;
84import org.apache.asterix.lang.common.expression.FieldAccessor;
85import org.apache.asterix.lang.common.expression.FieldBinding;
86import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
87import org.apache.asterix.lang.common.expression.IfExpr;
88import org.apache.asterix.lang.common.expression.IndexAccessor;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -070089import org.apache.asterix.lang.common.expression.IndexedTypeExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -070090import org.apache.asterix.lang.common.expression.ListConstructor;
91import org.apache.asterix.lang.common.expression.LiteralExpr;
92import org.apache.asterix.lang.common.expression.OperatorExpr;
93import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
94import org.apache.asterix.lang.common.expression.QuantifiedExpression;
95import org.apache.asterix.lang.common.expression.RecordConstructor;
96import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
97import org.apache.asterix.lang.common.expression.TypeExpression;
98import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
99import org.apache.asterix.lang.common.expression.UnaryExpr;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700100import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
101import org.apache.asterix.lang.common.expression.VariableExpr;
102import org.apache.asterix.lang.common.literal.DoubleLiteral;
103import org.apache.asterix.lang.common.literal.FalseLiteral;
104import org.apache.asterix.lang.common.literal.FloatLiteral;
105import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
Yingyi Bu535d86b2016-05-23 16:44:25 -0700106import org.apache.asterix.lang.common.literal.MissingLiteral;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700107import org.apache.asterix.lang.common.literal.NullLiteral;
108import org.apache.asterix.lang.common.literal.StringLiteral;
109import org.apache.asterix.lang.common.literal.TrueLiteral;
110import org.apache.asterix.lang.common.parser.ScopeChecker;
111import org.apache.asterix.lang.common.statement.CompactStatement;
112import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800113import org.apache.asterix.lang.common.statement.StartFeedStatement;
114import org.apache.asterix.lang.common.statement.StopFeedStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700115import org.apache.asterix.lang.common.statement.CreateDataverseStatement;
116import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement;
117import org.apache.asterix.lang.common.statement.CreateFeedStatement;
118import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
119import org.apache.asterix.lang.common.statement.CreateIndexStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700120import org.apache.asterix.lang.common.statement.DatasetDecl;
121import org.apache.asterix.lang.common.statement.DataverseDecl;
122import org.apache.asterix.lang.common.statement.DataverseDropStatement;
123import org.apache.asterix.lang.common.statement.DeleteStatement;
124import org.apache.asterix.lang.common.statement.DisconnectFeedStatement;
Yingyi Buab817482016-08-19 21:29:31 -0700125import org.apache.asterix.lang.common.statement.DropDatasetStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700126import org.apache.asterix.lang.common.statement.ExternalDetailsDecl;
127import org.apache.asterix.lang.common.statement.FeedDropStatement;
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300128import org.apache.asterix.lang.common.statement.FeedPolicyDropStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700129import org.apache.asterix.lang.common.statement.FunctionDecl;
130import org.apache.asterix.lang.common.statement.FunctionDropStatement;
131import org.apache.asterix.lang.common.statement.IndexDropStatement;
132import org.apache.asterix.lang.common.statement.InsertStatement;
133import org.apache.asterix.lang.common.statement.InternalDetailsDecl;
134import org.apache.asterix.lang.common.statement.LoadStatement;
135import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
136import org.apache.asterix.lang.common.statement.NodegroupDecl;
137import org.apache.asterix.lang.common.statement.Query;
138import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700139import 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;
Xikui Wangf6741682018-02-22 19:17:17 -0800161import org.apache.asterix.lang.common.clause.WhereClause;
Yingyi Buc8c067c2016-07-25 23:37:19 -0700162import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700163import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
164import org.apache.asterix.lang.sqlpp.optype.JoinType;
165import org.apache.asterix.lang.sqlpp.optype.SetOpType;
166import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
167import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
Yingyi Bu9e3f9be2016-07-01 10:07:37 -0700168import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil;
Xikui Wang96fd4022017-04-10 14:23:31 -0700169import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
Yingyi Buacc12a92016-03-26 17:25:05 -0700170import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -0800171import org.apache.asterix.om.functions.BuiltinFunctions;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700172import org.apache.hyracks.algebricks.common.utils.Pair;
173import org.apache.hyracks.algebricks.common.utils.Triple;
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800174import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700175import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
176import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
177import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
178
Yingyi Bucaea8f02015-11-16 15:12:15 -0800179class SQLPPParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700180
181 // optimizer hints
182 private static final String AUTO_HINT = "auto";
183 private static final String BROADCAST_JOIN_HINT = "bcast";
184 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
185 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
186 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
187 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
188 private static final String HASH_GROUP_BY_HINT = "hash";
189 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
190 private static final String INMEMORY_HINT = "inmem";
191 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
192 private static final String INTERVAL_HINT = "interval";
193 private static final String LIST_HINT = "list";
194 private static final String LIST_VAL_FILE_HINT = "list-val-file";
195 private static final String RANGE_HINT = "range";
196 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
197 private static final String VAL_FILE_HINT = "val-files";
198 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
199
200 private static final String GEN_FIELDS_HINT = "gen-fields";
201
202 // data generator hints
203 private static final String DGEN_HINT = "dgen";
204
Till Westmann7199a562016-09-17 16:07:32 -0700205 // error configuration
206 protected static final boolean REPORT_EXPECTED_TOKENS = false;
207
Yingyi Bu391f09e2015-10-29 13:49:39 -0700208 private static class IndexParams {
209 public IndexType type;
210 public int gramLength;
211
212 public IndexParams(IndexType type, int gramLength) {
213 this.type = type;
214 this.gramLength = gramLength;
215 }
216 };
217
218 private static class FunctionName {
219 public String dataverse = null;
220 public String library = null;
221 public String function = null;
222 public String hint = null;
223 }
224
225 private static String getHint(Token t) {
226 if (t.specialToken == null) {
227 return null;
228 }
229 String s = t.specialToken.image;
230 int n = s.length();
231 if (n < 2) {
232 return null;
233 }
234 return s.substring(1).trim();
235 }
236
237 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
238 IRecordFieldDataGen rfdg = null;
239 String splits[] = hint.split(" +");
240 if (splits[0].equals(VAL_FILE_HINT)) {
241 File[] valFiles = new File[splits.length - 1];
242 for (int k=1; k<splits.length; k++) {
243 valFiles[k-1] = new File(splits[k]);
244 }
245 rfdg = new FieldValFileDataGen(valFiles);
246 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
247 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
248 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
249 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
250 } else if (splits[0].equals(LIST_HINT)) {
251 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
252 } else if (splits[0].equals(INTERVAL_HINT)) {
253 FieldIntervalDataGen.ValueType vt;
254 if (splits[1].equals("int")) {
255 vt = FieldIntervalDataGen.ValueType.INT;
256 } else if (splits[1].equals("long")) {
257 vt = FieldIntervalDataGen.ValueType.LONG;
258 } else if (splits[1].equals("float")) {
259 vt = FieldIntervalDataGen.ValueType.FLOAT;
260 } else if (splits[1].equals("double")) {
261 vt = FieldIntervalDataGen.ValueType.DOUBLE;
262 } else {
263 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
264 }
265 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
266 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
267 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
268 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
269 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
270 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
271 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
272 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
273 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
274 } else if (splits[0].equals(AUTO_HINT)) {
275 rfdg = new AutoDataGen(splits[1]);
276 }
277 return rfdg;
278 }
279
Till Westmann7199a562016-09-17 16:07:32 -0700280 public SQLPPParser(String s) {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700281 this(new StringReader(s));
282 super.setInput(s);
283 }
284
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800285 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700286 File file = new File(args[0]);
287 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
288 SQLPPParser parser = new SQLPPParser(fis);
289 List<Statement> st = parser.parse();
290 //st.accept(new SQLPPPrintVisitor(), 0);
291 }
292
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800293 public List<Statement> parse() throws CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700294 try {
295 return Statement();
296 } catch (Error e) {
297 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
298 // 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 -0700299 final String msg = e.getClass().getSimpleName() + (e.getMessage() != null ? ": " + e.getMessage() : "");
Dmitry Lychagin85142c02018-04-05 17:27:36 -0700300 throw new CompilationException(ErrorCode.PARSE_ERROR, msg);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700301 } catch (ParseException e) {
Dmitry Lychagin85142c02018-04-05 17:27:36 -0700302 throw new CompilationException(ErrorCode.PARSE_ERROR, getMessage(e));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700303 }
304 }
Till Westmann7199a562016-09-17 16:07:32 -0700305
306 protected String getMessage(ParseException pe) {
307 Token currentToken = pe.currentToken;
308 if (currentToken == null) {
309 return pe.getMessage();
310 }
311 int[][] expectedTokenSequences = pe.expectedTokenSequences;
312 String[] tokenImage = pe.tokenImage;
313 String sep = REPORT_EXPECTED_TOKENS ? eol : " ";
314 StringBuilder expected = REPORT_EXPECTED_TOKENS ? new StringBuilder() : null;
315 int maxSize = appendExpected(expected, expectedTokenSequences, tokenImage);
316 Token tok = currentToken.next;
317 int line = tok.beginLine;
318 String message = "In line " + line + " >>" + getLine(line) + "<<" + sep + "Encountered ";
319 for (int i = 0; i < maxSize; i++) {
320 if (i != 0) {
321 message += " ";
322 }
323 if (tok.kind == 0) {
324 message += fixQuotes(tokenImage[0]);
325 break;
326 }
Till Westmanne3c9f272016-10-09 11:09:26 -0700327 final String fixedTokenImage = tokenImage[tok.kind];
328 if (! tok.image.equalsIgnoreCase(stripQuotes(fixedTokenImage))) {
329 message += fixQuotes(fixedTokenImage) + " ";
330 }
Till Westmann7199a562016-09-17 16:07:32 -0700331 message += quot + addEscapes(tok.image) + quot;
332 tok = tok.next;
333 }
334 message += " at column " + currentToken.next.beginColumn + "." + sep;
335 if (REPORT_EXPECTED_TOKENS) {
336 if (expectedTokenSequences.length == 1) {
337 message += "Was expecting:" + sep + " ";
338 } else {
339 message += "Was expecting one of:" + sep + " ";
340 }
341 message += expected.toString();
342 }
343 return message;
344 }
345
Yingyi Bu391f09e2015-10-29 13:49:39 -0700346}
347
348PARSER_END(SQLPPParser)
349
350
351List<Statement> Statement() throws ParseException:
352{
353 scopeStack.push(RootScopeFactory.createRootScope(this));
354 List<Statement> decls = new ArrayList<Statement>();
355 Statement stmt = null;
356}
357{
Murtadha Hubaildc775222017-08-21 15:22:45 +0300358 (
359 (stmt = SingleStatement()
360 {
361 decls.add(stmt);
362 }
363 )?
364 (<SEMICOLON>)+
Yingyi Bu391f09e2015-10-29 13:49:39 -0700365 )*
366 <EOF>
367 {
368 return decls;
369 }
370}
371
372Statement SingleStatement() throws ParseException:
373{
374 Statement stmt = null;
375}
376{
377 (
378 stmt = DataverseDeclaration()
379 | stmt = FunctionDeclaration()
380 | stmt = CreateStatement()
381 | stmt = LoadStatement()
382 | stmt = DropStatement()
383 | stmt = WriteStatement()
384 | stmt = SetStatement()
385 | stmt = InsertStatement()
386 | stmt = DeleteStatement()
387 | stmt = UpdateStatement()
Yingyi Bucb5bf332017-01-02 22:19:50 -0800388 | stmt = UpsertStatement()
Yingyi Buab817482016-08-19 21:29:31 -0700389 | stmt = ConnectionStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700390 | stmt = CompactStatement()
Till Westmannef3f0272016-07-27 18:34:01 -0700391 | stmt = ExplainStatement()
Murtadha Hubaildc775222017-08-21 15:22:45 +0300392 | stmt = Query(false)
Yingyi Bu391f09e2015-10-29 13:49:39 -0700393 | stmt = RefreshExternalDatasetStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700394 )
395 {
396 return stmt;
397 }
398}
399
400DataverseDecl DataverseDeclaration() throws ParseException:
401{
402 String dvName = null;
403}
404{
405 <USE> dvName = Identifier()
406 {
407 defaultDataverse = dvName;
408 return new DataverseDecl(new Identifier(dvName));
409 }
410}
411
412Statement CreateStatement() throws ParseException:
413{
414 String hint = null;
415 boolean dgen = false;
416 Statement stmt = null;
417}
418{
419 <CREATE>
420 (
421 {
422 hint = getHint(token);
423 if (hint != null && hint.startsWith(DGEN_HINT)) {
424 dgen = true;
425 }
426 }
427 stmt = TypeSpecification(hint, dgen)
428 | stmt = NodegroupSpecification()
429 | stmt = DatasetSpecification()
430 | stmt = IndexSpecification()
431 | stmt = DataverseSpecification()
432 | stmt = FunctionSpecification()
433 | stmt = FeedSpecification()
434 | stmt = FeedPolicySpecification()
435 )
436 {
437 return stmt;
438 }
439}
440
441TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
442{
443 Pair<Identifier,Identifier> nameComponents = null;
444 boolean ifNotExists = false;
445 TypeExpression typeExpr = null;
446}
447{
448 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmannf6028272016-09-30 14:34:42 -0700449 <AS> typeExpr = RecordTypeDef()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700450 {
451 long numValues = -1;
452 String filename = null;
453 if (dgen) {
454 String splits[] = hint.split(" +");
455 if (splits.length != 3) {
456 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
457 }
458 filename = splits[1];
459 numValues = Long.parseLong(splits[2]);
460 }
461 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
462 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
463 }
464}
465
466
467NodegroupDecl NodegroupSpecification() throws ParseException:
468{
469 String name = null;
470 String tmp = null;
471 boolean ifNotExists = false;
472 List<Identifier>ncNames = null;
473}
474{
475 <NODEGROUP> name = Identifier()
476 ifNotExists = IfNotExists() <ON> tmp = Identifier()
477 {
478 ncNames = new ArrayList<Identifier>();
479 ncNames.add(new Identifier(tmp));
480 }
481 ( <COMMA> tmp = Identifier()
482 {
483 ncNames.add(new Identifier(tmp));
484 }
485 )*
486 {
487 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
488 }
489}
490
491DatasetDecl DatasetSpecification() throws ParseException:
492{
493 Pair<Identifier,Identifier> nameComponents = null;
494 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800495 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700496 String adapterName = null;
497 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700498 FunctionSignature appliedFunction = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800499 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700500 String nodeGroupName = null;
501 Map<String,String> hints = new HashMap<String,String>();
502 DatasetDecl dsetDecl = null;
503 boolean autogenerated = false;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800504 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800505 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800506 RecordConstructor withRecord = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700507}
508{
509 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700510 <EXTERNAL> Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800511 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700512 ifNotExists = IfNotExists()
513 <USING> adapterName = AdapterName() properties = Configuration()
Till Westmannf3aa19f2017-12-01 17:42:35 -0800514 ( <ON> nodeGroupName = Identifier() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700515 ( <HINTS> hints = Properties() )?
Till Westmannf3aa19f2017-12-01 17:42:35 -0800516 ( <WITH> withRecord = RecordConstructor() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700517 {
518 ExternalDetailsDecl edd = new ExternalDetailsDecl();
519 edd.setAdapter(adapterName);
520 edd.setProperties(properties);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800521 try{
Yingyi Bu391f09e2015-10-29 13:49:39 -0700522 dsetDecl = new DatasetDecl(nameComponents.first,
523 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800524 typeComponents.first,
525 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800526 metaTypeComponents.first,
527 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700528 nodeGroupName != null? new Identifier(nodeGroupName): null,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700529 hints,
530 DatasetType.EXTERNAL,
531 edd,
Till Westmannf3aa19f2017-12-01 17:42:35 -0800532 withRecord,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700533 ifNotExists);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800534 } catch (CompilationException e){
535 throw new ParseException(e.getMessage());
536 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700537 }
538
Murtadha Hubail2c04ae02017-11-21 15:58:01 +0300539 | ( <INTERNAL> )?
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700540 Dataset() nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800541 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800542 (
543 { String name; }
544 <WITH>
545 name = Identifier()
546 {
547 if(!name.toLowerCase().equals("meta")){
548 throw new ParseException("We can only support one additional associated field called \"meta\".");
549 }
550 }
551 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
552 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700553 ifNotExists = IfNotExists()
554 primaryKeyFields = PrimaryKey()
555 (<AUTOGENERATED> { autogenerated = true; } )?
556 (<ON> nodeGroupName = Identifier() )?
557 ( <HINTS> hints = Properties() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700558 ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
Till Westmannf3aa19f2017-12-01 17:42:35 -0800559 ( <WITH> withRecord = RecordConstructor() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700560 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800561 if(filterField!=null && filterField.first!=0){
562 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
563 }
564 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
565 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700566 autogenerated,
Murtadha Hubail2c04ae02017-11-21 15:58:01 +0300567 filterField == null? null : filterField.second);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800568 try{
Yingyi Bu391f09e2015-10-29 13:49:39 -0700569 dsetDecl = new DatasetDecl(nameComponents.first,
570 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800571 typeComponents.first,
572 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800573 metaTypeComponents.first,
574 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700575 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700576 hints,
577 DatasetType.INTERNAL,
578 idd,
Till Westmannf3aa19f2017-12-01 17:42:35 -0800579 withRecord,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700580 ifNotExists);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800581 } catch (CompilationException e){
582 throw new ParseException(e.getMessage());
583 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700584 }
585 )
586 {
587 return dsetDecl;
588 }
589}
590
591RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
592{
593 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
594 Pair<Identifier,Identifier> nameComponents = null;
595 String datasetName = null;
596}
597{
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700598 <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700599 {
600 redss.setDataverseName(nameComponents.first);
601 redss.setDatasetName(nameComponents.second);
602 return redss;
603 }
604}
605
Yingyi Bu391f09e2015-10-29 13:49:39 -0700606CreateIndexStatement IndexSpecification() throws ParseException:
607{
608 CreateIndexStatement cis = new CreateIndexStatement();
609 String indexName = null;
610 boolean ifNotExists = false;
611 Pair<Identifier,Identifier> nameComponents = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -0700612 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700613 IndexParams indexType = null;
614 boolean enforced = false;
Ali Alsuliman8351d252017-09-24 00:43:15 -0700615 boolean isPrimaryIdx = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700616}
617{
Ali Alsuliman8351d252017-09-24 00:43:15 -0700618 (
619 (<INDEX> indexName = Identifier()
620 ifNotExists = IfNotExists()
621 <ON> nameComponents = QualifiedName()
622 <LEFTPAREN> ( fieldPair = OpenField()
623 {
624 cis.addFieldExprPair(fieldPair.second);
625 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700626 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700627 ) (<COMMA> fieldPair = OpenField()
628 {
629 cis.addFieldExprPair(fieldPair.second);
630 cis.addFieldIndexIndicator(fieldPair.first);
631 }
632 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
633 |
634 (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
635 (
636 (indexName = Identifier())? ifNotExists = IfNotExists()
637 )
638 <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
639 )
640 )
641 {
642 if (isPrimaryIdx && indexName == null) {
643 indexName = "primary_idx_" + nameComponents.second;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700644 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700645 cis.setIndexName(new Identifier(indexName));
646 cis.setIfNotExists(ifNotExists);
647 cis.setDataverseName(nameComponents.first);
648 cis.setDatasetName(nameComponents.second);
649 if (indexType != null) {
650 cis.setIndexType(indexType.type);
651 cis.setGramLength(indexType.gramLength);
652 }
653 cis.setEnforced(enforced);
654 return cis;
655 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700656}
657
658String CompactionPolicy() throws ParseException :
659{
660 String compactionPolicy = null;
661}
662{
663 compactionPolicy = Identifier()
664 {
665 return compactionPolicy;
666 }
667}
668
669String FilterField() throws ParseException :
670{
671 String filterField = null;
672}
673{
674 filterField = Identifier()
675 {
676 return filterField;
677 }
678}
679
680IndexParams IndexType() throws ParseException:
681{
682 IndexType type = null;
683 int gramLength = 0;
684}
685{
686 (<BTREE>
687 {
688 type = IndexType.BTREE;
689 }
690 | <RTREE>
691 {
692 type = IndexType.RTREE;
693 }
694 | <KEYWORD>
695 {
696 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
697 }
Taewoo Kimc49405a2017-01-04 00:30:43 -0800698 |<FULLTEXT>
699 {
700 type = IndexType.SINGLE_PARTITION_WORD_INVIX;
701 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700702 | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
703 {
704 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
705 gramLength = Integer.valueOf(token.image);
706 }
707 <RIGHTPAREN>)
708 {
709 return new IndexParams(type, gramLength);
710 }
711}
712
713CreateDataverseStatement DataverseSpecification() throws ParseException :
714{
715 String dvName = null;
716 boolean ifNotExists = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700717}
718{
719 <DATAVERSE> dvName = Identifier()
720 ifNotExists = IfNotExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700721 {
Till Westmannf6028272016-09-30 14:34:42 -0700722 return new CreateDataverseStatement(new Identifier(dvName), null, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700723 }
724}
725
726CreateFunctionStatement FunctionSpecification() throws ParseException:
727{
728 FunctionSignature signature;
729 boolean ifNotExists = false;
730 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
731 String functionBody;
732 VarIdentifier var = null;
733 Expression functionBodyExpr;
734 Token beginPos;
735 Token endPos;
736 FunctionName fctName = null;
Steven Glenn Jacobs665e9fe2017-12-27 10:30:39 -0800737 String currentDataverse = defaultDataverse;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700738
739 createNewScope();
740}
741{
742 <FUNCTION> fctName = FunctionName()
Steven Glenn Jacobs665e9fe2017-12-27 10:30:39 -0800743 {
744 defaultDataverse = fctName.dataverse;
745 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700746 ifNotExists = IfNotExists()
747 paramList = ParameterList()
748 <LEFTBRACE>
749 {
750 beginPos = token;
751 }
Xikui Wang3de700a2018-03-15 16:32:55 -0700752 (functionBodyExpr = SelectExpression(true) | functionBodyExpr = Expression())
753 <RIGHTBRACE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700754 {
755 endPos = token;
756 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
757 // TODO use fctName.library
758 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
759 getCurrentScope().addFunctionDescriptor(signature, false);
760 removeCurrentScope();
Steven Glenn Jacobs665e9fe2017-12-27 10:30:39 -0800761 defaultDataverse = currentDataverse;
762 return new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700763 }
764}
765
766CreateFeedStatement FeedSpecification() throws ParseException:
767{
768 Pair<Identifier,Identifier> nameComponents = null;
769 boolean ifNotExists = false;
770 String adapterName = null;
771 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700772 CreateFeedStatement cfs = null;
773 Pair<Identifier,Identifier> sourceNameComponents = null;
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800774 RecordConstructor withRecord = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700775}
776{
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800777 <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800778 <WITH> withRecord = RecordConstructor()
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800779 {
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800780 try {
781 cfs = new CreateFeedStatement(nameComponents, withRecord, ifNotExists);
782 return cfs;
783 } catch (AlgebricksException e) {
784 throw new ParseException(e.getMessage());
785 }
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800786 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700787}
788
789CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
790{
Michael Blowd6cf6412016-06-30 02:44:35 -0400791 String policyName = null;
792 String basePolicyName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700793 String sourcePolicyFile = null;
794 String definition = null;
795 boolean ifNotExists = false;
796 Map<String,String> properties = null;
797 CreateFeedPolicyStatement cfps = null;
798}
799{
800 (
801 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
Yingyi Bu6d57e492016-06-06 21:24:42 -0700802 <FROM>
803 (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700804 {
805 cfps = new CreateFeedPolicyStatement(policyName,
806 basePolicyName, properties, definition, ifNotExists);
807 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300808 | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700809 {
810 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
811 }
Yingyi Bu6d57e492016-06-06 21:24:42 -0700812 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700813 )
814 {
815 return cfps;
816 }
817}
818
819
820
821List<VarIdentifier> ParameterList() throws ParseException:
822{
823 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
824 VarIdentifier var = null;
825}
826{
827 <LEFTPAREN> (<IDENTIFIER>
828 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700829 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700830 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700831 }
832 (<COMMA> <IDENTIFIER>
833 {
Yingyi Buacc12a92016-03-26 17:25:05 -0700834 var = SqlppVariableUtil.toInternalVariableIdentifier(token.image);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700835 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700836 }
837 )*)? <RIGHTPAREN>
838 {
839 return paramList;
840 }
841}
842
843boolean IfNotExists() throws ParseException:
844{
845}
846{
Yingyi Budaa549c2016-06-28 22:30:52 -0700847 ( LOOKAHEAD(1) <IF> <NOT> <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700848 {
849 return true;
850 }
851 )?
852 {
853 return false;
854 }
855}
856
Xikui Wang9d63f622017-05-18 17:50:44 -0700857void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700858{
859 FunctionName functioName = null;
Xikui Wang261dc6d2017-03-29 21:23:15 -0700860 String fqFunctionName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700861}
862{
863 <APPLY> <FUNCTION> functioName = FunctionName()
864 {
Xikui Wang261dc6d2017-03-29 21:23:15 -0700865 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
866 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
867 }
868 (
869 <COMMA> functioName = FunctionName()
870 {
871 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
872 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
873 }
874 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -0700875}
876
877String GetPolicy() throws ParseException:
878{
879 String policy = null;
880}
881{
882 <USING> <POLICY> policy = Identifier()
883 {
884 return policy;
885 }
886
887}
888
889FunctionSignature FunctionSignature() throws ParseException:
890{
891 FunctionName fctName = null;
892 int arity = 0;
893}
894{
895 fctName = FunctionName() <ATT> <INTEGER_LITERAL>
896 {
897 arity = new Integer(token.image);
898 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
899 throw new ParseException(" invalid arity:" + arity);
900 }
901
902 // TODO use fctName.library
903 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
904 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
905 }
906}
907
Yingyi Buc9bfe252016-03-01 00:02:40 -0800908Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700909{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800910 Pair<Integer, List<String>> tmp = null;
911 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700912 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
913}
914{
915 <PRIMARY> <KEY> tmp = NestedField()
916 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800917 keyFieldSourceIndicators.add(tmp.first);
918 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700919 }
920 ( <COMMA> tmp = NestedField()
921 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800922 keyFieldSourceIndicators.add(tmp.first);
923 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700924 }
925 )*
926 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800927 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700928 }
929}
930
931Statement DropStatement() throws ParseException:
932{
933 String id = null;
934 Pair<Identifier,Identifier> pairId = null;
935 Triple<Identifier,Identifier,Identifier> tripleId = null;
936 FunctionSignature funcSig = null;
937 boolean ifExists = false;
938 Statement stmt = null;
939}
940{
941 <DROP>
942 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700943 Dataset() pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700944 {
Yingyi Buab817482016-08-19 21:29:31 -0700945 stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700946 }
947 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
948 {
949 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
950 }
951 | <NODEGROUP> id = Identifier() ifExists = IfExists()
952 {
953 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
954 }
955 | <TYPE> pairId = TypeName() ifExists = IfExists()
956 {
957 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
958 }
959 | <DATAVERSE> id = Identifier() ifExists = IfExists()
960 {
961 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
962 }
963 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
964 {
965 stmt = new FunctionDropStatement(funcSig, ifExists);
966 }
967 | <FEED> pairId = QualifiedName() ifExists = IfExists()
968 {
969 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
970 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300971 | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
972 {
973 stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
974 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700975 )
976 {
977 return stmt;
978 }
979}
980
981boolean IfExists() throws ParseException :
982{
983}
984{
985 ( LOOKAHEAD(1) <IF> <EXISTS>
986 {
987 return true;
988 }
989 )?
990 {
991 return false;
992 }
993}
994
995InsertStatement InsertStatement() throws ParseException:
996{
997 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800998 VariableExpr var = null;
999 Query query = null;
1000 Expression returnExpression = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001001}
1002{
Yingyi Bucb5bf332017-01-02 22:19:50 -08001003 <INSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
1004 query = Query(false)
1005 ( <RETURNING> returnExpression = Expression())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001006 {
Yingyi Bucb5bf332017-01-02 22:19:50 -08001007 if (returnExpression != null && var == null) {
1008 var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
1009 }
Yingyi Bucaea8f02015-11-16 15:12:15 -08001010 query.setTopLevel(true);
Yingyi Bucb5bf332017-01-02 22:19:50 -08001011 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1012 returnExpression);
1013 }
1014}
1015
1016UpsertStatement UpsertStatement() throws ParseException:
1017{
1018 Pair<Identifier,Identifier> nameComponents = null;
1019 VariableExpr var = null;
1020 Query query = null;
1021 Expression returnExpression = null;
1022}
1023{
1024 <UPSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
1025 query = Query(false)
1026 ( <RETURNING> returnExpression = Expression())?
1027 {
1028 if (returnExpression != null && var == null) {
1029 var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
1030 }
1031 query.setTopLevel(true);
1032 return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1033 returnExpression);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001034 }
1035}
1036
1037DeleteStatement DeleteStatement() throws ParseException:
1038{
Yingyi Bu20e085b2016-07-06 12:57:27 -07001039 VariableExpr varExpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001040 Expression condition = null;
1041 Pair<Identifier, Identifier> nameComponents;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001042}
1043{
Yingyi Bu20e085b2016-07-06 12:57:27 -07001044 <DELETE>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001045 <FROM> nameComponents = QualifiedName()
Yingyi Bu20e085b2016-07-06 12:57:27 -07001046 ((<AS>)? varExpr = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001047 (<WHERE> condition = Expression())?
Yingyi Bu20e085b2016-07-06 12:57:27 -07001048 {
Yingyi Bu20e085b2016-07-06 12:57:27 -07001049 if(varExpr == null){
1050 varExpr = new VariableExpr();
1051 VarIdentifier var = SqlppVariableUtil.toInternalVariableIdentifier(nameComponents.second.getValue());
1052 varExpr.setVar(var);
1053 }
1054 return new DeleteStatement(varExpr, nameComponents.first, nameComponents.second,
Abdullah Alamoudi6eb01752017-04-01 21:51:19 -07001055 condition, getVarCounter());
Yingyi Bu20e085b2016-07-06 12:57:27 -07001056 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001057}
1058
1059UpdateStatement UpdateStatement() throws ParseException:
1060{
1061 VariableExpr vars;
1062 Expression target;
1063 Expression condition;
1064 UpdateClause uc;
1065 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
1066}
1067{
1068 <UPDATE> vars = Variable() <IN> target = Expression()
1069 <WHERE> condition = Expression()
1070 <LEFTPAREN> (uc = UpdateClause()
1071 {
1072 ucs.add(uc);
1073 }
1074 (<COMMA> uc = UpdateClause()
1075 {
1076 ucs.add(uc);
1077 }
1078 )*) <RIGHTPAREN>
1079 {
1080 return new UpdateStatement(vars, target, condition, ucs);
1081 }
1082}
1083
1084UpdateClause UpdateClause() throws ParseException:
1085{
1086 Expression target = null;
1087 Expression value = null ;
1088 InsertStatement is = null;
1089 DeleteStatement ds = null;
1090 UpdateStatement us = null;
1091 Expression condition = null;
1092 UpdateClause ifbranch = null;
1093 UpdateClause elsebranch = null;
1094}
1095{
1096 (<SET> target = Expression() <EQ> value = Expression()
1097 | is = InsertStatement()
1098 | ds = DeleteStatement()
1099 | us = UpdateStatement()
1100 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
1101 <THEN> ifbranch = UpdateClause()
1102 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1103 {
1104 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1105 }
1106 )
1107}
1108
1109Statement SetStatement() throws ParseException:
1110{
1111 String pn = null;
1112 String pv = null;
1113}
1114{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001115 <SET> pn = Identifier() pv = ConstantString()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001116 {
1117 return new SetStatement(pn, pv);
1118 }
1119}
1120
1121Statement WriteStatement() throws ParseException:
1122{
1123 String nodeName = null;
1124 String fileName = null;
1125 Query query;
1126 String writerClass = null;
1127 Pair<Identifier,Identifier> nameComponents = null;
1128}
1129{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001130 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString()
1131 ( <USING> writerClass = ConstantString() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001132 {
1133 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1134 }
1135}
1136
1137LoadStatement LoadStatement() throws ParseException:
1138{
1139 Identifier dataverseName = null;
1140 Identifier datasetName = null;
1141 boolean alreadySorted = false;
1142 String adapterName;
1143 Map<String,String> properties;
1144 Pair<Identifier,Identifier> nameComponents = null;
1145}
1146{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001147 <LOAD> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001148 {
1149 dataverseName = nameComponents.first;
1150 datasetName = nameComponents.second;
1151 }
1152 <USING> adapterName = AdapterName() properties = Configuration()
1153 (<PRESORTED>
1154 {
1155 alreadySorted = true;
1156 }
1157 )?
1158 {
1159 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1160 }
1161}
1162
1163
1164String AdapterName() throws ParseException :
1165{
1166 String adapterName = null;
1167}
1168{
1169 adapterName = Identifier()
1170 {
1171 return adapterName;
1172 }
1173}
1174
1175Statement CompactStatement() throws ParseException:
1176{
1177 Pair<Identifier,Identifier> nameComponents = null;
1178 Statement stmt = null;
1179}
1180{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001181 <COMPACT> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001182 {
1183 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1184 }
1185 {
1186 return stmt;
1187 }
1188}
1189
Yingyi Buab817482016-08-19 21:29:31 -07001190Statement ConnectionStatement() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001191{
1192 Pair<Identifier,Identifier> feedNameComponents = null;
1193 Pair<Identifier,Identifier> datasetNameComponents = null;
1194
1195 Map<String,String> configuration = null;
1196 Statement stmt = null;
1197 String policy = null;
1198}
1199{
1200 (
Yingyi Buab817482016-08-19 21:29:31 -07001201 <CONNECT> stmt = ConnectStatement()
1202 | <DISCONNECT> stmt = DisconnectStatement()
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001203 | <START> stmt = StartStatement()
1204 | <STOP> stmt = StopStatement()
Yingyi Buab817482016-08-19 21:29:31 -07001205 )
1206 {
1207 return stmt;
1208 }
1209}
1210
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001211Statement StartStatement() throws ParseException:
1212{
1213 Pair<Identifier,Identifier> feedNameComponents = null;
1214
1215 Statement stmt = null;
1216}
1217{
1218 <FEED> feedNameComponents = QualifiedName()
1219 {
1220 stmt = new StartFeedStatement (feedNameComponents);
1221 return stmt;
1222 }
1223}
1224
1225Statement StopStatement () throws ParseException:
1226{
1227 Pair<Identifier,Identifier> feedNameComponents = null;
1228
1229 Statement stmt = null;
1230}
1231{
1232 <FEED> feedNameComponents = QualifiedName()
1233 {
1234 stmt = new StopFeedStatement (feedNameComponents);
1235 return stmt;
1236 }
1237}
1238
1239
Yingyi Buab817482016-08-19 21:29:31 -07001240Statement DisconnectStatement() throws ParseException:
1241{
1242 Pair<Identifier,Identifier> feedNameComponents = null;
1243 Pair<Identifier,Identifier> datasetNameComponents = null;
1244
1245 Map<String,String> configuration = null;
1246 Statement stmt = null;
1247 String policy = null;
1248}
1249{
1250 (
1251 <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001252 {
1253 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1254 }
1255 )
Yingyi Buab817482016-08-19 21:29:31 -07001256 {
1257 return stmt;
1258 }
1259}
1260
1261Statement ConnectStatement() throws ParseException:
1262{
1263 Pair<Identifier,Identifier> feedNameComponents = null;
1264 Pair<Identifier,Identifier> datasetNameComponents = null;
1265
1266 Map<String,String> configuration = null;
Xikui Wang9d63f622017-05-18 17:50:44 -07001267 List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
Yingyi Buab817482016-08-19 21:29:31 -07001268 Statement stmt = null;
1269 String policy = null;
Xikui Wangf6741682018-02-22 19:17:17 -08001270 String whereClauseBody = null;
1271 WhereClause whereClause = null;
1272 Token beginPos = null;
1273 Token endPos = null;
Yingyi Buab817482016-08-19 21:29:31 -07001274}
1275{
1276 (
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001277 <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName()
Xikui Wangf6741682018-02-22 19:17:17 -08001278 (ApplyFunction(appliedFunctions))?
1279 (policy = GetPolicy())?
1280 (
1281 <WHERE>
1282 {
1283 beginPos = token;
1284 whereClause = new WhereClause();
1285 Expression whereExpr;
1286 }
1287 whereExpr = Expression()
1288 {
1289 whereClause.setWhereExpr(whereExpr);
1290 }
1291 )?
1292 {
1293 if (whereClause != null) {
1294 endPos = token;
1295 whereClauseBody = extractFragment(beginPos.endLine, beginPos.endColumn, endPos.endLine, endPos.endColumn + 1);
1296 }
1297 }
Yingyi Buab817482016-08-19 21:29:31 -07001298 {
Xikui Wang261dc6d2017-03-29 21:23:15 -07001299 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions,
Xikui Wangf6741682018-02-22 19:17:17 -08001300 policy, whereClauseBody, getVarCounter());
Yingyi Buab817482016-08-19 21:29:31 -07001301 }
1302 )
1303 {
1304 return stmt;
1305 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001306}
1307
1308Map<String,String> Configuration() throws ParseException :
1309{
1310 Map<String,String> configuration = new LinkedHashMap<String,String>();
1311 Pair<String, String> keyValuePair = null;
1312}
1313{
1314 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1315 {
1316 configuration.put(keyValuePair.first, keyValuePair.second);
1317 }
1318 ( <COMMA> keyValuePair = KeyValuePair()
1319 {
1320 configuration.put(keyValuePair.first, keyValuePair.second);
1321 }
1322 )* )? <RIGHTPAREN>
1323 {
1324 return configuration;
1325 }
1326}
1327
1328Pair<String, String> KeyValuePair() throws ParseException:
1329{
1330 String key;
1331 String value;
1332}
1333{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001334 <LEFTPAREN> key = ConstantString() <EQ> value = ConstantString() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001335 {
1336 return new Pair<String, String>(key, value);
1337 }
1338}
1339
1340Map<String,String> Properties() throws ParseException:
1341{
1342 Map<String,String> properties = new HashMap<String,String>();
1343 Pair<String, String> property;
1344}
1345{
1346 (LOOKAHEAD(1) <LEFTPAREN> property = Property()
1347 {
1348 properties.put(property.first, property.second);
1349 }
1350 ( <COMMA> property = Property()
1351 {
1352 properties.put(property.first, property.second);
1353 }
1354 )* <RIGHTPAREN> )?
1355 {
1356 return properties;
1357 }
1358}
1359
1360Pair<String, String> Property() throws ParseException:
1361{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001362 String key = null;
1363 String value = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001364}
1365{
Yingyi Bu6d57e492016-06-06 21:24:42 -07001366 (key = Identifier() | key = StringLiteral())
1367 <EQ>
1368 ( value = ConstantString() | <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001369 {
1370 try {
1371 value = "" + Long.valueOf(token.image);
1372 } catch (NumberFormatException nfe) {
1373 throw new ParseException("inapproriate value: " + token.image);
1374 }
1375 }
1376 )
1377 {
1378 return new Pair<String, String>(key.toUpperCase(), value);
1379 }
1380}
1381
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001382IndexedTypeExpression IndexedTypeExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001383{
1384 TypeExpression typeExpr = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001385 boolean isUnknownable = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001386}
1387{
1388 (
1389 typeExpr = TypeReference()
1390 | typeExpr = OrderedListTypeDef()
1391 | typeExpr = UnorderedListTypeDef()
1392 )
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001393 ( <QUES> { isUnknownable = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001394 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001395 return new IndexedTypeExpression(typeExpr, isUnknownable);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001396 }
1397}
1398
1399TypeExpression TypeExpr() throws ParseException:
1400{
1401 TypeExpression typeExpr = null;
1402}
1403{
1404 (
1405 typeExpr = RecordTypeDef()
1406 | typeExpr = TypeReference()
1407 | typeExpr = OrderedListTypeDef()
1408 | typeExpr = UnorderedListTypeDef()
1409 )
1410 {
1411 return typeExpr;
1412 }
1413}
1414
1415RecordTypeDefinition RecordTypeDef() throws ParseException:
1416{
1417 RecordTypeDefinition recType = new RecordTypeDefinition();
1418 RecordTypeDefinition.RecordKind recordKind = null;
1419}
1420{
1421 ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1422 | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1423 <LEFTBRACE>
1424 {
1425 String hint = getHint(token);
1426 if (hint != null) {
1427 String splits[] = hint.split(" +");
1428 if (splits[0].equals(GEN_FIELDS_HINT)) {
1429 if (splits.length != 5) {
1430 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1431 }
1432 if (!splits[1].equals("int")) {
1433 throw new ParseException("The only supported type for gen-fields is int.");
1434 }
1435 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1436 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1437 recType.setUndeclaredFieldsDataGen(ufdg);
1438 }
1439 }
1440
1441 }
1442 (
1443 RecordField(recType)
1444 ( <COMMA> RecordField(recType) )*
1445 )?
1446 <RIGHTBRACE>
1447 {
1448 if (recordKind == null) {
1449 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1450 }
1451 recType.setRecordKind(recordKind);
1452 return recType;
1453 }
1454}
1455
1456void RecordField(RecordTypeDefinition recType) throws ParseException:
1457{
1458 String fieldName;
1459 TypeExpression type = null;
1460 boolean nullable = false;
1461}
1462{
1463 fieldName = Identifier()
1464 {
1465 String hint = getHint(token);
1466 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1467 }
1468 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1469 {
1470 recType.addField(fieldName, type, nullable, rfdg);
1471 }
1472}
1473
1474TypeReferenceExpression TypeReference() throws ParseException:
1475{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001476 Pair<Identifier,Identifier> id = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001477}
1478{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001479 id = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001480 {
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001481 if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
1482 id.second.setValue("int64");
Yingyi Bu391f09e2015-10-29 13:49:39 -07001483 }
1484
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001485 return new TypeReferenceExpression(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001486 }
1487}
1488
1489OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1490{
1491 TypeExpression type = null;
1492}
1493{
1494 <LEFTBRACKET>
1495 ( type = TypeExpr() )
1496 <RIGHTBRACKET>
1497 {
1498 return new OrderedListTypeDefinition(type);
1499 }
1500}
1501
1502
1503UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1504{
1505 TypeExpression type = null;
1506}
1507{
1508 <LEFTDBLBRACE>
1509 ( type = TypeExpr() )
1510 <RIGHTDBLBRACE>
1511 {
1512 return new UnorderedListTypeDefinition(type);
1513 }
1514}
1515
1516FunctionName FunctionName() throws ParseException:
1517{
1518 String first = null;
1519 String second = null;
1520 String third = null;
1521 boolean secondAfterDot = false;
1522}
1523{
Michael Blowd6cf6412016-06-30 02:44:35 -04001524 first = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001525 {
1526 FunctionName result = new FunctionName();
1527 result.hint = getHint(token);
Michael Blowd6cf6412016-06-30 02:44:35 -04001528 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001529 ( <DOT> second = Identifier()
1530 {
1531 secondAfterDot = true;
1532 }
1533 (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )?
1534 {
1535 if (second == null) {
1536 result.dataverse = defaultDataverse;
1537 result.library = null;
1538 result.function = first;
1539 } else if (third == null) {
1540 if (secondAfterDot) {
1541 result.dataverse = first;
1542 result.library = null;
1543 result.function = second;
1544 } else {
1545 result.dataverse = defaultDataverse;
1546 result.library = first;
1547 result.function = second;
1548 }
1549 } else {
1550 result.dataverse = first;
1551 result.library = second;
1552 result.function = third;
1553 }
1554
1555 if (result.function.equalsIgnoreCase("int")) {
1556 result.function = "int64";
1557 }
1558 return result;
1559 }
1560}
1561
1562Pair<Identifier,Identifier> TypeName() throws ParseException:
1563{
1564 Pair<Identifier,Identifier> name = null;
1565}
1566{
1567 name = QualifiedName()
1568 {
1569 if (name.first == null) {
1570 name.first = new Identifier(defaultDataverse);
1571 }
1572 return name;
1573 }
1574}
1575
1576String Identifier() throws ParseException:
1577{
1578 String lit = null;
1579}
1580{
1581 (<IDENTIFIER>
1582 {
1583 return token.image;
1584 }
1585 | lit = QuotedString()
1586 {
1587 return lit;
1588 }
1589 )
1590}
1591
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001592void Dataset() throws ParseException:
1593{
1594}
1595{
1596 (<DATASET>|<COLLECTION>)
1597}
1598
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001599Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001600{
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001601 IndexedTypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001602 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001603}
1604{
1605 fieldList = NestedField()
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001606 ( <COLON> fieldType = IndexedTypeExpr() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001607 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001608 return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
1609 (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001610 }
1611}
1612
Yingyi Buc9bfe252016-03-01 00:02:40 -08001613Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001614{
1615 List<String> exprList = new ArrayList<String>();
1616 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001617 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001618}
1619{
1620 lit = Identifier()
1621 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001622 boolean meetParens = false;
1623 }
1624 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001625 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001626 <LEFTPAREN><RIGHTPAREN>
1627 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001628 if(!lit.toLowerCase().equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001629 throw new ParseException("The string before () has to be \"meta\".");
1630 }
1631 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001632 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001633 }
1634 )?
1635 {
1636 if(!meetParens){
1637 exprList.add(lit);
1638 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001639 }
1640 (<DOT>
1641 lit = Identifier()
1642 {
1643 exprList.add(lit);
1644 }
1645 )*
1646 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001647 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001648 }
1649}
1650
Yingyi Bu6d57e492016-06-06 21:24:42 -07001651String ConstantString() throws ParseException:
1652{
1653 String value = null;
1654}
1655{
1656 (value = QuotedString() | value = StringLiteral())
1657 {
1658 return value;
1659 }
1660}
1661
Yingyi Bu391f09e2015-10-29 13:49:39 -07001662
1663String QuotedString() throws ParseException:
1664{
1665}
1666{
1667 <QUOTED_STRING>
1668 {
1669 return removeQuotesAndEscapes(token.image);
1670 }
1671}
1672
1673
1674String StringLiteral() throws ParseException:
1675{
1676}
1677{
1678 <STRING_LITERAL>
1679 {
1680 return removeQuotesAndEscapes(token.image);
1681 }
1682}
1683
1684Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1685{
1686 String first = null;
1687 String second = null;
1688}
1689{
1690 first = Identifier() (<DOT> second = Identifier())?
1691 {
1692 Identifier id1 = null;
1693 Identifier id2 = null;
1694 if (second == null) {
1695 id2 = new Identifier(first);
1696 } else
1697 {
1698 id1 = new Identifier(first);
1699 id2 = new Identifier(second);
1700 }
1701 return new Pair<Identifier,Identifier>(id1, id2);
1702 }
1703}
1704
1705Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1706{
1707 String first = null;
1708 String second = null;
1709 String third = null;
1710}
1711{
1712 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1713 {
1714 Identifier id1 = null;
1715 Identifier id2 = null;
1716 Identifier id3 = null;
1717 if (third == null) {
1718 id2 = new Identifier(first);
1719 id3 = new Identifier(second);
1720 } else {
1721 id1 = new Identifier(first);
1722 id2 = new Identifier(second);
1723 id3 = new Identifier(third);
1724 }
1725 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1726 }
1727}
1728
1729FunctionDecl FunctionDeclaration() throws ParseException:
1730{
1731 FunctionDecl funcDecl;
1732 FunctionSignature signature;
1733 String functionName;
1734 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1735 Expression funcBody;
1736 createNewScope();
1737}
1738{
Xikui Wang3de700a2018-03-15 16:32:55 -07001739 <DECLARE> <FUNCTION>
1740 functionName = Identifier()
1741 paramList = ParameterList()
1742 <LEFTBRACE>
1743 (funcBody = SelectExpression(true) | funcBody = Expression())
1744 <RIGHTBRACE>
1745 {
1746 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1747 getCurrentScope().addFunctionDescriptor(signature, false);
1748 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1749 removeCurrentScope();
1750 return funcDecl;
1751 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001752}
1753
Till Westmannef3f0272016-07-27 18:34:01 -07001754Query ExplainStatement() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001755{
Till Westmannef3f0272016-07-27 18:34:01 -07001756 Query query;
1757}
1758{
Till Westmann516d1a82016-08-02 14:45:53 -07001759 <EXPLAIN> query = Query(true)
Till Westmannef3f0272016-07-27 18:34:01 -07001760 {
1761 return query;
1762 }
1763}
1764
1765Query Query(boolean explain) throws ParseException:
1766{
1767 Query query = new Query(explain);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001768 Expression expr;
1769}
1770{
1771 (
1772 expr = Expression()
1773 |
1774 expr = SelectExpression(false)
1775 )
1776 {
1777 query.setBody(expr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001778 return query;
1779 }
1780}
1781
1782
1783
1784Expression Expression():
1785{
1786 Expression expr = null;
1787 Expression exprP = null;
1788}
1789{
1790(
1791 LOOKAHEAD(2)
1792 expr = OperatorExpr()
Yingyi Buc8c067c2016-07-25 23:37:19 -07001793 | expr = CaseExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001794 | expr = QuantifiedExpression()
1795)
1796 {
1797 return (exprP==null) ? expr : exprP;
1798 }
1799}
1800
1801
1802
1803Expression OperatorExpr()throws ParseException:
1804{
1805 OperatorExpr op = null;
1806 Expression operand = null;
1807}
1808{
1809 operand = AndExpr()
1810 (
1811
1812 <OR>
1813 {
1814 if (op == null) {
1815 op = new OperatorExpr();
1816 op.addOperand(operand);
Xikui Wang3de700a2018-03-15 16:32:55 -07001817 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001818 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001819 try{
1820 op.addOperator(token.image.toLowerCase());
1821 } catch (Exception e){
1822 throw new ParseException(e.getMessage());
1823 }
Xikui Wang3de700a2018-03-15 16:32:55 -07001824 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001825
Xikui Wang3de700a2018-03-15 16:32:55 -07001826 operand = AndExpr()
1827 {
1828 op.addOperand(operand);
1829 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001830
1831 )*
1832
1833 {
1834 return op==null? operand: op;
1835 }
1836}
1837
1838Expression AndExpr()throws ParseException:
1839{
1840 OperatorExpr op = null;
1841 Expression operand = null;
1842}
1843{
Yingyi Bu196db5d2016-07-15 19:07:20 -07001844 operand = NotExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001845 (
1846
1847 <AND>
1848 {
1849 if (op == null) {
1850 op = new OperatorExpr();
1851 op.addOperand(operand);
Yingyi Bu196db5d2016-07-15 19:07:20 -07001852 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001853 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001854 try{
1855 op.addOperator(token.image.toLowerCase());
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001856 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001857 throw new ParseException(e.getMessage());
1858 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001859 }
1860
Yingyi Bu196db5d2016-07-15 19:07:20 -07001861 operand = NotExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001862 {
1863 op.addOperand(operand);
1864 }
1865
1866 )*
1867
1868 {
1869 return op==null? operand: op;
1870 }
1871}
1872
Yingyi Bu196db5d2016-07-15 19:07:20 -07001873Expression NotExpr()throws ParseException:
1874{
1875 Expression inputExpr;
1876 boolean not = false;
1877}
1878{
1879 (<NOT> { not = true; } )? inputExpr = RelExpr()
1880 {
1881 if(not){
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08001882 FunctionSignature signature = new FunctionSignature(BuiltinFunctions.NOT);
Yingyi Bu196db5d2016-07-15 19:07:20 -07001883 return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
1884 } else {
1885 return inputExpr;
1886 }
1887 }
1888}
Yingyi Bu391f09e2015-10-29 13:49:39 -07001889
1890Expression RelExpr()throws ParseException:
1891{
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001892 boolean not = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001893 OperatorExpr op = null;
1894 Expression operand = null;
1895 boolean broadcast = false;
1896 IExpressionAnnotation annotation = null;
1897}
1898{
Yingyi Bu6c638342016-09-02 17:54:34 -07001899 operand = BetweenExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001900
1901 (
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001902 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? <IN>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001903 {
1904 String mhint = getHint(token);
1905 if (mhint != null) {
1906 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001907 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1908 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1909 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
Yingyi Buea4ec722016-11-04 01:26:16 -07001910 } else if (mhint.equals(BROADCAST_JOIN_HINT)) {
1911 broadcast = true;
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001912 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001913 }
Yingyi Buea4ec722016-11-04 01:26:16 -07001914
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001915 String operator = token.image.toLowerCase();
Yingyi Bu4a4b8962016-09-16 12:09:11 -07001916 if (operator.equals("<>")){
1917 operator = "!=";
1918 }
1919 if (not) {
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001920 operator = "not_" + operator;
1921 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001922 if (op == null) {
1923 op = new OperatorExpr();
Yingyi Buea4ec722016-11-04 01:26:16 -07001924 op.addOperand(operand, false); // broadcast is always for the right branch
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001925 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001926 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001927 try{
1928 op.addOperator(operator);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001929 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001930 throw new ParseException(e.getMessage());
1931 }
Yingyi Bua8baf6d2016-07-05 21:40:44 -07001932 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001933
Yingyi Bu6c638342016-09-02 17:54:34 -07001934 operand = BetweenExpr()
Yingyi Buea4ec722016-11-04 01:26:16 -07001935 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001936 op.addOperand(operand, broadcast);
Yingyi Buea4ec722016-11-04 01:26:16 -07001937 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001938 )?
1939
1940 {
1941 if (annotation != null) {
1942 op.addHint(annotation);
1943 }
1944 return op==null? operand: op;
1945 }
1946}
1947
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08001948
Yingyi Bu6c638342016-09-02 17:54:34 -07001949Expression BetweenExpr()throws ParseException:
1950{
1951 boolean not = false;
1952 OperatorExpr op = null;
1953 Expression operand = null;
1954 IExpressionAnnotation annotation = null;
1955}
1956{
1957 operand = IsExpr()
1958 (
1959 LOOKAHEAD(2)
1960 (<NOT> { not = true; })? <BETWEEN>
1961 {
1962 String mhint = getHint(token);
1963 if (mhint != null) {
1964 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1965 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1966 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1967 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1968 }
1969 }
1970 String operator = token.image.toLowerCase();
1971 if(not){
1972 operator = "not_" + operator;
1973 }
1974 if (op == null) {
1975 op = new OperatorExpr();
1976 op.addOperand(operand);
1977 op.setCurrentop(true);
1978 }
1979 try{
1980 op.addOperator(operator);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001981 } catch (CompilationException e){
Yingyi Bu6c638342016-09-02 17:54:34 -07001982 throw new ParseException(e.getMessage());
1983 }
1984 }
1985
1986 operand = IsExpr()
1987 {
1988 op.addOperand(operand);
1989 }
1990
1991 <AND>
1992 operand = IsExpr()
1993 {
Dmitry Lychaginef1719e2017-12-15 08:33:07 -08001994 op.addOperator(OperatorType.AND);
Yingyi Bu6c638342016-09-02 17:54:34 -07001995 op.addOperand(operand);
1996 }
1997 )?
1998
1999 {
2000 if (annotation != null) {
2001 op.addHint(annotation);
2002 }
2003 return op==null? operand: op;
2004 }
2005}
2006
Yingyi Budaa549c2016-06-28 22:30:52 -07002007Expression IsExpr() throws ParseException:
2008{
2009 Expression expr = null;
2010 Expression operand = null;
2011 boolean not = false;
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002012 FunctionIdentifier fn = null;
Yingyi Budaa549c2016-06-28 22:30:52 -07002013}
2014{
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08002015 operand = LikeExpr()
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002016 ( <IS>
2017 (<NOT> { not = true; })?
2018 (
2019 <NULL> { fn = BuiltinFunctions.IS_NULL; } |
2020 <MISSING> { fn = BuiltinFunctions.IS_MISSING; } |
Dmitry Lychagin7d594a32018-01-15 14:31:03 -08002021 <UNKNOWN> { fn = BuiltinFunctions.IS_UNKNOWN; } |
2022 <VALUED> { not = !not; fn = BuiltinFunctions.IS_UNKNOWN; }
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002023 )
Yingyi Budaa549c2016-06-28 22:30:52 -07002024 {
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002025 FunctionSignature signature = new FunctionSignature(fn);
Yingyi Budaa549c2016-06-28 22:30:52 -07002026 expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand)));
2027 if(not) {
Dmitry Lychagin7c53fcf2017-11-07 12:07:41 -08002028 FunctionSignature notSignature = new FunctionSignature(BuiltinFunctions.NOT);
Yingyi Budaa549c2016-06-28 22:30:52 -07002029 expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr)));
2030 }
2031 }
2032 )?
2033 {
2034 return expr = expr==null? operand : expr;
2035 }
2036}
2037
Yingyi Bu6e6a80c2017-01-21 20:18:49 -08002038
2039Expression LikeExpr()throws ParseException:
2040{
2041 boolean not = false;
2042 OperatorExpr op = null;
2043 Expression operand = null;
2044}
2045{
2046 operand = ConcatExpr()
2047 (
2048 LOOKAHEAD(2)
2049 (<NOT> { not = true; })? <LIKE>
2050 {
2051 op = new OperatorExpr();
2052 op.addOperand(operand);
2053 op.setCurrentop(true);
2054
2055 String operator = token.image.toLowerCase();
2056 if (not) {
2057 operator = "not_" + operator;
2058 }
2059 try{
2060 op.addOperator(operator);
2061 } catch (CompilationException e){
2062 throw new ParseException(e.getMessage());
2063 }
2064 }
2065
2066 operand = ConcatExpr()
2067 {
2068 op.addOperand(operand);
2069 }
2070 )?
2071
2072 {
2073 return op == null ? operand : op;
2074 }
2075}
2076
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002077Expression ConcatExpr()throws ParseException:
2078{
2079 OperatorExpr op = null;
2080 Expression operand = null;
2081}
2082{
2083 operand = AddExpr()
2084 (
2085 LOOKAHEAD(1)
2086 (<CONCAT>)
2087 {
2088 if (op == null) {
2089 op = new OperatorExpr();
2090 op.addOperand(operand);
2091 op.setCurrentop(true);
2092 }
2093 try{
2094 ((OperatorExpr)op).addOperator(token.image);
2095 } catch (Exception e){
2096 throw new ParseException(e.getMessage());
2097 }
2098 }
2099 operand = AddExpr()
2100 {
2101 op.addOperand(operand);
2102 }
2103 )*
2104
2105 {
2106 return op==null? operand: op;
2107 }
2108}
Yingyi Budaa549c2016-06-28 22:30:52 -07002109
Yingyi Bu391f09e2015-10-29 13:49:39 -07002110Expression AddExpr()throws ParseException:
2111{
2112 OperatorExpr op = null;
2113 Expression operand = null;
2114}
2115{
2116 operand = MultExpr()
Yingyi Budaa549c2016-06-28 22:30:52 -07002117 (
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002118 LOOKAHEAD(1)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002119 (<PLUS> | <MINUS>)
2120 {
2121 if (op == null) {
2122 op = new OperatorExpr();
2123 op.addOperand(operand);
2124 op.setCurrentop(true);
2125 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07002126 try{
2127 ((OperatorExpr)op).addOperator(token.image);
2128 } catch (Exception e){
2129 throw new ParseException(e.getMessage());
2130 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002131 }
2132
2133 operand = MultExpr()
2134 {
2135 op.addOperand(operand);
2136 }
2137 )*
2138
2139 {
2140 return op==null? operand: op;
2141 }
2142}
2143
2144Expression MultExpr()throws ParseException:
2145{
2146 OperatorExpr op = null;
2147 Expression operand = null;
2148}
2149{
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002150 operand = ExponentExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07002151
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002152 (( <MUL> | <DIV> | <MOD> | <IDIV>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002153 {
2154 if (op == null) {
2155 op = new OperatorExpr();
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002156 op.addOperand(operand);
2157 op.setCurrentop(true);
2158 }
2159 try{
2160 op.addOperator(token.image);
2161 } catch (Exception e){
2162 throw new ParseException(e.getMessage());
2163 }
2164 }
2165 operand = ExponentExpr()
2166 {
2167 op.addOperand(operand);
2168 }
2169 )*
2170
2171 {
2172 return op==null?operand:op;
2173 }
2174}
2175
2176Expression ExponentExpr()throws ParseException:
2177{
2178 OperatorExpr op = null;
2179 Expression operand = null;
2180}
2181{
2182 operand = UnaryExpr()
2183 (<CARET>
2184 {
2185 if (op == null) {
2186 op = new OperatorExpr();
2187 op.addOperand(operand);
2188 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002189 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07002190 try{
2191 op.addOperator(token.image);
2192 } catch (Exception e){
2193 throw new ParseException(e.getMessage());
2194 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002195 }
2196 operand = UnaryExpr()
2197 {
2198 op.addOperand(operand);
2199 }
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002200 )?
2201 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002202 return op==null?operand:op;
Yingyi Bu79ccdac2016-07-26 23:49:24 -07002203 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002204}
2205
2206Expression UnaryExpr() throws ParseException:
2207{
Yingyi Bu196db5d2016-07-15 19:07:20 -07002208 boolean not = false;
2209 UnaryExpr uexpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002210 Expression expr = null;
2211}
Yingyi Budaa549c2016-06-28 22:30:52 -07002212{
Yingyi Bu196db5d2016-07-15 19:07:20 -07002213 ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> )
Yingyi Bu391f09e2015-10-29 13:49:39 -07002214 {
Yingyi Bu196db5d2016-07-15 19:07:20 -07002215 String exprType = token.image.toLowerCase();
2216 if(not){
2217 exprType = "not_" + exprType;
2218 }
2219 uexpr = new UnaryExpr();
2220 try{
2221 uexpr.setExprType(exprType);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08002222 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07002223 throw new ParseException(e.getMessage());
Yingyi Budaa549c2016-06-28 22:30:52 -07002224 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002225 }
2226 )?
2227
2228 expr = ValueExpr()
2229 {
Yingyi Bu196db5d2016-07-15 19:07:20 -07002230 if(uexpr==null){
Yingyi Bu391f09e2015-10-29 13:49:39 -07002231 return expr;
Yingyi Bu196db5d2016-07-15 19:07:20 -07002232 }
2233 uexpr.setExpr(expr);
2234 return uexpr;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002235 }
2236}
2237
2238Expression ValueExpr()throws ParseException:
2239{
2240 Expression expr = null;
2241 Identifier ident = null;
2242 AbstractAccessor fa = null;
2243 Expression indexExpr = null;
2244}
2245{
2246 expr = PrimaryExpr() (
2247 ident = Field()
2248 {
2249 fa = (fa == null ? new FieldAccessor(expr, ident)
2250 : new FieldAccessor(fa, ident));
2251 }
2252 | indexExpr = Index()
2253 {
2254 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
2255 : new IndexAccessor(fa, indexExpr));
2256 }
2257 )*
2258 {
2259 return fa == null ? expr : fa;
2260 }
2261}
2262
2263Identifier Field() throws ParseException:
2264{
2265 String ident = null;
2266}
2267{
2268 <DOT> ident = Identifier()
2269 {
2270 return new Identifier(ident);
2271 }
2272}
2273
2274Expression Index() throws ParseException:
2275{
2276 Expression expr = null;
2277}
2278{
2279 <LEFTBRACKET> ( expr = Expression()
2280 {
2281 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
2282 {
2283 Literal lit = ((LiteralExpr)expr).getValue();
2284 if(lit.getLiteralType() != Literal.Type.INTEGER &&
2285 lit.getLiteralType() != Literal.Type.LONG) {
2286 throw new ParseException("Index should be an INTEGER");
2287 }
2288 }
2289 }
2290
2291 | <QUES> // ANY
2292
2293 )
2294
2295 <RIGHTBRACKET>
2296 {
2297 return expr;
2298 }
2299}
2300
2301
2302Expression PrimaryExpr()throws ParseException:
2303{
2304 Expression expr = null;
2305}
2306{
2307 ( LOOKAHEAD(4)
2308 expr = FunctionCallExpr()
2309 | expr = Literal()
2310 | expr = VariableRef()
2311 | expr = ListConstructor()
2312 | expr = RecordConstructor()
2313 | expr = ParenthesizedExpression()
2314 )
2315 {
2316 return expr;
2317 }
2318}
2319
2320Expression Literal() throws ParseException:
2321{
2322 LiteralExpr lit = new LiteralExpr();
2323 String str = null;
2324}
2325{
2326 ( str = StringLiteral()
2327 {
2328 lit.setValue(new StringLiteral(str));
2329 }
2330 | <INTEGER_LITERAL>
2331 {
Till Westmann68c6a992016-09-30 00:19:12 -07002332 try {
2333 lit.setValue(new LongIntegerLiteral(Long.valueOf(token.image)));
2334 } catch (NumberFormatException e) {
2335 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2336 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002337 }
2338 | <FLOAT_LITERAL>
2339 {
Till Westmann68c6a992016-09-30 00:19:12 -07002340 try {
2341 lit.setValue(new FloatLiteral(Float.valueOf(token.image)));
2342 } catch (NumberFormatException e) {
2343 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2344 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002345 }
2346 | <DOUBLE_LITERAL>
2347 {
Till Westmann68c6a992016-09-30 00:19:12 -07002348 try {
2349 lit.setValue(new DoubleLiteral(Double.valueOf(token.image)));
2350 } catch (NumberFormatException e) {
2351 throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
2352 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002353 }
Yingyi Bu535d86b2016-05-23 16:44:25 -07002354 | <MISSING>
2355 {
2356 lit.setValue(MissingLiteral.INSTANCE);
2357 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002358 | <NULL>
2359 {
2360 lit.setValue(NullLiteral.INSTANCE);
2361 }
2362 | <TRUE>
2363 {
2364 lit.setValue(TrueLiteral.INSTANCE);
2365 }
2366 | <FALSE>
2367 {
2368 lit.setValue(FalseLiteral.INSTANCE);
2369 }
2370 )
2371 {
2372 return lit;
2373 }
2374}
2375
2376
2377VariableExpr VariableRef() throws ParseException:
2378{
2379 VariableExpr varExp = new VariableExpr();
2380 VarIdentifier var = new VarIdentifier();
2381}
2382{
2383 { String id = null; }
2384 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
2385 {
Yingyi Buacc12a92016-03-26 17:25:05 -07002386 id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$"
Yingyi Bu391f09e2015-10-29 13:49:39 -07002387 Identifier ident = lookupSymbol(id);
2388 if (isInForbiddenScopes(id)) {
2389 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.");
2390 }
2391 if(ident != null) { // exist such ident
Yingyi Bu391f09e2015-10-29 13:49:39 -07002392 varExp.setVar((VarIdentifier)ident);
2393 } else {
2394 varExp.setVar(var);
Yingyi Buacc12a92016-03-26 17:25:05 -07002395 varExp.setIsNewVar(false);
2396 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002397 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002398 return varExp;
2399 }
2400}
2401
2402
2403VariableExpr Variable() throws ParseException:
2404{
2405 VariableExpr varExp = new VariableExpr();
2406 VarIdentifier var = new VarIdentifier();
2407}
2408{
2409 { String id = null; }
2410 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
2411 {
Yingyi Buacc12a92016-03-26 17:25:05 -07002412 id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$".
Yingyi Bu391f09e2015-10-29 13:49:39 -07002413 Identifier ident = lookupSymbol(id);
2414 if(ident != null) { // exist such ident
2415 varExp.setIsNewVar(false);
2416 }
2417 varExp.setVar(var);
Yingyi Bucaea8f02015-11-16 15:12:15 -08002418 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002419 return varExp;
2420 }
2421}
2422
2423Expression ListConstructor() throws ParseException:
2424{
2425 Expression expr = null;
2426}
2427{
2428 (
2429 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
2430 )
2431
2432 {
2433 return expr;
2434 }
2435}
2436
2437
2438ListConstructor OrderedListConstructor() throws ParseException:
2439{
2440 ListConstructor expr = new ListConstructor();
2441 List<Expression> exprList = null;
2442 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
2443}
2444{
2445 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
2446 {
2447 expr.setExprList(exprList);
2448 return expr;
2449 }
2450}
2451
2452ListConstructor UnorderedListConstructor() throws ParseException:
2453{
2454 ListConstructor expr = new ListConstructor();
2455 List<Expression> exprList = null;
2456 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2457}
2458{
2459 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2460 {
2461 expr.setExprList(exprList);
2462 return expr;
2463 }
2464}
2465
2466List<Expression> ExpressionList() throws ParseException:
2467{
2468 Expression expr = null;
2469 List<Expression> list = null;
2470 List<Expression> exprList = new ArrayList<Expression>();
2471}
2472{
2473 (
Till Westmann60f89982017-08-11 18:14:20 -07002474 expr = Expression()
2475 {
2476 exprList.add(expr);
2477 }
2478 ( <COMMA> expr = Expression()
2479 {
2480 exprList.add(expr);
2481 }
2482 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -07002483 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002484 {
Till Westmann60f89982017-08-11 18:14:20 -07002485 return exprList;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002486 }
2487}
2488
Yingyi Bu391f09e2015-10-29 13:49:39 -07002489RecordConstructor RecordConstructor() throws ParseException:
2490{
2491 RecordConstructor expr = new RecordConstructor();
2492 FieldBinding tmp = null;
2493 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2494}
2495{
2496 <LEFTBRACE> (tmp = FieldBinding()
2497 {
2498 fbList.add(tmp);
2499 }
2500 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2501 {
2502 expr.setFbList(fbList);
2503 return expr;
2504 }
2505}
2506
2507FieldBinding FieldBinding() throws ParseException:
2508{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002509 Expression left, right;
2510}
2511{
2512 left = Expression() <COLON> right = Expression()
2513 {
Dmitry Lychagin5cdaa5d2018-02-21 11:11:26 -08002514 return new FieldBinding(left, right);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002515 }
2516}
2517
2518
2519Expression FunctionCallExpr() throws ParseException:
2520{
2521 CallExpr callExpr;
2522 List<Expression> argList = new ArrayList<Expression>();
Yingyi Buf4d09842016-08-26 00:03:52 -07002523 Expression tmp = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002524 int arity = 0;
2525 FunctionName funcName = null;
2526 String hint = null;
Yingyi Buf4d09842016-08-26 00:03:52 -07002527 boolean star = false;
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002528 boolean distinct = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002529}
2530{
2531 funcName = FunctionName()
2532 {
2533 hint = funcName.hint;
2534 }
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002535 <LEFTPAREN> (
2536 ( <DISTINCT> { distinct = true; } )?
2537 ( tmp = Expression() | <MUL> { star = true; } )
Yingyi Bu391f09e2015-10-29 13:49:39 -07002538 {
Yingyi Buf4d09842016-08-26 00:03:52 -07002539 if(star){
2540 if(!funcName.function.toLowerCase().equals("count")){
2541 throw new ParseException("The parameter * can only be used in COUNT().");
2542 }
2543 argList.add(new LiteralExpr(new LongIntegerLiteral(1L)));
2544 } else {
2545 argList.add(tmp);
2546 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002547 arity ++;
2548 }
2549 (<COMMA> tmp = Expression()
2550 {
2551 argList.add(tmp);
2552 arity++;
2553 }
2554 )*)? <RIGHTPAREN>
2555 {
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002556 String name = funcName.function;
2557 if (distinct) {
2558 name += "-distinct";
2559 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002560 // TODO use funcName.library
Dmitry Lychagin7a4b5682017-09-11 18:53:07 -07002561 String fqFunctionName = funcName.library == null ? name : funcName.library + "#" + name;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002562 FunctionSignature signature
2563 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2564 if (signature == null) {
2565 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2566 }
Xikui Wang96fd4022017-04-10 14:23:31 -07002567 callExpr = FunctionMapUtil.normalizedListInputFunctions(new CallExpr(signature,argList));
Yingyi Bu391f09e2015-10-29 13:49:39 -07002568 if (hint != null) {
2569 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2570 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2571 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2572 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2573 }
2574 }
2575 return callExpr;
2576 }
2577}
2578
2579Expression ParenthesizedExpression() throws ParseException:
2580{
2581 Expression expr;
2582}
2583{
2584 (
2585 LOOKAHEAD(2)
2586 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2587 |
2588 expr = Subquery()
2589 )
2590 {
2591 return expr;
2592 }
2593}
2594
Yingyi Buc8c067c2016-07-25 23:37:19 -07002595
2596Expression CaseExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07002597{
Yingyi Buc8c067c2016-07-25 23:37:19 -07002598 Expression conditionExpr = new LiteralExpr(TrueLiteral.INSTANCE);
2599 List<Expression> whenExprs = new ArrayList<Expression>();
2600 List<Expression> thenExprs = new ArrayList<Expression>();
2601 Expression elseExpr = null;
Yingyi Bufdc71eb2016-08-24 22:41:57 -07002602
Yingyi Buc8c067c2016-07-25 23:37:19 -07002603 Expression whenExpr = null;
2604 Expression thenExpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002605}
2606{
Yingyi Buc8c067c2016-07-25 23:37:19 -07002607 <CASE> ( conditionExpr = Expression() )?
2608 (
2609 <WHEN> whenExpr = Expression()
2610 {
2611 whenExprs.add(whenExpr);
2612 }
2613 <THEN> thenExpr = Expression()
2614 {
2615 thenExprs.add(thenExpr);
2616 }
2617 )*
2618 (<ELSE> elseExpr = Expression() )?
2619 <END>
2620 {
2621 return new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr);
2622 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002623}
2624
Yingyi Buab817482016-08-19 21:29:31 -07002625SelectExpression SelectExpression(boolean subquery) throws ParseException:
2626{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002627 List<LetClause> letClauses = new ArrayList<LetClause>();
2628 SelectSetOperation selectSetOperation;
2629 OrderbyClause orderbyClause = null;
2630 LimitClause limitClause = null;
2631 createNewScope();
Yingyi Buab817482016-08-19 21:29:31 -07002632}
2633{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002634 ( letClauses = LetClause() )?
2635 selectSetOperation = SelectSetOperation()
2636 (orderbyClause = OrderbyClause() {})?
2637 (limitClause = LimitClause() {})?
2638 {
2639 return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
2640 }
2641}
2642
Yingyi Buab817482016-08-19 21:29:31 -07002643SelectSetOperation SelectSetOperation() throws ParseException:
2644{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002645 SetOperationInput setOperationInputLeft;
2646 List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>();
2647}
2648{
2649 {
2650 SelectBlock selectBlockLeft = null;
2651 SelectExpression subqueryLeft = null;
2652 Expression expr = null;
2653 }
2654 selectBlockLeft = SelectBlock()
2655 {
2656 setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft);
2657 }
2658 (
2659 {
2660 SetOpType opType = SetOpType.UNION;
2661 boolean setSemantics = true;
2662 SelectBlock selectBlockRight = null;
2663 SelectExpression subqueryRight = null;
2664 }
2665 (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )?
2666 (selectBlockRight = SelectBlock()| subqueryRight = Subquery())
2667 {
2668 setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight)));
2669 }
2670 )*
2671 {
2672 return new SelectSetOperation(setOperationInputLeft, setOperationRights);
2673 }
2674}
2675
Yingyi Buab817482016-08-19 21:29:31 -07002676SelectExpression Subquery() throws ParseException:
2677{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002678 SelectExpression selectExpr = null;
2679}
2680{
2681 <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN>
2682 {
2683 return selectExpr;
2684 }
2685}
2686
Yingyi Buab817482016-08-19 21:29:31 -07002687SelectBlock SelectBlock() throws ParseException:
2688{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002689 SelectClause selectClause = null;
2690 FromClause fromClause = null;
2691 List<LetClause> fromLetClauses = null;
2692 WhereClause whereClause = null;
2693 GroupbyClause groupbyClause = null;
2694 List<LetClause> gbyLetClauses = null;
2695 HavingClause havingClause = null;
2696}
2697{
2698 (
2699 selectClause = SelectClause()
2700 (
2701 LOOKAHEAD(1)
2702 fromClause = FromClause()
2703 (
2704 LOOKAHEAD(1)
2705 fromLetClauses = LetClause()
2706 )?
2707 )?
2708 (whereClause = WhereClause())?
2709 (
2710 groupbyClause = GroupbyClause()
2711 (
2712 LOOKAHEAD(1)
2713 gbyLetClauses = LetClause()
2714 )?
2715 (havingClause = HavingClause())?
2716 )?
2717 |
2718 fromClause = FromClause()
2719 (
2720 LOOKAHEAD(1)
2721 fromLetClauses = LetClause()
2722 )?
2723 (whereClause = WhereClause())?
2724 (
2725 groupbyClause = GroupbyClause()
2726 (
2727 gbyLetClauses = LetClause()
2728 )?
2729 (havingClause = HavingClause())?
2730 )?
2731 selectClause = SelectClause()
2732 )
2733 {
2734 return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
2735 }
2736}
2737
Yingyi Buab817482016-08-19 21:29:31 -07002738SelectClause SelectClause() throws ParseException:
2739{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002740 SelectRegular selectRegular = null;
2741 SelectElement selectElement = null;
2742 boolean distinct = false;
2743}
2744{
Michael Blowd6cf6412016-06-30 02:44:35 -04002745 <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002746 (
2747 selectRegular = SelectRegular()
Michael Blowd6cf6412016-06-30 02:44:35 -04002748 |
Yingyi Bu391f09e2015-10-29 13:49:39 -07002749 selectElement = SelectElement()
Yingyi Bua89fae62016-07-06 07:58:55 -07002750 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002751 {
Yingyi Bua89fae62016-07-06 07:58:55 -07002752 if(selectRegular == null && selectElement == null){
2753 Projection projection = new Projection(null, null, true, false);
2754 List<Projection> projections = new ArrayList<Projection>();
2755 projections.add(projection);
2756 selectRegular = new SelectRegular(projections);
2757 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002758 return new SelectClause(selectElement, selectRegular, distinct);
2759 }
2760}
2761
Yingyi Buab817482016-08-19 21:29:31 -07002762SelectRegular SelectRegular() throws ParseException:
2763{
Michael Blowd6cf6412016-06-30 02:44:35 -04002764 List<Projection> projections = new ArrayList<Projection>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002765}
2766{
2767 {
2768 Projection projection = null;
2769 }
Michael Blowd6cf6412016-06-30 02:44:35 -04002770 projection = Projection() { projections.add(projection); }
Yingyi Bua89fae62016-07-06 07:58:55 -07002771 ( LOOKAHEAD(2) <COMMA>
2772 projection = Projection() {projections.add(projection);}
2773 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -07002774 {
2775 return new SelectRegular(projections);
2776 }
2777}
2778
Yingyi Buab817482016-08-19 21:29:31 -07002779SelectElement SelectElement() throws ParseException:
2780{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002781 Expression expr = null;
2782 String name = null;
2783}
2784{
2785 (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
2786 {
2787 return new SelectElement(expr);
2788 }
2789}
2790
Yingyi Buab817482016-08-19 21:29:31 -07002791Projection Projection() throws ParseException :
2792{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002793 Expression expr = null;
2794 Identifier identifier = null;
2795 String name = null;
2796 boolean star = false;
Dmitry Lychagin5cdaa5d2018-02-21 11:11:26 -08002797 boolean varStar = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002798}
2799{
2800 (
Dmitry Lychagin5cdaa5d2018-02-21 11:11:26 -08002801 <MUL> {star = true; }
2802 | LOOKAHEAD(3) expr = VariableRef() <DOT> <MUL> {varStar = true; }
2803 | expr = Expression() ((<AS>)? name = Identifier())?
2804 {
2805 if (name == null) {
2806 String generatedColumnIdentifier = ExpressionToVariableUtil.getGeneratedIdentifier(expr, false);
2807 if (generatedColumnIdentifier != null) {
2808 name = SqlppVariableUtil.toUserDefinedName(generatedColumnIdentifier);
2809 }
2810 }
2811 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002812 )
2813 {
Dmitry Lychagin5cdaa5d2018-02-21 11:11:26 -08002814 return new Projection(expr, name, star, varStar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002815 }
2816}
2817
2818FromClause FromClause() throws ParseException :
2819{
2820 List<FromTerm> fromTerms = new ArrayList<FromTerm>();
2821 extendCurrentScope();
2822}
2823{
2824 {
2825 FromTerm fromTerm = null;
2826 }
Michael Blowd6cf6412016-06-30 02:44:35 -04002827 <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002828 (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
2829 {
2830 return new FromClause(fromTerms);
2831 }
2832}
2833
2834FromTerm FromTerm() throws ParseException :
2835{
2836 Expression leftExpr = null;
Michael Blowd6cf6412016-06-30 02:44:35 -04002837 VariableExpr leftVar = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002838 VariableExpr posVar = null;
2839 List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
2840}
2841{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002842 leftExpr = Expression() ((<AS>)? leftVar = Variable())? (<AT> posVar = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002843 (
2844 {JoinType joinType = JoinType.INNER; }
2845 (joinType = JoinType())?
2846 {
2847 AbstractBinaryCorrelateClause correlateClause = null;
2848 }
2849 (correlateClause = JoinClause(joinType)
Yingyi Bu6d999ed2016-07-13 11:59:06 -07002850 | correlateClause = UnnestClause(joinType)
Yingyi Bu391f09e2015-10-29 13:49:39 -07002851 )
2852 {
2853 correlateClauses.add(correlateClause);
2854 }
2855 )*
2856 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002857 if(leftVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002858 leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002859 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002860 return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
2861 }
2862}
2863
2864JoinClause JoinClause(JoinType joinType) throws ParseException :
2865{
2866 Expression rightExpr = null;
2867 VariableExpr rightVar = null;
2868 VariableExpr posVar = null;
2869 Expression conditionExpr = null;
2870}
2871{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002872 <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
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 JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2878 }
2879}
2880
Yingyi Bu391f09e2015-10-29 13:49:39 -07002881UnnestClause UnnestClause(JoinType joinType) throws ParseException :
2882{
2883 Expression rightExpr;
2884 VariableExpr rightVar;
2885 VariableExpr posVar = null;
2886}
2887{
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002888 (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002889 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002890 if(rightVar==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07002891 rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07002892 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002893 return new UnnestClause(joinType, rightExpr, rightVar, posVar);
2894 }
2895}
2896
2897
2898JoinType JoinType() throws ParseException :
2899{
2900 JoinType joinType = JoinType.INNER;
2901}
2902{
2903 (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; })
2904 {
2905 return joinType;
2906 }
2907}
2908
2909List<LetClause> LetClause() throws ParseException:
2910{
2911 List<LetClause> letList = new ArrayList<LetClause>();
2912 LetClause letClause;
2913}
2914{
2915 (
2916 (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })*
2917 |
2918 <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })*
2919 )
2920 {
2921 return letList;
2922 }
2923}
2924
2925WhereClause WhereClause()throws ParseException :
2926{
2927 WhereClause wc = new WhereClause();
2928 Expression whereExpr;
2929}
2930{
2931 <WHERE> whereExpr = Expression()
2932 {
2933 wc.setWhereExpr(whereExpr);
2934 return wc;
2935 }
2936}
2937
2938OrderbyClause OrderbyClause()throws ParseException :
2939{
2940 OrderbyClause oc = new OrderbyClause();
2941 Expression orderbyExpr;
2942 List<Expression> orderbyList = new ArrayList<Expression>();
2943 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2944 int numOfOrderby = 0;
2945}
2946{
2947 <ORDER>
2948 {
2949 String hint = getHint(token);
2950 if (hint != null) {
2951 if (hint.startsWith(INMEMORY_HINT)) {
2952 String splits[] = hint.split(" +");
2953 int numFrames = Integer.parseInt(splits[1]);
2954 int numTuples = Integer.parseInt(splits[2]);
2955 oc.setNumFrames(numFrames);
2956 oc.setNumTuples(numTuples);
2957 }
2958 }
2959 }
2960 <BY> orderbyExpr = Expression()
2961 {
2962 orderbyList.add(orderbyExpr);
2963 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2964 }
2965 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2966 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2967 {
2968 modifierList.add(modif);
2969 }
2970
2971 (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression()
2972 {
2973 orderbyList.add(orderbyExpr);
2974 modif = OrderbyClause.OrderModifier.ASC;
2975 }
2976 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2977 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2978 {
2979 modifierList.add(modif);
2980 }
2981 )*
2982
2983 {
2984 oc.setModifierList(modifierList);
2985 oc.setOrderbyList(orderbyList);
2986 return oc;
2987 }
2988}
2989
2990GroupbyClause GroupbyClause()throws ParseException :
2991{
2992 GroupbyClause gbc = new GroupbyClause();
2993 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2994 VariableExpr var = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002995 Expression expr = null;
2996 VariableExpr decorVar = null;
2997 Expression decorExpr = null;
Yingyi Buacc12a92016-03-26 17:25:05 -07002998
2999 VariableExpr groupVar = null;
3000 List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<Pair<Expression, Identifier>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07003001}
3002{
3003 {
3004 Scope newScope = extendCurrentScopeNoPush(true);
3005 // extendCurrentScope(true);
3006 }
3007 <GROUP>
3008 {
3009 String hint = getHint(token);
3010 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
3011 gbc.setHashGroupByHint(true);
3012 }
3013 }
3014 <BY> (
3015 expr = Expression()
3016 (LOOKAHEAD(1) (<AS>)?
3017 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08003018 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003019 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003020 if(var==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07003021 var = ExpressionToVariableUtil.getGeneratedVariable(expr, false);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003022 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003023 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
3024 vePairList.add(pair1);
3025 }
3026 ( LOOKAHEAD(1) <COMMA>
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003027 {
3028 var = null;
3029 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003030 expr = Expression()
3031 (LOOKAHEAD(1) (<AS>)?
3032 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08003033 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003034 {
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003035 if(var==null){
Yingyi Bu5b2d4c82016-07-13 17:56:48 -07003036 var = ExpressionToVariableUtil.getGeneratedVariable(expr, false);
Yingyi Bu9e3f9be2016-07-01 10:07:37 -07003037 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07003038 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
3039 vePairList.add(pair2);
3040 }
3041 )*
3042 )
Yingyi Buacc12a92016-03-26 17:25:05 -07003043 (<GROUP> <AS> groupVar = Variable()
3044 ( LOOKAHEAD(1)
3045 {
3046 VariableExpr fieldVarExpr = null;
3047 String fieldIdentifierStr = null;
3048 }
3049 <LEFTPAREN>
3050 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
3051 {
3052 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
3053 }
3054 (<COMMA>
3055 fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier()
3056 {
3057 groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr)));
3058 }
3059 )*
3060 <RIGHTPAREN>
3061 )?
3062 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003063 {
3064 gbc.setGbyPairList(vePairList);
3065 gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07003066 gbc.setWithVarMap(new HashMap<Expression, VariableExpr>());
Yingyi Buacc12a92016-03-26 17:25:05 -07003067 gbc.setGroupVar(groupVar);
3068 gbc.setGroupFieldList(groupFieldList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003069 replaceCurrentScope(newScope);
3070 return gbc;
3071 }
3072}
3073
3074HavingClause HavingClause() throws ParseException:
3075{
3076 Expression filterExpr = null;
3077}
3078{
3079 <HAVING> filterExpr = Expression()
3080 {
3081 return new HavingClause(filterExpr);
3082 }
3083}
3084
3085LimitClause LimitClause() throws ParseException:
3086{
3087 LimitClause lc = new LimitClause();
3088 Expression expr;
3089 pushForbiddenScope(getCurrentScope());
3090}
3091{
3092 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
3093 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
3094
3095 {
3096 popForbiddenScope();
3097 return lc;
3098 }
3099}
3100
3101QuantifiedExpression QuantifiedExpression()throws ParseException:
3102{
3103 QuantifiedExpression qc = new QuantifiedExpression();
3104 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
3105 Expression satisfiesExpr;
3106 VariableExpr var;
3107 Expression inExpr;
3108 QuantifiedPair pair;
3109}
3110{
3111 {
3112 createNewScope();
3113 }
3114
Yingyi Bu8aac7242016-09-13 23:14:09 -07003115 ( ((<ANY>|<SOME>) { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Michael Blowd6cf6412016-06-30 02:44:35 -04003116 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
Yingyi Bu391f09e2015-10-29 13:49:39 -07003117 var = Variable() <IN> inExpr = Expression()
3118 {
3119 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003120 quantifiedList.add(pair);
3121 }
3122 (
3123 <COMMA> var = Variable() <IN> inExpr = Expression()
3124 {
3125 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07003126 quantifiedList.add(pair);
3127 }
3128 )*
Yingyi Bu858efae2016-10-13 17:31:57 -07003129 <SATISFIES> satisfiesExpr = Expression() (<END>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003130 {
3131 qc.setSatisfiesExpr(satisfiesExpr);
3132 qc.setQuantifiedList(quantifiedList);
3133 removeCurrentScope();
3134 return qc;
3135 }
3136}
3137
3138LetClause LetElement() throws ParseException:
3139{
3140 LetClause lc = new LetClause();
3141 VariableExpr varExp;
3142 Expression beExp;
3143 extendCurrentScope();
3144}
3145{
3146 varExp = Variable() <EQ> beExp = Expression()
3147 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07003148 lc.setVarExpr(varExp);
3149 lc.setBindingExpr(beExp);
3150 return lc;
3151 }
3152}
3153
3154LetClause WithElement() throws ParseException:
3155{
3156 LetClause lc = new LetClause();
3157 VariableExpr varExp;
3158 Expression beExp;
3159 extendCurrentScope();
3160}
3161{
3162 varExp = Variable() <AS> beExp = Expression()
3163 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07003164 lc.setVarExpr(varExp);
3165 lc.setBindingExpr(beExp);
3166 return lc;
3167 }
3168}
3169
3170TOKEN_MGR_DECLS:
3171{
3172 public int commentDepth = 0;
Till Westmanne9b2adf2016-10-15 12:39:01 -07003173 public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07003174
3175 public void pushState() {
3176 lexerStateStack.push( curLexState );
3177 }
3178
3179 public void popState(String token) {
3180 if (lexerStateStack.size() > 0) {
3181 SwitchTo( lexerStateStack.pop() );
3182 } else {
3183 int errorLine = input_stream.getEndLine();
3184 int errorColumn = input_stream.getEndColumn();
3185 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
3186 + "\" but state stack is empty.";
3187 throw new TokenMgrError(msg, -1);
3188 }
3189 }
3190}
3191
3192<DEFAULT,IN_DBL_BRACE>
3193TOKEN [IGNORE_CASE]:
3194{
3195 <ALL : "all">
3196 | <AND : "and">
Yingyi Bu8aac7242016-09-13 23:14:09 -07003197 | <ANY : "any">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003198 | <APPLY : "apply">
3199 | <AS : "as">
3200 | <ASC : "asc">
3201 | <AT : "at">
3202 | <AUTOGENERATED : "autogenerated">
Yingyi Bua8baf6d2016-07-05 21:40:44 -07003203 | <BETWEEN : "between">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003204 | <BTREE : "btree">
3205 | <BY : "by">
3206 | <CASE : "case">
3207 | <CLOSED : "closed">
3208 | <CREATE : "create">
3209 | <COMPACTION : "compaction">
3210 | <COMPACT : "compact">
3211 | <CONNECT : "connect">
3212 | <CORRELATE : "correlate">
Yingyi Bud56ff032016-08-01 10:26:57 -07003213 | <DATASET : "dataset">
Yingyi Bu1c0fff52016-03-25 20:23:30 -07003214 | <COLLECTION : "collection">
Yingyi Bud56ff032016-08-01 10:26:57 -07003215 | <DATAVERSE : "dataverse">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003216 | <DECLARE : "declare">
3217 | <DEFINITION : "definition">
3218 | <DELETE : "delete">
3219 | <DESC : "desc">
3220 | <DISCONNECT : "disconnect">
3221 | <DISTINCT : "distinct">
3222 | <DROP : "drop">
3223 | <ELEMENT : "element">
Till Westmann516d1a82016-08-02 14:45:53 -07003224 | <EXPLAIN : "explain">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003225 | <ELSE : "else">
3226 | <ENFORCED : "enforced">
Yingyi Buc8c067c2016-07-25 23:37:19 -07003227 | <END : "end">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003228 | <EVERY : "every">
3229 | <EXCEPT : "except">
3230 | <EXISTS : "exists">
3231 | <EXTERNAL : "external">
3232 | <FEED : "feed">
3233 | <FILTER : "filter">
3234 | <FLATTEN : "flatten">
3235 | <FOR : "for">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003236 | <FROM : "from">
3237 | <FULL : "full">
Taewoo Kimc49405a2017-01-04 00:30:43 -08003238 | <FULLTEXT : "fulltext">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003239 | <FUNCTION : "function">
3240 | <GROUP : "group">
3241 | <HAVING : "having">
3242 | <HINTS : "hints">
3243 | <IF : "if">
3244 | <INTO : "into">
3245 | <IN : "in">
3246 | <INDEX : "index">
3247 | <INGESTION : "ingestion">
3248 | <INNER : "inner">
3249 | <INSERT : "insert">
3250 | <INTERNAL : "internal">
3251 | <INTERSECT : "intersect">
Yingyi Budaa549c2016-06-28 22:30:52 -07003252 | <IS : "is">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003253 | <JOIN : "join">
3254 | <KEYWORD : "keyword">
3255 | <KEY : "key">
3256 | <LEFT : "left">
3257 | <LETTING : "letting">
3258 | <LET : "let">
Yingyi Bua8baf6d2016-07-05 21:40:44 -07003259 | <LIKE : "like">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003260 | <LIMIT : "limit">
3261 | <LOAD : "load">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003262 | <NODEGROUP : "nodegroup">
3263 | <NGRAM : "ngram">
Yingyi Budaa549c2016-06-28 22:30:52 -07003264 | <NOT : "not">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003265 | <OFFSET : "offset">
3266 | <ON : "on">
3267 | <OPEN : "open">
3268 | <OR : "or">
3269 | <ORDER : "order">
3270 | <OUTER : "outer">
3271 | <OUTPUT : "output">
3272 | <PATH : "path">
3273 | <POLICY : "policy">
3274 | <PRESORTED : "pre-sorted">
3275 | <PRIMARY : "primary">
3276 | <RAW : "raw">
3277 | <REFRESH : "refresh">
3278 | <RETURN : "return">
Yingyi Bucb5bf332017-01-02 22:19:50 -08003279 | <RETURNING : "returning">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003280 | <RTREE : "rtree">
3281 | <RUN : "run">
3282 | <SATISFIES : "satisfies">
3283 | <SECONDARY : "secondary">
3284 | <SELECT : "select">
3285 | <SET : "set">
3286 | <SOME : "some">
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08003287 | <START : "start">
3288 | <STOP : "stop">
Murtadha Hubail2c04ae02017-11-21 15:58:01 +03003289 | <TEMPORARY : "temporary"> // intentionally not used but reserved for future usage
Yingyi Bu391f09e2015-10-29 13:49:39 -07003290 | <THEN : "then">
3291 | <TYPE : "type">
3292 | <TO : "to">
3293 | <UNION : "union">
Dmitry Lychagin8b6578a2017-11-08 15:04:35 -08003294 | <UNKNOWN : "unknown">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003295 | <UNNEST : "unnest">
Yingyi Budaa549c2016-06-28 22:30:52 -07003296 | <UPDATE : "update">
Yingyi Bucb5bf332017-01-02 22:19:50 -08003297 | <UPSERT : "upsert">
Yingyi Budaa549c2016-06-28 22:30:52 -07003298 | <USE : "use">
3299 | <USING : "using">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003300 | <VALUE : "value">
Dmitry Lychagin7d594a32018-01-15 14:31:03 -08003301 | <VALUED : "valued">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003302 | <WHEN : "when">
3303 | <WHERE : "where">
3304 | <WITH : "with">
3305 | <WRITE : "write">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003306}
3307
3308<DEFAULT,IN_DBL_BRACE>
3309TOKEN :
3310{
3311 <CARET : "^">
Yingyi Bufdc71eb2016-08-24 22:41:57 -07003312 | <CONCAT : "||">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003313 | <DIV : "/">
3314 | <IDIV : "idiv">
3315 | <MINUS : "-">
3316 | <MOD : "%">
3317 | <MUL : "*">
3318 | <PLUS : "+">
3319
3320 | <LEFTPAREN : "(">
3321 | <RIGHTPAREN : ")">
3322 | <LEFTBRACKET : "[">
3323 | <RIGHTBRACKET : "]">
3324
3325 | <ATT : "@">
3326 | <COLON : ":">
3327 | <COMMA : ",">
3328 | <DOT : ".">
3329 | <QUES : "?">
3330 | <SEMICOLON : ";">
3331 | <SHARP : "#">
3332
3333 | <LT : "<">
3334 | <GT : ">">
3335 | <LE : "<=">
3336 | <GE : ">=">
3337 | <EQ : "=">
3338 | <NE : "!=">
Yingyi Bu4a4b8962016-09-16 12:09:11 -07003339 | <LG : "<>">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003340 | <SIMILAR : "~=">
3341}
3342
3343<DEFAULT,IN_DBL_BRACE>
3344TOKEN :
3345{
3346 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
3347}
3348
3349<DEFAULT>
3350TOKEN :
3351{
3352 <RIGHTBRACE : "}"> { popState("}"); }
3353}
3354
3355<DEFAULT,IN_DBL_BRACE>
3356TOKEN :
3357{
3358 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
3359}
3360
3361<IN_DBL_BRACE>
3362TOKEN :
3363{
3364 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
3365}
3366
3367<DEFAULT,IN_DBL_BRACE>
3368TOKEN :
3369{
3370 <INTEGER_LITERAL : (<DIGIT>)+ >
3371}
3372
3373<DEFAULT,IN_DBL_BRACE>
Yingyi Bue311a632016-06-07 18:23:16 -07003374TOKEN [IGNORE_CASE]:
Yingyi Bu391f09e2015-10-29 13:49:39 -07003375{
Yingyi Bu535d86b2016-05-23 16:44:25 -07003376 <MISSING : "missing">
3377 | <NULL : "null">
Yingyi Bu391f09e2015-10-29 13:49:39 -07003378 | <TRUE : "true">
3379 | <FALSE : "false">
3380}
3381
3382<DEFAULT,IN_DBL_BRACE>
3383TOKEN :
3384{
3385 <#DIGIT : ["0" - "9"]>
3386}
3387
3388<DEFAULT,IN_DBL_BRACE>
3389TOKEN:
3390{
Dmitry Lychaginee8526b2018-03-30 14:21:01 -07003391 < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("+"|"-")? <DIGITS>)?
3392 | <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)
3393 | "." <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07003394 >
Yingyi Bue4d919e2016-10-30 10:47:03 -07003395 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
3396 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
3397 | "." <DIGITS> ( "f" | "F" )
Yingyi Bu391f09e2015-10-29 13:49:39 -07003398 >
3399 | <DIGITS : (<DIGIT>)+ >
3400}
3401
3402<DEFAULT,IN_DBL_BRACE>
3403TOKEN :
3404{
3405 <#LETTER : ["A" - "Z", "a" - "z"]>
Dmitry Lychagin9c83efb2018-01-16 14:31:58 -08003406 | <#IDENTIFIER_SPECIALCHARS_START : ["_"]>
3407 | <#IDENTIFIER_SPECIALCHARS_REST : ["$"]>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003408}
3409
3410<DEFAULT,IN_DBL_BRACE>
3411TOKEN :
3412{
3413 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
Yingyi Bu6d57e492016-06-06 21:24:42 -07003414 <QUOTED_STRING : "`" (
Yingyi Bu391f09e2015-10-29 13:49:39 -07003415 <EscapeQuot>
3416 | <EscapeBslash>
3417 | <EscapeSlash>
3418 | <EscapeBspace>
3419 | <EscapeFormf>
3420 | <EscapeNl>
3421 | <EscapeCr>
3422 | <EscapeTab>
Yingyi Bu6d57e492016-06-06 21:24:42 -07003423 | ~["`","\\"])* "`">
3424 | <STRING_LITERAL : ("\"" (
Yingyi Bu391f09e2015-10-29 13:49:39 -07003425 <EscapeQuot>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003426 | <EscapeBslash>
3427 | <EscapeSlash>
3428 | <EscapeBspace>
3429 | <EscapeFormf>
3430 | <EscapeNl>
3431 | <EscapeCr>
3432 | <EscapeTab>
Yingyi Bu6d57e492016-06-06 21:24:42 -07003433 | ~["\"","\\"])* "\"")
3434 | ("\'"(
3435 <EscapeApos>
3436 | <EscapeBslash>
3437 | <EscapeSlash>
3438 | <EscapeBspace>
3439 | <EscapeFormf>
3440 | <EscapeNl>
3441 | <EscapeCr>
3442 | <EscapeTab>
3443 | ~["\'","\\"])* "\'")>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003444 | < #EscapeQuot: "\\\"" >
3445 | < #EscapeApos: "\\\'" >
3446 | < #EscapeBslash: "\\\\" >
3447 | < #EscapeSlash: "\\/" >
3448 | < #EscapeBspace: "\\b" >
3449 | < #EscapeFormf: "\\f" >
3450 | < #EscapeNl: "\\n" >
3451 | < #EscapeCr: "\\r" >
3452 | < #EscapeTab: "\\t" >
3453}
3454
3455<DEFAULT,IN_DBL_BRACE>
3456TOKEN :
3457{
Dmitry Lychagin9c83efb2018-01-16 14:31:58 -08003458 <IDENTIFIER : ( <LETTER> | <IDENTIFIER_SPECIALCHARS_START> )
3459 ( <LETTER> | <DIGIT> | <IDENTIFIER_SPECIALCHARS_START> | <IDENTIFIER_SPECIALCHARS_REST> )*>
Yingyi Bu391f09e2015-10-29 13:49:39 -07003460}
3461
3462<DEFAULT,IN_DBL_BRACE>
3463SKIP:
3464{
3465 " "
3466 | "\t"
3467 | "\r"
3468 | "\n"
3469}
3470
3471<DEFAULT,IN_DBL_BRACE>
3472SKIP:
3473{
3474 <"//" (~["\n"])* "\n">
3475}
3476
3477<DEFAULT,IN_DBL_BRACE>
3478SKIP:
3479{
3480 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
3481}
3482
3483<DEFAULT,IN_DBL_BRACE>
3484SKIP:
3485{
Yingyi Bu93846a72016-09-13 16:30:39 -07003486 <"--" (~["\n"])* "\n">
3487}
3488
3489
3490<DEFAULT,IN_DBL_BRACE>
3491SKIP:
3492{
3493 <"--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
3494}
3495
3496<DEFAULT,IN_DBL_BRACE>
3497SKIP:
3498{
Yingyi Bu391f09e2015-10-29 13:49:39 -07003499 <"/*"> { pushState(); } : INSIDE_COMMENT
3500}
3501
3502<INSIDE_COMMENT>
3503SPECIAL_TOKEN:
3504{
3505 <"+"(" ")*(~["*"])*>
3506}
3507
3508<INSIDE_COMMENT>
3509SKIP:
3510{
3511 <"/*"> { pushState(); }
3512}
3513
3514<INSIDE_COMMENT>
3515SKIP:
3516{
3517 <"*/"> { popState("*/"); }
3518 | <~[]>
3519}