blob: f2fa66cca8d34b24435094b138de6097677005e4 [file] [log] [blame]
vinayakb38b7ca42012-03-05 05:44:15 +00001options {
2
3
4 STATIC = false;
5
6}
7
8
9PARSER_BEGIN(AQLParser)
10
11package edu.uci.ics.asterix.aql.parser;
12
13import java.io.*;
14import java.util.List;
15import java.util.ArrayList;
16import java.util.Stack;
17
18import java.util.Map;
19import java.util.HashMap;
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +000020import java.util.LinkedHashMap;
vinayakb38b7ca42012-03-05 05:44:15 +000021import edu.uci.ics.asterix.aql.literal.FloatLiteral;
22import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
23import edu.uci.ics.asterix.aql.literal.FalseLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000024import edu.uci.ics.asterix.aql.base.Literal;
vinayakb38b7ca42012-03-05 05:44:15 +000025import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000026import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +000027import edu.uci.ics.asterix.aql.literal.NullLiteral;
28import edu.uci.ics.asterix.aql.literal.StringLiteral;
29import edu.uci.ics.asterix.aql.literal.TrueLiteral;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000030import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
vinayakb38b7ca42012-03-05 05:44:15 +000031
32import edu.uci.ics.asterix.aql.base.*;
33import edu.uci.ics.asterix.aql.expression.*;
34import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
35import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
36import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
37import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
38import edu.uci.ics.asterix.aql.base.Statement.Kind;
39import edu.uci.ics.asterix.aql.context.Scope;
40import edu.uci.ics.asterix.aql.context.RootScopeFactory;
41import edu.uci.ics.asterix.common.annotations.*;
42import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000043import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000044import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000045import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
46import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000047import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
48import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
49import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
50
51
vinayakb38b7ca42012-03-05 05:44:15 +000052
53
54public class AQLParser extends ScopeChecker {
55
vinayakb38b7ca42012-03-05 05:44:15 +000056 // optimizer hints
57 private static final String HASH_GROUP_BY_HINT = "hash";
58 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000059 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000060 private static final String INMEMORY_HINT = "inmem";
61 private static final String VAL_FILE_HINT = "val-files";
62 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
63 private static final String INTERVAL_HINT = "interval";
64 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
65 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
66 private static final String LIST_VAL_FILE_HINT = "list-val-file";
67 private static final String LIST_HINT = "list";
68 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
69 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
70 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
71 private static final String AUTO_HINT = "auto";
72
73 private static final String GEN_FIELDS_HINT = "gen-fields";
74
75 // data generator hints
76 private static final String DGEN_HINT = "dgen";
Till Westmann31c21f92013-05-08 09:21:53 -070077
78 private static class IndexParams {
79 public IndexType type;
80 public int gramLength;
81
82 public IndexParams(IndexType type, int gramLength) {
83 this.type = type;
84 this.gramLength = gramLength;
85 }
86 };
vinayakb38b7ca42012-03-05 05:44:15 +000087
88 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070089 if (t.specialToken == null) {
90 return null;
91 }
92 String s = t.specialToken.image;
93 int n = s.length();
94 if (n < 2) {
95 return null;
96 }
97 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +000098 }
99
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000100 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700101 this(new StringReader(s));
102 super.setInput(s);
103 }
vinayakb38b7ca42012-03-05 05:44:15 +0000104
Till Westmann31c21f92013-05-08 09:21:53 -0700105 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
106 File file = new File(args[0]);
107 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
108 AQLParser parser = new AQLParser(fis);
109 List<Statement> st = parser.Statement();
110 //st.accept(new AQLPrintVisitor(), 0);
111 }
vinayakb38b7ca42012-03-05 05:44:15 +0000112}
113
114PARSER_END(AQLParser)
115
116
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000117List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000118{
vinayakb38b7ca42012-03-05 05:44:15 +0000119 scopeStack.push(RootScopeFactory.createRootScope(this));
120 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700121 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000122}
123{
Till Westmann31c21f92013-05-08 09:21:53 -0700124 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000125 {
Till Westmann31c21f92013-05-08 09:21:53 -0700126 decls.add(stmt);
127 }
128 )*
129 <EOF>
130 {
131 return decls;
132 }
133}
134
135Statement SingleStatement() throws ParseException:
136{
137 Statement stmt = null;
138}
139{
140 (
141 stmt = DataverseDeclaration()
142 | stmt = FunctionDeclaration()
143 | stmt = CreateStatement()
144 | stmt = LoadStatement()
145 | stmt = DropStatement()
146 | stmt = WriteStatement()
147 | stmt = SetStatement()
148 | stmt = InsertStatement()
149 | stmt = DeleteStatement()
150 | stmt = UpdateStatement()
151 | stmt = FeedStatement()
152 | stmt = Query()
153 )
154 {
155 return stmt;
156 }
157}
158
159DataverseDecl DataverseDeclaration() throws ParseException:
160{
Till Westmann14a20a72013-05-09 00:06:24 -0700161 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700162}
163{
Till Westmanna4242bc2013-05-08 17:49:55 -0700164 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700165 {
Till Westmann14a20a72013-05-09 00:06:24 -0700166 defaultDataverse = dvName;
167 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700168 }
169}
170
171Statement CreateStatement() throws ParseException:
172{
173 String hint = null;
174 boolean dgen = false;
175 Statement stmt = null;
176}
177{
178 "create"
179 (
180 {
181 hint = getHint(token);
182 if (hint != null && hint.startsWith(DGEN_HINT)) {
183 dgen = true;
184 }
185 }
186 stmt = TypeSpecification(hint, dgen)
187 | stmt = NodegroupSpecification()
188 | stmt = DatasetSpecification()
189 | stmt = IndexSpecification()
190 | stmt = DataverseSpecification()
191 | stmt = FunctionSpecification()
192 )
193 {
194 return stmt;
195 }
196}
197
198TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
199{
200 Pair<Identifier,Identifier> nameComponents = null;
201 boolean ifNotExists = false;
202 TypeExpression typeExpr = null;
203}
204{
205 "type" nameComponents = FunctionOrTypeName() ifNotExists = IfNotExists()
206 "as" typeExpr = TypeExpr()
207 {
208 long numValues = -1;
209 String filename = null;
210 if (dgen) {
211 String splits[] = hint.split(" +");
212 if (splits.length != 3) {
213 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
214 }
215 filename = splits[1];
216 numValues = Long.parseLong(splits[2]);
217 }
218 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
219 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
220 }
221}
222
223
224NodegroupDecl NodegroupSpecification() throws ParseException:
225{
Till Westmann14a20a72013-05-09 00:06:24 -0700226 String name = null;
227 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700228 boolean ifNotExists = false;
229 List<Identifier>ncNames = null;
230}
231{
Till Westmanna4242bc2013-05-08 17:49:55 -0700232 "nodegroup" name = Identifier()
233 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700234 {
235 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700236 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700237 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700238 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700239 {
Till Westmann14a20a72013-05-09 00:06:24 -0700240 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700241 }
242 )*
243 {
Till Westmann14a20a72013-05-09 00:06:24 -0700244 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700245 }
246}
247
248DatasetDecl DatasetSpecification() throws ParseException:
249{
250 Pair<Identifier,Identifier> nameComponents = null;
251 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700252 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700253 String adapterName = null;
254 Map<String,String> properties = null;
255 FunctionSignature appliedFunction = null;
256 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700257 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700258 Map<String,String> hints = new HashMap<String,String>();
259 DatasetDecl dsetDecl = null;
260}
261{
262 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700263 "external" <DATASET> nameComponents = QualifiedName()
264 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
265 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700266 "using" adapterName = AdapterName() properties = Configuration()
267 ( "hints" hints = Properties() )?
268 {
269 ExternalDetailsDecl edd = new ExternalDetailsDecl();
270 edd.setAdapter(adapterName);
271 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700272 dsetDecl = new DatasetDecl(nameComponents.first,
273 nameComponents.second,
274 new Identifier(typeName),
275 hints,
276 DatasetType.EXTERNAL,
277 edd,
278 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700279 }
280
Till Westmanna4242bc2013-05-08 17:49:55 -0700281 | "feed" <DATASET> nameComponents = QualifiedName()
282 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
283 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700284 "using" adapterName = AdapterName() properties = Configuration()
285 (appliedFunction = ApplyFunction())? primaryKeyFields = PrimaryKey()
Till Westmanna4242bc2013-05-08 17:49:55 -0700286 ( "on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700287 ( "hints" hints = Properties() )?
288 {
Till Westmann14a20a72013-05-09 00:06:24 -0700289 FeedDetailsDecl fdd = new FeedDetailsDecl(adapterName,
290 properties,
291 appliedFunction,
292 nodeGroupName != null
293 ? new Identifier(nodeGroupName)
294 : null,
295 primaryKeyFields);
296 dsetDecl = new DatasetDecl(nameComponents.first,
297 nameComponents.second,
298 new Identifier(typeName),
299 hints,
300 DatasetType.FEED,
301 fdd,
302 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700303 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700304 | <DATASET> nameComponents = QualifiedName()
305 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
306 ifNotExists = IfNotExists()
307 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700308 ( "hints" hints = Properties() )?
309 {
Till Westmann14a20a72013-05-09 00:06:24 -0700310 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
311 ? new Identifier(nodeGroupName)
312 : null,
313 primaryKeyFields);
314 dsetDecl = new DatasetDecl(nameComponents.first,
315 nameComponents.second,
316 new Identifier(typeName),
317 hints,
318 DatasetType.INTERNAL,
319 idd,
320 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700321 }
322 )
323 {
324 return dsetDecl;
325 }
326}
327
328CreateIndexStatement IndexSpecification() throws ParseException:
329{
330 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700331 String indexName = null;
332 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700333 boolean ifNotExists = false;
334 Pair<Identifier,Identifier> nameComponents = null;
335 IndexParams indexType = null;
336}
337{
Till Westmanna4242bc2013-05-08 17:49:55 -0700338 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700339 ifNotExists = IfNotExists()
340 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700341 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700342 {
Till Westmann14a20a72013-05-09 00:06:24 -0700343 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700344 }
Till Westmann14a20a72013-05-09 00:06:24 -0700345 ) ("," fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700346 {
Till Westmann14a20a72013-05-09 00:06:24 -0700347 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700348 }
349 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
350 {
Till Westmann14a20a72013-05-09 00:06:24 -0700351 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700352 cis.setIfNotExists(ifNotExists);
353 cis.setDataverseName(nameComponents.first);
354 cis.setDatasetName(nameComponents.second);
355 if (indexType != null) {
356 cis.setIndexType(indexType.type);
357 cis.setGramLength(indexType.gramLength);
358 }
359 return cis;
360 }
361}
362
363IndexParams IndexType() throws ParseException:
364{
365 IndexType type = null;
366 int gramLength = 0;
367}
368{
369 ("btree"
370 {
371 type = IndexType.BTREE;
372 }
373 | "rtree"
374 {
375 type = IndexType.RTREE;
376 }
377 | "keyword"
378 {
379 type = IndexType.WORD_INVIX;
380 }
381 | "fuzzy keyword"
382 {
383 type = IndexType.FUZZY_WORD_INVIX;
384 }
385 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
386 {
387 type = IndexType.NGRAM_INVIX;
388 gramLength = Integer.valueOf(token.image);
389 }
390 <RIGHTPAREN>
391 | "fuzzy ngram" <LEFTPAREN> <INTEGER_LITERAL>
392 {
393 type = IndexType.FUZZY_NGRAM_INVIX;
394 gramLength = Integer.valueOf(token.image);
395 }
396 <RIGHTPAREN>)
397 {
398 return new IndexParams(type, gramLength);
399 }
400}
401
402CreateDataverseStatement DataverseSpecification() throws ParseException :
403{
Till Westmann14a20a72013-05-09 00:06:24 -0700404 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700405 boolean ifNotExists = false;
406 String format = null;
407}
408{
Till Westmanna4242bc2013-05-08 17:49:55 -0700409 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700410 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700411 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700412 {
Till Westmann14a20a72013-05-09 00:06:24 -0700413 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700414 }
415}
416
417CreateFunctionStatement FunctionSpecification() throws ParseException:
418{
419 FunctionSignature signature;
420 boolean ifNotExists = false;
421 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
422 String functionBody;
423 VarIdentifier var = null;
424 Expression functionBodyExpr;
425 Token beginPos;
426 Token endPos;
427 Pair<Identifier,Identifier> nameComponents=null;
428
429 createNewScope();
430}
431{
432 "function" nameComponents = FunctionOrTypeName()
433 ifNotExists = IfNotExists()
434 <LEFTPAREN> (<VARIABLE>
435 {
436 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700437 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700438 paramList.add(var);
439 getCurrentScope().addNewVarSymbolToScope(var);
440 }
441 ("," <VARIABLE>
442 {
443 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700444 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700445 paramList.add(var);
446 getCurrentScope().addNewVarSymbolToScope(var);
447 }
448 )*)? <RIGHTPAREN> "{"
449 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700450 beginPos = token;
Till Westmann31c21f92013-05-08 09:21:53 -0700451 }
452 functionBodyExpr = Expression() "}"
453 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700454 endPos = token;
Till Westmann31c21f92013-05-08 09:21:53 -0700455 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
456 String dataverse = nameComponents.first.getValue();
457 String functionName = nameComponents.second.getValue();
458 signature = new FunctionSignature(dataverse, functionName, paramList.size());
459 getCurrentScope().addFunctionDescriptor(signature, false);
460 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
461 }
462}
463
464boolean IfNotExists() throws ParseException:
465{
466}
467{
468 ( "if not exists"
469 {
470 return true;
471 }
472 )?
473 {
474 return false;
475 }
476}
477
478FunctionSignature ApplyFunction() throws ParseException:
479{
480 FunctionSignature funcSig = null;
481}
482{
483 "apply" "function" funcSig = FunctionSignature()
484 {
485 return funcSig;
486 }
487}
488
489FunctionSignature FunctionSignature() throws ParseException:
490{
491 Pair<Identifier,Identifier> pairId = null;
492 int arity = 0;
493}
494{
495 pairId = FunctionOrTypeName() "@" <INTEGER_LITERAL>
496 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700497 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700498 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
499 throw new ParseException(" invalid arity:" + arity);
500 }
501
502 String dataverse = pairId.first.getValue();
503 String functionName = pairId.second.getValue();
504 return new FunctionSignature(dataverse, functionName, arity);
505 }
506}
507
508List<String> PrimaryKey() throws ParseException:
509{
Till Westmann14a20a72013-05-09 00:06:24 -0700510 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700511 List<String> primaryKeyFields = new ArrayList<String>();
512}
513{
Till Westmann14a20a72013-05-09 00:06:24 -0700514 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700515 {
Till Westmann14a20a72013-05-09 00:06:24 -0700516 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700517 }
Till Westmann14a20a72013-05-09 00:06:24 -0700518 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700519 {
Till Westmann14a20a72013-05-09 00:06:24 -0700520 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700521 }
522 )*
523 {
524 return primaryKeyFields;
525 }
526}
527
528Statement DropStatement() throws ParseException:
529{
Till Westmann14a20a72013-05-09 00:06:24 -0700530 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700531 Pair<Identifier,Identifier> pairId = null;
532 Triple<Identifier,Identifier,Identifier> tripleId = null;
533 FunctionSignature funcSig = null;
534 boolean ifExists = false;
535 Statement stmt = null;
536}
537{
538 "drop"
539 (
540 <DATASET> pairId = QualifiedName() ifExists = IfExists()
541 {
542 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
543 }
544 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
545 {
546 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
547 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700548 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700549 {
Till Westmann14a20a72013-05-09 00:06:24 -0700550 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700551 }
552 | "type" pairId = FunctionOrTypeName() ifExists = IfExists()
553 {
554 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
555 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700556 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700557 {
Till Westmann14a20a72013-05-09 00:06:24 -0700558 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700559 }
560 | "function" funcSig = FunctionSignature() ifExists = IfExists()
561 {
562 stmt = new FunctionDropStatement(funcSig, ifExists);
563 }
564 )
565 {
566 return stmt;
567 }
568}
569
570boolean IfExists() throws ParseException :
571{
572}
573{
574 ( "if" "exists"
575 {
576 return true;
577 }
578 )?
579 {
580 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000581 }
582}
583
584InsertStatement InsertStatement() throws ParseException:
585{
Till Westmann31c21f92013-05-08 09:21:53 -0700586 Pair<Identifier,Identifier> nameComponents = null;
587 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000588}
589{
Till Westmann31c21f92013-05-08 09:21:53 -0700590 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
591 {
592 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
593 }
vinayakb38b7ca42012-03-05 05:44:15 +0000594}
595
596DeleteStatement DeleteStatement() throws ParseException:
597{
Till Westmann31c21f92013-05-08 09:21:53 -0700598 VariableExpr var = null;
599 Expression condition = null;
600 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000601}
602{
Till Westmann31c21f92013-05-08 09:21:53 -0700603 "delete" var = Variable()
604 {
605 getCurrentScope().addNewVarSymbolToScope(var.getVar());
606 }
607 "from" <DATASET> nameComponents = QualifiedName()
608 ("where" condition = Expression())?
609 {
610 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
611 }
vinayakb38b7ca42012-03-05 05:44:15 +0000612}
613
614UpdateStatement UpdateStatement() throws ParseException:
615{
Till Westmann31c21f92013-05-08 09:21:53 -0700616 VariableExpr vars;
617 Expression target;
618 Expression condition;
619 UpdateClause uc;
620 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000621}
622{
Till Westmann31c21f92013-05-08 09:21:53 -0700623 "update" vars = Variable() "in" target = Expression()
624 "where" condition = Expression()
625 <LEFTPAREN> (uc = UpdateClause()
626 {
627 ucs.add(uc);
628 }
629 ("," uc = UpdateClause()
630 {
631 ucs.add(uc);
632 }
633 )*) <RIGHTPAREN>
634 {
635 return new UpdateStatement(vars, target, condition, ucs);
636 }
vinayakb38b7ca42012-03-05 05:44:15 +0000637}
638
vinayakb38b7ca42012-03-05 05:44:15 +0000639UpdateClause UpdateClause() throws ParseException:
640{
Till Westmann31c21f92013-05-08 09:21:53 -0700641 Expression target = null;
642 Expression value = null ;
643 InsertStatement is = null;
644 DeleteStatement ds = null;
645 UpdateStatement us = null;
646 Expression condition = null;
647 UpdateClause ifbranch = null;
648 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000649}
650{
651 "set" target = Expression() ":=" value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700652 | is = InsertStatement()
653 | ds = DeleteStatement()
654 | us = UpdateStatement()
655 | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN>
656 "then" ifbranch = UpdateClause()
657 [LOOKAHEAD(1) "else" elsebranch = UpdateClause()]
658 {
659 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
660 }
vinayakb38b7ca42012-03-05 05:44:15 +0000661}
662
vinayakb38b7ca42012-03-05 05:44:15 +0000663Statement SetStatement() throws ParseException:
664{
665 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700666 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000667}
668{
Till Westmann7d535322013-05-09 00:40:02 -0700669 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700670 {
Till Westmann31c21f92013-05-08 09:21:53 -0700671 return new SetStatement(pn, pv);
672 }
vinayakb38b7ca42012-03-05 05:44:15 +0000673}
674
675Statement WriteStatement() throws ParseException:
676{
Till Westmann14a20a72013-05-09 00:06:24 -0700677 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000678 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000679 Statement stmt = null;
680 Query query;
681 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000682 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000683}
684{
Till Westmann31c21f92013-05-08 09:21:53 -0700685 "write" ((
Till Westmann7d535322013-05-09 00:40:02 -0700686 "output" "to" nodeName = Identifier() ":" fileName = StringLiteral()
687 ( "using" writerClass = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700688 {
Till Westmann14a20a72013-05-09 00:06:24 -0700689 stmt = new WriteStatement(new Identifier(nodeName), fileName, writerClass);
Till Westmann31c21f92013-05-08 09:21:53 -0700690 }
691 ) | (
692 "into" <DATASET>
693 {
694 nameComponents = QualifiedName();
695 }
696 <LEFTPAREN> query = Query() <RIGHTPAREN>
697 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000698 stmt = new WriteFromQueryResultStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700699 }
700 ))
vinayakb38b7ca42012-03-05 05:44:15 +0000701 {
702 return stmt;
703 }
704}
705
vinayakb38b7ca42012-03-05 05:44:15 +0000706LoadFromFileStatement LoadStatement() throws ParseException:
707{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000708 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000709 Identifier datasetName = null;
710 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000711 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000712 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000713 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000714}
715{
Till Westmann31c21f92013-05-08 09:21:53 -0700716 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000717 {
Till Westmann31c21f92013-05-08 09:21:53 -0700718 dataverseName = nameComponents.first;
719 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000720 }
Till Westmann31c21f92013-05-08 09:21:53 -0700721 "using" adapterName = AdapterName() properties = Configuration()
722 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000723 {
Till Westmann31c21f92013-05-08 09:21:53 -0700724 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000725 }
726 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700727 {
728 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
729 }
vinayakb38b7ca42012-03-05 05:44:15 +0000730}
731
vinayakb38b7ca42012-03-05 05:44:15 +0000732
Till Westmann31c21f92013-05-08 09:21:53 -0700733String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000734{
ramangrover29669d8f62013-02-11 06:03:32 +0000735 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000736}
737{
Till Westmann68d99652013-05-09 11:15:21 -0700738 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000739 {
Till Westmann7d535322013-05-09 00:40:02 -0700740 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000741 }
vinayakb38b7ca42012-03-05 05:44:15 +0000742}
743
Till Westmann31c21f92013-05-08 09:21:53 -0700744Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000745{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000746 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700747 Map<String,String> configuration = null;
748 Statement stmt = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000749}
750{
Till Westmann31c21f92013-05-08 09:21:53 -0700751 (
752 "begin" "feed" nameComponents = QualifiedName()
753 {
754 stmt = new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter());
755 }
756 | "suspend" "feed" nameComponents = QualifiedName()
757 {
758 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, nameComponents.first, nameComponents.second);
759 }
760 | "resume" "feed" nameComponents = QualifiedName()
761 {
762 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, nameComponents.first, nameComponents.second);
763 }
764 | "end" "feed" nameComponents = QualifiedName()
765 {
766 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.END, nameComponents.first, nameComponents.second);
767 }
768 | "alter" "feed" nameComponents = QualifiedName() "set" configuration = Configuration()
769 {
770 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
771 }
772 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000773 {
Till Westmann31c21f92013-05-08 09:21:53 -0700774 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000775 }
776}
777
Till Westmann31c21f92013-05-08 09:21:53 -0700778Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000779{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000780 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700781 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000782}
783{
Till Westmann31c21f92013-05-08 09:21:53 -0700784 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000785 {
Till Westmann31c21f92013-05-08 09:21:53 -0700786 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000787 }
Till Westmann31c21f92013-05-08 09:21:53 -0700788 ( "," keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000789 {
Till Westmann31c21f92013-05-08 09:21:53 -0700790 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000791 }
Till Westmann31c21f92013-05-08 09:21:53 -0700792 )* )? <RIGHTPAREN>
793 {
794 return configuration;
795 }
796}
797
798Pair<String, String> KeyValuePair() throws ParseException:
799{
800 String key;
801 String value;
802}
803{
Till Westmann7d535322013-05-09 00:40:02 -0700804 <LEFTPAREN> key = StringLiteral() "=" value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700805 {
806 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000807 }
Till Westmann31c21f92013-05-08 09:21:53 -0700808}
809
810Map<String,String> Properties() throws ParseException:
811{
812 Map<String,String> properties = new HashMap<String,String>();
813 Pair<String, String> property;
814}
815{
816 ( <LEFTPAREN> property = Property()
817 {
818 properties.put(property.first, property.second);
819 }
820 ( "," property = Property()
821 {
822 properties.put(property.first, property.second);
823 }
824 )* <RIGHTPAREN> )?
825 {
826 return properties;
827 }
828}
829
830Pair<String, String> Property() throws ParseException:
831{
832 String key;
833 String value;
834}
835{
Till Westmann7d535322013-05-09 00:40:02 -0700836 key = Identifier() "=" ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700837 {
838 try {
839 value = "" + Long.valueOf(token.image);
840 } catch (NumberFormatException nfe) {
841 throw new ParseException("inapproriate value: " + token.image);
842 }
843 }
844 )
845 {
846 return new Pair<String, String>(key.toUpperCase(), value);
847 }
vinayakb38b7ca42012-03-05 05:44:15 +0000848}
849
850TypeExpression TypeExpr() throws ParseException:
851{
852 TypeExpression typeExpr = null;
853}
854{
855 (
856 typeExpr = RecordTypeDef()
857 | typeExpr = TypeReference()
858 | typeExpr = OrderedListTypeDef()
859 | typeExpr = UnorderedListTypeDef()
860 )
861 {
862 return typeExpr;
863 }
864}
865
866RecordTypeDefinition RecordTypeDef() throws ParseException:
867{
868 RecordTypeDefinition recType = new RecordTypeDefinition();
869 RecordTypeDefinition.RecordKind recordKind = null;
870}
871{
872 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
873 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
874 "{"
875 {
876 String hint = getHint(token);
877 if (hint != null) {
878 String splits[] = hint.split(" +");
879 if (splits[0].equals(GEN_FIELDS_HINT)) {
880 if (splits.length != 5) {
881 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
882 }
883 if (!splits[1].equals("int")) {
884 throw new ParseException("The only supported type for gen-fields is int.");
885 }
886 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
887 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
888 recType.setUndeclaredFieldsDataGen(ufdg);
889 }
890 }
891
892 }
893 (
894 RecordField(recType)
895 ( "," RecordField(recType) )*
896 )?
897 "}"
898 {
899 if (recordKind == null) {
900 recordKind = RecordTypeDefinition.RecordKind.OPEN;
901 }
902 recType.setRecordKind(recordKind);
903 return recType;
904 }
905}
906
907void RecordField(RecordTypeDefinition recType) throws ParseException:
908{
909 String fieldName;
910 TypeExpression type = null;
911 boolean nullable = false;
912}
913{
Till Westmann14a20a72013-05-09 00:06:24 -0700914 fieldName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000915 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700916 fieldName = token.image;
917 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +0000918 IRecordFieldDataGen rfdg = null;
919 if (hint != null) {
920 String splits[] = hint.split(" +");
921 if (splits[0].equals(VAL_FILE_HINT)) {
922 File[] valFiles = new File[splits.length - 1];
923 for (int k=1; k<splits.length; k++) {
924 valFiles[k-1] = new File(splits[k]);
925 }
926 rfdg = new FieldValFileDataGen(valFiles);
927 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
928 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
929 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
930 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
931 } else if (splits[0].equals(LIST_HINT)) {
932 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
933 } else if (splits[0].equals(INTERVAL_HINT)) {
934 FieldIntervalDataGen.ValueType vt;
935 if (splits[1].equals("int")) {
936 vt = FieldIntervalDataGen.ValueType.INT;
937 } else if (splits[1].equals("long")) {
938 vt = FieldIntervalDataGen.ValueType.LONG;
939 } else if (splits[1].equals("float")) {
940 vt = FieldIntervalDataGen.ValueType.FLOAT;
941 } else if (splits[1].equals("double")) {
942 vt = FieldIntervalDataGen.ValueType.DOUBLE;
943 } else {
944 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
945 }
946 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
947 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
948 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
949 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
950 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
951 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
952 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
953 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
954 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
955 } else if (splits[0].equals(AUTO_HINT)) {
956 rfdg = new AutoDataGen(splits[1]);
957 }
958 }
959 }
960 ":"
961 ( type = TypeExpr() )
962 ("?" { nullable = true; } )?
963 {
964 recType.addField(fieldName, type, nullable, rfdg);
965 }
966}
967
968TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000969{
Till Westmann14a20a72013-05-09 00:06:24 -0700970 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700971}
972{
973 id = Identifier()
974 {
Till Westmann14a20a72013-05-09 00:06:24 -0700975 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700976 }
vinayakb38b7ca42012-03-05 05:44:15 +0000977}
978
979OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
980{
981 TypeExpression type = null;
982}
983{
984 "["
985 ( type = TypeExpr() )
986 "]"
987 {
988 return new OrderedListTypeDefinition(type);
989 }
990}
991
992
993UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
994{
995 TypeExpression type = null;
996}
997{
998 "{{"
999 ( type = TypeExpr() )
1000 "}}"
1001 {
1002 return new UnorderedListTypeDefinition(type);
1003 }
1004}
1005
Till Westmann31c21f92013-05-08 09:21:53 -07001006
1007Pair<Identifier,Identifier> FunctionOrTypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001008{
Till Westmann31c21f92013-05-08 09:21:53 -07001009 Pair<Identifier,Identifier> name = null;
1010}
1011{
1012 name = QualifiedName()
1013 {
1014 if (name.first == null) {
1015 name.first = new Identifier(defaultDataverse);
1016 }
1017 return name;
1018 }
1019}
1020
Till Westmann14a20a72013-05-09 00:06:24 -07001021String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001022{
Till Westmann68d99652013-05-09 11:15:21 -07001023 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001024}
1025{
1026 <IDENTIFIER>
1027 {
Till Westmann14a20a72013-05-09 00:06:24 -07001028 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001029 }
Till Westmann68d99652013-05-09 11:15:21 -07001030 | lit = StringLiteral()
1031 {
1032 return lit;
1033 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001034}
1035
Till Westmann7d535322013-05-09 00:40:02 -07001036String StringLiteral() throws ParseException:
1037{
1038}
1039{
1040 <STRING_LITERAL>
1041 {
1042 return removeQuotesAndEscapes(token.image);
1043 }
1044}
1045
Till Westmann31c21f92013-05-08 09:21:53 -07001046Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1047{
Till Westmann14a20a72013-05-09 00:06:24 -07001048 String first = null;
1049 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001050}
1051{
Till Westmanna4242bc2013-05-08 17:49:55 -07001052 first = Identifier() ("." second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001053 {
Till Westmann14a20a72013-05-09 00:06:24 -07001054 Identifier id1 = null;
1055 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001056 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001057 id2 = new Identifier(first);
1058 } else
1059 {
1060 id1 = new Identifier(first);
1061 id2 = new Identifier(second);
1062 }
1063 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001064 }
1065}
1066
Till Westmann31c21f92013-05-08 09:21:53 -07001067Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001068{
Till Westmann14a20a72013-05-09 00:06:24 -07001069 String first = null;
1070 String second = null;
1071 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001072}
1073{
Till Westmanna4242bc2013-05-08 17:49:55 -07001074 first = Identifier() "." second = Identifier() ("." third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001075 {
Till Westmann14a20a72013-05-09 00:06:24 -07001076 Identifier id1 = null;
1077 Identifier id2 = null;
1078 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001079 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001080 id2 = new Identifier(first);
1081 id3 = new Identifier(second);
1082 } else {
1083 id1 = new Identifier(first);
1084 id2 = new Identifier(second);
1085 id3 = new Identifier(third);
1086 }
1087 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001088 }
1089}
1090
vinayakb38b7ca42012-03-05 05:44:15 +00001091FunctionDecl FunctionDeclaration() throws ParseException:
1092{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001093 FunctionDecl funcDecl;
1094 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001095 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001096 int arity = 0;
1097 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1098 Expression funcBody;
1099 VarIdentifier var = null;
1100 createNewScope();
1101}
1102{
Till Westmann14a20a72013-05-09 00:06:24 -07001103 "declare" "function" functionName = Identifier() <LEFTPAREN> (<VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001104 {
1105 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -07001106 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001107 paramList.add(var);
1108 getCurrentScope().addNewVarSymbolToScope(var);
1109 arity++;
1110 }
Till Westmann31c21f92013-05-08 09:21:53 -07001111 ("," <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001112 {
1113 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -07001114 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001115 paramList.add(var);
1116 getCurrentScope().addNewVarSymbolToScope(var);
1117 arity++;
Till Westmann31c21f92013-05-08 09:21:53 -07001118 }
1119 )*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
vinayakb38b7ca42012-03-05 05:44:15 +00001120 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001121 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1122 getCurrentScope().addFunctionDescriptor(signature, false);
1123 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001124 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001125 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001126 }
1127}
1128
vinayakb38b7ca42012-03-05 05:44:15 +00001129
Till Westmann31c21f92013-05-08 09:21:53 -07001130Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001131{
1132 Query query = new Query();
1133 Expression expr;
1134}
1135{
Till Westmann31c21f92013-05-08 09:21:53 -07001136 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001137 {
1138 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001139 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001140 return query;
1141 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001142
vinayakb38b7ca42012-03-05 05:44:15 +00001143}
1144
1145
1146
1147Expression Expression():
1148{
1149 Expression expr = null;
1150 Expression exprP = null;
1151}
1152{
1153(
1154
1155//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1156 expr = OperatorExpr()
1157 | expr = IfThenElse()
1158 | expr = FLWOGR()
1159 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001160
vinayakb38b7ca42012-03-05 05:44:15 +00001161
1162)
1163 {
1164 return (exprP==null) ? expr : exprP;
1165 }
1166}
1167
1168
1169
1170Expression OperatorExpr()throws ParseException:
1171{
1172 OperatorExpr op = null;
1173 Expression operand = null;
1174}
1175{
1176 operand = AndExpr()
1177 (
1178
1179 "or"
1180 {
1181 if (op == null) {
1182 op = new OperatorExpr();
1183 op.addOperand(operand);
1184 op.setCurrentop(true);
1185 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001186 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001187 }
1188
1189 operand = AndExpr()
1190 {
1191 op.addOperand(operand);
1192 }
1193
1194 )*
1195
1196 {
1197 return op==null? operand: op;
1198 }
1199}
1200
1201Expression AndExpr()throws ParseException:
1202{
1203 OperatorExpr op = null;
1204 Expression operand = null;
1205}
1206{
1207 operand = RelExpr()
1208 (
1209
1210 "and"
1211 {
1212 if (op == null) {
1213 op = new OperatorExpr();
1214 op.addOperand(operand);
1215 op.setCurrentop(true);
1216 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001217 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001218 }
1219
1220 operand = RelExpr()
1221 {
1222 op.addOperand(operand);
1223 }
1224
1225 )*
1226
1227 {
1228 return op==null? operand: op;
1229 }
1230}
1231
1232
1233
1234Expression RelExpr()throws ParseException:
1235{
1236 OperatorExpr op = null;
1237 Expression operand = null;
1238 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001239 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001240}
1241{
1242 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001243 {
1244 if (operand instanceof VariableExpr) {
1245 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001246 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001247 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001248 }
1249 }
1250 }
1251
1252 (
1253 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1254 {
alexander.behm07617fd2012-07-25 10:13:50 +00001255 String mhint = getHint(token);
1256 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1257 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1258 }
vinayakb38b7ca42012-03-05 05:44:15 +00001259 if (op == null) {
1260 op = new OperatorExpr();
1261 op.addOperand(operand, broadcast);
1262 op.setCurrentop(true);
1263 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001264 }
1265 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001266 }
1267
1268 operand = AddExpr()
1269 {
alexander.behm07617fd2012-07-25 10:13:50 +00001270 broadcast = false;
1271 if (operand instanceof VariableExpr) {
1272 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001273 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1274 broadcast = true;
1275 }
alexander.behm07617fd2012-07-25 10:13:50 +00001276 }
vinayakb38b7ca42012-03-05 05:44:15 +00001277 op.addOperand(operand, broadcast);
1278 }
1279 )?
1280
1281 {
alexander.behm07617fd2012-07-25 10:13:50 +00001282 if (annotation != null) {
1283 op.addHint(annotation);
1284 }
vinayakb38b7ca42012-03-05 05:44:15 +00001285 return op==null? operand: op;
1286 }
1287}
1288
1289Expression AddExpr()throws ParseException:
1290{
1291 OperatorExpr op = null;
1292 Expression operand = null;
1293}
1294{
1295 operand = MultExpr()
1296
1297 ( ("+" | "-")
1298 {
1299 if (op == null) {
1300 op = new OperatorExpr();
1301 op.addOperand(operand);
1302 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001303 }
1304 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001305 }
1306
1307 operand = MultExpr()
1308 {
1309 op.addOperand(operand);
1310 }
1311 )*
1312
1313 {
1314 return op==null? operand: op;
1315 }
1316}
1317
1318Expression MultExpr()throws ParseException:
1319{
1320 OperatorExpr op = null;
1321 Expression operand = null;
1322}
1323{
1324 operand = UnionExpr()
1325
1326 (( "*" | "/" | "%" | <CARET> | "idiv")
1327 {
1328 if (op == null) {
1329 op = new OperatorExpr();
1330 op.addOperand(operand);
1331 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001332 }
1333 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001334 }
1335 operand = UnionExpr()
1336 {
1337 op.addOperand(operand);
1338 }
1339 )*
1340
1341 {
1342 return op==null?operand:op;
1343 }
1344}
1345
1346Expression UnionExpr() throws ParseException:
1347{
1348 UnionExpr union = null;
1349 Expression operand1 = null;
1350 Expression operand2 = null;
1351}
1352{
1353 operand1 = UnaryExpr()
1354 ("union"
1355 (operand2 = UnaryExpr()) {
1356 if (union == null) {
1357 union = new UnionExpr();
1358 union.addExpr(operand1);
1359 }
1360 union.addExpr(operand2);
1361 } )*
1362 {
1363 return (union == null)? operand1: union;
1364 }
1365}
1366
1367Expression UnaryExpr() throws ParseException:
1368{
1369 Expression uexpr = null;
1370 Expression expr = null;
1371}
1372{
1373 (( "+"|"-")
1374 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001375 uexpr = new UnaryExpr();
1376 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001377 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001378 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001379 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1380 else
1381 throw new ParseException();
1382 }
1383 )?
1384
1385 expr = ValueExpr()
1386 {
1387 if(uexpr!=null){
1388 ((UnaryExpr)uexpr).setExpr(expr);
1389 return uexpr;
1390 }
1391 else{
1392 return expr;
1393 }
1394 }
1395}
1396
Till Westmann04478e72013-05-13 23:01:34 -07001397Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001398{
1399 Expression expr = null;
1400 Identifier ident = null;
1401 AbstractAccessor fa = null;
1402 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001403}
1404{
Till Westmann04478e72013-05-13 23:01:34 -07001405 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001406 {
Till Westmann04478e72013-05-13 23:01:34 -07001407 fa = (fa == null ? new FieldAccessor(expr, ident)
1408 : new FieldAccessor(fa, ident));
1409 }
1410 | index = Index()
1411 {
1412 fa = (fa == null ? new IndexAccessor(expr, index)
1413 : new IndexAccessor(fa, index));
1414 }
1415 )*
1416 {
1417 return fa == null ? expr : fa;
1418 }
vinayakb38b7ca42012-03-05 05:44:15 +00001419}
1420
1421Identifier Field() throws ParseException:
1422{
Till Westmann14a20a72013-05-09 00:06:24 -07001423 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001424}
1425{
Till Westmanna4242bc2013-05-08 17:49:55 -07001426 "." ident = Identifier()
1427 {
Till Westmann14a20a72013-05-09 00:06:24 -07001428 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001429 }
vinayakb38b7ca42012-03-05 05:44:15 +00001430}
1431
1432int Index() throws ParseException:
1433{
1434 Expression expr = null;
1435 int idx = -2;
1436}
1437{
1438 "[" ( expr = Expression()
1439 {
1440 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1441 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001442 Literal lit = ((LiteralExpr)expr).getValue();
1443 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1444 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001445 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001446 }
vinayakb38b7ca42012-03-05 05:44:15 +00001447 else {
1448 throw new ParseException("Index should be an INTEGER");
1449 }
1450 }
1451
1452 }
1453
1454 | "?"
1455 {
1456 idx = IndexAccessor.ANY;
1457 // ANY
1458 }
1459
1460 )
1461
1462 "]"
1463 {
1464 return idx;
1465 }
1466}
1467
1468
1469Expression PrimaryExpr()throws ParseException:
1470{
1471 Expression expr = null;
1472}
1473{
Till Westmann68d99652013-05-09 11:15:21 -07001474 ( LOOKAHEAD(2)
1475 expr = FunctionCallExpr()
1476 | expr = Literal()
1477 | expr = DatasetAccessExpression()
1478 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001479 {
1480 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001481 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001482 }
Till Westmann68d99652013-05-09 11:15:21 -07001483 | expr = ListConstructor()
1484 | expr = RecordConstructor()
1485 | expr = ParenthesizedExpression()
1486 )
1487 {
1488 return expr;
1489 }
vinayakb38b7ca42012-03-05 05:44:15 +00001490}
1491
1492Expression Literal() throws ParseException:
1493{
vinayakb38b7ca42012-03-05 05:44:15 +00001494 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001495 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001496}
1497{
Till Westmann7d535322013-05-09 00:40:02 -07001498 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001499 {
Till Westmann7d535322013-05-09 00:40:02 -07001500 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001501 }
1502 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001503 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001504 try {
1505 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1506 } catch(NumberFormatException ex) {
1507 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1508 }
1509 }
1510 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001511 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001512 lit.setValue(new FloatLiteral(new Float(token.image)));
1513 }
1514 | <DOUBLE_LITERAL>
1515 {
1516 lit.setValue(new DoubleLiteral(new Double(token.image)));
1517 }
1518 | <NULL>
1519 {
1520 lit.setValue(NullLiteral.INSTANCE);
1521 }
1522 | <TRUE>
1523 {
1524 lit.setValue(TrueLiteral.INSTANCE);
1525 }
1526 | <FALSE>
1527 {
1528 lit.setValue(FalseLiteral.INSTANCE);
1529 }
1530 )
vinayakb38b7ca42012-03-05 05:44:15 +00001531 {
1532 return lit;
1533 }
1534}
1535
1536
1537VariableExpr VariableRef() throws ParseException:
1538{
1539 VariableExpr varExp = new VariableExpr();
1540 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001541}
1542{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001543 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001544 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001545 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001546 Identifier ident = lookupSymbol(varName);
1547 if (isInForbiddenScopes(varName)) {
1548 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.");
1549 }
1550 if(ident != null) { // exist such ident
1551 varExp.setIsNewVar(false);
1552 varExp.setVar((VarIdentifier)ident);
1553 } else {
1554 varExp.setVar(var);
1555 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001556 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001557 return varExp;
1558 }
1559}
1560
1561
1562VariableExpr Variable() throws ParseException:
1563{
1564 VariableExpr varExp = new VariableExpr();
1565 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001566}
1567{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001568 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001569 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001570 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001571 if(ident != null) { // exist such ident
1572 varExp.setIsNewVar(false);
1573 }
1574 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001575 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001576 return varExp;
1577 }
1578}
1579
1580Expression ListConstructor() throws ParseException:
1581{
1582 Expression expr = null;
1583}
1584{
1585 (
1586 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1587 )
1588
1589 {
1590 return expr;
1591 }
1592}
1593
1594
1595ListConstructor OrderedListConstructor() throws ParseException:
1596{
1597 ListConstructor expr = new ListConstructor();
1598 Expression tmp = null;
1599 List<Expression> exprList = new ArrayList<Expression>();
1600 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1601}
1602{
1603
1604 "["
1605 ( tmp = Expression()
1606 {
1607 exprList.add(tmp);
1608 }
1609
1610 ("," tmp = Expression() { exprList.add(tmp); })*
1611 )?
1612
1613 "]"
1614
1615 {
1616 expr.setExprList(exprList);
1617 return expr;
1618 }
1619}
1620
1621ListConstructor UnorderedListConstructor() throws ParseException:
1622{
1623 ListConstructor expr = new ListConstructor();
1624 Expression tmp = null;
1625 List<Expression> exprList = new ArrayList<Expression>();
1626 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1627}
1628{
1629
1630 "{{" ( tmp = Expression()
1631 {
1632 exprList.add(tmp);
1633 }
1634 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1635 {
1636 expr.setExprList(exprList);
1637 return expr;
1638 }
1639}
1640
1641RecordConstructor RecordConstructor() throws ParseException:
1642{
1643 RecordConstructor expr = new RecordConstructor();
1644 FieldBinding tmp = null;
1645 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1646}
1647{
1648 "{" (tmp = FieldBinding()
1649 {
1650 fbList.add(tmp);
1651 }
1652 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
1653 {
1654 expr.setFbList(fbList);
1655 return expr;
1656 }
1657}
1658
1659FieldBinding FieldBinding() throws ParseException:
1660{
1661 FieldBinding fb = new FieldBinding();
1662 Expression left, right;
1663}
1664{
1665 left = Expression() ":" right = Expression()
1666 {
1667 fb.setLeftExpr(left);
1668 fb.setRightExpr(right);
1669 return fb;
1670 }
1671}
1672
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001673
vinayakb38b7ca42012-03-05 05:44:15 +00001674Expression FunctionCallExpr() throws ParseException:
1675{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001676 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001677 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001678 Expression tmp;
1679 int arity = 0;
Till Westmann31c21f92013-05-08 09:21:53 -07001680 Pair<Identifier,Identifier> funcId = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001681 String funcName;
1682 String dataverse;
Till Westmann31c21f92013-05-08 09:21:53 -07001683 String hint = null;
1684 String id1 = null;
1685 String id2 = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001686}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001687{
Till Westmann31c21f92013-05-08 09:21:53 -07001688 funcId = FunctionOrTypeName()
vinayakb38b7ca42012-03-05 05:44:15 +00001689 {
Till Westmann31c21f92013-05-08 09:21:53 -07001690 dataverse = funcId.first.getValue();
1691 funcName = funcId.second.getValue();
1692 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001693 }
Till Westmann31c21f92013-05-08 09:21:53 -07001694 <LEFTPAREN> (tmp = Expression()
1695 {
1696 argList.add(tmp);
1697 arity ++;
1698 }
1699 ("," tmp = Expression()
1700 {
1701 argList.add(tmp);
1702 arity++;
1703 }
1704 )*)? <RIGHTPAREN>
1705 {
1706 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity);
1707 if (signature == null) {
1708 signature = new FunctionSignature(dataverse, funcName, arity);
1709 }
1710 callExpr = new CallExpr(signature,argList);
1711 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1712 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1713 }
1714 return callExpr;
1715 }
vinayakb38b7ca42012-03-05 05:44:15 +00001716}
1717
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001718Expression DatasetAccessExpression() throws ParseException:
1719{
1720 CallExpr callExpr;
1721 List<Expression> argList = new ArrayList<Expression>();
1722 String funcName;
1723 String dataverse;
Till Westmann14a20a72013-05-09 00:06:24 -07001724 String arg1 = null;
1725 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001726 LiteralExpr ds;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001727 Expression nameArg;
1728 int arity = 0;
1729}
1730{
Till Westmann14a20a72013-05-09 00:06:24 -07001731 <DATASET>
1732 {
1733 dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1734 funcName = token.image;
1735 }
1736 ( ( arg1 = Identifier() ( "." arg2 = Identifier() )? )
1737 {
1738 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
1739 ds = new LiteralExpr();
1740 ds.setValue( new StringLiteral(name) );
1741 argList.add(ds);
1742 arity ++;
1743 }
1744 | ( <LEFTPAREN> nameArg = Expression()
1745 {
1746 argList.add(nameArg);
1747 arity ++;
1748 }
1749 ( "," nameArg = Expression()
1750 {
1751 argList.add(nameArg);
1752 arity++;
1753 }
1754 )* <RIGHTPAREN> ) )
1755 {
1756 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity);
1757 if (signature == null) {
1758 signature = new FunctionSignature(dataverse, funcName, arity);
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001759 }
Till Westmann14a20a72013-05-09 00:06:24 -07001760 callExpr = new CallExpr(signature,argList);
1761 return callExpr;
1762 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001763}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001764
vinayakb38b7ca42012-03-05 05:44:15 +00001765Expression ParenthesizedExpression() throws ParseException:
1766{
1767 Expression expr;
1768}
1769{
1770 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1771 {
1772 return expr;
1773 }
1774}
1775
1776Expression IfThenElse() throws ParseException:
1777{
1778 Expression condExpr;
1779 Expression thenExpr;
1780 Expression elseExpr;
1781 IfExpr ifExpr = new IfExpr();
1782}
1783{
1784 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
1785
1786 {
1787 ifExpr.setCondExpr(condExpr);
1788 ifExpr.setThenExpr(thenExpr);
1789 ifExpr.setElseExpr(elseExpr);
1790 return ifExpr;
1791 }
1792}
1793
1794Expression FLWOGR() throws ParseException:
1795{
1796 FLWOGRExpression flworg = new FLWOGRExpression();
1797 List<Clause> clauseList = new ArrayList<Clause>();
1798 Expression returnExpr;
1799 Clause tmp;
1800 createNewScope();
1801}
1802{
1803 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
1804 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
1805
1806 {
1807 flworg.setClauseList(clauseList);
1808 flworg.setReturnExpr(returnExpr);
1809 removeCurrentScope();
1810 return flworg;
1811 }
1812}
1813
1814Clause Clause()throws ParseException :
1815{
1816 Clause clause;
1817}
1818{
1819 (
1820 clause = ForClause()
1821 | clause = LetClause()
1822 | clause = WhereClause()
1823 | clause = OrderbyClause()
1824 | clause = GroupClause()
1825 | clause = LimitClause()
1826 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001827 )
1828 {
1829 return clause;
1830 }
1831}
1832
1833Clause ForClause()throws ParseException :
1834{
1835 ForClause fc = new ForClause();
1836 VariableExpr varExp;
1837 VariableExpr varPos = null;
1838 Expression inExp;
1839 extendCurrentScope();
1840}
1841{
1842 "for" varExp = Variable()
1843 {
1844 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
1845 }
1846 ("at" varPos = Variable()
1847 {
1848 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
1849 }
1850 )?
1851 "in" ( inExp = Expression() )
1852 {
1853 fc.setVarExpr(varExp);
1854 fc.setInExpr(inExp);
1855 if (varPos != null) {
1856 fc.setPosExpr(varPos);
1857 }
1858 return fc;
1859 }
1860}
1861
1862Clause LetClause() throws ParseException:
1863{
1864 LetClause lc = new LetClause();
1865 VariableExpr varExp;
1866 Expression beExp;
1867 extendCurrentScope();
1868}
1869{
ilovesoupb2527c12012-07-12 03:21:13 +00001870 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001871 {
1872 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001873 lc.setVarExpr(varExp);
1874 lc.setBeExpr(beExp);
1875 return lc;
1876 }
1877}
1878
1879Clause WhereClause()throws ParseException :
1880{
1881 WhereClause wc = new WhereClause();
1882 Expression whereExpr;
1883}
1884{
1885 "where" whereExpr = Expression()
1886 {
1887 wc.setWhereExpr(whereExpr);
1888 return wc;
1889 }
1890}
1891
1892Clause OrderbyClause()throws ParseException :
1893{
1894 OrderbyClause oc = new OrderbyClause();
1895 Expression orderbyExpr;
1896 List<Expression> orderbyList = new ArrayList<Expression>();
1897 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1898 int numOfOrderby = 0;
1899}
1900{
1901 (
1902 "order"
1903 {
1904 String hint = getHint(token);
1905 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1906 String splits[] = hint.split(" +");
1907 int numFrames = Integer.parseInt(splits[1]);
1908 int numTuples = Integer.parseInt(splits[2]);
1909 oc.setNumFrames(numFrames);
1910 oc.setNumTuples(numTuples);
1911 }
1912 }
1913 "by" orderbyExpr = Expression()
1914 {
1915 orderbyList.add(orderbyExpr);
1916 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1917 }
1918 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1919 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1920 {
1921 modifierList.add(modif);
1922 }
1923
1924 ("," orderbyExpr = Expression()
1925 {
1926 orderbyList.add(orderbyExpr);
1927 modif = OrderbyClause.OrderModifier.ASC;
1928 }
1929 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1930 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1931 {
1932 modifierList.add(modif);
1933 }
1934 )*
1935)
1936 {
1937 oc.setModifierList(modifierList);
1938 oc.setOrderbyList(orderbyList);
1939 return oc;
1940 }
1941}
1942Clause GroupClause()throws ParseException :
1943{
1944 GroupbyClause gbc = new GroupbyClause();
1945 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1946 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1947 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1948 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1949 VariableExpr var = null;
1950 VariableExpr withVar = null;
1951 Expression expr = null;
1952 VariableExpr decorVar = null;
1953 Expression decorExpr = null;
1954}
1955{
1956 {
1957 Scope newScope = extendCurrentScopeNoPush(true);
1958 // extendCurrentScope(true);
1959 }
1960 "group"
1961 {
1962 String hint = getHint(token);
1963 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1964 gbc.setHashGroupByHint(true);
1965 }
1966 }
1967 "by" (LOOKAHEAD(2) var = Variable()
1968 {
1969 newScope.addNewVarSymbolToScope(var.getVar());
1970 } ":=")?
1971 expr = Expression()
1972 {
1973 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1974 vePairList.add(pair1);
1975 }
1976 ("," ( LOOKAHEAD(2) var = Variable()
1977 {
1978 newScope.addNewVarSymbolToScope(var.getVar());
1979 } ":=")?
1980 expr = Expression()
1981 {
1982 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
1983 vePairList.add(pair2);
1984 }
1985 )*
1986 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
1987 {
1988 newScope.addNewVarSymbolToScope(decorVar.getVar());
1989 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
1990 decorPairList.add(pair3);
1991 }
1992 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
1993 {
1994 newScope.addNewVarSymbolToScope(decorVar.getVar());
1995 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
1996 decorPairList.add(pair4);
1997 }
1998 )*
1999 )?
2000 "with" withVar = VariableRef()
2001 {
2002 if(withVar.getIsNewVar()==true)
2003 throw new ParseException("can't find variable " + withVar.getVar());
2004 withVarList.add(withVar);
2005 newScope.addNewVarSymbolToScope(withVar.getVar());
2006 }
2007 ("," withVar = VariableRef()
2008 {
2009 if(withVar.getIsNewVar()==true)
2010 throw new ParseException("can't find variable " + withVar.getVar());
2011 withVarList.add(withVar);
2012 newScope.addNewVarSymbolToScope(withVar.getVar());
2013 })*
2014 {
2015 gbc.setGbyPairList(vePairList);
2016 gbc.setDecorPairList(decorPairList);
2017 gbc.setWithVarList(withVarList);
2018 replaceCurrentScope(newScope);
2019 return gbc;
2020 }
2021}
2022
2023
2024LimitClause LimitClause() throws ParseException:
2025{
2026 LimitClause lc = new LimitClause();
2027 Expression expr;
2028 pushForbiddenScope(getCurrentScope());
2029}
2030{
2031 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2032 ("offset" expr = Expression() { lc.setOffset(expr); })?
2033
2034 {
2035 popForbiddenScope();
2036 return lc;
2037 }
2038}
2039
2040DistinctClause DistinctClause() throws ParseException:
2041{
2042 List<Expression> exprs = new ArrayList<Expression>();
2043 Expression expr;
2044}
2045{
2046 "distinct" "by" expr = Expression()
2047 {
2048 exprs.add(expr);
2049 }
2050 ("," expr = Expression()
2051 {
2052 exprs.add(expr);
2053 }
2054 )*
2055 {
2056 return new DistinctClause(exprs);
2057 }
2058}
2059
vinayakb38b7ca42012-03-05 05:44:15 +00002060QuantifiedExpression QuantifiedExpression()throws ParseException:
2061{
2062 QuantifiedExpression qc = new QuantifiedExpression();
2063 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2064 Expression satisfiesExpr;
2065 VariableExpr var;
2066 Expression inExpr;
2067 QuantifiedPair pair;
2068}
2069{
2070 {
2071 createNewScope();
2072 }
2073
2074 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2075 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2076 var = Variable() "in" inExpr = Expression()
2077 {
2078 pair = new QuantifiedPair(var, inExpr);
2079 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2080 quantifiedList.add(pair);
2081 }
2082 (
2083 "," var = Variable() "in" inExpr = Expression()
2084 {
2085 pair = new QuantifiedPair(var, inExpr);
2086 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2087 quantifiedList.add(pair);
2088 }
2089 )*
2090 "satisfies" satisfiesExpr = Expression()
2091 {
2092 qc.setSatisfiesExpr(satisfiesExpr);
2093 qc.setQuantifiedList(quantifiedList);
2094 removeCurrentScope();
2095 return qc;
2096 }
2097}
2098
2099TOKEN_MGR_DECLS:
2100{
2101 public int commentDepth = 0;
2102}
2103
2104<DEFAULT>
2105TOKEN :
2106{
2107 <CARET : "^" >
2108}
2109
2110<DEFAULT>
2111TOKEN :
2112{
2113 <DATASET : "dataset" >
2114}
2115
2116<DEFAULT>
2117TOKEN :
2118{
2119 <LEFTPAREN : "(" >
2120}
2121
2122<DEFAULT>
2123TOKEN :
2124{
2125 <RIGHTPAREN : ")" >
2126}
2127
2128
2129<DEFAULT>
2130TOKEN :
2131{
2132 <INTEGER_LITERAL : (<DIGIT>)+ >
2133}
2134
2135
2136<DEFAULT>
2137TOKEN :
2138{
2139 <NULL : "null">
2140}
2141
2142<DEFAULT>
2143TOKEN :
2144{
2145 <TRUE : "true">
2146}
2147
2148<DEFAULT>
2149TOKEN :
2150{
2151 <FALSE : "false">
2152}
2153
2154<DEFAULT>
2155TOKEN :
2156{
2157 <#DIGIT : ["0" - "9"]>
2158}
2159
2160
2161TOKEN:
2162{
2163 < DOUBLE_LITERAL: <INTEGER>
2164 | <INTEGER> ( "." <INTEGER> )?
2165 | "." <INTEGER>
2166 >
2167 |
2168 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2169 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2170 | "." <INTEGER> ( "f" | "F" )
2171 >
2172 |
2173 <INTEGER : (<DIGIT>)+ >
2174}
2175
2176<DEFAULT>
2177TOKEN :
2178{
2179 <#LETTER : ["A" - "Z", "a" - "z"]>
2180}
2181
2182<DEFAULT>
2183TOKEN :
2184{
2185 <SPECIALCHARS : ["$", "_", "-"] >
2186}
2187
2188<DEFAULT>
2189TOKEN :
2190{
2191 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2192 |
2193 < #EscapeQuot: "\\\"" >
2194 |
2195 < #EscapeApos: "\\\'" >
2196}
2197
2198<DEFAULT>
2199TOKEN :
2200{
2201 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2202}
2203
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002204
vinayakb38b7ca42012-03-05 05:44:15 +00002205<DEFAULT>
2206TOKEN :
2207{
Till Westmann4f58e1a2013-05-20 18:29:54 -07002208 <VARIABLE : "$" (<LETTER>)+ (<LETTER> | <DIGIT> | "_")* >
vinayakb38b7ca42012-03-05 05:44:15 +00002209}
2210
2211SKIP:
2212{
2213 " "
2214| "\t"
2215| "\r"
2216| "\n"
2217}
2218
2219SKIP:
2220{
2221 <"//" (~["\n"])* "\n">
2222}
2223
2224SKIP:
2225{
2226 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2227}
2228
2229
2230SKIP:
2231{
2232 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2233}
2234
2235<INSIDE_COMMENT>
2236SPECIAL_TOKEN:
2237{
2238 <"+"(" ")*(~["*"])*>
2239}
2240
2241<INSIDE_COMMENT>
2242SKIP:
2243{
2244 <"/*"> {commentDepth++;}
2245}
2246
2247<INSIDE_COMMENT>
2248SKIP:
2249{
2250 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2251| <~[]>
2252}