blob: 78d1129b8b1b44695f10dc2aa4bfca87352ea266 [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;
20import edu.uci.ics.asterix.aql.literal.FloatLiteral;
21import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
22import edu.uci.ics.asterix.aql.literal.FalseLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000023import edu.uci.ics.asterix.aql.base.Literal;
vinayakb38b7ca42012-03-05 05:44:15 +000024import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000025import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +000026import edu.uci.ics.asterix.aql.literal.NullLiteral;
27import edu.uci.ics.asterix.aql.literal.StringLiteral;
28import edu.uci.ics.asterix.aql.literal.TrueLiteral;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000029import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
vinayakb38b7ca42012-03-05 05:44:15 +000030
31import edu.uci.ics.asterix.aql.base.*;
32import edu.uci.ics.asterix.aql.expression.*;
33import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
34import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
35import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
36import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
37import edu.uci.ics.asterix.aql.base.Statement.Kind;
38import edu.uci.ics.asterix.aql.context.Scope;
39import edu.uci.ics.asterix.aql.context.RootScopeFactory;
40import edu.uci.ics.asterix.common.annotations.*;
41import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000042import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000043import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000044import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
45import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000046import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
47import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
48import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
49
50
vinayakb38b7ca42012-03-05 05:44:15 +000051
52
53public class AQLParser extends ScopeChecker {
54
vinayakb38b7ca42012-03-05 05:44:15 +000055 // optimizer hints
56 private static final String HASH_GROUP_BY_HINT = "hash";
57 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000058 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000059 private static final String INMEMORY_HINT = "inmem";
60 private static final String VAL_FILE_HINT = "val-files";
61 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
62 private static final String INTERVAL_HINT = "interval";
63 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
64 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
65 private static final String LIST_VAL_FILE_HINT = "list-val-file";
66 private static final String LIST_HINT = "list";
67 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
68 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
69 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
70 private static final String AUTO_HINT = "auto";
71
72 private static final String GEN_FIELDS_HINT = "gen-fields";
73
74 // data generator hints
75 private static final String DGEN_HINT = "dgen";
76
77 private static String getHint(Token t) {
78 if (t.specialToken == null) {
79 return null;
80 }
81 String s = t.specialToken.image;
82 int n = s.length();
83 if (n < 2) {
84 return null;
85 }
86 return s.substring(1).trim();
87 }
88
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000089 public AQLParser(String s){
90 this(new StringReader(s));
91 super.setInput(s);
92 }
93
vinayakb38b7ca42012-03-05 05:44:15 +000094 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
95 File file = new File(args[0]);
96 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
97 AQLParser parser = new AQLParser(fis);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000098 List<Statement> st = parser.Statement();
99 //st.accept(new AQLPrintVisitor(), 0);
vinayakb38b7ca42012-03-05 05:44:15 +0000100 }
101
102
103}
104
105PARSER_END(AQLParser)
106
107
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000108List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000109{
vinayakb38b7ca42012-03-05 05:44:15 +0000110 scopeStack.push(RootScopeFactory.createRootScope(this));
111 List<Statement> decls = new ArrayList<Statement>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000112 Query query=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000113}
114{
115 (
116 (
117 (
118 "use"
119 {
120 decls.add(DataverseDeclaration());
121 }
122 | "declare" "function" {
123 decls.add(FunctionDeclaration());
124 }
125 | "create" (
126 {
127 String hint = getHint(token);
128 boolean dgen = false;
129 if (hint != null && hint.startsWith(DGEN_HINT)) {
130 dgen = true;
131 }
132 }
133 "type"
134 {
135 decls.add(TypeDeclaration(dgen, hint));
136 }
137 | "nodegroup"
138 {
139 decls.add(NodegroupDeclaration());
140 }
141 | "external" <DATASET>
142 {
143 decls.add(DatasetDeclaration(DatasetType.EXTERNAL));
144 }
145 | "feed" <DATASET>
146 {
147 decls.add(DatasetDeclaration(DatasetType.FEED));
148 }
149 | <DATASET>
150 {
151 decls.add(DatasetDeclaration(DatasetType.INTERNAL));
152 }
153 | "index"
154 {
155 decls.add(CreateIndexStatement());
156 }
157 | "dataverse"
158 {
159 decls.add(CreateDataverseStatement());
160 }
161 | "function"
162 {
163 decls.add(FunctionCreation());
164 }
165 )
166 | "load" {
167 decls.add(LoadStatement());
168 }
169
170 | "drop"
171 (
172 <DATASET>
173 {
174 decls.add(DropStatement());
175 }
176 | "index"
177 {
178 decls.add(IndexDropStatement());
179 }
180 | "nodegroup"
181 {
182 decls.add(NodeGroupDropStatement());
183 }
184 | "type"
185 {
186 decls.add(TypeDropStatement());
187 }
188 | "dataverse"
189 {
190 decls.add(DataverseDropStatement());
191 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000192 | "function"
193 {
194 decls.add(FunctionDropStatement());
195 }
vinayakb38b7ca42012-03-05 05:44:15 +0000196 )
197 | "write" {
198 decls.add(WriteStatement());
199 }
200 | "set" {
201 decls.add(SetStatement());
202 }
203 | "insert" {
204 decls.add(InsertStatement());
205 }
206 | "delete" {
207 decls.add(DeleteStatement());
208 }
209 | "update" {
210 decls.add(UpdateStatement());
211 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000212 | "begin" "feed"
213 {
214 Pair<Identifier,Identifier> nameComponents = getDotSeparatedPair();
215 decls.add(new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter()));
216 } ";"
217
218 | "suspend" "feed"
219 {
220 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.SUSPEND));
221 } ";"
222 | "resume" "feed" {
223 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.RESUME));
vinayakb38b7ca42012-03-05 05:44:15 +0000224 } ";"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000225 | "end" "feed" {
226 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.END));
vinayakb38b7ca42012-03-05 05:44:15 +0000227 } ";"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000228 | "alter" "feed" {
229 decls.add(AlterFeedDeclaration());
230 } ";"
231
232 | (query = Query()) {
233 decls.add(query);
234 }
235 )*
236 // (query = Query())?
vinayakb38b7ca42012-03-05 05:44:15 +0000237 )
238
239 <EOF>
240 )
241 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000242 return decls;
vinayakb38b7ca42012-03-05 05:44:15 +0000243 }
244}
245
246InsertStatement InsertStatement() throws ParseException:
247{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000248 Identifier dataverseName;
vinayakb38b7ca42012-03-05 05:44:15 +0000249 Identifier datasetName;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000250 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000251 Query query;
252}
253{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000254 "into" <DATASET>
255
256 {
257 nameComponents = getDotSeparatedPair();
258 dataverseName = nameComponents.first;
259 datasetName = nameComponents.second;
260 }
261
262 <LEFTPAREN> query = Query() <RIGHTPAREN> ";"
263 {return new InsertStatement(dataverseName, datasetName, query, getVarCounter());}
vinayakb38b7ca42012-03-05 05:44:15 +0000264}
265
266DeleteStatement DeleteStatement() throws ParseException:
267{
268 VariableExpr var = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000269 Identifier dataverseName;
vinayakb38b7ca42012-03-05 05:44:15 +0000270 Identifier datasetName = null;
271 Expression condition = null;
272 Clause dieClause = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000273 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000274}
275{
276 var = Variable() { getCurrentScope().addNewVarSymbolToScope(var.getVar()); }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000277 "from"
278 <DATASET>
279 {
280 nameComponents = getDotSeparatedPair();
281 }
282 ("where" condition = Expression())? (dieClause = DieClause())? ";"
283 {return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, dieClause, getVarCounter()); }
vinayakb38b7ca42012-03-05 05:44:15 +0000284}
285
286UpdateStatement UpdateStatement() throws ParseException:
287{
288 VariableExpr vars;
289 Expression target;
290 Expression condition;
291 UpdateClause uc;
292 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
293}
294{
295 vars = Variable() "in" target = Expression()
296 "where" condition = Expression()
297 <LEFTPAREN> (uc=UpdateClause() {ucs.add(uc); } ("," uc=UpdateClause() {ucs.add(uc); } )*) <RIGHTPAREN> ";"
298 {return new UpdateStatement(vars, target, condition, ucs);}
299}
300
301
302
303UpdateClause UpdateClause() throws ParseException:
304{
305 Expression target = null;
306 Expression value = null ;
307 InsertStatement is = null;
308 DeleteStatement ds = null;
309 UpdateStatement us = null;
310 Expression condition = null;
311 UpdateClause ifbranch = null;
312 UpdateClause elsebranch = null;
313}
314{
315 "set" target = Expression() ":=" value = Expression()
316 | "insert" is = InsertStatement()
317 | "delete" ds = DeleteStatement()
318 | "update" us = UpdateStatement()
319 | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN> "then" ifbranch = UpdateClause() [LOOKAHEAD(1) "else" elsebranch = UpdateClause()]
320 {return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);}
321}
322
323
324Statement SetStatement() throws ParseException:
325{
326 String pn = null;
327 Statement stmt = null;
328}
329{
330 <IDENTIFIER> { pn = token.image; }
331 <STRING_LITERAL>
332 { String pv = removeQuotesAndEscapes(token.image); }
333 ";"
334 {
335 return new SetStatement(pn, pv);
336 }
337}
338
339Statement WriteStatement() throws ParseException:
340{
341 Identifier nodeName = null;
342 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000343 Statement stmt = null;
344 Query query;
345 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000346 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000347}
348{
349 (( "output" "to"
350 <IDENTIFIER> { nodeName = new Identifier(token.image); }
351 ":" <STRING_LITERAL> { fileName = removeQuotesAndEscapes(token.image); }
352 ( "using" <STRING_LITERAL> { writerClass = removeQuotesAndEscapes(token.image); } )?
353 {
354 stmt = new WriteStatement(nodeName, fileName, writerClass);
355 } )
356 |
357 ( "into"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000358 <DATASET>
359
360 {
361 nameComponents = getDotSeparatedPair();
362 }
363
vinayakb38b7ca42012-03-05 05:44:15 +0000364 <LEFTPAREN> query = Query() <RIGHTPAREN>
365 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000366 stmt = new WriteFromQueryResultStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +0000367 } ))
368
369 ";"
370 {
371 return stmt;
372 }
373}
374
375CreateIndexStatement CreateIndexStatement() throws ParseException:
376{
377 CreateIndexStatement cis = new CreateIndexStatement();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000378 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000379}
380{
381 <IDENTIFIER> { cis.setIndexName(new Identifier(token.image)); }
382 (
383 "if not exists"
384 {
385 cis.setIfNotExists(true);
386 }
387 )?
388 "on"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000389
390 {
391 nameComponents = getDotSeparatedPair();
392 cis.setDataverseName(nameComponents.first);
393 cis.setDatasetName(nameComponents.second);
394 }
395
vinayakb38b7ca42012-03-05 05:44:15 +0000396 <LEFTPAREN>
397 ( <IDENTIFIER> { cis.addFieldExpr(token.image); } )
398 ("," <IDENTIFIER> { cis.addFieldExpr(token.image); })*
399 <RIGHTPAREN>
400 ("type"
401 ("btree" { cis.setIndexType(IndexType.BTREE); }
alexander.behmc576c602012-07-06 02:41:15 +0000402 | "keyword" { cis.setIndexType(IndexType.WORD_INVIX); }
403 | "rtree" { cis.setIndexType(IndexType.RTREE); }
404 | "ngram"
405 <LEFTPAREN>
406 (<INTEGER_LITERAL>
407 {
408 cis.setIndexType(IndexType.NGRAM_INVIX);
409 cis.setGramLength(Integer.valueOf(token.image));
410 }
411 )
412 <RIGHTPAREN>
413 )
vinayakb38b7ca42012-03-05 05:44:15 +0000414 ";"
415 | ";"
416 )
417 {
418 return cis;
419 }
420}
421
422DataverseDecl DataverseDeclaration() throws ParseException:
423{
424 Identifier dvName = null;
425}
426{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000427 "dataverse" <IDENTIFIER> { defaultDataverse = token.image;}
vinayakb38b7ca42012-03-05 05:44:15 +0000428 ";"
429 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000430 return new DataverseDecl(new Identifier(defaultDataverse));
vinayakb38b7ca42012-03-05 05:44:15 +0000431 }
432}
433
434DropStatement DropStatement() throws ParseException :
435{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000436 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000437 Identifier datasetName = null;
438 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000439 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000440}
441{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000442 {
443 nameComponents = getDotSeparatedPair();
444 dataverseName = nameComponents.first;
445 datasetName = nameComponents.second;
446 }
447
448
vinayakb38b7ca42012-03-05 05:44:15 +0000449 (
450 "if exists"
451 {
452 ifExists = true;
453 }
454 )? ";"
455 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000456 return new DropStatement(dataverseName, datasetName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000457 }
458}
459
460IndexDropStatement IndexDropStatement() throws ParseException :
461{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000462 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000463 Identifier datasetName = null;
464 Identifier indexName = null;
465 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000466 Triple<Identifier,Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000467}
468{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000469
vinayakb38b7ca42012-03-05 05:44:15 +0000470 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000471 nameComponents = getDotSeparatedTriple();
472 dataverseName = nameComponents.first;
473 datasetName = nameComponents.second;
474 indexName = nameComponents.third;
475 }
476
vinayakb38b7ca42012-03-05 05:44:15 +0000477 (
478 "if exists"
479 {
480 ifExists = true;
481 }
482 )? ";"
483 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000484 return new IndexDropStatement(dataverseName, datasetName, indexName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000485 }
486}
487
488NodeGroupDropStatement NodeGroupDropStatement() throws ParseException :
489{
490 Identifier groupName = null;
491 boolean ifExists = false;
492}
493{
494 < IDENTIFIER >
495 {
496 groupName = new Identifier(token.image);
497 }
498 (
499 "if exists"
500 {
501 ifExists = true;
502 }
503 )? ";"
504 {
505 return new NodeGroupDropStatement(groupName, ifExists);
506 }
507}
508
509TypeDropStatement TypeDropStatement() throws ParseException :
510{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000511 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000512 Identifier typeName = null;
513 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000514 Pair<Identifier,Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000515}
516{
vinayakb38b7ca42012-03-05 05:44:15 +0000517 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000518 nameComponents = getDotSeparatedPair();
519 dataverseName = nameComponents.first == null ? new Identifier(defaultDataverse) : nameComponents.first;
520 typeName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000521 }
522 (
523 "if exists"
524 {
525 ifExists = true;
526 }
527 )? ";"
528 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000529 return new TypeDropStatement(dataverseName, typeName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000530 }
531}
532
533DataverseDropStatement DataverseDropStatement() throws ParseException :
534{
535 Identifier dataverseName = null;
536 boolean ifExists = false;
537}
538{
539 < IDENTIFIER >
540 {
541 dataverseName = new Identifier(token.image);
542 }
543 (
544 "if exists"
545 {
546 ifExists = true;
547 }
548 )? ";"
549 {
550 return new DataverseDropStatement(dataverseName, ifExists);
551 }
552}
553
554CreateDataverseStatement CreateDataverseStatement() throws ParseException :
555{
556 Identifier dvName = null;
557 boolean ifNotExists = false;
558 String format = null;
559}
560{
561 < IDENTIFIER >
562 {
563 dvName = new Identifier(token.image);
564 }
565 (
566 "if not exists"
567 {
568 ifNotExists = true;
569 }
570 )?
571 (
572 "with format" < STRING_LITERAL >
573 {
574 format = removeQuotesAndEscapes(token.image);
575 }
576 )?
577 ";"
578 {
579 return new CreateDataverseStatement(dvName, format, ifNotExists);
580 }
581}
582
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000583
584FunctionDropStatement FunctionDropStatement() throws ParseException :
585{
586 String dataverse;
587 String functionName;
588 int arity=0;
589 boolean ifExists = false;
590 Pair<Identifier, Identifier> nameComponents=null;
591}
592{
593 {
594 nameComponents = getDotSeparatedPair();
595 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
596 functionName = nameComponents.second.getValue();
597 }
598
599 "@"
600 <INTEGER_LITERAL>
601 {
602 Token t= getToken(0);
603 arity = new Integer(t.image);
604 if( arity < 0 && arity != FunctionIdentifier.VARARGS){
605 throw new ParseException(" invalid arity:" + arity);
606 }
607 }
608
609 (
610 "if exists"
611 {
612 ifExists = true;
613 }
614 )? ";"
615 {
616 return new FunctionDropStatement(new FunctionSignature(dataverse, functionName, arity), ifExists);
617 }
618}
619
620
vinayakb38b7ca42012-03-05 05:44:15 +0000621LoadFromFileStatement LoadStatement() throws ParseException:
622{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000623 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000624 Identifier datasetName = null;
625 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000626 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000627 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000628 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000629}
630{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000631 <DATASET>
632 {
633 nameComponents = getDotSeparatedPair();
634 dataverseName = nameComponents.first;
635 datasetName = nameComponents.second;
636 }
637
vinayakb38b7ca42012-03-05 05:44:15 +0000638 "using"
ramangrover29669d8f62013-02-11 06:03:32 +0000639
vinayakb38b7ca42012-03-05 05:44:15 +0000640 {
ramangrover29669d8f62013-02-11 06:03:32 +0000641 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000642 }
ramangrover29669d8f62013-02-11 06:03:32 +0000643
vinayakb38b7ca42012-03-05 05:44:15 +0000644 {
645 properties = getConfiguration();
646 }
647
648 ("pre-sorted"
649 { alreadySorted = true; }
650 )?
651
652 ";"
653 {
ramangrover29669d8f62013-02-11 06:03:32 +0000654 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
vinayakb38b7ca42012-03-05 05:44:15 +0000655 }
656}
657
658
ramangrover29669d8f62013-02-11 06:03:32 +0000659String getAdapterName() throws ParseException :
660{
661 String adapterName = null;
662}
663{
664 (
665 <IDENTIFIER> {
666 adapterName = (new Identifier(token.image)).getValue();;
667 }
668 |
669 <STRING_LITERAL>
670 {
671 adapterName = removeQuotesAndEscapes(token.image);
672 }
673 )
674 {
675 return adapterName;
676 }
677}
678
vinayakb38b7ca42012-03-05 05:44:15 +0000679
680DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException :
681{
682 DatasetDecl dd = null;
683 Identifier datasetName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000684 Identifier dataverseName = null;
685 Identifier itemDataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000686 Identifier itemTypeName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000687 String nameComponentFirst = null;
688 String nameComponentSecond = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000689 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000690 IDatasetDetailsDecl datasetDetails = null;
ramangrover2971e5c6a2013-01-30 05:30:12 +0000691 Pair<Identifier,Identifier> nameComponents = null;
692 Map<String,String> hints = new HashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000693}
694{
vinayakb38b7ca42012-03-05 05:44:15 +0000695 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000696 nameComponents = getDotSeparatedPair();
697 dataverseName = nameComponents.first;
698 datasetName = nameComponents.second;
699 }
700
vinayakb38b7ca42012-03-05 05:44:15 +0000701 (
702 "if not exists"
703 {
704 ifNotExists = true;
705 }
706 )?
707 (
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000708 < LEFTPAREN > <IDENTIFIER>
vinayakb38b7ca42012-03-05 05:44:15 +0000709 {
710 itemTypeName = new Identifier(token.image);
711 }
712 < RIGHTPAREN >
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +0000713 )
vinayakb38b7ca42012-03-05 05:44:15 +0000714 {
715 if(datasetType == DatasetType.INTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000716 datasetDetails = InternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000717 }
718 else if(datasetType == DatasetType.EXTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000719 datasetDetails = ExternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000720 }
721 else if(datasetType == DatasetType.FEED) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000722 datasetDetails = FeedDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000723 }
vinayakb38b7ca42012-03-05 05:44:15 +0000724 }
ramangrover2971e5c6a2013-01-30 05:30:12 +0000725
726 (
727 "hints"
vinayakb38b7ca42012-03-05 05:44:15 +0000728 {
ramangrover2971e5c6a2013-01-30 05:30:12 +0000729 initProperties(hints);
730 }
731 )?
732 ";"
733
734 {
735 dd = new DatasetDecl(dataverseName, datasetName, itemTypeName, hints, datasetType, datasetDetails,ifNotExists);
736 return dd;
vinayakb38b7ca42012-03-05 05:44:15 +0000737 }
738}
739
740InternalDetailsDecl InternalDatasetDeclaration() throws ParseException :
741{
742 InternalDetailsDecl idd = null;
ramangrover292f199b02013-02-13 05:32:01 +0000743 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000744 Identifier nodeGroupName=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000745}
746{
vinayakb38b7ca42012-03-05 05:44:15 +0000747 (
vinayakb38b7ca42012-03-05 05:44:15 +0000748 {
ramangrover292f199b02013-02-13 05:32:01 +0000749 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000750 }
ramangrover29669d8f62013-02-11 06:03:32 +0000751 )
752
vinayakb38b7ca42012-03-05 05:44:15 +0000753 (
754 "on" < IDENTIFIER >
755 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000756 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000757 }
758 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000759
vinayakb38b7ca42012-03-05 05:44:15 +0000760 {
ramangrover292f199b02013-02-13 05:32:01 +0000761 idd = new InternalDetailsDecl(nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000762 return idd;
763 }
764}
765
766ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException :
767{
768 ExternalDetailsDecl edd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000769 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000770 Map < String, String > properties;
771}
772{
773 {
774 edd = new ExternalDetailsDecl();
775 }
776
777 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000778 {
ramangrover29669d8f62013-02-11 06:03:32 +0000779 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000780 }
781
782 {
783 properties = getConfiguration();
784 }
785
786 {
787 edd = new ExternalDetailsDecl();
ramangrover29669d8f62013-02-11 06:03:32 +0000788 edd.setAdapter(adapterName);
vinayakb38b7ca42012-03-05 05:44:15 +0000789 edd.setProperties(properties);
790 }
vinayakb38b7ca42012-03-05 05:44:15 +0000791
792 {
793 return edd;
794 }
795}
796
797FeedDetailsDecl FeedDatasetDeclaration() throws ParseException :
798{
799 FeedDetailsDecl fdd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000800 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000801 Map < String, String > properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000802 Pair<Identifier,Identifier> nameComponents;
ramangrover292f199b02013-02-13 05:32:01 +0000803 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000804 Identifier nodeGroupName=null;
805 FunctionSignature appliedFunction=null;
806 String dataverse;
807 String functionName;
808 int arity;
vinayakb38b7ca42012-03-05 05:44:15 +0000809}
810{
vinayakb38b7ca42012-03-05 05:44:15 +0000811 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000812 {
ramangrover29669d8f62013-02-11 06:03:32 +0000813 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000814 }
815
816 {
817 properties = getConfiguration();
818 }
819
820 ("apply" "function"
vinayakb38b7ca42012-03-05 05:44:15 +0000821 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000822 nameComponents = getDotSeparatedPair();
823 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
824 functionName = nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +0000825 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000826 ("@" <INTEGER_LITERAL>
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000827 {
828 arity = Integer.parseInt(token.image);
829 }
830 )
831
832 {
833 appliedFunction = new FunctionSignature(dataverse, functionName, arity);
834 }
vinayakb38b7ca42012-03-05 05:44:15 +0000835 )?
836
vinayakb38b7ca42012-03-05 05:44:15 +0000837 (
vinayakb38b7ca42012-03-05 05:44:15 +0000838 {
ramangrover292f199b02013-02-13 05:32:01 +0000839 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000840 }
ramangrover29669d8f62013-02-11 06:03:32 +0000841 )
842
vinayakb38b7ca42012-03-05 05:44:15 +0000843 (
844 "on" < IDENTIFIER >
845 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000846 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000847 }
848 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000849
vinayakb38b7ca42012-03-05 05:44:15 +0000850 {
ramangrover292f199b02013-02-13 05:32:01 +0000851 fdd = new FeedDetailsDecl(adapterName, properties, appliedFunction, nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000852 return fdd;
853 }
854}
855
ramangrover292f199b02013-02-13 05:32:01 +0000856List<String> getPrimaryKeyFields() throws ParseException :
ramangrover29669d8f62013-02-11 06:03:32 +0000857{
ramangrover292f199b02013-02-13 05:32:01 +0000858 List<String> primaryKeyFields = new ArrayList<String>();
ramangrover29669d8f62013-02-11 06:03:32 +0000859}
860{
861
862 "primary" "key"
863 < IDENTIFIER >
864 {
ramangrover292f199b02013-02-13 05:32:01 +0000865 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000866 }
867 (
868 "," < IDENTIFIER >
869 {
ramangrover292f199b02013-02-13 05:32:01 +0000870 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000871 }
872 )*
873 {
ramangrover292f199b02013-02-13 05:32:01 +0000874 return primaryKeyFields;
ramangrover29669d8f62013-02-11 06:03:32 +0000875 }
876
877}
878
879
880
881
882
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000883ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000884{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000885 Pair<Identifier,Identifier> nameComponents = null;
886}
887{
888 {
889 nameComponents = getDotSeparatedPair();
890 return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second);
891 }
892}
893
894
895ControlFeedStatement AlterFeedDeclaration() throws ParseException :
896{
897 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000898 Map < String, String > configuration = new HashMap < String, String > ();
899}
900{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000901 {
902 nameComponents = getDotSeparatedPair();
903 }
904
vinayakb38b7ca42012-03-05 05:44:15 +0000905 "set"
906 {
907 configuration = getConfiguration();
908 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000909
vinayakb38b7ca42012-03-05 05:44:15 +0000910 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000911 return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
vinayakb38b7ca42012-03-05 05:44:15 +0000912 }
913}
914
915Map<String,String> getConfiguration() throws ParseException :
916{
917 Map<String,String> configuration = new HashMap<String,String>();
918 String key;
919 String value;
920}
921{
922
923<LEFTPAREN>
924 (
925 (
926 <LEFTPAREN>
927 (
928 <STRING_LITERAL>
929 {
930 key = removeQuotesAndEscapes(token.image);
931 }
932 "=" <STRING_LITERAL>
933 {
934 value = removeQuotesAndEscapes(token.image);
935 }
936 )
937 <RIGHTPAREN>
938 {
939 configuration.put(key, value);
940 }
941 )
942 (
943 "," <LEFTPAREN>
944 (
945 <STRING_LITERAL>
946 {
947 key = removeQuotesAndEscapes(token.image);
948 }
949 "=" <STRING_LITERAL>
950 {
951 value = removeQuotesAndEscapes(token.image);
952 }
953 )
954 <RIGHTPAREN>
955 {
956 configuration.put(key, value);
957 }
958 )*
959 )?
960 <RIGHTPAREN>
961 {
962 return configuration;
963 }
964}
965
ramangrover2971e5c6a2013-01-30 05:30:12 +0000966void initProperties(Map<String,String> properties) throws ParseException :
967{
968 String key;
969 String value;
970}
971{
972 (
973 <LEFTPAREN>
974 (
975 <IDENTIFIER>
976 {
977 key = (new Identifier(token.image)).getValue();
978 }
979 "="
980 (
981 (<STRING_LITERAL>
982 {
983 value = removeQuotesAndEscapes(token.image);
984 }
985 ) |
986 (<INTEGER_LITERAL>
987 {
988 try{
ramangrover2921b88182013-01-31 00:51:19 +0000989 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +0000990 } catch (NumberFormatException nfe){
991 throw new ParseException("inapproriate value: " + token.image);
992 }
993 }
994 )
995 )
996 {
ramangrover2954f1fc42013-02-09 00:46:26 +0000997 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +0000998 }
999 (
1000 ","
1001 (
1002 <IDENTIFIER>
1003 {
1004 key = (new Identifier(token.image)).getValue();
1005 }
1006 "="
1007 (
1008 (<STRING_LITERAL>
1009 {
1010 value = removeQuotesAndEscapes(token.image);
1011 }
1012 ) |
1013 (<INTEGER_LITERAL>
1014 {
1015 try{
ramangrover2921b88182013-01-31 00:51:19 +00001016 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001017 } catch (NumberFormatException nfe){
1018 throw new ParseException("inapproriate value: " + token.image);
1019 }
1020 }
1021 )
1022 )
1023 )
1024 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001025 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001026 }
1027
1028 )*
1029 )
1030 <RIGHTPAREN>
1031 )?
1032}
1033
1034
vinayakb38b7ca42012-03-05 05:44:15 +00001035
1036NodegroupDecl NodegroupDeclaration() throws ParseException :
1037{
1038 Identifier name = null;
1039 List < Identifier > ncNames = new ArrayList < Identifier > ();
1040 boolean ifNotExists = false;
1041}
1042{
1043 < IDENTIFIER >
1044 {
1045 name = new Identifier(token.image);
1046 }
1047 (
1048 "if not exists"
1049 {
1050 ifNotExists = true;
1051 }
1052 )?
1053 "on" < IDENTIFIER >
1054 {
1055 ncNames.add(new Identifier(token.image));
1056 }
1057 (
1058 "," < IDENTIFIER >
1059 {
1060 ncNames.add(new Identifier(token.image));
1061 }
1062 )*
1063 ";"
1064 {
1065 return new NodegroupDecl(name, ncNames, ifNotExists);
1066 }
1067}
1068
1069
1070TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException:
1071{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001072 Identifier dataverse;
vinayakb38b7ca42012-03-05 05:44:15 +00001073 Identifier ident;
1074 TypeExpression typeExpr;
1075 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001076 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001077}
1078{
vinayakb38b7ca42012-03-05 05:44:15 +00001079 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001080 nameComponents = getDotSeparatedPair();
1081 dataverse = nameComponents.first;
1082 ident = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001083 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001084
vinayakb38b7ca42012-03-05 05:44:15 +00001085 (
1086 "if not exists"
1087 {
1088 ifNotExists = true;
1089 }
1090 )?
1091 "as"
1092 ( typeExpr = TypeExpr() )
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001093 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001094 {
1095 long numValues = -1;
1096 String filename = null;
1097 if (dgen) {
1098 String splits[] = hint.split(" +");
1099 if (splits.length != 3) {
1100 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
1101 }
1102 filename = splits[1];
1103 numValues = Long.parseLong(splits[2]);
1104 }
1105 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001106 return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001107 }
1108}
1109
1110TypeExpression TypeExpr() throws ParseException:
1111{
1112 TypeExpression typeExpr = null;
1113}
1114{
1115 (
1116 typeExpr = RecordTypeDef()
1117 | typeExpr = TypeReference()
1118 | typeExpr = OrderedListTypeDef()
1119 | typeExpr = UnorderedListTypeDef()
1120 )
1121 {
1122 return typeExpr;
1123 }
1124}
1125
1126RecordTypeDefinition RecordTypeDef() throws ParseException:
1127{
1128 RecordTypeDefinition recType = new RecordTypeDefinition();
1129 RecordTypeDefinition.RecordKind recordKind = null;
1130}
1131{
1132 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1133 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1134 "{"
1135 {
1136 String hint = getHint(token);
1137 if (hint != null) {
1138 String splits[] = hint.split(" +");
1139 if (splits[0].equals(GEN_FIELDS_HINT)) {
1140 if (splits.length != 5) {
1141 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1142 }
1143 if (!splits[1].equals("int")) {
1144 throw new ParseException("The only supported type for gen-fields is int.");
1145 }
1146 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1147 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1148 recType.setUndeclaredFieldsDataGen(ufdg);
1149 }
1150 }
1151
1152 }
1153 (
1154 RecordField(recType)
1155 ( "," RecordField(recType) )*
1156 )?
1157 "}"
1158 {
1159 if (recordKind == null) {
1160 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1161 }
1162 recType.setRecordKind(recordKind);
1163 return recType;
1164 }
1165}
1166
1167void RecordField(RecordTypeDefinition recType) throws ParseException:
1168{
1169 String fieldName;
1170 TypeExpression type = null;
1171 boolean nullable = false;
1172}
1173{
1174 <IDENTIFIER>
1175 {
1176 Token t = getToken(0);
1177 fieldName = t.toString();
1178 String hint = getHint(t);
1179 IRecordFieldDataGen rfdg = null;
1180 if (hint != null) {
1181 String splits[] = hint.split(" +");
1182 if (splits[0].equals(VAL_FILE_HINT)) {
1183 File[] valFiles = new File[splits.length - 1];
1184 for (int k=1; k<splits.length; k++) {
1185 valFiles[k-1] = new File(splits[k]);
1186 }
1187 rfdg = new FieldValFileDataGen(valFiles);
1188 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
1189 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
1190 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
1191 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
1192 } else if (splits[0].equals(LIST_HINT)) {
1193 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1194 } else if (splits[0].equals(INTERVAL_HINT)) {
1195 FieldIntervalDataGen.ValueType vt;
1196 if (splits[1].equals("int")) {
1197 vt = FieldIntervalDataGen.ValueType.INT;
1198 } else if (splits[1].equals("long")) {
1199 vt = FieldIntervalDataGen.ValueType.LONG;
1200 } else if (splits[1].equals("float")) {
1201 vt = FieldIntervalDataGen.ValueType.FLOAT;
1202 } else if (splits[1].equals("double")) {
1203 vt = FieldIntervalDataGen.ValueType.DOUBLE;
1204 } else {
1205 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
1206 }
1207 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
1208 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
1209 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
1210 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
1211 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1212 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
1213 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1214 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
1215 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
1216 } else if (splits[0].equals(AUTO_HINT)) {
1217 rfdg = new AutoDataGen(splits[1]);
1218 }
1219 }
1220 }
1221 ":"
1222 ( type = TypeExpr() )
1223 ("?" { nullable = true; } )?
1224 {
1225 recType.addField(fieldName, type, nullable, rfdg);
1226 }
1227}
1228
1229TypeReferenceExpression TypeReference() throws ParseException:
1230{}
1231{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001232 <IDENTIFIER>
1233 {
1234 Token t = getToken(0);
1235 Identifier id = new Identifier(t.toString());
1236 return new TypeReferenceExpression(id);
1237 }
vinayakb38b7ca42012-03-05 05:44:15 +00001238}
1239
1240OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1241{
1242 TypeExpression type = null;
1243}
1244{
1245 "["
1246 ( type = TypeExpr() )
1247 "]"
1248 {
1249 return new OrderedListTypeDefinition(type);
1250 }
1251}
1252
1253
1254UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1255{
1256 TypeExpression type = null;
1257}
1258{
1259 "{{"
1260 ( type = TypeExpr() )
1261 "}}"
1262 {
1263 return new UnorderedListTypeDefinition(type);
1264 }
1265}
1266
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001267Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException:
1268{
1269 Identifier first = null;
1270 Identifier second = null;
1271}
1272{
1273 < IDENTIFIER >
1274 {
1275 first = new Identifier(token.image);
1276 }
1277 ("." <IDENTIFIER>
1278 {
1279 second = new Identifier(token.image);
1280 }
1281 )?
1282
1283 {
1284 if(second == null){
1285 second = first;
1286 first = null;
1287 }
1288
1289 return new Pair<Identifier,Identifier>(first,second);
1290 }
1291}
1292
1293Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException:
1294{
1295 Identifier first = null;
1296 Identifier second = null;
1297 Identifier third = null;
1298}
1299{
1300 < IDENTIFIER >
1301 {
1302 first = new Identifier(token.image);
1303 }
1304 "." <IDENTIFIER>
1305 {
1306 second = new Identifier(token.image);
1307 }
1308 (
1309 "." <IDENTIFIER>
1310 {
1311 third = new Identifier(token.image);
1312 }
1313 )?
1314
1315 {
1316 if(third == null){
1317 third = second;
1318 second = first;
1319 first = null;
1320 }
1321
1322 return new Triple<Identifier,Identifier,Identifier>(first,second,third);
1323 }
1324}
1325
1326
1327
vinayakb38b7ca42012-03-05 05:44:15 +00001328
1329FunctionDecl FunctionDeclaration() throws ParseException:
1330{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001331 FunctionDecl funcDecl;
1332 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001333 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001334 int arity = 0;
1335 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1336 Expression funcBody;
1337 VarIdentifier var = null;
1338 createNewScope();
1339}
1340{
1341
1342 <IDENTIFIER>
1343 {
1344 Token t = getToken(0);
ramangrover29a13f2422012-03-15 23:01:27 +00001345 functionName = t.toString();
vinayakb38b7ca42012-03-05 05:44:15 +00001346 }
1347 <LEFTPAREN> (<VARIABLE>
1348 {
1349 var = new VarIdentifier();
1350 var.setValue(getToken(0).toString());
1351 paramList.add(var);
1352 getCurrentScope().addNewVarSymbolToScope(var);
1353 arity++;
1354 }
1355 ("," <VARIABLE>
1356 {
1357 var = new VarIdentifier();
1358 var.setValue(getToken(0).toString());
1359 paramList.add(var);
1360 getCurrentScope().addNewVarSymbolToScope(var);
1361 arity++;
1362 })*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
1363
1364 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001365 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1366 getCurrentScope().addFunctionDescriptor(signature, false);
1367 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1368 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001369 }
1370}
1371
1372CreateFunctionStatement FunctionCreation() throws ParseException:
1373{
1374 CreateFunctionStatement cfs = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001375 FunctionSignature signature;
1376 String dataverse;
ramangrover29a13f2422012-03-15 23:01:27 +00001377 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001378 boolean ifNotExists = false;
1379 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001380 String functionBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001381 VarIdentifier var = null;
1382 createNewScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001383 Expression functionBodyExpr;
1384 Token beginPos;
1385 Token endPos;
1386 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001387}
1388{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001389 {
1390 nameComponents = getDotSeparatedPair();
1391 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
1392 functionName= nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +00001393 }
1394
1395 (
1396 "if not exists"
1397 {
1398 ifNotExists = true;
1399 }
1400 )?
1401
1402 <LEFTPAREN> (<VARIABLE>
1403 {
1404 var = new VarIdentifier();
1405 var.setValue(getToken(0).toString());
1406 paramList.add(var);
1407 getCurrentScope().addNewVarSymbolToScope(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001408 }
1409 ("," <VARIABLE>
1410 {
1411 var = new VarIdentifier();
1412 var.setValue(getToken(0).toString());
1413 paramList.add(var);
1414 getCurrentScope().addNewVarSymbolToScope(var);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001415 })*)? <RIGHTPAREN> "{"
vinayakb38b7ca42012-03-05 05:44:15 +00001416 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001417 beginPos = getToken(0);
1418 }
1419 functionBodyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001420 "}"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001421 {
1422 endPos = getToken(0);
1423 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
1424 }
vinayakb38b7ca42012-03-05 05:44:15 +00001425 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001426 signature = new FunctionSignature(dataverse, functionName, paramList.size());
1427 getCurrentScope().addFunctionDescriptor(signature, false);
1428 cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001429 return cfs;
1430 }
1431}
1432
1433
1434
1435Query Query()throws ParseException:
1436{
1437 Query query = new Query();
1438 Expression expr;
1439}
1440{
1441 expr = Expression()
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001442 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001443 {
1444 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001445 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001446 return query;
1447 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001448
vinayakb38b7ca42012-03-05 05:44:15 +00001449}
1450
1451
1452
1453Expression Expression():
1454{
1455 Expression expr = null;
1456 Expression exprP = null;
1457}
1458{
1459(
1460
1461//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1462 expr = OperatorExpr()
1463 | expr = IfThenElse()
1464 | expr = FLWOGR()
1465 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001466
vinayakb38b7ca42012-03-05 05:44:15 +00001467
1468)
1469 {
1470 return (exprP==null) ? expr : exprP;
1471 }
1472}
1473
1474
1475
1476Expression OperatorExpr()throws ParseException:
1477{
1478 OperatorExpr op = null;
1479 Expression operand = null;
1480}
1481{
1482 operand = AndExpr()
1483 (
1484
1485 "or"
1486 {
1487 if (op == null) {
1488 op = new OperatorExpr();
1489 op.addOperand(operand);
1490 op.setCurrentop(true);
1491 }
1492 Token t = getToken(0);
1493 op.addOperator(t.toString());
1494 }
1495
1496 operand = AndExpr()
1497 {
1498 op.addOperand(operand);
1499 }
1500
1501 )*
1502
1503 {
1504 return op==null? operand: op;
1505 }
1506}
1507
1508Expression AndExpr()throws ParseException:
1509{
1510 OperatorExpr op = null;
1511 Expression operand = null;
1512}
1513{
1514 operand = RelExpr()
1515 (
1516
1517 "and"
1518 {
1519 if (op == null) {
1520 op = new OperatorExpr();
1521 op.addOperand(operand);
1522 op.setCurrentop(true);
1523 }
1524 Token t = getToken(0);
1525 op.addOperator(t.toString());
1526 }
1527
1528 operand = RelExpr()
1529 {
1530 op.addOperand(operand);
1531 }
1532
1533 )*
1534
1535 {
1536 return op==null? operand: op;
1537 }
1538}
1539
1540
1541
1542Expression RelExpr()throws ParseException:
1543{
1544 OperatorExpr op = null;
1545 Expression operand = null;
1546 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001547 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001548}
1549{
1550 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001551 {
1552 if (operand instanceof VariableExpr) {
1553 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001554 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001555 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001556 }
1557 }
1558 }
1559
1560 (
1561 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1562 {
alexander.behm07617fd2012-07-25 10:13:50 +00001563 String mhint = getHint(token);
1564 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1565 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1566 }
vinayakb38b7ca42012-03-05 05:44:15 +00001567 if (op == null) {
1568 op = new OperatorExpr();
1569 op.addOperand(operand, broadcast);
1570 op.setCurrentop(true);
1571 broadcast = false;
1572 }
1573 Token t = getToken(0);
1574 op.addOperator(t.toString());
1575 }
1576
1577 operand = AddExpr()
1578 {
alexander.behm07617fd2012-07-25 10:13:50 +00001579 broadcast = false;
1580 if (operand instanceof VariableExpr) {
1581 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001582 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1583 broadcast = true;
1584 }
alexander.behm07617fd2012-07-25 10:13:50 +00001585 }
vinayakb38b7ca42012-03-05 05:44:15 +00001586 op.addOperand(operand, broadcast);
1587 }
1588 )?
1589
1590 {
alexander.behm07617fd2012-07-25 10:13:50 +00001591 if (annotation != null) {
1592 op.addHint(annotation);
1593 }
vinayakb38b7ca42012-03-05 05:44:15 +00001594 return op==null? operand: op;
1595 }
1596}
1597
1598Expression AddExpr()throws ParseException:
1599{
1600 OperatorExpr op = null;
1601 Expression operand = null;
1602}
1603{
1604 operand = MultExpr()
1605
1606 ( ("+" | "-")
1607 {
1608 if (op == null) {
1609 op = new OperatorExpr();
1610 op.addOperand(operand);
1611 op.setCurrentop(true);
1612 }
1613 Token t = getToken(0);
1614 ((OperatorExpr)op).addOperator(t.toString());
1615 }
1616
1617 operand = MultExpr()
1618 {
1619 op.addOperand(operand);
1620 }
1621 )*
1622
1623 {
1624 return op==null? operand: op;
1625 }
1626}
1627
1628Expression MultExpr()throws ParseException:
1629{
1630 OperatorExpr op = null;
1631 Expression operand = null;
1632}
1633{
1634 operand = UnionExpr()
1635
1636 (( "*" | "/" | "%" | <CARET> | "idiv")
1637 {
1638 if (op == null) {
1639 op = new OperatorExpr();
1640 op.addOperand(operand);
1641 op.setCurrentop(true);
1642 }
1643 Token t = getToken(0);
1644 op.addOperator(t.toString());
1645 }
1646 operand = UnionExpr()
1647 {
1648 op.addOperand(operand);
1649 }
1650 )*
1651
1652 {
1653 return op==null?operand:op;
1654 }
1655}
1656
1657Expression UnionExpr() throws ParseException:
1658{
1659 UnionExpr union = null;
1660 Expression operand1 = null;
1661 Expression operand2 = null;
1662}
1663{
1664 operand1 = UnaryExpr()
1665 ("union"
1666 (operand2 = UnaryExpr()) {
1667 if (union == null) {
1668 union = new UnionExpr();
1669 union.addExpr(operand1);
1670 }
1671 union.addExpr(operand2);
1672 } )*
1673 {
1674 return (union == null)? operand1: union;
1675 }
1676}
1677
1678Expression UnaryExpr() throws ParseException:
1679{
1680 Expression uexpr = null;
1681 Expression expr = null;
1682}
1683{
1684 (( "+"|"-")
1685 {
1686 uexpr = new UnaryExpr();
1687 Token t = getToken(0);
1688 if("+".equals(t.toString()))
1689 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1690 else if("-".equals(t.toString()))
1691 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1692 else
1693 throw new ParseException();
1694 }
1695 )?
1696
1697 expr = ValueExpr()
1698 {
1699 if(uexpr!=null){
1700 ((UnaryExpr)uexpr).setExpr(expr);
1701 return uexpr;
1702 }
1703 else{
1704 return expr;
1705 }
1706 }
1707}
1708
1709Expression ValueExpr() throws ParseException:
1710{
1711 Expression expr;
1712}
1713{
1714 expr = FieldOrIndexAccessor()
1715 {
1716 return expr;
1717 }
1718}
1719
1720
1721Expression FieldOrIndexAccessor()throws ParseException:
1722{
1723 Expression expr = null;
1724 Identifier ident = null;
1725 AbstractAccessor fa = null;
1726 int index;
1727
1728}
1729{
1730 ( expr = PrimaryExpr()
1731
1732 )
1733
1734
1735 (
1736 (
1737 ident = Field()
1738 {
1739 if(fa == null)
1740 fa = new FieldAccessor(expr, ident);
1741 else
1742 fa = new FieldAccessor(fa, ident);
1743 }
1744 )
1745 | (
1746 index = Index()
1747 {
1748 if(fa == null)
1749 fa = new IndexAccessor(expr, index);
1750 else
1751 fa = new IndexAccessor(fa, index);
1752 }
1753 )
1754 )*
1755
1756
1757 {
1758 return fa==null?expr:fa;
1759 }
1760}
1761
1762Identifier Field() throws ParseException:
1763{
1764 Identifier ident = null;
1765
1766}
1767{
1768 "." < IDENTIFIER >
1769 {
1770
1771 ident = new Identifier();
1772 ident.setValue(getToken(0).toString());
1773
1774 return ident;
1775 }
1776}
1777
1778int Index() throws ParseException:
1779{
1780 Expression expr = null;
1781 int idx = -2;
1782}
1783{
1784 "[" ( expr = Expression()
1785 {
1786 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1787 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001788 Literal lit = ((LiteralExpr)expr).getValue();
1789 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1790 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001791 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001792 }
vinayakb38b7ca42012-03-05 05:44:15 +00001793 else {
1794 throw new ParseException("Index should be an INTEGER");
1795 }
1796 }
1797
1798 }
1799
1800 | "?"
1801 {
1802 idx = IndexAccessor.ANY;
1803 // ANY
1804 }
1805
1806 )
1807
1808 "]"
1809 {
1810 return idx;
1811 }
1812}
1813
1814
1815Expression PrimaryExpr()throws ParseException:
1816{
1817 Expression expr = null;
1818}
1819{
ilovesoupc9fef1d2012-07-08 19:30:42 +00001820 //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
vinayakb38b7ca42012-03-05 05:44:15 +00001821 (
1822 expr =Literal()
1823 | expr = FunctionCallExpr()
1824 | expr =VariableRef()
1825
1826 {
1827 if(((VariableExpr)expr).getIsNewVar() == true)
1828 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
1829 }
1830 | expr = ListConstructor()
1831 | expr = RecordConstructor()
1832 | expr = ParenthesizedExpression()
1833 )
1834 {
1835 return expr;
1836 }
1837}
1838
1839Expression Literal() throws ParseException:
1840{
1841
1842 LiteralExpr lit = new LiteralExpr();
1843 Token t;
1844}
1845{
1846(
1847 <STRING_LITERAL>
1848 {
1849 t= getToken(0);
1850 lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image)));
1851 }
1852
1853 | <INTEGER_LITERAL>
1854 {
1855 t= getToken(0);
ilovesoupc9fef1d2012-07-08 19:30:42 +00001856 try {
1857 lit.setValue(new IntegerLiteral(new Integer(t.image)));
1858 } catch(NumberFormatException ex) {
1859 lit.setValue(new LongIntegerLiteral(new Long(t.image)));
1860 }
vinayakb38b7ca42012-03-05 05:44:15 +00001861 }
1862 | < FLOAT_LITERAL >
1863 {
1864 t= getToken(0);
1865 lit.setValue(new FloatLiteral(new Float(t.image)));
1866 }
1867 | < DOUBLE_LITERAL >
1868 {
1869 t= getToken(0);
1870 lit.setValue(new DoubleLiteral(new Double(t.image)));
1871 }
1872 | <NULL>
1873 {
1874 t= getToken(0);
1875 lit.setValue(NullLiteral.INSTANCE);
1876 }
1877 | <TRUE>
1878 {
1879 t= getToken(0);
1880 lit.setValue(TrueLiteral.INSTANCE);
1881 }
1882 | <FALSE>
1883 {
1884 t= getToken(0);
1885 lit.setValue(FalseLiteral.INSTANCE);
1886 }
1887)
1888 {
1889 return lit;
1890 }
1891}
1892
1893
1894VariableExpr VariableRef() throws ParseException:
1895{
1896 VariableExpr varExp = new VariableExpr();
1897 VarIdentifier var = new VarIdentifier();
1898 Token t;
1899}
1900{
1901 <VARIABLE>
1902 {
1903 t = getToken(0);//get current token
1904 String varName = t.toString();
1905 Identifier ident = lookupSymbol(varName);
1906 if (isInForbiddenScopes(varName)) {
1907 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.");
1908 }
1909 if(ident != null) { // exist such ident
1910 varExp.setIsNewVar(false);
1911 varExp.setVar((VarIdentifier)ident);
1912 } else {
1913 varExp.setVar(var);
1914 }
1915 var.setValue(t.toString());
1916 return varExp;
1917 }
1918}
1919
1920
1921VariableExpr Variable() throws ParseException:
1922{
1923 VariableExpr varExp = new VariableExpr();
1924 VarIdentifier var = new VarIdentifier();
1925 Token t;
1926}
1927{
1928 <VARIABLE>
1929 {
1930 t = getToken(0);//get current token
1931 Identifier ident = lookupSymbol(t.toString());
1932 if(ident != null) { // exist such ident
1933 varExp.setIsNewVar(false);
1934 }
1935 varExp.setVar(var);
1936 var.setValue(t.toString());
1937 return varExp;
1938 }
1939}
1940
1941Expression ListConstructor() throws ParseException:
1942{
1943 Expression expr = null;
1944}
1945{
1946 (
1947 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1948 )
1949
1950 {
1951 return expr;
1952 }
1953}
1954
1955
1956ListConstructor OrderedListConstructor() throws ParseException:
1957{
1958 ListConstructor expr = new ListConstructor();
1959 Expression tmp = null;
1960 List<Expression> exprList = new ArrayList<Expression>();
1961 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1962}
1963{
1964
1965 "["
1966 ( tmp = Expression()
1967 {
1968 exprList.add(tmp);
1969 }
1970
1971 ("," tmp = Expression() { exprList.add(tmp); })*
1972 )?
1973
1974 "]"
1975
1976 {
1977 expr.setExprList(exprList);
1978 return expr;
1979 }
1980}
1981
1982ListConstructor UnorderedListConstructor() throws ParseException:
1983{
1984 ListConstructor expr = new ListConstructor();
1985 Expression tmp = null;
1986 List<Expression> exprList = new ArrayList<Expression>();
1987 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1988}
1989{
1990
1991 "{{" ( tmp = Expression()
1992 {
1993 exprList.add(tmp);
1994 }
1995 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1996 {
1997 expr.setExprList(exprList);
1998 return expr;
1999 }
2000}
2001
2002RecordConstructor RecordConstructor() throws ParseException:
2003{
2004 RecordConstructor expr = new RecordConstructor();
2005 FieldBinding tmp = null;
2006 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2007}
2008{
2009 "{" (tmp = FieldBinding()
2010 {
2011 fbList.add(tmp);
2012 }
2013 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
2014 {
2015 expr.setFbList(fbList);
2016 return expr;
2017 }
2018}
2019
2020FieldBinding FieldBinding() throws ParseException:
2021{
2022 FieldBinding fb = new FieldBinding();
2023 Expression left, right;
2024}
2025{
2026 left = Expression() ":" right = Expression()
2027 {
2028 fb.setLeftExpr(left);
2029 fb.setRightExpr(right);
2030 return fb;
2031 }
2032}
2033
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002034
vinayakb38b7ca42012-03-05 05:44:15 +00002035Expression FunctionCallExpr() throws ParseException:
2036{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002037 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002038 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002039 Expression tmp;
2040 int arity = 0;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002041 String funcName;
2042 String dataverse;
2043 String hint=null;
2044 String id1=null;
2045 String id2=null;
vinayakb38b7ca42012-03-05 05:44:15 +00002046}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002047{
2048 ( <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 +00002049 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002050 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002051 }
2052 <LEFTPAREN> (tmp = Expression()
2053 {
2054 argList.add(tmp);
2055 arity ++;
2056 } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
2057
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002058 {
2059 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2060 if(signature == null)
2061 {
2062 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2063 }
2064 callExpr = new CallExpr(signature,argList);
2065 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2066 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2067 }
2068 return callExpr;
vinayakb38b7ca42012-03-05 05:44:15 +00002069 }
2070}
2071
2072
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002073
vinayakb38b7ca42012-03-05 05:44:15 +00002074Expression ParenthesizedExpression() throws ParseException:
2075{
2076 Expression expr;
2077}
2078{
2079 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2080 {
2081 return expr;
2082 }
2083}
2084
2085Expression IfThenElse() throws ParseException:
2086{
2087 Expression condExpr;
2088 Expression thenExpr;
2089 Expression elseExpr;
2090 IfExpr ifExpr = new IfExpr();
2091}
2092{
2093 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
2094
2095 {
2096 ifExpr.setCondExpr(condExpr);
2097 ifExpr.setThenExpr(thenExpr);
2098 ifExpr.setElseExpr(elseExpr);
2099 return ifExpr;
2100 }
2101}
2102
2103Expression FLWOGR() throws ParseException:
2104{
2105 FLWOGRExpression flworg = new FLWOGRExpression();
2106 List<Clause> clauseList = new ArrayList<Clause>();
2107 Expression returnExpr;
2108 Clause tmp;
2109 createNewScope();
2110}
2111{
2112 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2113 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
2114
2115 {
2116 flworg.setClauseList(clauseList);
2117 flworg.setReturnExpr(returnExpr);
2118 removeCurrentScope();
2119 return flworg;
2120 }
2121}
2122
2123Clause Clause()throws ParseException :
2124{
2125 Clause clause;
2126}
2127{
2128 (
2129 clause = ForClause()
2130 | clause = LetClause()
2131 | clause = WhereClause()
2132 | clause = OrderbyClause()
2133 | clause = GroupClause()
2134 | clause = LimitClause()
2135 | clause = DistinctClause()
2136 | clause = DieClause()
2137 )
2138 {
2139 return clause;
2140 }
2141}
2142
2143Clause ForClause()throws ParseException :
2144{
2145 ForClause fc = new ForClause();
2146 VariableExpr varExp;
2147 VariableExpr varPos = null;
2148 Expression inExp;
2149 extendCurrentScope();
2150}
2151{
2152 "for" varExp = Variable()
2153 {
2154 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2155 }
2156 ("at" varPos = Variable()
2157 {
2158 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2159 }
2160 )?
2161 "in" ( inExp = Expression() )
2162 {
2163 fc.setVarExpr(varExp);
2164 fc.setInExpr(inExp);
2165 if (varPos != null) {
2166 fc.setPosExpr(varPos);
2167 }
2168 return fc;
2169 }
2170}
2171
2172Clause LetClause() throws ParseException:
2173{
2174 LetClause lc = new LetClause();
2175 VariableExpr varExp;
2176 Expression beExp;
2177 extendCurrentScope();
2178}
2179{
ilovesoupb2527c12012-07-12 03:21:13 +00002180 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002181 {
2182 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002183 lc.setVarExpr(varExp);
2184 lc.setBeExpr(beExp);
2185 return lc;
2186 }
2187}
2188
2189Clause WhereClause()throws ParseException :
2190{
2191 WhereClause wc = new WhereClause();
2192 Expression whereExpr;
2193}
2194{
2195 "where" whereExpr = Expression()
2196 {
2197 wc.setWhereExpr(whereExpr);
2198 return wc;
2199 }
2200}
2201
2202Clause OrderbyClause()throws ParseException :
2203{
2204 OrderbyClause oc = new OrderbyClause();
2205 Expression orderbyExpr;
2206 List<Expression> orderbyList = new ArrayList<Expression>();
2207 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2208 int numOfOrderby = 0;
2209}
2210{
2211 (
2212 "order"
2213 {
2214 String hint = getHint(token);
2215 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2216 String splits[] = hint.split(" +");
2217 int numFrames = Integer.parseInt(splits[1]);
2218 int numTuples = Integer.parseInt(splits[2]);
2219 oc.setNumFrames(numFrames);
2220 oc.setNumTuples(numTuples);
2221 }
2222 }
2223 "by" orderbyExpr = Expression()
2224 {
2225 orderbyList.add(orderbyExpr);
2226 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2227 }
2228 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2229 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2230 {
2231 modifierList.add(modif);
2232 }
2233
2234 ("," orderbyExpr = Expression()
2235 {
2236 orderbyList.add(orderbyExpr);
2237 modif = OrderbyClause.OrderModifier.ASC;
2238 }
2239 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2240 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2241 {
2242 modifierList.add(modif);
2243 }
2244 )*
2245)
2246 {
2247 oc.setModifierList(modifierList);
2248 oc.setOrderbyList(orderbyList);
2249 return oc;
2250 }
2251}
2252Clause GroupClause()throws ParseException :
2253{
2254 GroupbyClause gbc = new GroupbyClause();
2255 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2256 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2257 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2258 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2259 VariableExpr var = null;
2260 VariableExpr withVar = null;
2261 Expression expr = null;
2262 VariableExpr decorVar = null;
2263 Expression decorExpr = null;
2264}
2265{
2266 {
2267 Scope newScope = extendCurrentScopeNoPush(true);
2268 // extendCurrentScope(true);
2269 }
2270 "group"
2271 {
2272 String hint = getHint(token);
2273 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2274 gbc.setHashGroupByHint(true);
2275 }
2276 }
2277 "by" (LOOKAHEAD(2) var = Variable()
2278 {
2279 newScope.addNewVarSymbolToScope(var.getVar());
2280 } ":=")?
2281 expr = Expression()
2282 {
2283 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2284 vePairList.add(pair1);
2285 }
2286 ("," ( LOOKAHEAD(2) var = Variable()
2287 {
2288 newScope.addNewVarSymbolToScope(var.getVar());
2289 } ":=")?
2290 expr = Expression()
2291 {
2292 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2293 vePairList.add(pair2);
2294 }
2295 )*
2296 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2297 {
2298 newScope.addNewVarSymbolToScope(decorVar.getVar());
2299 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2300 decorPairList.add(pair3);
2301 }
2302 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2303 {
2304 newScope.addNewVarSymbolToScope(decorVar.getVar());
2305 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2306 decorPairList.add(pair4);
2307 }
2308 )*
2309 )?
2310 "with" withVar = VariableRef()
2311 {
2312 if(withVar.getIsNewVar()==true)
2313 throw new ParseException("can't find variable " + withVar.getVar());
2314 withVarList.add(withVar);
2315 newScope.addNewVarSymbolToScope(withVar.getVar());
2316 }
2317 ("," withVar = VariableRef()
2318 {
2319 if(withVar.getIsNewVar()==true)
2320 throw new ParseException("can't find variable " + withVar.getVar());
2321 withVarList.add(withVar);
2322 newScope.addNewVarSymbolToScope(withVar.getVar());
2323 })*
2324 {
2325 gbc.setGbyPairList(vePairList);
2326 gbc.setDecorPairList(decorPairList);
2327 gbc.setWithVarList(withVarList);
2328 replaceCurrentScope(newScope);
2329 return gbc;
2330 }
2331}
2332
2333
2334LimitClause LimitClause() throws ParseException:
2335{
2336 LimitClause lc = new LimitClause();
2337 Expression expr;
2338 pushForbiddenScope(getCurrentScope());
2339}
2340{
2341 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2342 ("offset" expr = Expression() { lc.setOffset(expr); })?
2343
2344 {
2345 popForbiddenScope();
2346 return lc;
2347 }
2348}
2349
2350DistinctClause DistinctClause() throws ParseException:
2351{
2352 List<Expression> exprs = new ArrayList<Expression>();
2353 Expression expr;
2354}
2355{
2356 "distinct" "by" expr = Expression()
2357 {
2358 exprs.add(expr);
2359 }
2360 ("," expr = Expression()
2361 {
2362 exprs.add(expr);
2363 }
2364 )*
2365 {
2366 return new DistinctClause(exprs);
2367 }
2368}
2369
2370DieClause DieClause() throws ParseException:
2371{
2372 DieClause lc = new DieClause();
2373 Expression expr;
2374 pushForbiddenScope(getCurrentScope());
2375}
2376{
2377 "die" "after" expr = Expression() { lc.setDieExpr(expr); }
2378 {
2379 popForbiddenScope();
2380 return lc;
2381 }
2382}
2383
2384
2385QuantifiedExpression QuantifiedExpression()throws ParseException:
2386{
2387 QuantifiedExpression qc = new QuantifiedExpression();
2388 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2389 Expression satisfiesExpr;
2390 VariableExpr var;
2391 Expression inExpr;
2392 QuantifiedPair pair;
2393}
2394{
2395 {
2396 createNewScope();
2397 }
2398
2399 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2400 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2401 var = Variable() "in" inExpr = Expression()
2402 {
2403 pair = new QuantifiedPair(var, inExpr);
2404 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2405 quantifiedList.add(pair);
2406 }
2407 (
2408 "," var = Variable() "in" inExpr = Expression()
2409 {
2410 pair = new QuantifiedPair(var, inExpr);
2411 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2412 quantifiedList.add(pair);
2413 }
2414 )*
2415 "satisfies" satisfiesExpr = Expression()
2416 {
2417 qc.setSatisfiesExpr(satisfiesExpr);
2418 qc.setQuantifiedList(quantifiedList);
2419 removeCurrentScope();
2420 return qc;
2421 }
2422}
2423
2424TOKEN_MGR_DECLS:
2425{
2426 public int commentDepth = 0;
2427}
2428
2429<DEFAULT>
2430TOKEN :
2431{
2432 <CARET : "^" >
2433}
2434
2435<DEFAULT>
2436TOKEN :
2437{
2438 <DATASET : "dataset" >
2439}
2440
2441<DEFAULT>
2442TOKEN :
2443{
2444 <LEFTPAREN : "(" >
2445}
2446
2447<DEFAULT>
2448TOKEN :
2449{
2450 <RIGHTPAREN : ")" >
2451}
2452
2453
2454<DEFAULT>
2455TOKEN :
2456{
2457 <INTEGER_LITERAL : (<DIGIT>)+ >
2458}
2459
2460
2461<DEFAULT>
2462TOKEN :
2463{
2464 <NULL : "null">
2465}
2466
2467<DEFAULT>
2468TOKEN :
2469{
2470 <TRUE : "true">
2471}
2472
2473<DEFAULT>
2474TOKEN :
2475{
2476 <FALSE : "false">
2477}
2478
2479<DEFAULT>
2480TOKEN :
2481{
2482 <#DIGIT : ["0" - "9"]>
2483}
2484
2485
2486TOKEN:
2487{
2488 < DOUBLE_LITERAL: <INTEGER>
2489 | <INTEGER> ( "." <INTEGER> )?
2490 | "." <INTEGER>
2491 >
2492 |
2493 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2494 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2495 | "." <INTEGER> ( "f" | "F" )
2496 >
2497 |
2498 <INTEGER : (<DIGIT>)+ >
2499}
2500
2501<DEFAULT>
2502TOKEN :
2503{
2504 <#LETTER : ["A" - "Z", "a" - "z"]>
2505}
2506
2507<DEFAULT>
2508TOKEN :
2509{
2510 <SPECIALCHARS : ["$", "_", "-"] >
2511}
2512
2513<DEFAULT>
2514TOKEN :
2515{
2516 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2517 |
2518 < #EscapeQuot: "\\\"" >
2519 |
2520 < #EscapeApos: "\\\'" >
2521}
2522
2523<DEFAULT>
2524TOKEN :
2525{
2526 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2527}
2528
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002529
vinayakb38b7ca42012-03-05 05:44:15 +00002530<DEFAULT>
2531TOKEN :
2532{
2533 <VARIABLE : "$" <IDENTIFIER> >
2534}
2535
2536SKIP:
2537{
2538 " "
2539| "\t"
2540| "\r"
2541| "\n"
2542}
2543
2544SKIP:
2545{
2546 <"//" (~["\n"])* "\n">
2547}
2548
2549SKIP:
2550{
2551 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2552}
2553
2554
2555SKIP:
2556{
2557 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2558}
2559
2560<INSIDE_COMMENT>
2561SPECIAL_TOKEN:
2562{
2563 <"+"(" ")*(~["*"])*>
2564}
2565
2566<INSIDE_COMMENT>
2567SKIP:
2568{
2569 <"/*"> {commentDepth++;}
2570}
2571
2572<INSIDE_COMMENT>
2573SKIP:
2574{
2575 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2576| <~[]>
2577}