blob: e296266261ecd14ccfbb6e8fb52f2734eec5c5b4 [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";
77
78 private static String getHint(Token t) {
79 if (t.specialToken == null) {
80 return null;
81 }
82 String s = t.specialToken.image;
83 int n = s.length();
84 if (n < 2) {
85 return null;
86 }
87 return s.substring(1).trim();
88 }
89
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000090 public AQLParser(String s){
91 this(new StringReader(s));
92 super.setInput(s);
93 }
94
vinayakb38b7ca42012-03-05 05:44:15 +000095 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
96 File file = new File(args[0]);
97 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
98 AQLParser parser = new AQLParser(fis);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000099 List<Statement> st = parser.Statement();
100 //st.accept(new AQLPrintVisitor(), 0);
vinayakb38b7ca42012-03-05 05:44:15 +0000101 }
102
103
104}
105
106PARSER_END(AQLParser)
107
108
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000109List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000110{
vinayakb38b7ca42012-03-05 05:44:15 +0000111 scopeStack.push(RootScopeFactory.createRootScope(this));
112 List<Statement> decls = new ArrayList<Statement>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000113 Query query=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000114}
115{
116 (
117 (
118 (
119 "use"
120 {
121 decls.add(DataverseDeclaration());
122 }
123 | "declare" "function" {
124 decls.add(FunctionDeclaration());
125 }
126 | "create" (
127 {
128 String hint = getHint(token);
129 boolean dgen = false;
130 if (hint != null && hint.startsWith(DGEN_HINT)) {
131 dgen = true;
132 }
133 }
134 "type"
135 {
136 decls.add(TypeDeclaration(dgen, hint));
137 }
138 | "nodegroup"
139 {
140 decls.add(NodegroupDeclaration());
141 }
142 | "external" <DATASET>
143 {
144 decls.add(DatasetDeclaration(DatasetType.EXTERNAL));
145 }
146 | "feed" <DATASET>
147 {
148 decls.add(DatasetDeclaration(DatasetType.FEED));
149 }
150 | <DATASET>
151 {
152 decls.add(DatasetDeclaration(DatasetType.INTERNAL));
153 }
154 | "index"
155 {
156 decls.add(CreateIndexStatement());
157 }
158 | "dataverse"
159 {
160 decls.add(CreateDataverseStatement());
161 }
162 | "function"
163 {
164 decls.add(FunctionCreation());
165 }
166 )
167 | "load" {
168 decls.add(LoadStatement());
169 }
170
171 | "drop"
172 (
173 <DATASET>
174 {
175 decls.add(DropStatement());
176 }
177 | "index"
178 {
179 decls.add(IndexDropStatement());
180 }
181 | "nodegroup"
182 {
183 decls.add(NodeGroupDropStatement());
184 }
185 | "type"
186 {
187 decls.add(TypeDropStatement());
188 }
189 | "dataverse"
190 {
191 decls.add(DataverseDropStatement());
192 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000193 | "function"
194 {
195 decls.add(FunctionDropStatement());
196 }
vinayakb38b7ca42012-03-05 05:44:15 +0000197 )
198 | "write" {
199 decls.add(WriteStatement());
200 }
201 | "set" {
202 decls.add(SetStatement());
203 }
204 | "insert" {
205 decls.add(InsertStatement());
206 }
207 | "delete" {
208 decls.add(DeleteStatement());
209 }
210 | "update" {
211 decls.add(UpdateStatement());
212 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000213 | "begin" "feed"
214 {
215 Pair<Identifier,Identifier> nameComponents = getDotSeparatedPair();
216 decls.add(new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter()));
217 } ";"
218
219 | "suspend" "feed"
220 {
221 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.SUSPEND));
222 } ";"
223 | "resume" "feed" {
224 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.RESUME));
vinayakb38b7ca42012-03-05 05:44:15 +0000225 } ";"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000226 | "end" "feed" {
227 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.END));
vinayakb38b7ca42012-03-05 05:44:15 +0000228 } ";"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000229 | "alter" "feed" {
230 decls.add(AlterFeedDeclaration());
231 } ";"
232
233 | (query = Query()) {
234 decls.add(query);
235 }
236 )*
237 // (query = Query())?
vinayakb38b7ca42012-03-05 05:44:15 +0000238 )
239
240 <EOF>
241 )
242 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000243 return decls;
vinayakb38b7ca42012-03-05 05:44:15 +0000244 }
245}
246
247InsertStatement InsertStatement() throws ParseException:
248{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000249 Identifier dataverseName;
vinayakb38b7ca42012-03-05 05:44:15 +0000250 Identifier datasetName;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000251 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000252 Query query;
253}
254{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000255 "into" <DATASET>
256
257 {
258 nameComponents = getDotSeparatedPair();
259 dataverseName = nameComponents.first;
260 datasetName = nameComponents.second;
261 }
262
263 <LEFTPAREN> query = Query() <RIGHTPAREN> ";"
264 {return new InsertStatement(dataverseName, datasetName, query, getVarCounter());}
vinayakb38b7ca42012-03-05 05:44:15 +0000265}
266
267DeleteStatement DeleteStatement() throws ParseException:
268{
269 VariableExpr var = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000270 Identifier dataverseName;
vinayakb38b7ca42012-03-05 05:44:15 +0000271 Identifier datasetName = null;
272 Expression condition = null;
273 Clause dieClause = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000274 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000275}
276{
277 var = Variable() { getCurrentScope().addNewVarSymbolToScope(var.getVar()); }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000278 "from"
279 <DATASET>
280 {
281 nameComponents = getDotSeparatedPair();
282 }
283 ("where" condition = Expression())? (dieClause = DieClause())? ";"
284 {return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, dieClause, getVarCounter()); }
vinayakb38b7ca42012-03-05 05:44:15 +0000285}
286
287UpdateStatement UpdateStatement() throws ParseException:
288{
289 VariableExpr vars;
290 Expression target;
291 Expression condition;
292 UpdateClause uc;
293 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
294}
295{
296 vars = Variable() "in" target = Expression()
297 "where" condition = Expression()
298 <LEFTPAREN> (uc=UpdateClause() {ucs.add(uc); } ("," uc=UpdateClause() {ucs.add(uc); } )*) <RIGHTPAREN> ";"
299 {return new UpdateStatement(vars, target, condition, ucs);}
300}
301
302
303
304UpdateClause UpdateClause() throws ParseException:
305{
306 Expression target = null;
307 Expression value = null ;
308 InsertStatement is = null;
309 DeleteStatement ds = null;
310 UpdateStatement us = null;
311 Expression condition = null;
312 UpdateClause ifbranch = null;
313 UpdateClause elsebranch = null;
314}
315{
316 "set" target = Expression() ":=" value = Expression()
317 | "insert" is = InsertStatement()
318 | "delete" ds = DeleteStatement()
319 | "update" us = UpdateStatement()
320 | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN> "then" ifbranch = UpdateClause() [LOOKAHEAD(1) "else" elsebranch = UpdateClause()]
321 {return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);}
322}
323
324
325Statement SetStatement() throws ParseException:
326{
327 String pn = null;
328 Statement stmt = null;
329}
330{
331 <IDENTIFIER> { pn = token.image; }
332 <STRING_LITERAL>
333 { String pv = removeQuotesAndEscapes(token.image); }
334 ";"
335 {
336 return new SetStatement(pn, pv);
337 }
338}
339
340Statement WriteStatement() throws ParseException:
341{
342 Identifier nodeName = null;
343 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000344 Statement stmt = null;
345 Query query;
346 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000347 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000348}
349{
350 (( "output" "to"
351 <IDENTIFIER> { nodeName = new Identifier(token.image); }
352 ":" <STRING_LITERAL> { fileName = removeQuotesAndEscapes(token.image); }
353 ( "using" <STRING_LITERAL> { writerClass = removeQuotesAndEscapes(token.image); } )?
354 {
355 stmt = new WriteStatement(nodeName, fileName, writerClass);
356 } )
357 |
358 ( "into"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000359 <DATASET>
360
361 {
362 nameComponents = getDotSeparatedPair();
363 }
364
vinayakb38b7ca42012-03-05 05:44:15 +0000365 <LEFTPAREN> query = Query() <RIGHTPAREN>
366 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000367 stmt = new WriteFromQueryResultStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +0000368 } ))
369
370 ";"
371 {
372 return stmt;
373 }
374}
375
376CreateIndexStatement CreateIndexStatement() throws ParseException:
377{
378 CreateIndexStatement cis = new CreateIndexStatement();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000379 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000380}
381{
382 <IDENTIFIER> { cis.setIndexName(new Identifier(token.image)); }
383 (
384 "if not exists"
385 {
386 cis.setIfNotExists(true);
387 }
388 )?
389 "on"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000390
391 {
392 nameComponents = getDotSeparatedPair();
393 cis.setDataverseName(nameComponents.first);
394 cis.setDatasetName(nameComponents.second);
395 }
396
vinayakb38b7ca42012-03-05 05:44:15 +0000397 <LEFTPAREN>
398 ( <IDENTIFIER> { cis.addFieldExpr(token.image); } )
399 ("," <IDENTIFIER> { cis.addFieldExpr(token.image); })*
400 <RIGHTPAREN>
401 ("type"
402 ("btree" { cis.setIndexType(IndexType.BTREE); }
alexander.behmc576c602012-07-06 02:41:15 +0000403 | "keyword" { cis.setIndexType(IndexType.WORD_INVIX); }
404 | "rtree" { cis.setIndexType(IndexType.RTREE); }
405 | "ngram"
406 <LEFTPAREN>
407 (<INTEGER_LITERAL>
408 {
409 cis.setIndexType(IndexType.NGRAM_INVIX);
410 cis.setGramLength(Integer.valueOf(token.image));
411 }
412 )
413 <RIGHTPAREN>
414 )
vinayakb38b7ca42012-03-05 05:44:15 +0000415 ";"
416 | ";"
417 )
418 {
419 return cis;
420 }
421}
422
423DataverseDecl DataverseDeclaration() throws ParseException:
424{
425 Identifier dvName = null;
426}
427{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000428 "dataverse" <IDENTIFIER> { defaultDataverse = token.image;}
vinayakb38b7ca42012-03-05 05:44:15 +0000429 ";"
430 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000431 return new DataverseDecl(new Identifier(defaultDataverse));
vinayakb38b7ca42012-03-05 05:44:15 +0000432 }
433}
434
435DropStatement DropStatement() throws ParseException :
436{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000437 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000438 Identifier datasetName = null;
439 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000440 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000441}
442{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000443 {
444 nameComponents = getDotSeparatedPair();
445 dataverseName = nameComponents.first;
446 datasetName = nameComponents.second;
447 }
448
449
vinayakb38b7ca42012-03-05 05:44:15 +0000450 (
451 "if exists"
452 {
453 ifExists = true;
454 }
455 )? ";"
456 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000457 return new DropStatement(dataverseName, datasetName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000458 }
459}
460
461IndexDropStatement IndexDropStatement() throws ParseException :
462{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000463 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000464 Identifier datasetName = null;
465 Identifier indexName = null;
466 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000467 Triple<Identifier,Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000468}
469{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000470
vinayakb38b7ca42012-03-05 05:44:15 +0000471 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000472 nameComponents = getDotSeparatedTriple();
473 dataverseName = nameComponents.first;
474 datasetName = nameComponents.second;
475 indexName = nameComponents.third;
476 }
477
vinayakb38b7ca42012-03-05 05:44:15 +0000478 (
479 "if exists"
480 {
481 ifExists = true;
482 }
483 )? ";"
484 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000485 return new IndexDropStatement(dataverseName, datasetName, indexName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000486 }
487}
488
489NodeGroupDropStatement NodeGroupDropStatement() throws ParseException :
490{
491 Identifier groupName = null;
492 boolean ifExists = false;
493}
494{
495 < IDENTIFIER >
496 {
497 groupName = new Identifier(token.image);
498 }
499 (
500 "if exists"
501 {
502 ifExists = true;
503 }
504 )? ";"
505 {
506 return new NodeGroupDropStatement(groupName, ifExists);
507 }
508}
509
510TypeDropStatement TypeDropStatement() throws ParseException :
511{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000512 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000513 Identifier typeName = null;
514 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000515 Pair<Identifier,Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000516}
517{
vinayakb38b7ca42012-03-05 05:44:15 +0000518 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000519 nameComponents = getDotSeparatedPair();
520 dataverseName = nameComponents.first == null ? new Identifier(defaultDataverse) : nameComponents.first;
521 typeName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000522 }
523 (
524 "if exists"
525 {
526 ifExists = true;
527 }
528 )? ";"
529 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000530 return new TypeDropStatement(dataverseName, typeName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000531 }
532}
533
534DataverseDropStatement DataverseDropStatement() throws ParseException :
535{
536 Identifier dataverseName = null;
537 boolean ifExists = false;
538}
539{
540 < IDENTIFIER >
541 {
542 dataverseName = new Identifier(token.image);
543 }
544 (
545 "if exists"
546 {
547 ifExists = true;
548 }
549 )? ";"
550 {
551 return new DataverseDropStatement(dataverseName, ifExists);
552 }
553}
554
555CreateDataverseStatement CreateDataverseStatement() throws ParseException :
556{
557 Identifier dvName = null;
558 boolean ifNotExists = false;
559 String format = null;
560}
561{
562 < IDENTIFIER >
563 {
564 dvName = new Identifier(token.image);
565 }
566 (
567 "if not exists"
568 {
569 ifNotExists = true;
570 }
571 )?
572 (
573 "with format" < STRING_LITERAL >
574 {
575 format = removeQuotesAndEscapes(token.image);
576 }
577 )?
578 ";"
579 {
580 return new CreateDataverseStatement(dvName, format, ifNotExists);
581 }
582}
583
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000584
585FunctionDropStatement FunctionDropStatement() throws ParseException :
586{
587 String dataverse;
588 String functionName;
589 int arity=0;
590 boolean ifExists = false;
591 Pair<Identifier, Identifier> nameComponents=null;
592}
593{
594 {
595 nameComponents = getDotSeparatedPair();
596 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
597 functionName = nameComponents.second.getValue();
598 }
599
600 "@"
601 <INTEGER_LITERAL>
602 {
603 Token t= getToken(0);
604 arity = new Integer(t.image);
605 if( arity < 0 && arity != FunctionIdentifier.VARARGS){
606 throw new ParseException(" invalid arity:" + arity);
607 }
608 }
609
610 (
611 "if exists"
612 {
613 ifExists = true;
614 }
615 )? ";"
616 {
617 return new FunctionDropStatement(new FunctionSignature(dataverse, functionName, arity), ifExists);
618 }
619}
620
621
vinayakb38b7ca42012-03-05 05:44:15 +0000622LoadFromFileStatement LoadStatement() throws ParseException:
623{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000624 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000625 Identifier datasetName = null;
626 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000627 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000628 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000629 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000630}
631{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000632 <DATASET>
633 {
634 nameComponents = getDotSeparatedPair();
635 dataverseName = nameComponents.first;
636 datasetName = nameComponents.second;
637 }
638
vinayakb38b7ca42012-03-05 05:44:15 +0000639 "using"
ramangrover29669d8f62013-02-11 06:03:32 +0000640
vinayakb38b7ca42012-03-05 05:44:15 +0000641 {
ramangrover29669d8f62013-02-11 06:03:32 +0000642 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000643 }
ramangrover29669d8f62013-02-11 06:03:32 +0000644
vinayakb38b7ca42012-03-05 05:44:15 +0000645 {
646 properties = getConfiguration();
647 }
648
649 ("pre-sorted"
650 { alreadySorted = true; }
651 )?
652
653 ";"
654 {
ramangrover29669d8f62013-02-11 06:03:32 +0000655 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
vinayakb38b7ca42012-03-05 05:44:15 +0000656 }
657}
658
659
ramangrover29669d8f62013-02-11 06:03:32 +0000660String getAdapterName() throws ParseException :
661{
662 String adapterName = null;
663}
664{
665 (
666 <IDENTIFIER> {
667 adapterName = (new Identifier(token.image)).getValue();;
668 }
669 |
670 <STRING_LITERAL>
671 {
672 adapterName = removeQuotesAndEscapes(token.image);
673 }
674 )
675 {
676 return adapterName;
677 }
678}
679
vinayakb38b7ca42012-03-05 05:44:15 +0000680
681DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException :
682{
683 DatasetDecl dd = null;
684 Identifier datasetName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000685 Identifier dataverseName = null;
686 Identifier itemDataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000687 Identifier itemTypeName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000688 String nameComponentFirst = null;
689 String nameComponentSecond = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000690 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000691 IDatasetDetailsDecl datasetDetails = null;
ramangrover2971e5c6a2013-01-30 05:30:12 +0000692 Pair<Identifier,Identifier> nameComponents = null;
693 Map<String,String> hints = new HashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000694}
695{
vinayakb38b7ca42012-03-05 05:44:15 +0000696 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000697 nameComponents = getDotSeparatedPair();
698 dataverseName = nameComponents.first;
699 datasetName = nameComponents.second;
700 }
701
vinayakb38b7ca42012-03-05 05:44:15 +0000702 (
703 "if not exists"
704 {
705 ifNotExists = true;
706 }
707 )?
708 (
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000709 < LEFTPAREN > <IDENTIFIER>
vinayakb38b7ca42012-03-05 05:44:15 +0000710 {
711 itemTypeName = new Identifier(token.image);
712 }
713 < RIGHTPAREN >
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +0000714 )
vinayakb38b7ca42012-03-05 05:44:15 +0000715 {
716 if(datasetType == DatasetType.INTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000717 datasetDetails = InternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000718 }
719 else if(datasetType == DatasetType.EXTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000720 datasetDetails = ExternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000721 }
722 else if(datasetType == DatasetType.FEED) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000723 datasetDetails = FeedDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000724 }
vinayakb38b7ca42012-03-05 05:44:15 +0000725 }
ramangrover2971e5c6a2013-01-30 05:30:12 +0000726
727 (
728 "hints"
vinayakb38b7ca42012-03-05 05:44:15 +0000729 {
ramangrover2971e5c6a2013-01-30 05:30:12 +0000730 initProperties(hints);
731 }
732 )?
733 ";"
734
735 {
736 dd = new DatasetDecl(dataverseName, datasetName, itemTypeName, hints, datasetType, datasetDetails,ifNotExists);
737 return dd;
vinayakb38b7ca42012-03-05 05:44:15 +0000738 }
739}
740
741InternalDetailsDecl InternalDatasetDeclaration() throws ParseException :
742{
743 InternalDetailsDecl idd = null;
ramangrover292f199b02013-02-13 05:32:01 +0000744 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000745 Identifier nodeGroupName=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000746}
747{
vinayakb38b7ca42012-03-05 05:44:15 +0000748 (
vinayakb38b7ca42012-03-05 05:44:15 +0000749 {
ramangrover292f199b02013-02-13 05:32:01 +0000750 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000751 }
ramangrover29669d8f62013-02-11 06:03:32 +0000752 )
753
vinayakb38b7ca42012-03-05 05:44:15 +0000754 (
755 "on" < IDENTIFIER >
756 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000757 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000758 }
759 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000760
vinayakb38b7ca42012-03-05 05:44:15 +0000761 {
ramangrover292f199b02013-02-13 05:32:01 +0000762 idd = new InternalDetailsDecl(nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000763 return idd;
764 }
765}
766
767ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException :
768{
769 ExternalDetailsDecl edd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000770 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000771 Map < String, String > properties;
772}
773{
774 {
775 edd = new ExternalDetailsDecl();
776 }
777
778 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000779 {
ramangrover29669d8f62013-02-11 06:03:32 +0000780 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000781 }
782
783 {
784 properties = getConfiguration();
785 }
786
787 {
788 edd = new ExternalDetailsDecl();
ramangrover29669d8f62013-02-11 06:03:32 +0000789 edd.setAdapter(adapterName);
vinayakb38b7ca42012-03-05 05:44:15 +0000790 edd.setProperties(properties);
791 }
vinayakb38b7ca42012-03-05 05:44:15 +0000792
793 {
794 return edd;
795 }
796}
797
798FeedDetailsDecl FeedDatasetDeclaration() throws ParseException :
799{
800 FeedDetailsDecl fdd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000801 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000802 Map < String, String > properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000803 Pair<Identifier,Identifier> nameComponents;
ramangrover292f199b02013-02-13 05:32:01 +0000804 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000805 Identifier nodeGroupName=null;
806 FunctionSignature appliedFunction=null;
807 String dataverse;
808 String functionName;
809 int arity;
vinayakb38b7ca42012-03-05 05:44:15 +0000810}
811{
vinayakb38b7ca42012-03-05 05:44:15 +0000812 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000813 {
ramangrover29669d8f62013-02-11 06:03:32 +0000814 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000815 }
816
817 {
818 properties = getConfiguration();
819 }
820
821 ("apply" "function"
vinayakb38b7ca42012-03-05 05:44:15 +0000822 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000823 nameComponents = getDotSeparatedPair();
824 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
825 functionName = nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +0000826 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000827 ("@" <INTEGER_LITERAL>
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000828 {
829 arity = Integer.parseInt(token.image);
830 }
831 )
832
833 {
834 appliedFunction = new FunctionSignature(dataverse, functionName, arity);
835 }
vinayakb38b7ca42012-03-05 05:44:15 +0000836 )?
837
vinayakb38b7ca42012-03-05 05:44:15 +0000838 (
vinayakb38b7ca42012-03-05 05:44:15 +0000839 {
ramangrover292f199b02013-02-13 05:32:01 +0000840 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000841 }
ramangrover29669d8f62013-02-11 06:03:32 +0000842 )
843
vinayakb38b7ca42012-03-05 05:44:15 +0000844 (
845 "on" < IDENTIFIER >
846 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000847 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000848 }
849 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000850
vinayakb38b7ca42012-03-05 05:44:15 +0000851 {
ramangrover292f199b02013-02-13 05:32:01 +0000852 fdd = new FeedDetailsDecl(adapterName, properties, appliedFunction, nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000853 return fdd;
854 }
855}
856
ramangrover292f199b02013-02-13 05:32:01 +0000857List<String> getPrimaryKeyFields() throws ParseException :
ramangrover29669d8f62013-02-11 06:03:32 +0000858{
ramangrover292f199b02013-02-13 05:32:01 +0000859 List<String> primaryKeyFields = new ArrayList<String>();
ramangrover29669d8f62013-02-11 06:03:32 +0000860}
861{
862
863 "primary" "key"
864 < IDENTIFIER >
865 {
ramangrover292f199b02013-02-13 05:32:01 +0000866 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000867 }
868 (
869 "," < IDENTIFIER >
870 {
ramangrover292f199b02013-02-13 05:32:01 +0000871 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000872 }
873 )*
874 {
ramangrover292f199b02013-02-13 05:32:01 +0000875 return primaryKeyFields;
ramangrover29669d8f62013-02-11 06:03:32 +0000876 }
877
878}
879
880
881
882
883
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000884ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000885{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000886 Pair<Identifier,Identifier> nameComponents = null;
887}
888{
889 {
890 nameComponents = getDotSeparatedPair();
891 return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second);
892 }
893}
894
895
896ControlFeedStatement AlterFeedDeclaration() throws ParseException :
897{
898 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000899 Map < String, String > configuration = new HashMap < String, String > ();
900}
901{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000902 {
903 nameComponents = getDotSeparatedPair();
904 }
905
vinayakb38b7ca42012-03-05 05:44:15 +0000906 "set"
907 {
908 configuration = getConfiguration();
909 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000910
vinayakb38b7ca42012-03-05 05:44:15 +0000911 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000912 return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
vinayakb38b7ca42012-03-05 05:44:15 +0000913 }
914}
915
916Map<String,String> getConfiguration() throws ParseException :
917{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000918 Map<String,String> configuration = new LinkedHashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000919 String key;
920 String value;
921}
922{
923
924<LEFTPAREN>
925 (
926 (
927 <LEFTPAREN>
928 (
929 <STRING_LITERAL>
930 {
931 key = removeQuotesAndEscapes(token.image);
932 }
933 "=" <STRING_LITERAL>
934 {
935 value = removeQuotesAndEscapes(token.image);
936 }
937 )
938 <RIGHTPAREN>
939 {
940 configuration.put(key, value);
941 }
942 )
943 (
944 "," <LEFTPAREN>
945 (
946 <STRING_LITERAL>
947 {
948 key = removeQuotesAndEscapes(token.image);
949 }
950 "=" <STRING_LITERAL>
951 {
952 value = removeQuotesAndEscapes(token.image);
953 }
954 )
955 <RIGHTPAREN>
956 {
957 configuration.put(key, value);
958 }
959 )*
960 )?
961 <RIGHTPAREN>
962 {
963 return configuration;
964 }
965}
966
ramangrover2971e5c6a2013-01-30 05:30:12 +0000967void initProperties(Map<String,String> properties) throws ParseException :
968{
969 String key;
970 String value;
971}
972{
973 (
974 <LEFTPAREN>
975 (
976 <IDENTIFIER>
977 {
978 key = (new Identifier(token.image)).getValue();
979 }
980 "="
981 (
982 (<STRING_LITERAL>
983 {
984 value = removeQuotesAndEscapes(token.image);
985 }
986 ) |
987 (<INTEGER_LITERAL>
988 {
989 try{
ramangrover2921b88182013-01-31 00:51:19 +0000990 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +0000991 } catch (NumberFormatException nfe){
992 throw new ParseException("inapproriate value: " + token.image);
993 }
994 }
995 )
996 )
997 {
ramangrover2954f1fc42013-02-09 00:46:26 +0000998 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +0000999 }
1000 (
1001 ","
1002 (
1003 <IDENTIFIER>
1004 {
1005 key = (new Identifier(token.image)).getValue();
1006 }
1007 "="
1008 (
1009 (<STRING_LITERAL>
1010 {
1011 value = removeQuotesAndEscapes(token.image);
1012 }
1013 ) |
1014 (<INTEGER_LITERAL>
1015 {
1016 try{
ramangrover2921b88182013-01-31 00:51:19 +00001017 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001018 } catch (NumberFormatException nfe){
1019 throw new ParseException("inapproriate value: " + token.image);
1020 }
1021 }
1022 )
1023 )
1024 )
1025 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001026 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001027 }
1028
1029 )*
1030 )
1031 <RIGHTPAREN>
1032 )?
1033}
1034
1035
vinayakb38b7ca42012-03-05 05:44:15 +00001036
1037NodegroupDecl NodegroupDeclaration() throws ParseException :
1038{
1039 Identifier name = null;
1040 List < Identifier > ncNames = new ArrayList < Identifier > ();
1041 boolean ifNotExists = false;
1042}
1043{
1044 < IDENTIFIER >
1045 {
1046 name = new Identifier(token.image);
1047 }
1048 (
1049 "if not exists"
1050 {
1051 ifNotExists = true;
1052 }
1053 )?
1054 "on" < IDENTIFIER >
1055 {
1056 ncNames.add(new Identifier(token.image));
1057 }
1058 (
1059 "," < IDENTIFIER >
1060 {
1061 ncNames.add(new Identifier(token.image));
1062 }
1063 )*
1064 ";"
1065 {
1066 return new NodegroupDecl(name, ncNames, ifNotExists);
1067 }
1068}
1069
1070
1071TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException:
1072{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001073 Identifier dataverse;
vinayakb38b7ca42012-03-05 05:44:15 +00001074 Identifier ident;
1075 TypeExpression typeExpr;
1076 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001077 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001078}
1079{
vinayakb38b7ca42012-03-05 05:44:15 +00001080 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001081 nameComponents = getDotSeparatedPair();
1082 dataverse = nameComponents.first;
1083 ident = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001084 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001085
vinayakb38b7ca42012-03-05 05:44:15 +00001086 (
1087 "if not exists"
1088 {
1089 ifNotExists = true;
1090 }
1091 )?
1092 "as"
1093 ( typeExpr = TypeExpr() )
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001094 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001095 {
1096 long numValues = -1;
1097 String filename = null;
1098 if (dgen) {
1099 String splits[] = hint.split(" +");
1100 if (splits.length != 3) {
1101 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
1102 }
1103 filename = splits[1];
1104 numValues = Long.parseLong(splits[2]);
1105 }
1106 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001107 return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001108 }
1109}
1110
1111TypeExpression TypeExpr() throws ParseException:
1112{
1113 TypeExpression typeExpr = null;
1114}
1115{
1116 (
1117 typeExpr = RecordTypeDef()
1118 | typeExpr = TypeReference()
1119 | typeExpr = OrderedListTypeDef()
1120 | typeExpr = UnorderedListTypeDef()
1121 )
1122 {
1123 return typeExpr;
1124 }
1125}
1126
1127RecordTypeDefinition RecordTypeDef() throws ParseException:
1128{
1129 RecordTypeDefinition recType = new RecordTypeDefinition();
1130 RecordTypeDefinition.RecordKind recordKind = null;
1131}
1132{
1133 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1134 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1135 "{"
1136 {
1137 String hint = getHint(token);
1138 if (hint != null) {
1139 String splits[] = hint.split(" +");
1140 if (splits[0].equals(GEN_FIELDS_HINT)) {
1141 if (splits.length != 5) {
1142 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1143 }
1144 if (!splits[1].equals("int")) {
1145 throw new ParseException("The only supported type for gen-fields is int.");
1146 }
1147 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1148 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1149 recType.setUndeclaredFieldsDataGen(ufdg);
1150 }
1151 }
1152
1153 }
1154 (
1155 RecordField(recType)
1156 ( "," RecordField(recType) )*
1157 )?
1158 "}"
1159 {
1160 if (recordKind == null) {
1161 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1162 }
1163 recType.setRecordKind(recordKind);
1164 return recType;
1165 }
1166}
1167
1168void RecordField(RecordTypeDefinition recType) throws ParseException:
1169{
1170 String fieldName;
1171 TypeExpression type = null;
1172 boolean nullable = false;
1173}
1174{
1175 <IDENTIFIER>
1176 {
1177 Token t = getToken(0);
1178 fieldName = t.toString();
1179 String hint = getHint(t);
1180 IRecordFieldDataGen rfdg = null;
1181 if (hint != null) {
1182 String splits[] = hint.split(" +");
1183 if (splits[0].equals(VAL_FILE_HINT)) {
1184 File[] valFiles = new File[splits.length - 1];
1185 for (int k=1; k<splits.length; k++) {
1186 valFiles[k-1] = new File(splits[k]);
1187 }
1188 rfdg = new FieldValFileDataGen(valFiles);
1189 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
1190 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
1191 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
1192 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
1193 } else if (splits[0].equals(LIST_HINT)) {
1194 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1195 } else if (splits[0].equals(INTERVAL_HINT)) {
1196 FieldIntervalDataGen.ValueType vt;
1197 if (splits[1].equals("int")) {
1198 vt = FieldIntervalDataGen.ValueType.INT;
1199 } else if (splits[1].equals("long")) {
1200 vt = FieldIntervalDataGen.ValueType.LONG;
1201 } else if (splits[1].equals("float")) {
1202 vt = FieldIntervalDataGen.ValueType.FLOAT;
1203 } else if (splits[1].equals("double")) {
1204 vt = FieldIntervalDataGen.ValueType.DOUBLE;
1205 } else {
1206 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
1207 }
1208 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
1209 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
1210 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
1211 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
1212 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1213 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
1214 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1215 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
1216 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
1217 } else if (splits[0].equals(AUTO_HINT)) {
1218 rfdg = new AutoDataGen(splits[1]);
1219 }
1220 }
1221 }
1222 ":"
1223 ( type = TypeExpr() )
1224 ("?" { nullable = true; } )?
1225 {
1226 recType.addField(fieldName, type, nullable, rfdg);
1227 }
1228}
1229
1230TypeReferenceExpression TypeReference() throws ParseException:
1231{}
1232{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001233 <IDENTIFIER>
1234 {
1235 Token t = getToken(0);
1236 Identifier id = new Identifier(t.toString());
1237 return new TypeReferenceExpression(id);
1238 }
vinayakb38b7ca42012-03-05 05:44:15 +00001239}
1240
1241OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1242{
1243 TypeExpression type = null;
1244}
1245{
1246 "["
1247 ( type = TypeExpr() )
1248 "]"
1249 {
1250 return new OrderedListTypeDefinition(type);
1251 }
1252}
1253
1254
1255UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1256{
1257 TypeExpression type = null;
1258}
1259{
1260 "{{"
1261 ( type = TypeExpr() )
1262 "}}"
1263 {
1264 return new UnorderedListTypeDefinition(type);
1265 }
1266}
1267
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001268Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException:
1269{
1270 Identifier first = null;
1271 Identifier second = null;
1272}
1273{
1274 < IDENTIFIER >
1275 {
1276 first = new Identifier(token.image);
1277 }
1278 ("." <IDENTIFIER>
1279 {
1280 second = new Identifier(token.image);
1281 }
1282 )?
1283
1284 {
1285 if(second == null){
1286 second = first;
1287 first = null;
1288 }
1289
1290 return new Pair<Identifier,Identifier>(first,second);
1291 }
1292}
1293
1294Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException:
1295{
1296 Identifier first = null;
1297 Identifier second = null;
1298 Identifier third = null;
1299}
1300{
1301 < IDENTIFIER >
1302 {
1303 first = new Identifier(token.image);
1304 }
1305 "." <IDENTIFIER>
1306 {
1307 second = new Identifier(token.image);
1308 }
1309 (
1310 "." <IDENTIFIER>
1311 {
1312 third = new Identifier(token.image);
1313 }
1314 )?
1315
1316 {
1317 if(third == null){
1318 third = second;
1319 second = first;
1320 first = null;
1321 }
1322
1323 return new Triple<Identifier,Identifier,Identifier>(first,second,third);
1324 }
1325}
1326
1327
1328
vinayakb38b7ca42012-03-05 05:44:15 +00001329
1330FunctionDecl FunctionDeclaration() throws ParseException:
1331{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001332 FunctionDecl funcDecl;
1333 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001334 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001335 int arity = 0;
1336 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1337 Expression funcBody;
1338 VarIdentifier var = null;
1339 createNewScope();
1340}
1341{
1342
1343 <IDENTIFIER>
1344 {
1345 Token t = getToken(0);
ramangrover29a13f2422012-03-15 23:01:27 +00001346 functionName = t.toString();
vinayakb38b7ca42012-03-05 05:44:15 +00001347 }
1348 <LEFTPAREN> (<VARIABLE>
1349 {
1350 var = new VarIdentifier();
1351 var.setValue(getToken(0).toString());
1352 paramList.add(var);
1353 getCurrentScope().addNewVarSymbolToScope(var);
1354 arity++;
1355 }
1356 ("," <VARIABLE>
1357 {
1358 var = new VarIdentifier();
1359 var.setValue(getToken(0).toString());
1360 paramList.add(var);
1361 getCurrentScope().addNewVarSymbolToScope(var);
1362 arity++;
1363 })*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
1364
1365 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001366 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1367 getCurrentScope().addFunctionDescriptor(signature, false);
1368 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1369 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001370 }
1371}
1372
1373CreateFunctionStatement FunctionCreation() throws ParseException:
1374{
1375 CreateFunctionStatement cfs = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001376 FunctionSignature signature;
1377 String dataverse;
ramangrover29a13f2422012-03-15 23:01:27 +00001378 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001379 boolean ifNotExists = false;
1380 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001381 String functionBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001382 VarIdentifier var = null;
1383 createNewScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001384 Expression functionBodyExpr;
1385 Token beginPos;
1386 Token endPos;
1387 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001388}
1389{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001390 {
1391 nameComponents = getDotSeparatedPair();
1392 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
1393 functionName= nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +00001394 }
1395
1396 (
1397 "if not exists"
1398 {
1399 ifNotExists = true;
1400 }
1401 )?
1402
1403 <LEFTPAREN> (<VARIABLE>
1404 {
1405 var = new VarIdentifier();
1406 var.setValue(getToken(0).toString());
1407 paramList.add(var);
1408 getCurrentScope().addNewVarSymbolToScope(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001409 }
1410 ("," <VARIABLE>
1411 {
1412 var = new VarIdentifier();
1413 var.setValue(getToken(0).toString());
1414 paramList.add(var);
1415 getCurrentScope().addNewVarSymbolToScope(var);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001416 })*)? <RIGHTPAREN> "{"
vinayakb38b7ca42012-03-05 05:44:15 +00001417 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001418 beginPos = getToken(0);
1419 }
1420 functionBodyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001421 "}"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001422 {
1423 endPos = getToken(0);
1424 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
1425 }
vinayakb38b7ca42012-03-05 05:44:15 +00001426 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001427 signature = new FunctionSignature(dataverse, functionName, paramList.size());
1428 getCurrentScope().addFunctionDescriptor(signature, false);
1429 cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001430 return cfs;
1431 }
1432}
1433
1434
1435
1436Query Query()throws ParseException:
1437{
1438 Query query = new Query();
1439 Expression expr;
1440}
1441{
1442 expr = Expression()
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001443 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001444 {
1445 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001446 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001447 return query;
1448 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001449
vinayakb38b7ca42012-03-05 05:44:15 +00001450}
1451
1452
1453
1454Expression Expression():
1455{
1456 Expression expr = null;
1457 Expression exprP = null;
1458}
1459{
1460(
1461
1462//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1463 expr = OperatorExpr()
1464 | expr = IfThenElse()
1465 | expr = FLWOGR()
1466 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001467
vinayakb38b7ca42012-03-05 05:44:15 +00001468
1469)
1470 {
1471 return (exprP==null) ? expr : exprP;
1472 }
1473}
1474
1475
1476
1477Expression OperatorExpr()throws ParseException:
1478{
1479 OperatorExpr op = null;
1480 Expression operand = null;
1481}
1482{
1483 operand = AndExpr()
1484 (
1485
1486 "or"
1487 {
1488 if (op == null) {
1489 op = new OperatorExpr();
1490 op.addOperand(operand);
1491 op.setCurrentop(true);
1492 }
1493 Token t = getToken(0);
1494 op.addOperator(t.toString());
1495 }
1496
1497 operand = AndExpr()
1498 {
1499 op.addOperand(operand);
1500 }
1501
1502 )*
1503
1504 {
1505 return op==null? operand: op;
1506 }
1507}
1508
1509Expression AndExpr()throws ParseException:
1510{
1511 OperatorExpr op = null;
1512 Expression operand = null;
1513}
1514{
1515 operand = RelExpr()
1516 (
1517
1518 "and"
1519 {
1520 if (op == null) {
1521 op = new OperatorExpr();
1522 op.addOperand(operand);
1523 op.setCurrentop(true);
1524 }
1525 Token t = getToken(0);
1526 op.addOperator(t.toString());
1527 }
1528
1529 operand = RelExpr()
1530 {
1531 op.addOperand(operand);
1532 }
1533
1534 )*
1535
1536 {
1537 return op==null? operand: op;
1538 }
1539}
1540
1541
1542
1543Expression RelExpr()throws ParseException:
1544{
1545 OperatorExpr op = null;
1546 Expression operand = null;
1547 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001548 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001549}
1550{
1551 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001552 {
1553 if (operand instanceof VariableExpr) {
1554 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001555 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001556 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001557 }
1558 }
1559 }
1560
1561 (
1562 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1563 {
alexander.behm07617fd2012-07-25 10:13:50 +00001564 String mhint = getHint(token);
1565 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1566 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1567 }
vinayakb38b7ca42012-03-05 05:44:15 +00001568 if (op == null) {
1569 op = new OperatorExpr();
1570 op.addOperand(operand, broadcast);
1571 op.setCurrentop(true);
1572 broadcast = false;
1573 }
1574 Token t = getToken(0);
1575 op.addOperator(t.toString());
1576 }
1577
1578 operand = AddExpr()
1579 {
alexander.behm07617fd2012-07-25 10:13:50 +00001580 broadcast = false;
1581 if (operand instanceof VariableExpr) {
1582 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001583 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1584 broadcast = true;
1585 }
alexander.behm07617fd2012-07-25 10:13:50 +00001586 }
vinayakb38b7ca42012-03-05 05:44:15 +00001587 op.addOperand(operand, broadcast);
1588 }
1589 )?
1590
1591 {
alexander.behm07617fd2012-07-25 10:13:50 +00001592 if (annotation != null) {
1593 op.addHint(annotation);
1594 }
vinayakb38b7ca42012-03-05 05:44:15 +00001595 return op==null? operand: op;
1596 }
1597}
1598
1599Expression AddExpr()throws ParseException:
1600{
1601 OperatorExpr op = null;
1602 Expression operand = null;
1603}
1604{
1605 operand = MultExpr()
1606
1607 ( ("+" | "-")
1608 {
1609 if (op == null) {
1610 op = new OperatorExpr();
1611 op.addOperand(operand);
1612 op.setCurrentop(true);
1613 }
1614 Token t = getToken(0);
1615 ((OperatorExpr)op).addOperator(t.toString());
1616 }
1617
1618 operand = MultExpr()
1619 {
1620 op.addOperand(operand);
1621 }
1622 )*
1623
1624 {
1625 return op==null? operand: op;
1626 }
1627}
1628
1629Expression MultExpr()throws ParseException:
1630{
1631 OperatorExpr op = null;
1632 Expression operand = null;
1633}
1634{
1635 operand = UnionExpr()
1636
1637 (( "*" | "/" | "%" | <CARET> | "idiv")
1638 {
1639 if (op == null) {
1640 op = new OperatorExpr();
1641 op.addOperand(operand);
1642 op.setCurrentop(true);
1643 }
1644 Token t = getToken(0);
1645 op.addOperator(t.toString());
1646 }
1647 operand = UnionExpr()
1648 {
1649 op.addOperand(operand);
1650 }
1651 )*
1652
1653 {
1654 return op==null?operand:op;
1655 }
1656}
1657
1658Expression UnionExpr() throws ParseException:
1659{
1660 UnionExpr union = null;
1661 Expression operand1 = null;
1662 Expression operand2 = null;
1663}
1664{
1665 operand1 = UnaryExpr()
1666 ("union"
1667 (operand2 = UnaryExpr()) {
1668 if (union == null) {
1669 union = new UnionExpr();
1670 union.addExpr(operand1);
1671 }
1672 union.addExpr(operand2);
1673 } )*
1674 {
1675 return (union == null)? operand1: union;
1676 }
1677}
1678
1679Expression UnaryExpr() throws ParseException:
1680{
1681 Expression uexpr = null;
1682 Expression expr = null;
1683}
1684{
1685 (( "+"|"-")
1686 {
1687 uexpr = new UnaryExpr();
1688 Token t = getToken(0);
1689 if("+".equals(t.toString()))
1690 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1691 else if("-".equals(t.toString()))
1692 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1693 else
1694 throw new ParseException();
1695 }
1696 )?
1697
1698 expr = ValueExpr()
1699 {
1700 if(uexpr!=null){
1701 ((UnaryExpr)uexpr).setExpr(expr);
1702 return uexpr;
1703 }
1704 else{
1705 return expr;
1706 }
1707 }
1708}
1709
1710Expression ValueExpr() throws ParseException:
1711{
1712 Expression expr;
1713}
1714{
1715 expr = FieldOrIndexAccessor()
1716 {
1717 return expr;
1718 }
1719}
1720
1721
1722Expression FieldOrIndexAccessor()throws ParseException:
1723{
1724 Expression expr = null;
1725 Identifier ident = null;
1726 AbstractAccessor fa = null;
1727 int index;
1728
1729}
1730{
1731 ( expr = PrimaryExpr()
1732
1733 )
1734
1735
1736 (
1737 (
1738 ident = Field()
1739 {
1740 if(fa == null)
1741 fa = new FieldAccessor(expr, ident);
1742 else
1743 fa = new FieldAccessor(fa, ident);
1744 }
1745 )
1746 | (
1747 index = Index()
1748 {
1749 if(fa == null)
1750 fa = new IndexAccessor(expr, index);
1751 else
1752 fa = new IndexAccessor(fa, index);
1753 }
1754 )
1755 )*
1756
1757
1758 {
1759 return fa==null?expr:fa;
1760 }
1761}
1762
1763Identifier Field() throws ParseException:
1764{
1765 Identifier ident = null;
1766
1767}
1768{
1769 "." < IDENTIFIER >
1770 {
1771
1772 ident = new Identifier();
1773 ident.setValue(getToken(0).toString());
1774
1775 return ident;
1776 }
1777}
1778
1779int Index() throws ParseException:
1780{
1781 Expression expr = null;
1782 int idx = -2;
1783}
1784{
1785 "[" ( expr = Expression()
1786 {
1787 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1788 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001789 Literal lit = ((LiteralExpr)expr).getValue();
1790 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1791 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001792 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001793 }
vinayakb38b7ca42012-03-05 05:44:15 +00001794 else {
1795 throw new ParseException("Index should be an INTEGER");
1796 }
1797 }
1798
1799 }
1800
1801 | "?"
1802 {
1803 idx = IndexAccessor.ANY;
1804 // ANY
1805 }
1806
1807 )
1808
1809 "]"
1810 {
1811 return idx;
1812 }
1813}
1814
1815
1816Expression PrimaryExpr()throws ParseException:
1817{
1818 Expression expr = null;
1819}
1820{
ilovesoupc9fef1d2012-07-08 19:30:42 +00001821 //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
vinayakb38b7ca42012-03-05 05:44:15 +00001822 (
1823 expr =Literal()
1824 | expr = FunctionCallExpr()
1825 | expr =VariableRef()
1826
1827 {
1828 if(((VariableExpr)expr).getIsNewVar() == true)
1829 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
1830 }
1831 | expr = ListConstructor()
1832 | expr = RecordConstructor()
1833 | expr = ParenthesizedExpression()
1834 )
1835 {
1836 return expr;
1837 }
1838}
1839
1840Expression Literal() throws ParseException:
1841{
1842
1843 LiteralExpr lit = new LiteralExpr();
1844 Token t;
1845}
1846{
1847(
1848 <STRING_LITERAL>
1849 {
1850 t= getToken(0);
1851 lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image)));
1852 }
1853
1854 | <INTEGER_LITERAL>
1855 {
1856 t= getToken(0);
ilovesoupc9fef1d2012-07-08 19:30:42 +00001857 try {
1858 lit.setValue(new IntegerLiteral(new Integer(t.image)));
1859 } catch(NumberFormatException ex) {
1860 lit.setValue(new LongIntegerLiteral(new Long(t.image)));
1861 }
vinayakb38b7ca42012-03-05 05:44:15 +00001862 }
1863 | < FLOAT_LITERAL >
1864 {
1865 t= getToken(0);
1866 lit.setValue(new FloatLiteral(new Float(t.image)));
1867 }
1868 | < DOUBLE_LITERAL >
1869 {
1870 t= getToken(0);
1871 lit.setValue(new DoubleLiteral(new Double(t.image)));
1872 }
1873 | <NULL>
1874 {
1875 t= getToken(0);
1876 lit.setValue(NullLiteral.INSTANCE);
1877 }
1878 | <TRUE>
1879 {
1880 t= getToken(0);
1881 lit.setValue(TrueLiteral.INSTANCE);
1882 }
1883 | <FALSE>
1884 {
1885 t= getToken(0);
1886 lit.setValue(FalseLiteral.INSTANCE);
1887 }
1888)
1889 {
1890 return lit;
1891 }
1892}
1893
1894
1895VariableExpr VariableRef() throws ParseException:
1896{
1897 VariableExpr varExp = new VariableExpr();
1898 VarIdentifier var = new VarIdentifier();
1899 Token t;
1900}
1901{
1902 <VARIABLE>
1903 {
1904 t = getToken(0);//get current token
1905 String varName = t.toString();
1906 Identifier ident = lookupSymbol(varName);
1907 if (isInForbiddenScopes(varName)) {
1908 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.");
1909 }
1910 if(ident != null) { // exist such ident
1911 varExp.setIsNewVar(false);
1912 varExp.setVar((VarIdentifier)ident);
1913 } else {
1914 varExp.setVar(var);
1915 }
1916 var.setValue(t.toString());
1917 return varExp;
1918 }
1919}
1920
1921
1922VariableExpr Variable() throws ParseException:
1923{
1924 VariableExpr varExp = new VariableExpr();
1925 VarIdentifier var = new VarIdentifier();
1926 Token t;
1927}
1928{
1929 <VARIABLE>
1930 {
1931 t = getToken(0);//get current token
1932 Identifier ident = lookupSymbol(t.toString());
1933 if(ident != null) { // exist such ident
1934 varExp.setIsNewVar(false);
1935 }
1936 varExp.setVar(var);
1937 var.setValue(t.toString());
1938 return varExp;
1939 }
1940}
1941
1942Expression ListConstructor() throws ParseException:
1943{
1944 Expression expr = null;
1945}
1946{
1947 (
1948 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1949 )
1950
1951 {
1952 return expr;
1953 }
1954}
1955
1956
1957ListConstructor OrderedListConstructor() throws ParseException:
1958{
1959 ListConstructor expr = new ListConstructor();
1960 Expression tmp = null;
1961 List<Expression> exprList = new ArrayList<Expression>();
1962 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1963}
1964{
1965
1966 "["
1967 ( tmp = Expression()
1968 {
1969 exprList.add(tmp);
1970 }
1971
1972 ("," tmp = Expression() { exprList.add(tmp); })*
1973 )?
1974
1975 "]"
1976
1977 {
1978 expr.setExprList(exprList);
1979 return expr;
1980 }
1981}
1982
1983ListConstructor UnorderedListConstructor() throws ParseException:
1984{
1985 ListConstructor expr = new ListConstructor();
1986 Expression tmp = null;
1987 List<Expression> exprList = new ArrayList<Expression>();
1988 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1989}
1990{
1991
1992 "{{" ( tmp = Expression()
1993 {
1994 exprList.add(tmp);
1995 }
1996 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1997 {
1998 expr.setExprList(exprList);
1999 return expr;
2000 }
2001}
2002
2003RecordConstructor RecordConstructor() throws ParseException:
2004{
2005 RecordConstructor expr = new RecordConstructor();
2006 FieldBinding tmp = null;
2007 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2008}
2009{
2010 "{" (tmp = FieldBinding()
2011 {
2012 fbList.add(tmp);
2013 }
2014 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
2015 {
2016 expr.setFbList(fbList);
2017 return expr;
2018 }
2019}
2020
2021FieldBinding FieldBinding() throws ParseException:
2022{
2023 FieldBinding fb = new FieldBinding();
2024 Expression left, right;
2025}
2026{
2027 left = Expression() ":" right = Expression()
2028 {
2029 fb.setLeftExpr(left);
2030 fb.setRightExpr(right);
2031 return fb;
2032 }
2033}
2034
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002035
vinayakb38b7ca42012-03-05 05:44:15 +00002036Expression FunctionCallExpr() throws ParseException:
2037{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002038 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002039 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002040 Expression tmp;
2041 int arity = 0;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002042 String funcName;
2043 String dataverse;
2044 String hint=null;
2045 String id1=null;
2046 String id2=null;
vinayakb38b7ca42012-03-05 05:44:15 +00002047}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002048{
2049 ( <IDENTIFIER> { dataverse = defaultDataverse; funcName = token.image;} ("." <IDENTIFIER> { dataverse = funcName; funcName = token.image;})? | <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();})
vinayakb38b7ca42012-03-05 05:44:15 +00002050 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002051 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002052 }
2053 <LEFTPAREN> (tmp = Expression()
2054 {
2055 argList.add(tmp);
2056 arity ++;
2057 } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
2058
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002059 {
2060 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2061 if(signature == null)
2062 {
2063 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2064 }
2065 callExpr = new CallExpr(signature,argList);
2066 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2067 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2068 }
2069 return callExpr;
vinayakb38b7ca42012-03-05 05:44:15 +00002070 }
2071}
2072
2073
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002074
vinayakb38b7ca42012-03-05 05:44:15 +00002075Expression ParenthesizedExpression() throws ParseException:
2076{
2077 Expression expr;
2078}
2079{
2080 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2081 {
2082 return expr;
2083 }
2084}
2085
2086Expression IfThenElse() throws ParseException:
2087{
2088 Expression condExpr;
2089 Expression thenExpr;
2090 Expression elseExpr;
2091 IfExpr ifExpr = new IfExpr();
2092}
2093{
2094 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
2095
2096 {
2097 ifExpr.setCondExpr(condExpr);
2098 ifExpr.setThenExpr(thenExpr);
2099 ifExpr.setElseExpr(elseExpr);
2100 return ifExpr;
2101 }
2102}
2103
2104Expression FLWOGR() throws ParseException:
2105{
2106 FLWOGRExpression flworg = new FLWOGRExpression();
2107 List<Clause> clauseList = new ArrayList<Clause>();
2108 Expression returnExpr;
2109 Clause tmp;
2110 createNewScope();
2111}
2112{
2113 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2114 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
2115
2116 {
2117 flworg.setClauseList(clauseList);
2118 flworg.setReturnExpr(returnExpr);
2119 removeCurrentScope();
2120 return flworg;
2121 }
2122}
2123
2124Clause Clause()throws ParseException :
2125{
2126 Clause clause;
2127}
2128{
2129 (
2130 clause = ForClause()
2131 | clause = LetClause()
2132 | clause = WhereClause()
2133 | clause = OrderbyClause()
2134 | clause = GroupClause()
2135 | clause = LimitClause()
2136 | clause = DistinctClause()
2137 | clause = DieClause()
2138 )
2139 {
2140 return clause;
2141 }
2142}
2143
2144Clause ForClause()throws ParseException :
2145{
2146 ForClause fc = new ForClause();
2147 VariableExpr varExp;
2148 VariableExpr varPos = null;
2149 Expression inExp;
2150 extendCurrentScope();
2151}
2152{
2153 "for" varExp = Variable()
2154 {
2155 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2156 }
2157 ("at" varPos = Variable()
2158 {
2159 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2160 }
2161 )?
2162 "in" ( inExp = Expression() )
2163 {
2164 fc.setVarExpr(varExp);
2165 fc.setInExpr(inExp);
2166 if (varPos != null) {
2167 fc.setPosExpr(varPos);
2168 }
2169 return fc;
2170 }
2171}
2172
2173Clause LetClause() throws ParseException:
2174{
2175 LetClause lc = new LetClause();
2176 VariableExpr varExp;
2177 Expression beExp;
2178 extendCurrentScope();
2179}
2180{
ilovesoupb2527c12012-07-12 03:21:13 +00002181 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002182 {
2183 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002184 lc.setVarExpr(varExp);
2185 lc.setBeExpr(beExp);
2186 return lc;
2187 }
2188}
2189
2190Clause WhereClause()throws ParseException :
2191{
2192 WhereClause wc = new WhereClause();
2193 Expression whereExpr;
2194}
2195{
2196 "where" whereExpr = Expression()
2197 {
2198 wc.setWhereExpr(whereExpr);
2199 return wc;
2200 }
2201}
2202
2203Clause OrderbyClause()throws ParseException :
2204{
2205 OrderbyClause oc = new OrderbyClause();
2206 Expression orderbyExpr;
2207 List<Expression> orderbyList = new ArrayList<Expression>();
2208 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2209 int numOfOrderby = 0;
2210}
2211{
2212 (
2213 "order"
2214 {
2215 String hint = getHint(token);
2216 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2217 String splits[] = hint.split(" +");
2218 int numFrames = Integer.parseInt(splits[1]);
2219 int numTuples = Integer.parseInt(splits[2]);
2220 oc.setNumFrames(numFrames);
2221 oc.setNumTuples(numTuples);
2222 }
2223 }
2224 "by" orderbyExpr = Expression()
2225 {
2226 orderbyList.add(orderbyExpr);
2227 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2228 }
2229 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2230 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2231 {
2232 modifierList.add(modif);
2233 }
2234
2235 ("," orderbyExpr = Expression()
2236 {
2237 orderbyList.add(orderbyExpr);
2238 modif = OrderbyClause.OrderModifier.ASC;
2239 }
2240 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2241 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2242 {
2243 modifierList.add(modif);
2244 }
2245 )*
2246)
2247 {
2248 oc.setModifierList(modifierList);
2249 oc.setOrderbyList(orderbyList);
2250 return oc;
2251 }
2252}
2253Clause GroupClause()throws ParseException :
2254{
2255 GroupbyClause gbc = new GroupbyClause();
2256 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2257 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2258 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2259 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2260 VariableExpr var = null;
2261 VariableExpr withVar = null;
2262 Expression expr = null;
2263 VariableExpr decorVar = null;
2264 Expression decorExpr = null;
2265}
2266{
2267 {
2268 Scope newScope = extendCurrentScopeNoPush(true);
2269 // extendCurrentScope(true);
2270 }
2271 "group"
2272 {
2273 String hint = getHint(token);
2274 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2275 gbc.setHashGroupByHint(true);
2276 }
2277 }
2278 "by" (LOOKAHEAD(2) var = Variable()
2279 {
2280 newScope.addNewVarSymbolToScope(var.getVar());
2281 } ":=")?
2282 expr = Expression()
2283 {
2284 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2285 vePairList.add(pair1);
2286 }
2287 ("," ( LOOKAHEAD(2) var = Variable()
2288 {
2289 newScope.addNewVarSymbolToScope(var.getVar());
2290 } ":=")?
2291 expr = Expression()
2292 {
2293 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2294 vePairList.add(pair2);
2295 }
2296 )*
2297 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2298 {
2299 newScope.addNewVarSymbolToScope(decorVar.getVar());
2300 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2301 decorPairList.add(pair3);
2302 }
2303 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2304 {
2305 newScope.addNewVarSymbolToScope(decorVar.getVar());
2306 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2307 decorPairList.add(pair4);
2308 }
2309 )*
2310 )?
2311 "with" withVar = VariableRef()
2312 {
2313 if(withVar.getIsNewVar()==true)
2314 throw new ParseException("can't find variable " + withVar.getVar());
2315 withVarList.add(withVar);
2316 newScope.addNewVarSymbolToScope(withVar.getVar());
2317 }
2318 ("," withVar = VariableRef()
2319 {
2320 if(withVar.getIsNewVar()==true)
2321 throw new ParseException("can't find variable " + withVar.getVar());
2322 withVarList.add(withVar);
2323 newScope.addNewVarSymbolToScope(withVar.getVar());
2324 })*
2325 {
2326 gbc.setGbyPairList(vePairList);
2327 gbc.setDecorPairList(decorPairList);
2328 gbc.setWithVarList(withVarList);
2329 replaceCurrentScope(newScope);
2330 return gbc;
2331 }
2332}
2333
2334
2335LimitClause LimitClause() throws ParseException:
2336{
2337 LimitClause lc = new LimitClause();
2338 Expression expr;
2339 pushForbiddenScope(getCurrentScope());
2340}
2341{
2342 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2343 ("offset" expr = Expression() { lc.setOffset(expr); })?
2344
2345 {
2346 popForbiddenScope();
2347 return lc;
2348 }
2349}
2350
2351DistinctClause DistinctClause() throws ParseException:
2352{
2353 List<Expression> exprs = new ArrayList<Expression>();
2354 Expression expr;
2355}
2356{
2357 "distinct" "by" expr = Expression()
2358 {
2359 exprs.add(expr);
2360 }
2361 ("," expr = Expression()
2362 {
2363 exprs.add(expr);
2364 }
2365 )*
2366 {
2367 return new DistinctClause(exprs);
2368 }
2369}
2370
2371DieClause DieClause() throws ParseException:
2372{
2373 DieClause lc = new DieClause();
2374 Expression expr;
2375 pushForbiddenScope(getCurrentScope());
2376}
2377{
2378 "die" "after" expr = Expression() { lc.setDieExpr(expr); }
2379 {
2380 popForbiddenScope();
2381 return lc;
2382 }
2383}
2384
2385
2386QuantifiedExpression QuantifiedExpression()throws ParseException:
2387{
2388 QuantifiedExpression qc = new QuantifiedExpression();
2389 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2390 Expression satisfiesExpr;
2391 VariableExpr var;
2392 Expression inExpr;
2393 QuantifiedPair pair;
2394}
2395{
2396 {
2397 createNewScope();
2398 }
2399
2400 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2401 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2402 var = Variable() "in" inExpr = Expression()
2403 {
2404 pair = new QuantifiedPair(var, inExpr);
2405 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2406 quantifiedList.add(pair);
2407 }
2408 (
2409 "," var = Variable() "in" inExpr = Expression()
2410 {
2411 pair = new QuantifiedPair(var, inExpr);
2412 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2413 quantifiedList.add(pair);
2414 }
2415 )*
2416 "satisfies" satisfiesExpr = Expression()
2417 {
2418 qc.setSatisfiesExpr(satisfiesExpr);
2419 qc.setQuantifiedList(quantifiedList);
2420 removeCurrentScope();
2421 return qc;
2422 }
2423}
2424
2425TOKEN_MGR_DECLS:
2426{
2427 public int commentDepth = 0;
2428}
2429
2430<DEFAULT>
2431TOKEN :
2432{
2433 <CARET : "^" >
2434}
2435
2436<DEFAULT>
2437TOKEN :
2438{
2439 <DATASET : "dataset" >
2440}
2441
2442<DEFAULT>
2443TOKEN :
2444{
2445 <LEFTPAREN : "(" >
2446}
2447
2448<DEFAULT>
2449TOKEN :
2450{
2451 <RIGHTPAREN : ")" >
2452}
2453
2454
2455<DEFAULT>
2456TOKEN :
2457{
2458 <INTEGER_LITERAL : (<DIGIT>)+ >
2459}
2460
2461
2462<DEFAULT>
2463TOKEN :
2464{
2465 <NULL : "null">
2466}
2467
2468<DEFAULT>
2469TOKEN :
2470{
2471 <TRUE : "true">
2472}
2473
2474<DEFAULT>
2475TOKEN :
2476{
2477 <FALSE : "false">
2478}
2479
2480<DEFAULT>
2481TOKEN :
2482{
2483 <#DIGIT : ["0" - "9"]>
2484}
2485
2486
2487TOKEN:
2488{
2489 < DOUBLE_LITERAL: <INTEGER>
2490 | <INTEGER> ( "." <INTEGER> )?
2491 | "." <INTEGER>
2492 >
2493 |
2494 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2495 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2496 | "." <INTEGER> ( "f" | "F" )
2497 >
2498 |
2499 <INTEGER : (<DIGIT>)+ >
2500}
2501
2502<DEFAULT>
2503TOKEN :
2504{
2505 <#LETTER : ["A" - "Z", "a" - "z"]>
2506}
2507
2508<DEFAULT>
2509TOKEN :
2510{
2511 <SPECIALCHARS : ["$", "_", "-"] >
2512}
2513
2514<DEFAULT>
2515TOKEN :
2516{
2517 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2518 |
2519 < #EscapeQuot: "\\\"" >
2520 |
2521 < #EscapeApos: "\\\'" >
2522}
2523
2524<DEFAULT>
2525TOKEN :
2526{
2527 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2528}
2529
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002530
vinayakb38b7ca42012-03-05 05:44:15 +00002531<DEFAULT>
2532TOKEN :
2533{
2534 <VARIABLE : "$" <IDENTIFIER> >
2535}
2536
2537SKIP:
2538{
2539 " "
2540| "\t"
2541| "\r"
2542| "\n"
2543}
2544
2545SKIP:
2546{
2547 <"//" (~["\n"])* "\n">
2548}
2549
2550SKIP:
2551{
2552 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2553}
2554
2555
2556SKIP:
2557{
2558 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2559}
2560
2561<INSIDE_COMMENT>
2562SPECIAL_TOKEN:
2563{
2564 <"+"(" ")*(~["*"])*>
2565}
2566
2567<INSIDE_COMMENT>
2568SKIP:
2569{
2570 <"/*"> {commentDepth++;}
2571}
2572
2573<INSIDE_COMMENT>
2574SKIP:
2575{
2576 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2577| <~[]>
2578}