blob: fd5aaaabc9c87f4b7ab173a755dee6edfb1983a1 [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;
626 String adapterClassname;
627 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"
639
640 <STRING_LITERAL>
641 {
642 adapterClassname = removeQuotesAndEscapes(token.image);
643 }
644
645 {
646 properties = getConfiguration();
647 }
648
649 ("pre-sorted"
650 { alreadySorted = true; }
651 )?
652
653 ";"
654 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000655 return new LoadFromFileStatement(dataverseName, datasetName, adapterClassname, properties, alreadySorted);
vinayakb38b7ca42012-03-05 05:44:15 +0000656 }
657}
658
659
660
661DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException :
662{
663 DatasetDecl dd = null;
664 Identifier datasetName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000665 Identifier dataverseName = null;
666 Identifier itemDataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000667 Identifier itemTypeName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000668 String nameComponentFirst = null;
669 String nameComponentSecond = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000670 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000671 IDatasetDetailsDecl datasetDetails = null;
ramangrover2971e5c6a2013-01-30 05:30:12 +0000672 Pair<Identifier,Identifier> nameComponents = null;
673 Map<String,String> hints = new HashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000674}
675{
vinayakb38b7ca42012-03-05 05:44:15 +0000676 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000677 nameComponents = getDotSeparatedPair();
678 dataverseName = nameComponents.first;
679 datasetName = nameComponents.second;
680 }
681
vinayakb38b7ca42012-03-05 05:44:15 +0000682 (
683 "if not exists"
684 {
685 ifNotExists = true;
686 }
687 )?
688 (
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000689 < LEFTPAREN > <IDENTIFIER>
vinayakb38b7ca42012-03-05 05:44:15 +0000690 {
691 itemTypeName = new Identifier(token.image);
692 }
693 < RIGHTPAREN >
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +0000694 )
vinayakb38b7ca42012-03-05 05:44:15 +0000695 {
696 if(datasetType == DatasetType.INTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000697 datasetDetails = InternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000698 }
699 else if(datasetType == DatasetType.EXTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000700 datasetDetails = ExternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000701 }
702 else if(datasetType == DatasetType.FEED) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000703 datasetDetails = FeedDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000704 }
vinayakb38b7ca42012-03-05 05:44:15 +0000705 }
ramangrover2971e5c6a2013-01-30 05:30:12 +0000706
707 (
708 "hints"
vinayakb38b7ca42012-03-05 05:44:15 +0000709 {
ramangrover2971e5c6a2013-01-30 05:30:12 +0000710 initProperties(hints);
711 }
712 )?
713 ";"
714
715 {
716 dd = new DatasetDecl(dataverseName, datasetName, itemTypeName, hints, datasetType, datasetDetails,ifNotExists);
717 return dd;
vinayakb38b7ca42012-03-05 05:44:15 +0000718 }
719}
720
721InternalDetailsDecl InternalDatasetDeclaration() throws ParseException :
722{
723 InternalDetailsDecl idd = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000724 List<String> partitioningExprs = new ArrayList<String>();
725 Identifier nodeGroupName=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000726}
727{
vinayakb38b7ca42012-03-05 05:44:15 +0000728 "partitioned" "by" "key"
729 < IDENTIFIER >
730 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000731 partitioningExprs.add(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000732 }
733 (
734 "," < IDENTIFIER >
735 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000736 partitioningExprs.add(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000737 }
738 )*
739 (
740 "on" < IDENTIFIER >
741 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000742 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000743 }
744 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000745
vinayakb38b7ca42012-03-05 05:44:15 +0000746 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000747 idd = new InternalDetailsDecl(nodeGroupName, partitioningExprs);
vinayakb38b7ca42012-03-05 05:44:15 +0000748 return idd;
749 }
750}
751
752ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException :
753{
754 ExternalDetailsDecl edd = null;
755 String adapterClassname = null;
756 Map < String, String > properties;
757}
758{
759 {
760 edd = new ExternalDetailsDecl();
761 }
762
763 "using"
764
765 <STRING_LITERAL>
766 {
767 adapterClassname = removeQuotesAndEscapes(token.image);
768 }
769
770 {
771 properties = getConfiguration();
772 }
773
774 {
775 edd = new ExternalDetailsDecl();
776 edd.setAdapter(adapterClassname);
777 edd.setProperties(properties);
778 }
vinayakb38b7ca42012-03-05 05:44:15 +0000779
780 {
781 return edd;
782 }
783}
784
785FeedDetailsDecl FeedDatasetDeclaration() throws ParseException :
786{
787 FeedDetailsDecl fdd = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000788 String adapterFactoryClassname = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000789 Map < String, String > properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000790 Pair<Identifier,Identifier> nameComponents;
791 List<String> partitioningExprs = new ArrayList<String>();
792 Identifier nodeGroupName=null;
793 FunctionSignature appliedFunction=null;
794 String dataverse;
795 String functionName;
796 int arity;
vinayakb38b7ca42012-03-05 05:44:15 +0000797}
798{
vinayakb38b7ca42012-03-05 05:44:15 +0000799 "using"
800
801 <STRING_LITERAL>
802 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000803 adapterFactoryClassname = removeQuotesAndEscapes(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000804 }
805
806 {
807 properties = getConfiguration();
808 }
809
810 ("apply" "function"
vinayakb38b7ca42012-03-05 05:44:15 +0000811 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000812 nameComponents = getDotSeparatedPair();
813 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
814 functionName = nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +0000815 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000816 ("@" <INTEGER_LITERAL>
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000817 {
818 arity = Integer.parseInt(token.image);
819 }
820 )
821
822 {
823 appliedFunction = new FunctionSignature(dataverse, functionName, arity);
824 }
vinayakb38b7ca42012-03-05 05:44:15 +0000825 )?
826
827 "partitioned" "by" "key"
828 < IDENTIFIER >
829 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000830 partitioningExprs.add(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000831 }
832 (
833 "," < IDENTIFIER >
834 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000835 partitioningExprs.add(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000836 }
837 )*
838 (
839 "on" < IDENTIFIER >
840 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000841 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000842 }
843 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000844
vinayakb38b7ca42012-03-05 05:44:15 +0000845 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000846 fdd = new FeedDetailsDecl(adapterFactoryClassname, properties, appliedFunction, nodeGroupName, partitioningExprs);
vinayakb38b7ca42012-03-05 05:44:15 +0000847 return fdd;
848 }
849}
850
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000851ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000852{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000853 Pair<Identifier,Identifier> nameComponents = null;
854}
855{
856 {
857 nameComponents = getDotSeparatedPair();
858 return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second);
859 }
860}
861
862
863ControlFeedStatement AlterFeedDeclaration() throws ParseException :
864{
865 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000866 Map < String, String > configuration = new HashMap < String, String > ();
867}
868{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000869 {
870 nameComponents = getDotSeparatedPair();
871 }
872
vinayakb38b7ca42012-03-05 05:44:15 +0000873 "set"
874 {
875 configuration = getConfiguration();
876 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000877
vinayakb38b7ca42012-03-05 05:44:15 +0000878 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000879 return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
vinayakb38b7ca42012-03-05 05:44:15 +0000880 }
881}
882
883Map<String,String> getConfiguration() throws ParseException :
884{
885 Map<String,String> configuration = new HashMap<String,String>();
886 String key;
887 String value;
888}
889{
890
891<LEFTPAREN>
892 (
893 (
894 <LEFTPAREN>
895 (
896 <STRING_LITERAL>
897 {
898 key = removeQuotesAndEscapes(token.image);
899 }
900 "=" <STRING_LITERAL>
901 {
902 value = removeQuotesAndEscapes(token.image);
903 }
904 )
905 <RIGHTPAREN>
906 {
907 configuration.put(key, value);
908 }
909 )
910 (
911 "," <LEFTPAREN>
912 (
913 <STRING_LITERAL>
914 {
915 key = removeQuotesAndEscapes(token.image);
916 }
917 "=" <STRING_LITERAL>
918 {
919 value = removeQuotesAndEscapes(token.image);
920 }
921 )
922 <RIGHTPAREN>
923 {
924 configuration.put(key, value);
925 }
926 )*
927 )?
928 <RIGHTPAREN>
929 {
930 return configuration;
931 }
932}
933
ramangrover2971e5c6a2013-01-30 05:30:12 +0000934void initProperties(Map<String,String> properties) throws ParseException :
935{
936 String key;
937 String value;
938}
939{
940 (
941 <LEFTPAREN>
942 (
943 <IDENTIFIER>
944 {
945 key = (new Identifier(token.image)).getValue();
946 }
947 "="
948 (
949 (<STRING_LITERAL>
950 {
951 value = removeQuotesAndEscapes(token.image);
952 }
953 ) |
954 (<INTEGER_LITERAL>
955 {
956 try{
957 value = "" + Integer.valueOf(token.image);
958 } catch (NumberFormatException nfe){
959 throw new ParseException("inapproriate value: " + token.image);
960 }
961 }
962 )
963 )
964 {
965 properties.put(key, value);
966 }
967 (
968 ","
969 (
970 <IDENTIFIER>
971 {
972 key = (new Identifier(token.image)).getValue();
973 }
974 "="
975 (
976 (<STRING_LITERAL>
977 {
978 value = removeQuotesAndEscapes(token.image);
979 }
980 ) |
981 (<INTEGER_LITERAL>
982 {
983 try{
984 value = "" + Integer.valueOf(token.image);
985 } catch (NumberFormatException nfe){
986 throw new ParseException("inapproriate value: " + token.image);
987 }
988 }
989 )
990 )
991 )
992 {
993 properties.put(key, value);
994 }
995
996 )*
997 )
998 <RIGHTPAREN>
999 )?
1000}
1001
1002
vinayakb38b7ca42012-03-05 05:44:15 +00001003
1004NodegroupDecl NodegroupDeclaration() throws ParseException :
1005{
1006 Identifier name = null;
1007 List < Identifier > ncNames = new ArrayList < Identifier > ();
1008 boolean ifNotExists = false;
1009}
1010{
1011 < IDENTIFIER >
1012 {
1013 name = new Identifier(token.image);
1014 }
1015 (
1016 "if not exists"
1017 {
1018 ifNotExists = true;
1019 }
1020 )?
1021 "on" < IDENTIFIER >
1022 {
1023 ncNames.add(new Identifier(token.image));
1024 }
1025 (
1026 "," < IDENTIFIER >
1027 {
1028 ncNames.add(new Identifier(token.image));
1029 }
1030 )*
1031 ";"
1032 {
1033 return new NodegroupDecl(name, ncNames, ifNotExists);
1034 }
1035}
1036
1037
1038TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException:
1039{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001040 Identifier dataverse;
vinayakb38b7ca42012-03-05 05:44:15 +00001041 Identifier ident;
1042 TypeExpression typeExpr;
1043 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001044 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001045}
1046{
vinayakb38b7ca42012-03-05 05:44:15 +00001047 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001048 nameComponents = getDotSeparatedPair();
1049 dataverse = nameComponents.first;
1050 ident = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001051 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001052
vinayakb38b7ca42012-03-05 05:44:15 +00001053 (
1054 "if not exists"
1055 {
1056 ifNotExists = true;
1057 }
1058 )?
1059 "as"
1060 ( typeExpr = TypeExpr() )
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001061 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001062 {
1063 long numValues = -1;
1064 String filename = null;
1065 if (dgen) {
1066 String splits[] = hint.split(" +");
1067 if (splits.length != 3) {
1068 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
1069 }
1070 filename = splits[1];
1071 numValues = Long.parseLong(splits[2]);
1072 }
1073 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001074 return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001075 }
1076}
1077
1078TypeExpression TypeExpr() throws ParseException:
1079{
1080 TypeExpression typeExpr = null;
1081}
1082{
1083 (
1084 typeExpr = RecordTypeDef()
1085 | typeExpr = TypeReference()
1086 | typeExpr = OrderedListTypeDef()
1087 | typeExpr = UnorderedListTypeDef()
1088 )
1089 {
1090 return typeExpr;
1091 }
1092}
1093
1094RecordTypeDefinition RecordTypeDef() throws ParseException:
1095{
1096 RecordTypeDefinition recType = new RecordTypeDefinition();
1097 RecordTypeDefinition.RecordKind recordKind = null;
1098}
1099{
1100 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1101 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1102 "{"
1103 {
1104 String hint = getHint(token);
1105 if (hint != null) {
1106 String splits[] = hint.split(" +");
1107 if (splits[0].equals(GEN_FIELDS_HINT)) {
1108 if (splits.length != 5) {
1109 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1110 }
1111 if (!splits[1].equals("int")) {
1112 throw new ParseException("The only supported type for gen-fields is int.");
1113 }
1114 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1115 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1116 recType.setUndeclaredFieldsDataGen(ufdg);
1117 }
1118 }
1119
1120 }
1121 (
1122 RecordField(recType)
1123 ( "," RecordField(recType) )*
1124 )?
1125 "}"
1126 {
1127 if (recordKind == null) {
1128 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1129 }
1130 recType.setRecordKind(recordKind);
1131 return recType;
1132 }
1133}
1134
1135void RecordField(RecordTypeDefinition recType) throws ParseException:
1136{
1137 String fieldName;
1138 TypeExpression type = null;
1139 boolean nullable = false;
1140}
1141{
1142 <IDENTIFIER>
1143 {
1144 Token t = getToken(0);
1145 fieldName = t.toString();
1146 String hint = getHint(t);
1147 IRecordFieldDataGen rfdg = null;
1148 if (hint != null) {
1149 String splits[] = hint.split(" +");
1150 if (splits[0].equals(VAL_FILE_HINT)) {
1151 File[] valFiles = new File[splits.length - 1];
1152 for (int k=1; k<splits.length; k++) {
1153 valFiles[k-1] = new File(splits[k]);
1154 }
1155 rfdg = new FieldValFileDataGen(valFiles);
1156 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
1157 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
1158 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
1159 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
1160 } else if (splits[0].equals(LIST_HINT)) {
1161 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1162 } else if (splits[0].equals(INTERVAL_HINT)) {
1163 FieldIntervalDataGen.ValueType vt;
1164 if (splits[1].equals("int")) {
1165 vt = FieldIntervalDataGen.ValueType.INT;
1166 } else if (splits[1].equals("long")) {
1167 vt = FieldIntervalDataGen.ValueType.LONG;
1168 } else if (splits[1].equals("float")) {
1169 vt = FieldIntervalDataGen.ValueType.FLOAT;
1170 } else if (splits[1].equals("double")) {
1171 vt = FieldIntervalDataGen.ValueType.DOUBLE;
1172 } else {
1173 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
1174 }
1175 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
1176 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
1177 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
1178 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
1179 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1180 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
1181 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1182 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
1183 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
1184 } else if (splits[0].equals(AUTO_HINT)) {
1185 rfdg = new AutoDataGen(splits[1]);
1186 }
1187 }
1188 }
1189 ":"
1190 ( type = TypeExpr() )
1191 ("?" { nullable = true; } )?
1192 {
1193 recType.addField(fieldName, type, nullable, rfdg);
1194 }
1195}
1196
1197TypeReferenceExpression TypeReference() throws ParseException:
1198{}
1199{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001200 <IDENTIFIER>
1201 {
1202 Token t = getToken(0);
1203 Identifier id = new Identifier(t.toString());
1204 return new TypeReferenceExpression(id);
1205 }
vinayakb38b7ca42012-03-05 05:44:15 +00001206}
1207
1208OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1209{
1210 TypeExpression type = null;
1211}
1212{
1213 "["
1214 ( type = TypeExpr() )
1215 "]"
1216 {
1217 return new OrderedListTypeDefinition(type);
1218 }
1219}
1220
1221
1222UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1223{
1224 TypeExpression type = null;
1225}
1226{
1227 "{{"
1228 ( type = TypeExpr() )
1229 "}}"
1230 {
1231 return new UnorderedListTypeDefinition(type);
1232 }
1233}
1234
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001235Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException:
1236{
1237 Identifier first = null;
1238 Identifier second = null;
1239}
1240{
1241 < IDENTIFIER >
1242 {
1243 first = new Identifier(token.image);
1244 }
1245 ("." <IDENTIFIER>
1246 {
1247 second = new Identifier(token.image);
1248 }
1249 )?
1250
1251 {
1252 if(second == null){
1253 second = first;
1254 first = null;
1255 }
1256
1257 return new Pair<Identifier,Identifier>(first,second);
1258 }
1259}
1260
1261Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException:
1262{
1263 Identifier first = null;
1264 Identifier second = null;
1265 Identifier third = null;
1266}
1267{
1268 < IDENTIFIER >
1269 {
1270 first = new Identifier(token.image);
1271 }
1272 "." <IDENTIFIER>
1273 {
1274 second = new Identifier(token.image);
1275 }
1276 (
1277 "." <IDENTIFIER>
1278 {
1279 third = new Identifier(token.image);
1280 }
1281 )?
1282
1283 {
1284 if(third == null){
1285 third = second;
1286 second = first;
1287 first = null;
1288 }
1289
1290 return new Triple<Identifier,Identifier,Identifier>(first,second,third);
1291 }
1292}
1293
1294
1295
vinayakb38b7ca42012-03-05 05:44:15 +00001296
1297FunctionDecl FunctionDeclaration() throws ParseException:
1298{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001299 FunctionDecl funcDecl;
1300 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001301 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001302 int arity = 0;
1303 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1304 Expression funcBody;
1305 VarIdentifier var = null;
1306 createNewScope();
1307}
1308{
1309
1310 <IDENTIFIER>
1311 {
1312 Token t = getToken(0);
ramangrover29a13f2422012-03-15 23:01:27 +00001313 functionName = t.toString();
vinayakb38b7ca42012-03-05 05:44:15 +00001314 }
1315 <LEFTPAREN> (<VARIABLE>
1316 {
1317 var = new VarIdentifier();
1318 var.setValue(getToken(0).toString());
1319 paramList.add(var);
1320 getCurrentScope().addNewVarSymbolToScope(var);
1321 arity++;
1322 }
1323 ("," <VARIABLE>
1324 {
1325 var = new VarIdentifier();
1326 var.setValue(getToken(0).toString());
1327 paramList.add(var);
1328 getCurrentScope().addNewVarSymbolToScope(var);
1329 arity++;
1330 })*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
1331
1332 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001333 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1334 getCurrentScope().addFunctionDescriptor(signature, false);
1335 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1336 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001337 }
1338}
1339
1340CreateFunctionStatement FunctionCreation() throws ParseException:
1341{
1342 CreateFunctionStatement cfs = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001343 FunctionSignature signature;
1344 String dataverse;
ramangrover29a13f2422012-03-15 23:01:27 +00001345 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001346 boolean ifNotExists = false;
1347 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001348 String functionBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001349 VarIdentifier var = null;
1350 createNewScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001351 Expression functionBodyExpr;
1352 Token beginPos;
1353 Token endPos;
1354 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001355}
1356{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001357 {
1358 nameComponents = getDotSeparatedPair();
1359 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
1360 functionName= nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +00001361 }
1362
1363 (
1364 "if not exists"
1365 {
1366 ifNotExists = true;
1367 }
1368 )?
1369
1370 <LEFTPAREN> (<VARIABLE>
1371 {
1372 var = new VarIdentifier();
1373 var.setValue(getToken(0).toString());
1374 paramList.add(var);
1375 getCurrentScope().addNewVarSymbolToScope(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001376 }
1377 ("," <VARIABLE>
1378 {
1379 var = new VarIdentifier();
1380 var.setValue(getToken(0).toString());
1381 paramList.add(var);
1382 getCurrentScope().addNewVarSymbolToScope(var);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001383 })*)? <RIGHTPAREN> "{"
vinayakb38b7ca42012-03-05 05:44:15 +00001384 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001385 beginPos = getToken(0);
1386 }
1387 functionBodyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001388 "}"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001389 {
1390 endPos = getToken(0);
1391 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
1392 }
vinayakb38b7ca42012-03-05 05:44:15 +00001393 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001394 signature = new FunctionSignature(dataverse, functionName, paramList.size());
1395 getCurrentScope().addFunctionDescriptor(signature, false);
1396 cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001397 return cfs;
1398 }
1399}
1400
1401
1402
1403Query Query()throws ParseException:
1404{
1405 Query query = new Query();
1406 Expression expr;
1407}
1408{
1409 expr = Expression()
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001410 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001411 {
1412 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001413 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001414 return query;
1415 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001416
vinayakb38b7ca42012-03-05 05:44:15 +00001417}
1418
1419
1420
1421Expression Expression():
1422{
1423 Expression expr = null;
1424 Expression exprP = null;
1425}
1426{
1427(
1428
1429//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1430 expr = OperatorExpr()
1431 | expr = IfThenElse()
1432 | expr = FLWOGR()
1433 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001434
vinayakb38b7ca42012-03-05 05:44:15 +00001435
1436)
1437 {
1438 return (exprP==null) ? expr : exprP;
1439 }
1440}
1441
1442
1443
1444Expression OperatorExpr()throws ParseException:
1445{
1446 OperatorExpr op = null;
1447 Expression operand = null;
1448}
1449{
1450 operand = AndExpr()
1451 (
1452
1453 "or"
1454 {
1455 if (op == null) {
1456 op = new OperatorExpr();
1457 op.addOperand(operand);
1458 op.setCurrentop(true);
1459 }
1460 Token t = getToken(0);
1461 op.addOperator(t.toString());
1462 }
1463
1464 operand = AndExpr()
1465 {
1466 op.addOperand(operand);
1467 }
1468
1469 )*
1470
1471 {
1472 return op==null? operand: op;
1473 }
1474}
1475
1476Expression AndExpr()throws ParseException:
1477{
1478 OperatorExpr op = null;
1479 Expression operand = null;
1480}
1481{
1482 operand = RelExpr()
1483 (
1484
1485 "and"
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 = RelExpr()
1497 {
1498 op.addOperand(operand);
1499 }
1500
1501 )*
1502
1503 {
1504 return op==null? operand: op;
1505 }
1506}
1507
1508
1509
1510Expression RelExpr()throws ParseException:
1511{
1512 OperatorExpr op = null;
1513 Expression operand = null;
1514 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001515 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001516}
1517{
1518 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001519 {
1520 if (operand instanceof VariableExpr) {
1521 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001522 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001523 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001524 }
1525 }
1526 }
1527
1528 (
1529 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1530 {
alexander.behm07617fd2012-07-25 10:13:50 +00001531 String mhint = getHint(token);
1532 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1533 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1534 }
vinayakb38b7ca42012-03-05 05:44:15 +00001535 if (op == null) {
1536 op = new OperatorExpr();
1537 op.addOperand(operand, broadcast);
1538 op.setCurrentop(true);
1539 broadcast = false;
1540 }
1541 Token t = getToken(0);
1542 op.addOperator(t.toString());
1543 }
1544
1545 operand = AddExpr()
1546 {
alexander.behm07617fd2012-07-25 10:13:50 +00001547 broadcast = false;
1548 if (operand instanceof VariableExpr) {
1549 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001550 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1551 broadcast = true;
1552 }
alexander.behm07617fd2012-07-25 10:13:50 +00001553 }
vinayakb38b7ca42012-03-05 05:44:15 +00001554 op.addOperand(operand, broadcast);
1555 }
1556 )?
1557
1558 {
alexander.behm07617fd2012-07-25 10:13:50 +00001559 if (annotation != null) {
1560 op.addHint(annotation);
1561 }
vinayakb38b7ca42012-03-05 05:44:15 +00001562 return op==null? operand: op;
1563 }
1564}
1565
1566Expression AddExpr()throws ParseException:
1567{
1568 OperatorExpr op = null;
1569 Expression operand = null;
1570}
1571{
1572 operand = MultExpr()
1573
1574 ( ("+" | "-")
1575 {
1576 if (op == null) {
1577 op = new OperatorExpr();
1578 op.addOperand(operand);
1579 op.setCurrentop(true);
1580 }
1581 Token t = getToken(0);
1582 ((OperatorExpr)op).addOperator(t.toString());
1583 }
1584
1585 operand = MultExpr()
1586 {
1587 op.addOperand(operand);
1588 }
1589 )*
1590
1591 {
1592 return op==null? operand: op;
1593 }
1594}
1595
1596Expression MultExpr()throws ParseException:
1597{
1598 OperatorExpr op = null;
1599 Expression operand = null;
1600}
1601{
1602 operand = UnionExpr()
1603
1604 (( "*" | "/" | "%" | <CARET> | "idiv")
1605 {
1606 if (op == null) {
1607 op = new OperatorExpr();
1608 op.addOperand(operand);
1609 op.setCurrentop(true);
1610 }
1611 Token t = getToken(0);
1612 op.addOperator(t.toString());
1613 }
1614 operand = UnionExpr()
1615 {
1616 op.addOperand(operand);
1617 }
1618 )*
1619
1620 {
1621 return op==null?operand:op;
1622 }
1623}
1624
1625Expression UnionExpr() throws ParseException:
1626{
1627 UnionExpr union = null;
1628 Expression operand1 = null;
1629 Expression operand2 = null;
1630}
1631{
1632 operand1 = UnaryExpr()
1633 ("union"
1634 (operand2 = UnaryExpr()) {
1635 if (union == null) {
1636 union = new UnionExpr();
1637 union.addExpr(operand1);
1638 }
1639 union.addExpr(operand2);
1640 } )*
1641 {
1642 return (union == null)? operand1: union;
1643 }
1644}
1645
1646Expression UnaryExpr() throws ParseException:
1647{
1648 Expression uexpr = null;
1649 Expression expr = null;
1650}
1651{
1652 (( "+"|"-")
1653 {
1654 uexpr = new UnaryExpr();
1655 Token t = getToken(0);
1656 if("+".equals(t.toString()))
1657 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1658 else if("-".equals(t.toString()))
1659 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1660 else
1661 throw new ParseException();
1662 }
1663 )?
1664
1665 expr = ValueExpr()
1666 {
1667 if(uexpr!=null){
1668 ((UnaryExpr)uexpr).setExpr(expr);
1669 return uexpr;
1670 }
1671 else{
1672 return expr;
1673 }
1674 }
1675}
1676
1677Expression ValueExpr() throws ParseException:
1678{
1679 Expression expr;
1680}
1681{
1682 expr = FieldOrIndexAccessor()
1683 {
1684 return expr;
1685 }
1686}
1687
1688
1689Expression FieldOrIndexAccessor()throws ParseException:
1690{
1691 Expression expr = null;
1692 Identifier ident = null;
1693 AbstractAccessor fa = null;
1694 int index;
1695
1696}
1697{
1698 ( expr = PrimaryExpr()
1699
1700 )
1701
1702
1703 (
1704 (
1705 ident = Field()
1706 {
1707 if(fa == null)
1708 fa = new FieldAccessor(expr, ident);
1709 else
1710 fa = new FieldAccessor(fa, ident);
1711 }
1712 )
1713 | (
1714 index = Index()
1715 {
1716 if(fa == null)
1717 fa = new IndexAccessor(expr, index);
1718 else
1719 fa = new IndexAccessor(fa, index);
1720 }
1721 )
1722 )*
1723
1724
1725 {
1726 return fa==null?expr:fa;
1727 }
1728}
1729
1730Identifier Field() throws ParseException:
1731{
1732 Identifier ident = null;
1733
1734}
1735{
1736 "." < IDENTIFIER >
1737 {
1738
1739 ident = new Identifier();
1740 ident.setValue(getToken(0).toString());
1741
1742 return ident;
1743 }
1744}
1745
1746int Index() throws ParseException:
1747{
1748 Expression expr = null;
1749 int idx = -2;
1750}
1751{
1752 "[" ( expr = Expression()
1753 {
1754 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1755 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001756 Literal lit = ((LiteralExpr)expr).getValue();
1757 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1758 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001759 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001760 }
vinayakb38b7ca42012-03-05 05:44:15 +00001761 else {
1762 throw new ParseException("Index should be an INTEGER");
1763 }
1764 }
1765
1766 }
1767
1768 | "?"
1769 {
1770 idx = IndexAccessor.ANY;
1771 // ANY
1772 }
1773
1774 )
1775
1776 "]"
1777 {
1778 return idx;
1779 }
1780}
1781
1782
1783Expression PrimaryExpr()throws ParseException:
1784{
1785 Expression expr = null;
1786}
1787{
ilovesoupc9fef1d2012-07-08 19:30:42 +00001788 //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
vinayakb38b7ca42012-03-05 05:44:15 +00001789 (
1790 expr =Literal()
1791 | expr = FunctionCallExpr()
1792 | expr =VariableRef()
1793
1794 {
1795 if(((VariableExpr)expr).getIsNewVar() == true)
1796 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
1797 }
1798 | expr = ListConstructor()
1799 | expr = RecordConstructor()
1800 | expr = ParenthesizedExpression()
1801 )
1802 {
1803 return expr;
1804 }
1805}
1806
1807Expression Literal() throws ParseException:
1808{
1809
1810 LiteralExpr lit = new LiteralExpr();
1811 Token t;
1812}
1813{
1814(
1815 <STRING_LITERAL>
1816 {
1817 t= getToken(0);
1818 lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image)));
1819 }
1820
1821 | <INTEGER_LITERAL>
1822 {
1823 t= getToken(0);
ilovesoupc9fef1d2012-07-08 19:30:42 +00001824 try {
1825 lit.setValue(new IntegerLiteral(new Integer(t.image)));
1826 } catch(NumberFormatException ex) {
1827 lit.setValue(new LongIntegerLiteral(new Long(t.image)));
1828 }
vinayakb38b7ca42012-03-05 05:44:15 +00001829 }
1830 | < FLOAT_LITERAL >
1831 {
1832 t= getToken(0);
1833 lit.setValue(new FloatLiteral(new Float(t.image)));
1834 }
1835 | < DOUBLE_LITERAL >
1836 {
1837 t= getToken(0);
1838 lit.setValue(new DoubleLiteral(new Double(t.image)));
1839 }
1840 | <NULL>
1841 {
1842 t= getToken(0);
1843 lit.setValue(NullLiteral.INSTANCE);
1844 }
1845 | <TRUE>
1846 {
1847 t= getToken(0);
1848 lit.setValue(TrueLiteral.INSTANCE);
1849 }
1850 | <FALSE>
1851 {
1852 t= getToken(0);
1853 lit.setValue(FalseLiteral.INSTANCE);
1854 }
1855)
1856 {
1857 return lit;
1858 }
1859}
1860
1861
1862VariableExpr VariableRef() throws ParseException:
1863{
1864 VariableExpr varExp = new VariableExpr();
1865 VarIdentifier var = new VarIdentifier();
1866 Token t;
1867}
1868{
1869 <VARIABLE>
1870 {
1871 t = getToken(0);//get current token
1872 String varName = t.toString();
1873 Identifier ident = lookupSymbol(varName);
1874 if (isInForbiddenScopes(varName)) {
1875 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.");
1876 }
1877 if(ident != null) { // exist such ident
1878 varExp.setIsNewVar(false);
1879 varExp.setVar((VarIdentifier)ident);
1880 } else {
1881 varExp.setVar(var);
1882 }
1883 var.setValue(t.toString());
1884 return varExp;
1885 }
1886}
1887
1888
1889VariableExpr Variable() throws ParseException:
1890{
1891 VariableExpr varExp = new VariableExpr();
1892 VarIdentifier var = new VarIdentifier();
1893 Token t;
1894}
1895{
1896 <VARIABLE>
1897 {
1898 t = getToken(0);//get current token
1899 Identifier ident = lookupSymbol(t.toString());
1900 if(ident != null) { // exist such ident
1901 varExp.setIsNewVar(false);
1902 }
1903 varExp.setVar(var);
1904 var.setValue(t.toString());
1905 return varExp;
1906 }
1907}
1908
1909Expression ListConstructor() throws ParseException:
1910{
1911 Expression expr = null;
1912}
1913{
1914 (
1915 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1916 )
1917
1918 {
1919 return expr;
1920 }
1921}
1922
1923
1924ListConstructor OrderedListConstructor() throws ParseException:
1925{
1926 ListConstructor expr = new ListConstructor();
1927 Expression tmp = null;
1928 List<Expression> exprList = new ArrayList<Expression>();
1929 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1930}
1931{
1932
1933 "["
1934 ( tmp = Expression()
1935 {
1936 exprList.add(tmp);
1937 }
1938
1939 ("," tmp = Expression() { exprList.add(tmp); })*
1940 )?
1941
1942 "]"
1943
1944 {
1945 expr.setExprList(exprList);
1946 return expr;
1947 }
1948}
1949
1950ListConstructor UnorderedListConstructor() throws ParseException:
1951{
1952 ListConstructor expr = new ListConstructor();
1953 Expression tmp = null;
1954 List<Expression> exprList = new ArrayList<Expression>();
1955 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1956}
1957{
1958
1959 "{{" ( tmp = Expression()
1960 {
1961 exprList.add(tmp);
1962 }
1963 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1964 {
1965 expr.setExprList(exprList);
1966 return expr;
1967 }
1968}
1969
1970RecordConstructor RecordConstructor() throws ParseException:
1971{
1972 RecordConstructor expr = new RecordConstructor();
1973 FieldBinding tmp = null;
1974 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1975}
1976{
1977 "{" (tmp = FieldBinding()
1978 {
1979 fbList.add(tmp);
1980 }
1981 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
1982 {
1983 expr.setFbList(fbList);
1984 return expr;
1985 }
1986}
1987
1988FieldBinding FieldBinding() throws ParseException:
1989{
1990 FieldBinding fb = new FieldBinding();
1991 Expression left, right;
1992}
1993{
1994 left = Expression() ":" right = Expression()
1995 {
1996 fb.setLeftExpr(left);
1997 fb.setRightExpr(right);
1998 return fb;
1999 }
2000}
2001
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002002
vinayakb38b7ca42012-03-05 05:44:15 +00002003Expression FunctionCallExpr() throws ParseException:
2004{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002005 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002006 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002007 Expression tmp;
2008 int arity = 0;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002009 String funcName;
2010 String dataverse;
2011 String hint=null;
2012 String id1=null;
2013 String id2=null;
vinayakb38b7ca42012-03-05 05:44:15 +00002014}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002015{
2016 ( <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 +00002017 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002018 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002019 }
2020 <LEFTPAREN> (tmp = Expression()
2021 {
2022 argList.add(tmp);
2023 arity ++;
2024 } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
2025
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002026 {
2027 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2028 if(signature == null)
2029 {
2030 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2031 }
2032 callExpr = new CallExpr(signature,argList);
2033 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2034 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2035 }
2036 return callExpr;
vinayakb38b7ca42012-03-05 05:44:15 +00002037 }
2038}
2039
2040
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002041
vinayakb38b7ca42012-03-05 05:44:15 +00002042Expression ParenthesizedExpression() throws ParseException:
2043{
2044 Expression expr;
2045}
2046{
2047 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2048 {
2049 return expr;
2050 }
2051}
2052
2053Expression IfThenElse() throws ParseException:
2054{
2055 Expression condExpr;
2056 Expression thenExpr;
2057 Expression elseExpr;
2058 IfExpr ifExpr = new IfExpr();
2059}
2060{
2061 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
2062
2063 {
2064 ifExpr.setCondExpr(condExpr);
2065 ifExpr.setThenExpr(thenExpr);
2066 ifExpr.setElseExpr(elseExpr);
2067 return ifExpr;
2068 }
2069}
2070
2071Expression FLWOGR() throws ParseException:
2072{
2073 FLWOGRExpression flworg = new FLWOGRExpression();
2074 List<Clause> clauseList = new ArrayList<Clause>();
2075 Expression returnExpr;
2076 Clause tmp;
2077 createNewScope();
2078}
2079{
2080 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2081 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
2082
2083 {
2084 flworg.setClauseList(clauseList);
2085 flworg.setReturnExpr(returnExpr);
2086 removeCurrentScope();
2087 return flworg;
2088 }
2089}
2090
2091Clause Clause()throws ParseException :
2092{
2093 Clause clause;
2094}
2095{
2096 (
2097 clause = ForClause()
2098 | clause = LetClause()
2099 | clause = WhereClause()
2100 | clause = OrderbyClause()
2101 | clause = GroupClause()
2102 | clause = LimitClause()
2103 | clause = DistinctClause()
2104 | clause = DieClause()
2105 )
2106 {
2107 return clause;
2108 }
2109}
2110
2111Clause ForClause()throws ParseException :
2112{
2113 ForClause fc = new ForClause();
2114 VariableExpr varExp;
2115 VariableExpr varPos = null;
2116 Expression inExp;
2117 extendCurrentScope();
2118}
2119{
2120 "for" varExp = Variable()
2121 {
2122 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2123 }
2124 ("at" varPos = Variable()
2125 {
2126 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2127 }
2128 )?
2129 "in" ( inExp = Expression() )
2130 {
2131 fc.setVarExpr(varExp);
2132 fc.setInExpr(inExp);
2133 if (varPos != null) {
2134 fc.setPosExpr(varPos);
2135 }
2136 return fc;
2137 }
2138}
2139
2140Clause LetClause() throws ParseException:
2141{
2142 LetClause lc = new LetClause();
2143 VariableExpr varExp;
2144 Expression beExp;
2145 extendCurrentScope();
2146}
2147{
ilovesoupb2527c12012-07-12 03:21:13 +00002148 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002149 {
2150 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002151 lc.setVarExpr(varExp);
2152 lc.setBeExpr(beExp);
2153 return lc;
2154 }
2155}
2156
2157Clause WhereClause()throws ParseException :
2158{
2159 WhereClause wc = new WhereClause();
2160 Expression whereExpr;
2161}
2162{
2163 "where" whereExpr = Expression()
2164 {
2165 wc.setWhereExpr(whereExpr);
2166 return wc;
2167 }
2168}
2169
2170Clause OrderbyClause()throws ParseException :
2171{
2172 OrderbyClause oc = new OrderbyClause();
2173 Expression orderbyExpr;
2174 List<Expression> orderbyList = new ArrayList<Expression>();
2175 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2176 int numOfOrderby = 0;
2177}
2178{
2179 (
2180 "order"
2181 {
2182 String hint = getHint(token);
2183 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2184 String splits[] = hint.split(" +");
2185 int numFrames = Integer.parseInt(splits[1]);
2186 int numTuples = Integer.parseInt(splits[2]);
2187 oc.setNumFrames(numFrames);
2188 oc.setNumTuples(numTuples);
2189 }
2190 }
2191 "by" orderbyExpr = Expression()
2192 {
2193 orderbyList.add(orderbyExpr);
2194 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2195 }
2196 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2197 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2198 {
2199 modifierList.add(modif);
2200 }
2201
2202 ("," orderbyExpr = Expression()
2203 {
2204 orderbyList.add(orderbyExpr);
2205 modif = OrderbyClause.OrderModifier.ASC;
2206 }
2207 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2208 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2209 {
2210 modifierList.add(modif);
2211 }
2212 )*
2213)
2214 {
2215 oc.setModifierList(modifierList);
2216 oc.setOrderbyList(orderbyList);
2217 return oc;
2218 }
2219}
2220Clause GroupClause()throws ParseException :
2221{
2222 GroupbyClause gbc = new GroupbyClause();
2223 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2224 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2225 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2226 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2227 VariableExpr var = null;
2228 VariableExpr withVar = null;
2229 Expression expr = null;
2230 VariableExpr decorVar = null;
2231 Expression decorExpr = null;
2232}
2233{
2234 {
2235 Scope newScope = extendCurrentScopeNoPush(true);
2236 // extendCurrentScope(true);
2237 }
2238 "group"
2239 {
2240 String hint = getHint(token);
2241 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2242 gbc.setHashGroupByHint(true);
2243 }
2244 }
2245 "by" (LOOKAHEAD(2) var = Variable()
2246 {
2247 newScope.addNewVarSymbolToScope(var.getVar());
2248 } ":=")?
2249 expr = Expression()
2250 {
2251 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2252 vePairList.add(pair1);
2253 }
2254 ("," ( LOOKAHEAD(2) var = Variable()
2255 {
2256 newScope.addNewVarSymbolToScope(var.getVar());
2257 } ":=")?
2258 expr = Expression()
2259 {
2260 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2261 vePairList.add(pair2);
2262 }
2263 )*
2264 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2265 {
2266 newScope.addNewVarSymbolToScope(decorVar.getVar());
2267 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2268 decorPairList.add(pair3);
2269 }
2270 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2271 {
2272 newScope.addNewVarSymbolToScope(decorVar.getVar());
2273 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2274 decorPairList.add(pair4);
2275 }
2276 )*
2277 )?
2278 "with" withVar = VariableRef()
2279 {
2280 if(withVar.getIsNewVar()==true)
2281 throw new ParseException("can't find variable " + withVar.getVar());
2282 withVarList.add(withVar);
2283 newScope.addNewVarSymbolToScope(withVar.getVar());
2284 }
2285 ("," withVar = VariableRef()
2286 {
2287 if(withVar.getIsNewVar()==true)
2288 throw new ParseException("can't find variable " + withVar.getVar());
2289 withVarList.add(withVar);
2290 newScope.addNewVarSymbolToScope(withVar.getVar());
2291 })*
2292 {
2293 gbc.setGbyPairList(vePairList);
2294 gbc.setDecorPairList(decorPairList);
2295 gbc.setWithVarList(withVarList);
2296 replaceCurrentScope(newScope);
2297 return gbc;
2298 }
2299}
2300
2301
2302LimitClause LimitClause() throws ParseException:
2303{
2304 LimitClause lc = new LimitClause();
2305 Expression expr;
2306 pushForbiddenScope(getCurrentScope());
2307}
2308{
2309 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2310 ("offset" expr = Expression() { lc.setOffset(expr); })?
2311
2312 {
2313 popForbiddenScope();
2314 return lc;
2315 }
2316}
2317
2318DistinctClause DistinctClause() throws ParseException:
2319{
2320 List<Expression> exprs = new ArrayList<Expression>();
2321 Expression expr;
2322}
2323{
2324 "distinct" "by" expr = Expression()
2325 {
2326 exprs.add(expr);
2327 }
2328 ("," expr = Expression()
2329 {
2330 exprs.add(expr);
2331 }
2332 )*
2333 {
2334 return new DistinctClause(exprs);
2335 }
2336}
2337
2338DieClause DieClause() throws ParseException:
2339{
2340 DieClause lc = new DieClause();
2341 Expression expr;
2342 pushForbiddenScope(getCurrentScope());
2343}
2344{
2345 "die" "after" expr = Expression() { lc.setDieExpr(expr); }
2346 {
2347 popForbiddenScope();
2348 return lc;
2349 }
2350}
2351
2352
2353QuantifiedExpression QuantifiedExpression()throws ParseException:
2354{
2355 QuantifiedExpression qc = new QuantifiedExpression();
2356 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2357 Expression satisfiesExpr;
2358 VariableExpr var;
2359 Expression inExpr;
2360 QuantifiedPair pair;
2361}
2362{
2363 {
2364 createNewScope();
2365 }
2366
2367 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2368 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2369 var = Variable() "in" inExpr = Expression()
2370 {
2371 pair = new QuantifiedPair(var, inExpr);
2372 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2373 quantifiedList.add(pair);
2374 }
2375 (
2376 "," var = Variable() "in" inExpr = Expression()
2377 {
2378 pair = new QuantifiedPair(var, inExpr);
2379 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2380 quantifiedList.add(pair);
2381 }
2382 )*
2383 "satisfies" satisfiesExpr = Expression()
2384 {
2385 qc.setSatisfiesExpr(satisfiesExpr);
2386 qc.setQuantifiedList(quantifiedList);
2387 removeCurrentScope();
2388 return qc;
2389 }
2390}
2391
2392TOKEN_MGR_DECLS:
2393{
2394 public int commentDepth = 0;
2395}
2396
2397<DEFAULT>
2398TOKEN :
2399{
2400 <CARET : "^" >
2401}
2402
2403<DEFAULT>
2404TOKEN :
2405{
2406 <DATASET : "dataset" >
2407}
2408
2409<DEFAULT>
2410TOKEN :
2411{
2412 <LEFTPAREN : "(" >
2413}
2414
2415<DEFAULT>
2416TOKEN :
2417{
2418 <RIGHTPAREN : ")" >
2419}
2420
2421
2422<DEFAULT>
2423TOKEN :
2424{
2425 <INTEGER_LITERAL : (<DIGIT>)+ >
2426}
2427
2428
2429<DEFAULT>
2430TOKEN :
2431{
2432 <NULL : "null">
2433}
2434
2435<DEFAULT>
2436TOKEN :
2437{
2438 <TRUE : "true">
2439}
2440
2441<DEFAULT>
2442TOKEN :
2443{
2444 <FALSE : "false">
2445}
2446
2447<DEFAULT>
2448TOKEN :
2449{
2450 <#DIGIT : ["0" - "9"]>
2451}
2452
2453
2454TOKEN:
2455{
2456 < DOUBLE_LITERAL: <INTEGER>
2457 | <INTEGER> ( "." <INTEGER> )?
2458 | "." <INTEGER>
2459 >
2460 |
2461 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2462 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2463 | "." <INTEGER> ( "f" | "F" )
2464 >
2465 |
2466 <INTEGER : (<DIGIT>)+ >
2467}
2468
2469<DEFAULT>
2470TOKEN :
2471{
2472 <#LETTER : ["A" - "Z", "a" - "z"]>
2473}
2474
2475<DEFAULT>
2476TOKEN :
2477{
2478 <SPECIALCHARS : ["$", "_", "-"] >
2479}
2480
2481<DEFAULT>
2482TOKEN :
2483{
2484 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2485 |
2486 < #EscapeQuot: "\\\"" >
2487 |
2488 < #EscapeApos: "\\\'" >
2489}
2490
2491<DEFAULT>
2492TOKEN :
2493{
2494 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2495}
2496
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002497
vinayakb38b7ca42012-03-05 05:44:15 +00002498<DEFAULT>
2499TOKEN :
2500{
2501 <VARIABLE : "$" <IDENTIFIER> >
2502}
2503
2504SKIP:
2505{
2506 " "
2507| "\t"
2508| "\r"
2509| "\n"
2510}
2511
2512SKIP:
2513{
2514 <"//" (~["\n"])* "\n">
2515}
2516
2517SKIP:
2518{
2519 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2520}
2521
2522
2523SKIP:
2524{
2525 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2526}
2527
2528<INSIDE_COMMENT>
2529SPECIAL_TOKEN:
2530{
2531 <"+"(" ")*(~["*"])*>
2532}
2533
2534<INSIDE_COMMENT>
2535SKIP:
2536{
2537 <"/*"> {commentDepth++;}
2538}
2539
2540<INSIDE_COMMENT>
2541SKIP:
2542{
2543 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2544| <~[]>
2545}