blob: 68e149747e18d6a41a756588d8da266904ed1c41 [file] [log] [blame]
vinayakb38b7ca42012-03-05 05:44:15 +00001options {
2
3
4 STATIC = false;
5
6}
7
8
9PARSER_BEGIN(AQLParser)
10
11package edu.uci.ics.asterix.aql.parser;
12
13import java.io.*;
14import java.util.List;
15import java.util.ArrayList;
16import java.util.Stack;
17
18import java.util.Map;
19import java.util.HashMap;
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +000020import java.util.LinkedHashMap;
vinayakb38b7ca42012-03-05 05:44:15 +000021import edu.uci.ics.asterix.aql.literal.FloatLiteral;
22import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
23import edu.uci.ics.asterix.aql.literal.FalseLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000024import edu.uci.ics.asterix.aql.base.Literal;
vinayakb38b7ca42012-03-05 05:44:15 +000025import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000026import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +000027import edu.uci.ics.asterix.aql.literal.NullLiteral;
28import edu.uci.ics.asterix.aql.literal.StringLiteral;
29import edu.uci.ics.asterix.aql.literal.TrueLiteral;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000030import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
vinayakb38b7ca42012-03-05 05:44:15 +000031
32import edu.uci.ics.asterix.aql.base.*;
33import edu.uci.ics.asterix.aql.expression.*;
34import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
35import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
36import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
37import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
38import edu.uci.ics.asterix.aql.base.Statement.Kind;
39import edu.uci.ics.asterix.aql.context.Scope;
40import edu.uci.ics.asterix.aql.context.RootScopeFactory;
41import edu.uci.ics.asterix.common.annotations.*;
42import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000043import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000044import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000045import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
46import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000047import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
48import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
49import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
50
51
vinayakb38b7ca42012-03-05 05:44:15 +000052
53
54public class AQLParser extends ScopeChecker {
55
vinayakb38b7ca42012-03-05 05:44:15 +000056 // optimizer hints
57 private static final String HASH_GROUP_BY_HINT = "hash";
58 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000059 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000060 private static final String INMEMORY_HINT = "inmem";
61 private static final String VAL_FILE_HINT = "val-files";
62 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
63 private static final String INTERVAL_HINT = "interval";
64 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
65 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
66 private static final String LIST_VAL_FILE_HINT = "list-val-file";
67 private static final String LIST_HINT = "list";
68 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
69 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
70 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
71 private static final String AUTO_HINT = "auto";
72
73 private static final String GEN_FIELDS_HINT = "gen-fields";
74
75 // data generator hints
76 private static final String DGEN_HINT = "dgen";
77
78 private static String getHint(Token t) {
79 if (t.specialToken == null) {
80 return null;
81 }
82 String s = t.specialToken.image;
83 int n = s.length();
84 if (n < 2) {
85 return null;
86 }
87 return s.substring(1).trim();
88 }
89
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000090 public AQLParser(String s){
91 this(new StringReader(s));
92 super.setInput(s);
93 }
94
vinayakb38b7ca42012-03-05 05:44:15 +000095 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
96 File file = new File(args[0]);
97 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
98 AQLParser parser = new AQLParser(fis);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000099 List<Statement> st = parser.Statement();
100 //st.accept(new AQLPrintVisitor(), 0);
vinayakb38b7ca42012-03-05 05:44:15 +0000101 }
102
103
104}
105
106PARSER_END(AQLParser)
107
108
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000109List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000110{
vinayakb38b7ca42012-03-05 05:44:15 +0000111 scopeStack.push(RootScopeFactory.createRootScope(this));
112 List<Statement> decls = new ArrayList<Statement>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000113 Query query=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000114}
115{
116 (
117 (
118 (
119 "use"
120 {
121 decls.add(DataverseDeclaration());
122 }
123 | "declare" "function" {
124 decls.add(FunctionDeclaration());
125 }
126 | "create" (
127 {
128 String hint = getHint(token);
129 boolean dgen = false;
130 if (hint != null && hint.startsWith(DGEN_HINT)) {
131 dgen = true;
132 }
133 }
134 "type"
135 {
136 decls.add(TypeDeclaration(dgen, hint));
137 }
138 | "nodegroup"
139 {
140 decls.add(NodegroupDeclaration());
141 }
142 | "external" <DATASET>
143 {
144 decls.add(DatasetDeclaration(DatasetType.EXTERNAL));
145 }
146 | "feed" <DATASET>
147 {
148 decls.add(DatasetDeclaration(DatasetType.FEED));
149 }
150 | <DATASET>
151 {
152 decls.add(DatasetDeclaration(DatasetType.INTERNAL));
153 }
154 | "index"
155 {
156 decls.add(CreateIndexStatement());
157 }
158 | "dataverse"
159 {
160 decls.add(CreateDataverseStatement());
161 }
162 | "function"
163 {
164 decls.add(FunctionCreation());
165 }
166 )
167 | "load" {
168 decls.add(LoadStatement());
169 }
170
171 | "drop"
172 (
173 <DATASET>
174 {
175 decls.add(DropStatement());
176 }
177 | "index"
178 {
179 decls.add(IndexDropStatement());
180 }
181 | "nodegroup"
182 {
183 decls.add(NodeGroupDropStatement());
184 }
185 | "type"
186 {
187 decls.add(TypeDropStatement());
188 }
189 | "dataverse"
190 {
191 decls.add(DataverseDropStatement());
192 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000193 | "function"
194 {
195 decls.add(FunctionDropStatement());
196 }
vinayakb38b7ca42012-03-05 05:44:15 +0000197 )
198 | "write" {
199 decls.add(WriteStatement());
200 }
201 | "set" {
202 decls.add(SetStatement());
203 }
204 | "insert" {
205 decls.add(InsertStatement());
206 }
207 | "delete" {
208 decls.add(DeleteStatement());
209 }
210 | "update" {
211 decls.add(UpdateStatement());
212 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000213 | "begin" "feed"
214 {
215 Pair<Identifier,Identifier> nameComponents = getDotSeparatedPair();
216 decls.add(new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter()));
217 } ";"
218
219 | "suspend" "feed"
220 {
221 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.SUSPEND));
222 } ";"
223 | "resume" "feed" {
224 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.RESUME));
vinayakb38b7ca42012-03-05 05:44:15 +0000225 } ";"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000226 | "end" "feed" {
227 decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.END));
vinayakb38b7ca42012-03-05 05:44:15 +0000228 } ";"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000229 | "alter" "feed" {
230 decls.add(AlterFeedDeclaration());
231 } ";"
232
233 | (query = Query()) {
234 decls.add(query);
235 }
236 )*
237 // (query = Query())?
vinayakb38b7ca42012-03-05 05:44:15 +0000238 )
239
240 <EOF>
241 )
242 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000243 return decls;
vinayakb38b7ca42012-03-05 05:44:15 +0000244 }
245}
246
247InsertStatement InsertStatement() throws ParseException:
248{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000249 Identifier dataverseName;
vinayakb38b7ca42012-03-05 05:44:15 +0000250 Identifier datasetName;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000251 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000252 Query query;
253}
254{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000255 "into" <DATASET>
256
257 {
258 nameComponents = getDotSeparatedPair();
259 dataverseName = nameComponents.first;
260 datasetName = nameComponents.second;
261 }
262
vinayakbe2aaa38c2013-04-03 05:53:44 +0000263 query = Query() (";")?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000264 {return new InsertStatement(dataverseName, datasetName, query, getVarCounter());}
vinayakb38b7ca42012-03-05 05:44:15 +0000265}
266
267DeleteStatement DeleteStatement() throws ParseException:
268{
269 VariableExpr var = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000270 Identifier dataverseName;
vinayakb38b7ca42012-03-05 05:44:15 +0000271 Identifier datasetName = null;
272 Expression condition = null;
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 }
salsubaiee29c2f832013-04-26 20:58:51 -0700282 ("where" condition = Expression())? (";")?
283 {return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, 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"
alexander.behmb742e092012-11-24 11:54:56 +0000401 ("btree" { cis.setIndexType(IndexType.BTREE); }
alexander.behmc576c602012-07-06 02:41:15 +0000402 | "rtree" { cis.setIndexType(IndexType.RTREE); }
alexander.behmb742e092012-11-24 11:54:56 +0000403 | "keyword" { cis.setIndexType(IndexType.WORD_INVIX); }
404 | "fuzzy keyword" { cis.setIndexType(IndexType.FUZZY_WORD_INVIX); }
alexander.behmc576c602012-07-06 02:41:15 +0000405 | "ngram"
406 <LEFTPAREN>
407 (<INTEGER_LITERAL>
408 {
409 cis.setIndexType(IndexType.NGRAM_INVIX);
410 cis.setGramLength(Integer.valueOf(token.image));
411 }
412 )
alexander.behmb742e092012-11-24 11:54:56 +0000413 <RIGHTPAREN>
414 | "fuzzy ngram"
415 <LEFTPAREN>
416 (<INTEGER_LITERAL>
417 {
418 cis.setIndexType(IndexType.FUZZY_NGRAM_INVIX);
419 cis.setGramLength(Integer.valueOf(token.image));
420 }
421 )
422 <RIGHTPAREN>
alexander.behmc576c602012-07-06 02:41:15 +0000423 )
vinayakb38b7ca42012-03-05 05:44:15 +0000424 ";"
425 | ";"
426 )
427 {
428 return cis;
429 }
430}
431
432DataverseDecl DataverseDeclaration() throws ParseException:
433{
434 Identifier dvName = null;
435}
436{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000437 "dataverse" <IDENTIFIER> { defaultDataverse = token.image;}
vinayakb38b7ca42012-03-05 05:44:15 +0000438 ";"
439 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000440 return new DataverseDecl(new Identifier(defaultDataverse));
vinayakb38b7ca42012-03-05 05:44:15 +0000441 }
442}
443
444DropStatement DropStatement() throws ParseException :
445{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000446 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000447 Identifier datasetName = null;
448 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000449 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000450}
451{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000452 {
453 nameComponents = getDotSeparatedPair();
454 dataverseName = nameComponents.first;
455 datasetName = nameComponents.second;
456 }
457
458
vinayakb38b7ca42012-03-05 05:44:15 +0000459 (
460 "if exists"
461 {
462 ifExists = true;
463 }
464 )? ";"
465 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000466 return new DropStatement(dataverseName, datasetName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000467 }
468}
469
470IndexDropStatement IndexDropStatement() throws ParseException :
471{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000472 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000473 Identifier datasetName = null;
474 Identifier indexName = null;
475 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000476 Triple<Identifier,Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000477}
478{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000479
vinayakb38b7ca42012-03-05 05:44:15 +0000480 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000481 nameComponents = getDotSeparatedTriple();
482 dataverseName = nameComponents.first;
483 datasetName = nameComponents.second;
484 indexName = nameComponents.third;
485 }
486
vinayakb38b7ca42012-03-05 05:44:15 +0000487 (
488 "if exists"
489 {
490 ifExists = true;
491 }
492 )? ";"
493 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000494 return new IndexDropStatement(dataverseName, datasetName, indexName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000495 }
496}
497
498NodeGroupDropStatement NodeGroupDropStatement() throws ParseException :
499{
500 Identifier groupName = null;
501 boolean ifExists = false;
502}
503{
504 < IDENTIFIER >
505 {
506 groupName = new Identifier(token.image);
507 }
508 (
509 "if exists"
510 {
511 ifExists = true;
512 }
513 )? ";"
514 {
515 return new NodeGroupDropStatement(groupName, ifExists);
516 }
517}
518
519TypeDropStatement TypeDropStatement() throws ParseException :
520{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000521 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000522 Identifier typeName = null;
523 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000524 Pair<Identifier,Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000525}
526{
vinayakb38b7ca42012-03-05 05:44:15 +0000527 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000528 nameComponents = getDotSeparatedPair();
529 dataverseName = nameComponents.first == null ? new Identifier(defaultDataverse) : nameComponents.first;
530 typeName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000531 }
532 (
533 "if exists"
534 {
535 ifExists = true;
536 }
537 )? ";"
538 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000539 return new TypeDropStatement(dataverseName, typeName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000540 }
541}
542
543DataverseDropStatement DataverseDropStatement() throws ParseException :
544{
545 Identifier dataverseName = null;
546 boolean ifExists = false;
547}
548{
549 < IDENTIFIER >
550 {
551 dataverseName = new Identifier(token.image);
552 }
553 (
554 "if exists"
555 {
556 ifExists = true;
557 }
558 )? ";"
559 {
560 return new DataverseDropStatement(dataverseName, ifExists);
561 }
562}
563
564CreateDataverseStatement CreateDataverseStatement() throws ParseException :
565{
566 Identifier dvName = null;
567 boolean ifNotExists = false;
568 String format = null;
569}
570{
571 < IDENTIFIER >
572 {
573 dvName = new Identifier(token.image);
574 }
575 (
576 "if not exists"
577 {
578 ifNotExists = true;
579 }
580 )?
581 (
582 "with format" < STRING_LITERAL >
583 {
584 format = removeQuotesAndEscapes(token.image);
585 }
586 )?
587 ";"
588 {
589 return new CreateDataverseStatement(dvName, format, ifNotExists);
590 }
591}
592
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000593
594FunctionDropStatement FunctionDropStatement() throws ParseException :
595{
596 String dataverse;
597 String functionName;
598 int arity=0;
599 boolean ifExists = false;
600 Pair<Identifier, Identifier> nameComponents=null;
601}
602{
603 {
604 nameComponents = getDotSeparatedPair();
605 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
606 functionName = nameComponents.second.getValue();
607 }
608
609 "@"
610 <INTEGER_LITERAL>
611 {
612 Token t= getToken(0);
613 arity = new Integer(t.image);
614 if( arity < 0 && arity != FunctionIdentifier.VARARGS){
615 throw new ParseException(" invalid arity:" + arity);
616 }
617 }
618
619 (
620 "if exists"
621 {
622 ifExists = true;
623 }
624 )? ";"
625 {
626 return new FunctionDropStatement(new FunctionSignature(dataverse, functionName, arity), ifExists);
627 }
628}
629
630
vinayakb38b7ca42012-03-05 05:44:15 +0000631LoadFromFileStatement LoadStatement() throws ParseException:
632{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000633 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000634 Identifier datasetName = null;
635 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000636 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000637 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000638 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000639}
640{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000641 <DATASET>
642 {
643 nameComponents = getDotSeparatedPair();
644 dataverseName = nameComponents.first;
645 datasetName = nameComponents.second;
646 }
647
vinayakb38b7ca42012-03-05 05:44:15 +0000648 "using"
ramangrover29669d8f62013-02-11 06:03:32 +0000649
vinayakb38b7ca42012-03-05 05:44:15 +0000650 {
ramangrover29669d8f62013-02-11 06:03:32 +0000651 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000652 }
ramangrover29669d8f62013-02-11 06:03:32 +0000653
vinayakb38b7ca42012-03-05 05:44:15 +0000654 {
655 properties = getConfiguration();
656 }
657
658 ("pre-sorted"
659 { alreadySorted = true; }
660 )?
661
662 ";"
663 {
ramangrover29669d8f62013-02-11 06:03:32 +0000664 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
vinayakb38b7ca42012-03-05 05:44:15 +0000665 }
666}
667
668
ramangrover29669d8f62013-02-11 06:03:32 +0000669String getAdapterName() throws ParseException :
670{
671 String adapterName = null;
672}
673{
674 (
675 <IDENTIFIER> {
676 adapterName = (new Identifier(token.image)).getValue();;
677 }
678 |
679 <STRING_LITERAL>
680 {
681 adapterName = removeQuotesAndEscapes(token.image);
682 }
683 )
684 {
685 return adapterName;
686 }
687}
688
vinayakb38b7ca42012-03-05 05:44:15 +0000689
690DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException :
691{
692 DatasetDecl dd = null;
693 Identifier datasetName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000694 Identifier dataverseName = null;
695 Identifier itemDataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000696 Identifier itemTypeName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000697 String nameComponentFirst = null;
698 String nameComponentSecond = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000699 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000700 IDatasetDetailsDecl datasetDetails = null;
ramangrover2971e5c6a2013-01-30 05:30:12 +0000701 Pair<Identifier,Identifier> nameComponents = null;
702 Map<String,String> hints = new HashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000703}
704{
vinayakb38b7ca42012-03-05 05:44:15 +0000705 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000706 nameComponents = getDotSeparatedPair();
707 dataverseName = nameComponents.first;
708 datasetName = nameComponents.second;
709 }
710
vinayakb38b7ca42012-03-05 05:44:15 +0000711 (
712 "if not exists"
713 {
714 ifNotExists = true;
715 }
716 )?
717 (
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000718 < LEFTPAREN > <IDENTIFIER>
vinayakb38b7ca42012-03-05 05:44:15 +0000719 {
720 itemTypeName = new Identifier(token.image);
721 }
722 < RIGHTPAREN >
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +0000723 )
vinayakb38b7ca42012-03-05 05:44:15 +0000724 {
725 if(datasetType == DatasetType.INTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000726 datasetDetails = InternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000727 }
728 else if(datasetType == DatasetType.EXTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000729 datasetDetails = ExternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000730 }
731 else if(datasetType == DatasetType.FEED) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000732 datasetDetails = FeedDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000733 }
vinayakb38b7ca42012-03-05 05:44:15 +0000734 }
ramangrover2971e5c6a2013-01-30 05:30:12 +0000735
736 (
737 "hints"
vinayakb38b7ca42012-03-05 05:44:15 +0000738 {
ramangrover2971e5c6a2013-01-30 05:30:12 +0000739 initProperties(hints);
740 }
741 )?
742 ";"
743
744 {
745 dd = new DatasetDecl(dataverseName, datasetName, itemTypeName, hints, datasetType, datasetDetails,ifNotExists);
746 return dd;
vinayakb38b7ca42012-03-05 05:44:15 +0000747 }
748}
749
750InternalDetailsDecl InternalDatasetDeclaration() throws ParseException :
751{
752 InternalDetailsDecl idd = null;
ramangrover292f199b02013-02-13 05:32:01 +0000753 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000754 Identifier nodeGroupName=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000755}
756{
vinayakb38b7ca42012-03-05 05:44:15 +0000757 (
vinayakb38b7ca42012-03-05 05:44:15 +0000758 {
ramangrover292f199b02013-02-13 05:32:01 +0000759 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000760 }
ramangrover29669d8f62013-02-11 06:03:32 +0000761 )
762
vinayakb38b7ca42012-03-05 05:44:15 +0000763 (
764 "on" < IDENTIFIER >
765 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000766 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000767 }
768 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000769
vinayakb38b7ca42012-03-05 05:44:15 +0000770 {
ramangrover292f199b02013-02-13 05:32:01 +0000771 idd = new InternalDetailsDecl(nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000772 return idd;
773 }
774}
775
776ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException :
777{
778 ExternalDetailsDecl edd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000779 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000780 Map < String, String > properties;
781}
782{
783 {
784 edd = new ExternalDetailsDecl();
785 }
786
787 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000788 {
ramangrover29669d8f62013-02-11 06:03:32 +0000789 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000790 }
791
792 {
793 properties = getConfiguration();
794 }
795
796 {
797 edd = new ExternalDetailsDecl();
ramangrover29669d8f62013-02-11 06:03:32 +0000798 edd.setAdapter(adapterName);
vinayakb38b7ca42012-03-05 05:44:15 +0000799 edd.setProperties(properties);
800 }
vinayakb38b7ca42012-03-05 05:44:15 +0000801
802 {
803 return edd;
804 }
805}
806
807FeedDetailsDecl FeedDatasetDeclaration() throws ParseException :
808{
809 FeedDetailsDecl fdd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000810 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000811 Map < String, String > properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000812 Pair<Identifier,Identifier> nameComponents;
ramangrover292f199b02013-02-13 05:32:01 +0000813 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000814 Identifier nodeGroupName=null;
815 FunctionSignature appliedFunction=null;
816 String dataverse;
817 String functionName;
818 int arity;
vinayakb38b7ca42012-03-05 05:44:15 +0000819}
820{
vinayakb38b7ca42012-03-05 05:44:15 +0000821 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000822 {
ramangrover29669d8f62013-02-11 06:03:32 +0000823 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000824 }
825
826 {
827 properties = getConfiguration();
828 }
829
830 ("apply" "function"
vinayakb38b7ca42012-03-05 05:44:15 +0000831 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000832 nameComponents = getDotSeparatedPair();
833 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
834 functionName = nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +0000835 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000836 ("@" <INTEGER_LITERAL>
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000837 {
838 arity = Integer.parseInt(token.image);
839 }
840 )
841
842 {
843 appliedFunction = new FunctionSignature(dataverse, functionName, arity);
844 }
vinayakb38b7ca42012-03-05 05:44:15 +0000845 )?
846
vinayakb38b7ca42012-03-05 05:44:15 +0000847 (
vinayakb38b7ca42012-03-05 05:44:15 +0000848 {
ramangrover292f199b02013-02-13 05:32:01 +0000849 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000850 }
ramangrover29669d8f62013-02-11 06:03:32 +0000851 )
852
vinayakb38b7ca42012-03-05 05:44:15 +0000853 (
854 "on" < IDENTIFIER >
855 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000856 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000857 }
858 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000859
vinayakb38b7ca42012-03-05 05:44:15 +0000860 {
ramangrover292f199b02013-02-13 05:32:01 +0000861 fdd = new FeedDetailsDecl(adapterName, properties, appliedFunction, nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000862 return fdd;
863 }
864}
865
ramangrover292f199b02013-02-13 05:32:01 +0000866List<String> getPrimaryKeyFields() throws ParseException :
ramangrover29669d8f62013-02-11 06:03:32 +0000867{
ramangrover292f199b02013-02-13 05:32:01 +0000868 List<String> primaryKeyFields = new ArrayList<String>();
ramangrover29669d8f62013-02-11 06:03:32 +0000869}
870{
871
872 "primary" "key"
873 < IDENTIFIER >
874 {
ramangrover292f199b02013-02-13 05:32:01 +0000875 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000876 }
877 (
878 "," < IDENTIFIER >
879 {
ramangrover292f199b02013-02-13 05:32:01 +0000880 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000881 }
882 )*
883 {
ramangrover292f199b02013-02-13 05:32:01 +0000884 return primaryKeyFields;
ramangrover29669d8f62013-02-11 06:03:32 +0000885 }
886
887}
888
889
890
891
892
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000893ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000894{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000895 Pair<Identifier,Identifier> nameComponents = null;
896}
897{
898 {
899 nameComponents = getDotSeparatedPair();
900 return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second);
901 }
902}
903
904
905ControlFeedStatement AlterFeedDeclaration() throws ParseException :
906{
907 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000908 Map < String, String > configuration = new HashMap < String, String > ();
909}
910{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000911 {
912 nameComponents = getDotSeparatedPair();
913 }
914
vinayakb38b7ca42012-03-05 05:44:15 +0000915 "set"
916 {
917 configuration = getConfiguration();
918 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000919
vinayakb38b7ca42012-03-05 05:44:15 +0000920 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000921 return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
vinayakb38b7ca42012-03-05 05:44:15 +0000922 }
923}
924
925Map<String,String> getConfiguration() throws ParseException :
926{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000927 Map<String,String> configuration = new LinkedHashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000928 String key;
929 String value;
930}
931{
932
933<LEFTPAREN>
934 (
935 (
936 <LEFTPAREN>
937 (
938 <STRING_LITERAL>
939 {
940 key = removeQuotesAndEscapes(token.image);
941 }
942 "=" <STRING_LITERAL>
943 {
944 value = removeQuotesAndEscapes(token.image);
945 }
946 )
947 <RIGHTPAREN>
948 {
949 configuration.put(key, value);
950 }
951 )
952 (
953 "," <LEFTPAREN>
954 (
955 <STRING_LITERAL>
956 {
957 key = removeQuotesAndEscapes(token.image);
958 }
959 "=" <STRING_LITERAL>
960 {
961 value = removeQuotesAndEscapes(token.image);
962 }
963 )
964 <RIGHTPAREN>
965 {
966 configuration.put(key, value);
967 }
968 )*
969 )?
970 <RIGHTPAREN>
971 {
972 return configuration;
973 }
974}
975
ramangrover2971e5c6a2013-01-30 05:30:12 +0000976void initProperties(Map<String,String> properties) throws ParseException :
977{
978 String key;
979 String value;
980}
981{
982 (
983 <LEFTPAREN>
984 (
985 <IDENTIFIER>
986 {
987 key = (new Identifier(token.image)).getValue();
988 }
989 "="
990 (
991 (<STRING_LITERAL>
992 {
993 value = removeQuotesAndEscapes(token.image);
994 }
995 ) |
996 (<INTEGER_LITERAL>
997 {
998 try{
ramangrover2921b88182013-01-31 00:51:19 +0000999 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001000 } catch (NumberFormatException nfe){
1001 throw new ParseException("inapproriate value: " + token.image);
1002 }
1003 }
1004 )
1005 )
1006 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001007 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001008 }
1009 (
1010 ","
1011 (
1012 <IDENTIFIER>
1013 {
1014 key = (new Identifier(token.image)).getValue();
1015 }
1016 "="
1017 (
1018 (<STRING_LITERAL>
1019 {
1020 value = removeQuotesAndEscapes(token.image);
1021 }
1022 ) |
1023 (<INTEGER_LITERAL>
1024 {
1025 try{
ramangrover2921b88182013-01-31 00:51:19 +00001026 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001027 } catch (NumberFormatException nfe){
1028 throw new ParseException("inapproriate value: " + token.image);
1029 }
1030 }
1031 )
1032 )
1033 )
1034 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001035 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001036 }
1037
1038 )*
1039 )
1040 <RIGHTPAREN>
1041 )?
1042}
1043
1044
vinayakb38b7ca42012-03-05 05:44:15 +00001045
1046NodegroupDecl NodegroupDeclaration() throws ParseException :
1047{
1048 Identifier name = null;
1049 List < Identifier > ncNames = new ArrayList < Identifier > ();
1050 boolean ifNotExists = false;
1051}
1052{
1053 < IDENTIFIER >
1054 {
1055 name = new Identifier(token.image);
1056 }
1057 (
1058 "if not exists"
1059 {
1060 ifNotExists = true;
1061 }
1062 )?
1063 "on" < IDENTIFIER >
1064 {
1065 ncNames.add(new Identifier(token.image));
1066 }
1067 (
1068 "," < IDENTIFIER >
1069 {
1070 ncNames.add(new Identifier(token.image));
1071 }
1072 )*
1073 ";"
1074 {
1075 return new NodegroupDecl(name, ncNames, ifNotExists);
1076 }
1077}
1078
1079
1080TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException:
1081{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001082 Identifier dataverse;
vinayakb38b7ca42012-03-05 05:44:15 +00001083 Identifier ident;
1084 TypeExpression typeExpr;
1085 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001086 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001087}
1088{
vinayakb38b7ca42012-03-05 05:44:15 +00001089 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001090 nameComponents = getDotSeparatedPair();
1091 dataverse = nameComponents.first;
1092 ident = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001093 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001094
vinayakb38b7ca42012-03-05 05:44:15 +00001095 (
1096 "if not exists"
1097 {
1098 ifNotExists = true;
1099 }
1100 )?
1101 "as"
1102 ( typeExpr = TypeExpr() )
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001103 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001104 {
1105 long numValues = -1;
1106 String filename = null;
1107 if (dgen) {
1108 String splits[] = hint.split(" +");
1109 if (splits.length != 3) {
1110 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
1111 }
1112 filename = splits[1];
1113 numValues = Long.parseLong(splits[2]);
1114 }
1115 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001116 return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001117 }
1118}
1119
1120TypeExpression TypeExpr() throws ParseException:
1121{
1122 TypeExpression typeExpr = null;
1123}
1124{
1125 (
1126 typeExpr = RecordTypeDef()
1127 | typeExpr = TypeReference()
1128 | typeExpr = OrderedListTypeDef()
1129 | typeExpr = UnorderedListTypeDef()
1130 )
1131 {
1132 return typeExpr;
1133 }
1134}
1135
1136RecordTypeDefinition RecordTypeDef() throws ParseException:
1137{
1138 RecordTypeDefinition recType = new RecordTypeDefinition();
1139 RecordTypeDefinition.RecordKind recordKind = null;
1140}
1141{
1142 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1143 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1144 "{"
1145 {
1146 String hint = getHint(token);
1147 if (hint != null) {
1148 String splits[] = hint.split(" +");
1149 if (splits[0].equals(GEN_FIELDS_HINT)) {
1150 if (splits.length != 5) {
1151 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1152 }
1153 if (!splits[1].equals("int")) {
1154 throw new ParseException("The only supported type for gen-fields is int.");
1155 }
1156 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1157 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1158 recType.setUndeclaredFieldsDataGen(ufdg);
1159 }
1160 }
1161
1162 }
1163 (
1164 RecordField(recType)
1165 ( "," RecordField(recType) )*
1166 )?
1167 "}"
1168 {
1169 if (recordKind == null) {
1170 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1171 }
1172 recType.setRecordKind(recordKind);
1173 return recType;
1174 }
1175}
1176
1177void RecordField(RecordTypeDefinition recType) throws ParseException:
1178{
1179 String fieldName;
1180 TypeExpression type = null;
1181 boolean nullable = false;
1182}
1183{
1184 <IDENTIFIER>
1185 {
1186 Token t = getToken(0);
1187 fieldName = t.toString();
1188 String hint = getHint(t);
1189 IRecordFieldDataGen rfdg = null;
1190 if (hint != null) {
1191 String splits[] = hint.split(" +");
1192 if (splits[0].equals(VAL_FILE_HINT)) {
1193 File[] valFiles = new File[splits.length - 1];
1194 for (int k=1; k<splits.length; k++) {
1195 valFiles[k-1] = new File(splits[k]);
1196 }
1197 rfdg = new FieldValFileDataGen(valFiles);
1198 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
1199 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
1200 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
1201 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
1202 } else if (splits[0].equals(LIST_HINT)) {
1203 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1204 } else if (splits[0].equals(INTERVAL_HINT)) {
1205 FieldIntervalDataGen.ValueType vt;
1206 if (splits[1].equals("int")) {
1207 vt = FieldIntervalDataGen.ValueType.INT;
1208 } else if (splits[1].equals("long")) {
1209 vt = FieldIntervalDataGen.ValueType.LONG;
1210 } else if (splits[1].equals("float")) {
1211 vt = FieldIntervalDataGen.ValueType.FLOAT;
1212 } else if (splits[1].equals("double")) {
1213 vt = FieldIntervalDataGen.ValueType.DOUBLE;
1214 } else {
1215 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
1216 }
1217 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
1218 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
1219 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
1220 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
1221 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1222 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
1223 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1224 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
1225 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
1226 } else if (splits[0].equals(AUTO_HINT)) {
1227 rfdg = new AutoDataGen(splits[1]);
1228 }
1229 }
1230 }
1231 ":"
1232 ( type = TypeExpr() )
1233 ("?" { nullable = true; } )?
1234 {
1235 recType.addField(fieldName, type, nullable, rfdg);
1236 }
1237}
1238
1239TypeReferenceExpression TypeReference() throws ParseException:
1240{}
1241{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001242 <IDENTIFIER>
1243 {
1244 Token t = getToken(0);
1245 Identifier id = new Identifier(t.toString());
1246 return new TypeReferenceExpression(id);
1247 }
vinayakb38b7ca42012-03-05 05:44:15 +00001248}
1249
1250OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1251{
1252 TypeExpression type = null;
1253}
1254{
1255 "["
1256 ( type = TypeExpr() )
1257 "]"
1258 {
1259 return new OrderedListTypeDefinition(type);
1260 }
1261}
1262
1263
1264UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1265{
1266 TypeExpression type = null;
1267}
1268{
1269 "{{"
1270 ( type = TypeExpr() )
1271 "}}"
1272 {
1273 return new UnorderedListTypeDefinition(type);
1274 }
1275}
1276
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001277Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException:
1278{
1279 Identifier first = null;
1280 Identifier second = null;
1281}
1282{
1283 < IDENTIFIER >
1284 {
1285 first = new Identifier(token.image);
1286 }
1287 ("." <IDENTIFIER>
1288 {
1289 second = new Identifier(token.image);
1290 }
1291 )?
1292
1293 {
1294 if(second == null){
1295 second = first;
1296 first = null;
1297 }
1298
1299 return new Pair<Identifier,Identifier>(first,second);
1300 }
1301}
1302
1303Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException:
1304{
1305 Identifier first = null;
1306 Identifier second = null;
1307 Identifier third = null;
1308}
1309{
1310 < IDENTIFIER >
1311 {
1312 first = new Identifier(token.image);
1313 }
1314 "." <IDENTIFIER>
1315 {
1316 second = new Identifier(token.image);
1317 }
1318 (
1319 "." <IDENTIFIER>
1320 {
1321 third = new Identifier(token.image);
1322 }
1323 )?
1324
1325 {
1326 if(third == null){
1327 third = second;
1328 second = first;
1329 first = null;
1330 }
1331
1332 return new Triple<Identifier,Identifier,Identifier>(first,second,third);
1333 }
1334}
1335
1336
1337
vinayakb38b7ca42012-03-05 05:44:15 +00001338
1339FunctionDecl FunctionDeclaration() throws ParseException:
1340{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001341 FunctionDecl funcDecl;
1342 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001343 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001344 int arity = 0;
1345 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1346 Expression funcBody;
1347 VarIdentifier var = null;
1348 createNewScope();
1349}
1350{
1351
1352 <IDENTIFIER>
1353 {
1354 Token t = getToken(0);
ramangrover29a13f2422012-03-15 23:01:27 +00001355 functionName = t.toString();
vinayakb38b7ca42012-03-05 05:44:15 +00001356 }
1357 <LEFTPAREN> (<VARIABLE>
1358 {
1359 var = new VarIdentifier();
1360 var.setValue(getToken(0).toString());
1361 paramList.add(var);
1362 getCurrentScope().addNewVarSymbolToScope(var);
1363 arity++;
1364 }
1365 ("," <VARIABLE>
1366 {
1367 var = new VarIdentifier();
1368 var.setValue(getToken(0).toString());
1369 paramList.add(var);
1370 getCurrentScope().addNewVarSymbolToScope(var);
1371 arity++;
1372 })*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001373 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001374 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001375 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1376 getCurrentScope().addFunctionDescriptor(signature, false);
1377 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1378 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001379 }
1380}
1381
1382CreateFunctionStatement FunctionCreation() throws ParseException:
1383{
1384 CreateFunctionStatement cfs = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001385 FunctionSignature signature;
1386 String dataverse;
ramangrover29a13f2422012-03-15 23:01:27 +00001387 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001388 boolean ifNotExists = false;
1389 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001390 String functionBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001391 VarIdentifier var = null;
1392 createNewScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001393 Expression functionBodyExpr;
1394 Token beginPos;
1395 Token endPos;
1396 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001397}
1398{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001399 {
1400 nameComponents = getDotSeparatedPair();
1401 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
1402 functionName= nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +00001403 }
1404
1405 (
1406 "if not exists"
1407 {
1408 ifNotExists = true;
1409 }
1410 )?
1411
1412 <LEFTPAREN> (<VARIABLE>
1413 {
1414 var = new VarIdentifier();
1415 var.setValue(getToken(0).toString());
1416 paramList.add(var);
1417 getCurrentScope().addNewVarSymbolToScope(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001418 }
1419 ("," <VARIABLE>
1420 {
1421 var = new VarIdentifier();
1422 var.setValue(getToken(0).toString());
1423 paramList.add(var);
1424 getCurrentScope().addNewVarSymbolToScope(var);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001425 })*)? <RIGHTPAREN> "{"
vinayakb38b7ca42012-03-05 05:44:15 +00001426 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001427 beginPos = getToken(0);
1428 }
1429 functionBodyExpr = Expression()
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001430 "}"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001431 {
1432 endPos = getToken(0);
1433 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
1434 }
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001435 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001436 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001437 signature = new FunctionSignature(dataverse, functionName, paramList.size());
1438 getCurrentScope().addFunctionDescriptor(signature, false);
1439 cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001440 return cfs;
1441 }
1442}
1443
1444
1445
1446Query Query()throws ParseException:
1447{
1448 Query query = new Query();
1449 Expression expr;
1450}
1451{
1452 expr = Expression()
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001453 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001454 {
1455 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001456 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001457 return query;
1458 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001459
vinayakb38b7ca42012-03-05 05:44:15 +00001460}
1461
1462
1463
1464Expression Expression():
1465{
1466 Expression expr = null;
1467 Expression exprP = null;
1468}
1469{
1470(
1471
1472//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1473 expr = OperatorExpr()
1474 | expr = IfThenElse()
1475 | expr = FLWOGR()
1476 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001477
vinayakb38b7ca42012-03-05 05:44:15 +00001478
1479)
1480 {
1481 return (exprP==null) ? expr : exprP;
1482 }
1483}
1484
1485
1486
1487Expression OperatorExpr()throws ParseException:
1488{
1489 OperatorExpr op = null;
1490 Expression operand = null;
1491}
1492{
1493 operand = AndExpr()
1494 (
1495
1496 "or"
1497 {
1498 if (op == null) {
1499 op = new OperatorExpr();
1500 op.addOperand(operand);
1501 op.setCurrentop(true);
1502 }
1503 Token t = getToken(0);
1504 op.addOperator(t.toString());
1505 }
1506
1507 operand = AndExpr()
1508 {
1509 op.addOperand(operand);
1510 }
1511
1512 )*
1513
1514 {
1515 return op==null? operand: op;
1516 }
1517}
1518
1519Expression AndExpr()throws ParseException:
1520{
1521 OperatorExpr op = null;
1522 Expression operand = null;
1523}
1524{
1525 operand = RelExpr()
1526 (
1527
1528 "and"
1529 {
1530 if (op == null) {
1531 op = new OperatorExpr();
1532 op.addOperand(operand);
1533 op.setCurrentop(true);
1534 }
1535 Token t = getToken(0);
1536 op.addOperator(t.toString());
1537 }
1538
1539 operand = RelExpr()
1540 {
1541 op.addOperand(operand);
1542 }
1543
1544 )*
1545
1546 {
1547 return op==null? operand: op;
1548 }
1549}
1550
1551
1552
1553Expression RelExpr()throws ParseException:
1554{
1555 OperatorExpr op = null;
1556 Expression operand = null;
1557 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001558 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001559}
1560{
1561 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001562 {
1563 if (operand instanceof VariableExpr) {
1564 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001565 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001566 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001567 }
1568 }
1569 }
1570
1571 (
1572 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1573 {
alexander.behm07617fd2012-07-25 10:13:50 +00001574 String mhint = getHint(token);
1575 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1576 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1577 }
vinayakb38b7ca42012-03-05 05:44:15 +00001578 if (op == null) {
1579 op = new OperatorExpr();
1580 op.addOperand(operand, broadcast);
1581 op.setCurrentop(true);
1582 broadcast = false;
1583 }
1584 Token t = getToken(0);
1585 op.addOperator(t.toString());
1586 }
1587
1588 operand = AddExpr()
1589 {
alexander.behm07617fd2012-07-25 10:13:50 +00001590 broadcast = false;
1591 if (operand instanceof VariableExpr) {
1592 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001593 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1594 broadcast = true;
1595 }
alexander.behm07617fd2012-07-25 10:13:50 +00001596 }
vinayakb38b7ca42012-03-05 05:44:15 +00001597 op.addOperand(operand, broadcast);
1598 }
1599 )?
1600
1601 {
alexander.behm07617fd2012-07-25 10:13:50 +00001602 if (annotation != null) {
1603 op.addHint(annotation);
1604 }
vinayakb38b7ca42012-03-05 05:44:15 +00001605 return op==null? operand: op;
1606 }
1607}
1608
1609Expression AddExpr()throws ParseException:
1610{
1611 OperatorExpr op = null;
1612 Expression operand = null;
1613}
1614{
1615 operand = MultExpr()
1616
1617 ( ("+" | "-")
1618 {
1619 if (op == null) {
1620 op = new OperatorExpr();
1621 op.addOperand(operand);
1622 op.setCurrentop(true);
1623 }
1624 Token t = getToken(0);
1625 ((OperatorExpr)op).addOperator(t.toString());
1626 }
1627
1628 operand = MultExpr()
1629 {
1630 op.addOperand(operand);
1631 }
1632 )*
1633
1634 {
1635 return op==null? operand: op;
1636 }
1637}
1638
1639Expression MultExpr()throws ParseException:
1640{
1641 OperatorExpr op = null;
1642 Expression operand = null;
1643}
1644{
1645 operand = UnionExpr()
1646
1647 (( "*" | "/" | "%" | <CARET> | "idiv")
1648 {
1649 if (op == null) {
1650 op = new OperatorExpr();
1651 op.addOperand(operand);
1652 op.setCurrentop(true);
1653 }
1654 Token t = getToken(0);
1655 op.addOperator(t.toString());
1656 }
1657 operand = UnionExpr()
1658 {
1659 op.addOperand(operand);
1660 }
1661 )*
1662
1663 {
1664 return op==null?operand:op;
1665 }
1666}
1667
1668Expression UnionExpr() throws ParseException:
1669{
1670 UnionExpr union = null;
1671 Expression operand1 = null;
1672 Expression operand2 = null;
1673}
1674{
1675 operand1 = UnaryExpr()
1676 ("union"
1677 (operand2 = UnaryExpr()) {
1678 if (union == null) {
1679 union = new UnionExpr();
1680 union.addExpr(operand1);
1681 }
1682 union.addExpr(operand2);
1683 } )*
1684 {
1685 return (union == null)? operand1: union;
1686 }
1687}
1688
1689Expression UnaryExpr() throws ParseException:
1690{
1691 Expression uexpr = null;
1692 Expression expr = null;
1693}
1694{
1695 (( "+"|"-")
1696 {
1697 uexpr = new UnaryExpr();
1698 Token t = getToken(0);
1699 if("+".equals(t.toString()))
1700 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1701 else if("-".equals(t.toString()))
1702 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1703 else
1704 throw new ParseException();
1705 }
1706 )?
1707
1708 expr = ValueExpr()
1709 {
1710 if(uexpr!=null){
1711 ((UnaryExpr)uexpr).setExpr(expr);
1712 return uexpr;
1713 }
1714 else{
1715 return expr;
1716 }
1717 }
1718}
1719
1720Expression ValueExpr() throws ParseException:
1721{
1722 Expression expr;
1723}
1724{
1725 expr = FieldOrIndexAccessor()
1726 {
1727 return expr;
1728 }
1729}
1730
1731
1732Expression FieldOrIndexAccessor()throws ParseException:
1733{
1734 Expression expr = null;
1735 Identifier ident = null;
1736 AbstractAccessor fa = null;
1737 int index;
1738
1739}
1740{
1741 ( expr = PrimaryExpr()
1742
1743 )
1744
1745
1746 (
1747 (
1748 ident = Field()
1749 {
1750 if(fa == null)
1751 fa = new FieldAccessor(expr, ident);
1752 else
1753 fa = new FieldAccessor(fa, ident);
1754 }
1755 )
1756 | (
1757 index = Index()
1758 {
1759 if(fa == null)
1760 fa = new IndexAccessor(expr, index);
1761 else
1762 fa = new IndexAccessor(fa, index);
1763 }
1764 )
1765 )*
1766
1767
1768 {
1769 return fa==null?expr:fa;
1770 }
1771}
1772
1773Identifier Field() throws ParseException:
1774{
1775 Identifier ident = null;
1776
1777}
1778{
1779 "." < IDENTIFIER >
1780 {
1781
1782 ident = new Identifier();
1783 ident.setValue(getToken(0).toString());
1784
1785 return ident;
1786 }
1787}
1788
1789int Index() throws ParseException:
1790{
1791 Expression expr = null;
1792 int idx = -2;
1793}
1794{
1795 "[" ( expr = Expression()
1796 {
1797 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1798 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001799 Literal lit = ((LiteralExpr)expr).getValue();
1800 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1801 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001802 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001803 }
vinayakb38b7ca42012-03-05 05:44:15 +00001804 else {
1805 throw new ParseException("Index should be an INTEGER");
1806 }
1807 }
1808
1809 }
1810
1811 | "?"
1812 {
1813 idx = IndexAccessor.ANY;
1814 // ANY
1815 }
1816
1817 )
1818
1819 "]"
1820 {
1821 return idx;
1822 }
1823}
1824
1825
1826Expression PrimaryExpr()throws ParseException:
1827{
1828 Expression expr = null;
1829}
1830{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001831 //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | DatasetAccessExpression | ParenthesizedExpression
vinayakb38b7ca42012-03-05 05:44:15 +00001832 (
1833 expr =Literal()
1834 | expr = FunctionCallExpr()
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001835 | expr = DatasetAccessExpression()
vinayakb38b7ca42012-03-05 05:44:15 +00001836 | expr =VariableRef()
1837
1838 {
1839 if(((VariableExpr)expr).getIsNewVar() == true)
1840 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
1841 }
1842 | expr = ListConstructor()
1843 | expr = RecordConstructor()
1844 | expr = ParenthesizedExpression()
1845 )
1846 {
1847 return expr;
1848 }
1849}
1850
1851Expression Literal() throws ParseException:
1852{
1853
1854 LiteralExpr lit = new LiteralExpr();
1855 Token t;
1856}
1857{
1858(
1859 <STRING_LITERAL>
1860 {
1861 t= getToken(0);
1862 lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image)));
1863 }
1864
1865 | <INTEGER_LITERAL>
1866 {
1867 t= getToken(0);
ilovesoupc9fef1d2012-07-08 19:30:42 +00001868 try {
1869 lit.setValue(new IntegerLiteral(new Integer(t.image)));
1870 } catch(NumberFormatException ex) {
1871 lit.setValue(new LongIntegerLiteral(new Long(t.image)));
1872 }
vinayakb38b7ca42012-03-05 05:44:15 +00001873 }
1874 | < FLOAT_LITERAL >
1875 {
1876 t= getToken(0);
1877 lit.setValue(new FloatLiteral(new Float(t.image)));
1878 }
1879 | < DOUBLE_LITERAL >
1880 {
1881 t= getToken(0);
1882 lit.setValue(new DoubleLiteral(new Double(t.image)));
1883 }
1884 | <NULL>
1885 {
1886 t= getToken(0);
1887 lit.setValue(NullLiteral.INSTANCE);
1888 }
1889 | <TRUE>
1890 {
1891 t= getToken(0);
1892 lit.setValue(TrueLiteral.INSTANCE);
1893 }
1894 | <FALSE>
1895 {
1896 t= getToken(0);
1897 lit.setValue(FalseLiteral.INSTANCE);
1898 }
1899)
1900 {
1901 return lit;
1902 }
1903}
1904
1905
1906VariableExpr VariableRef() throws ParseException:
1907{
1908 VariableExpr varExp = new VariableExpr();
1909 VarIdentifier var = new VarIdentifier();
1910 Token t;
1911}
1912{
1913 <VARIABLE>
1914 {
1915 t = getToken(0);//get current token
1916 String varName = t.toString();
1917 Identifier ident = lookupSymbol(varName);
1918 if (isInForbiddenScopes(varName)) {
1919 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.");
1920 }
1921 if(ident != null) { // exist such ident
1922 varExp.setIsNewVar(false);
1923 varExp.setVar((VarIdentifier)ident);
1924 } else {
1925 varExp.setVar(var);
1926 }
1927 var.setValue(t.toString());
1928 return varExp;
1929 }
1930}
1931
1932
1933VariableExpr Variable() throws ParseException:
1934{
1935 VariableExpr varExp = new VariableExpr();
1936 VarIdentifier var = new VarIdentifier();
1937 Token t;
1938}
1939{
1940 <VARIABLE>
1941 {
1942 t = getToken(0);//get current token
1943 Identifier ident = lookupSymbol(t.toString());
1944 if(ident != null) { // exist such ident
1945 varExp.setIsNewVar(false);
1946 }
1947 varExp.setVar(var);
1948 var.setValue(t.toString());
1949 return varExp;
1950 }
1951}
1952
1953Expression ListConstructor() throws ParseException:
1954{
1955 Expression expr = null;
1956}
1957{
1958 (
1959 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1960 )
1961
1962 {
1963 return expr;
1964 }
1965}
1966
1967
1968ListConstructor OrderedListConstructor() throws ParseException:
1969{
1970 ListConstructor expr = new ListConstructor();
1971 Expression tmp = null;
1972 List<Expression> exprList = new ArrayList<Expression>();
1973 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1974}
1975{
1976
1977 "["
1978 ( tmp = Expression()
1979 {
1980 exprList.add(tmp);
1981 }
1982
1983 ("," tmp = Expression() { exprList.add(tmp); })*
1984 )?
1985
1986 "]"
1987
1988 {
1989 expr.setExprList(exprList);
1990 return expr;
1991 }
1992}
1993
1994ListConstructor UnorderedListConstructor() throws ParseException:
1995{
1996 ListConstructor expr = new ListConstructor();
1997 Expression tmp = null;
1998 List<Expression> exprList = new ArrayList<Expression>();
1999 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2000}
2001{
2002
2003 "{{" ( tmp = Expression()
2004 {
2005 exprList.add(tmp);
2006 }
2007 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
2008 {
2009 expr.setExprList(exprList);
2010 return expr;
2011 }
2012}
2013
2014RecordConstructor RecordConstructor() throws ParseException:
2015{
2016 RecordConstructor expr = new RecordConstructor();
2017 FieldBinding tmp = null;
2018 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2019}
2020{
2021 "{" (tmp = FieldBinding()
2022 {
2023 fbList.add(tmp);
2024 }
2025 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
2026 {
2027 expr.setFbList(fbList);
2028 return expr;
2029 }
2030}
2031
2032FieldBinding FieldBinding() throws ParseException:
2033{
2034 FieldBinding fb = new FieldBinding();
2035 Expression left, right;
2036}
2037{
2038 left = Expression() ":" right = Expression()
2039 {
2040 fb.setLeftExpr(left);
2041 fb.setRightExpr(right);
2042 return fb;
2043 }
2044}
2045
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002046
vinayakb38b7ca42012-03-05 05:44:15 +00002047Expression FunctionCallExpr() throws ParseException:
2048{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002049 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002050 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002051 Expression tmp;
2052 int arity = 0;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002053 String funcName;
2054 String dataverse;
2055 String hint=null;
2056 String id1=null;
2057 String id2=null;
vinayakb38b7ca42012-03-05 05:44:15 +00002058}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002059{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002060
2061 <IDENTIFIER> { dataverse = defaultDataverse; funcName = token.image;} ("." <IDENTIFIER> { dataverse = funcName; funcName = token.image;})?
vinayakb38b7ca42012-03-05 05:44:15 +00002062 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002063 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002064 }
2065 <LEFTPAREN> (tmp = Expression()
2066 {
2067 argList.add(tmp);
2068 arity ++;
2069 } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
2070
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002071 {
2072 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2073 if(signature == null)
2074 {
2075 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2076 }
2077 callExpr = new CallExpr(signature,argList);
2078 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2079 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2080 }
2081 return callExpr;
vinayakb38b7ca42012-03-05 05:44:15 +00002082 }
2083}
2084
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002085Expression DatasetAccessExpression() throws ParseException:
2086{
2087 CallExpr callExpr;
2088 List<Expression> argList = new ArrayList<Expression>();
2089 String funcName;
2090 String dataverse;
2091 LiteralExpr ds;
2092 LiteralExpr dvds;
2093 Expression nameArg;
2094 int arity = 0;
2095}
2096{
2097 <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();}
2098 (
2099 (<IDENTIFIER> {ds = new LiteralExpr(); ds.setValue( new StringLiteral(token.image) ); argList.add(ds); arity ++;} ("." <IDENTIFIER> { dvds = new LiteralExpr(); dvds.setValue(new StringLiteral(ds.getValue()+"."+token.image)); argList.remove(0); argList.add(dvds);})? ) |
2100 (<LEFTPAREN> nameArg = Expression() {argList.add(nameArg); arity ++;} ("," nameArg = Expression() { argList.add(nameArg); arity++; })* <RIGHTPAREN>)
2101 )
2102
2103 {
2104 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2105 if(signature == null)
2106 {
2107 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2108 }
2109 callExpr = new CallExpr(signature,argList);
2110 return callExpr;
2111 }
2112}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002113
vinayakb38b7ca42012-03-05 05:44:15 +00002114Expression ParenthesizedExpression() throws ParseException:
2115{
2116 Expression expr;
2117}
2118{
2119 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2120 {
2121 return expr;
2122 }
2123}
2124
2125Expression IfThenElse() throws ParseException:
2126{
2127 Expression condExpr;
2128 Expression thenExpr;
2129 Expression elseExpr;
2130 IfExpr ifExpr = new IfExpr();
2131}
2132{
2133 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
2134
2135 {
2136 ifExpr.setCondExpr(condExpr);
2137 ifExpr.setThenExpr(thenExpr);
2138 ifExpr.setElseExpr(elseExpr);
2139 return ifExpr;
2140 }
2141}
2142
2143Expression FLWOGR() throws ParseException:
2144{
2145 FLWOGRExpression flworg = new FLWOGRExpression();
2146 List<Clause> clauseList = new ArrayList<Clause>();
2147 Expression returnExpr;
2148 Clause tmp;
2149 createNewScope();
2150}
2151{
2152 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2153 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
2154
2155 {
2156 flworg.setClauseList(clauseList);
2157 flworg.setReturnExpr(returnExpr);
2158 removeCurrentScope();
2159 return flworg;
2160 }
2161}
2162
2163Clause Clause()throws ParseException :
2164{
2165 Clause clause;
2166}
2167{
2168 (
2169 clause = ForClause()
2170 | clause = LetClause()
2171 | clause = WhereClause()
2172 | clause = OrderbyClause()
2173 | clause = GroupClause()
2174 | clause = LimitClause()
2175 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002176 )
2177 {
2178 return clause;
2179 }
2180}
2181
2182Clause ForClause()throws ParseException :
2183{
2184 ForClause fc = new ForClause();
2185 VariableExpr varExp;
2186 VariableExpr varPos = null;
2187 Expression inExp;
2188 extendCurrentScope();
2189}
2190{
2191 "for" varExp = Variable()
2192 {
2193 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2194 }
2195 ("at" varPos = Variable()
2196 {
2197 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2198 }
2199 )?
2200 "in" ( inExp = Expression() )
2201 {
2202 fc.setVarExpr(varExp);
2203 fc.setInExpr(inExp);
2204 if (varPos != null) {
2205 fc.setPosExpr(varPos);
2206 }
2207 return fc;
2208 }
2209}
2210
2211Clause LetClause() throws ParseException:
2212{
2213 LetClause lc = new LetClause();
2214 VariableExpr varExp;
2215 Expression beExp;
2216 extendCurrentScope();
2217}
2218{
ilovesoupb2527c12012-07-12 03:21:13 +00002219 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002220 {
2221 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002222 lc.setVarExpr(varExp);
2223 lc.setBeExpr(beExp);
2224 return lc;
2225 }
2226}
2227
2228Clause WhereClause()throws ParseException :
2229{
2230 WhereClause wc = new WhereClause();
2231 Expression whereExpr;
2232}
2233{
2234 "where" whereExpr = Expression()
2235 {
2236 wc.setWhereExpr(whereExpr);
2237 return wc;
2238 }
2239}
2240
2241Clause OrderbyClause()throws ParseException :
2242{
2243 OrderbyClause oc = new OrderbyClause();
2244 Expression orderbyExpr;
2245 List<Expression> orderbyList = new ArrayList<Expression>();
2246 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2247 int numOfOrderby = 0;
2248}
2249{
2250 (
2251 "order"
2252 {
2253 String hint = getHint(token);
2254 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2255 String splits[] = hint.split(" +");
2256 int numFrames = Integer.parseInt(splits[1]);
2257 int numTuples = Integer.parseInt(splits[2]);
2258 oc.setNumFrames(numFrames);
2259 oc.setNumTuples(numTuples);
2260 }
2261 }
2262 "by" orderbyExpr = Expression()
2263 {
2264 orderbyList.add(orderbyExpr);
2265 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2266 }
2267 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2268 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2269 {
2270 modifierList.add(modif);
2271 }
2272
2273 ("," orderbyExpr = Expression()
2274 {
2275 orderbyList.add(orderbyExpr);
2276 modif = OrderbyClause.OrderModifier.ASC;
2277 }
2278 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2279 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2280 {
2281 modifierList.add(modif);
2282 }
2283 )*
2284)
2285 {
2286 oc.setModifierList(modifierList);
2287 oc.setOrderbyList(orderbyList);
2288 return oc;
2289 }
2290}
2291Clause GroupClause()throws ParseException :
2292{
2293 GroupbyClause gbc = new GroupbyClause();
2294 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2295 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2296 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2297 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2298 VariableExpr var = null;
2299 VariableExpr withVar = null;
2300 Expression expr = null;
2301 VariableExpr decorVar = null;
2302 Expression decorExpr = null;
2303}
2304{
2305 {
2306 Scope newScope = extendCurrentScopeNoPush(true);
2307 // extendCurrentScope(true);
2308 }
2309 "group"
2310 {
2311 String hint = getHint(token);
2312 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2313 gbc.setHashGroupByHint(true);
2314 }
2315 }
2316 "by" (LOOKAHEAD(2) var = Variable()
2317 {
2318 newScope.addNewVarSymbolToScope(var.getVar());
2319 } ":=")?
2320 expr = Expression()
2321 {
2322 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2323 vePairList.add(pair1);
2324 }
2325 ("," ( LOOKAHEAD(2) var = Variable()
2326 {
2327 newScope.addNewVarSymbolToScope(var.getVar());
2328 } ":=")?
2329 expr = Expression()
2330 {
2331 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2332 vePairList.add(pair2);
2333 }
2334 )*
2335 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2336 {
2337 newScope.addNewVarSymbolToScope(decorVar.getVar());
2338 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2339 decorPairList.add(pair3);
2340 }
2341 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2342 {
2343 newScope.addNewVarSymbolToScope(decorVar.getVar());
2344 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2345 decorPairList.add(pair4);
2346 }
2347 )*
2348 )?
2349 "with" withVar = VariableRef()
2350 {
2351 if(withVar.getIsNewVar()==true)
2352 throw new ParseException("can't find variable " + withVar.getVar());
2353 withVarList.add(withVar);
2354 newScope.addNewVarSymbolToScope(withVar.getVar());
2355 }
2356 ("," withVar = VariableRef()
2357 {
2358 if(withVar.getIsNewVar()==true)
2359 throw new ParseException("can't find variable " + withVar.getVar());
2360 withVarList.add(withVar);
2361 newScope.addNewVarSymbolToScope(withVar.getVar());
2362 })*
2363 {
2364 gbc.setGbyPairList(vePairList);
2365 gbc.setDecorPairList(decorPairList);
2366 gbc.setWithVarList(withVarList);
2367 replaceCurrentScope(newScope);
2368 return gbc;
2369 }
2370}
2371
2372
2373LimitClause LimitClause() throws ParseException:
2374{
2375 LimitClause lc = new LimitClause();
2376 Expression expr;
2377 pushForbiddenScope(getCurrentScope());
2378}
2379{
2380 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2381 ("offset" expr = Expression() { lc.setOffset(expr); })?
2382
2383 {
2384 popForbiddenScope();
2385 return lc;
2386 }
2387}
2388
2389DistinctClause DistinctClause() throws ParseException:
2390{
2391 List<Expression> exprs = new ArrayList<Expression>();
2392 Expression expr;
2393}
2394{
2395 "distinct" "by" expr = Expression()
2396 {
2397 exprs.add(expr);
2398 }
2399 ("," expr = Expression()
2400 {
2401 exprs.add(expr);
2402 }
2403 )*
2404 {
2405 return new DistinctClause(exprs);
2406 }
2407}
2408
vinayakb38b7ca42012-03-05 05:44:15 +00002409QuantifiedExpression QuantifiedExpression()throws ParseException:
2410{
2411 QuantifiedExpression qc = new QuantifiedExpression();
2412 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2413 Expression satisfiesExpr;
2414 VariableExpr var;
2415 Expression inExpr;
2416 QuantifiedPair pair;
2417}
2418{
2419 {
2420 createNewScope();
2421 }
2422
2423 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2424 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2425 var = Variable() "in" inExpr = Expression()
2426 {
2427 pair = new QuantifiedPair(var, inExpr);
2428 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2429 quantifiedList.add(pair);
2430 }
2431 (
2432 "," var = Variable() "in" inExpr = Expression()
2433 {
2434 pair = new QuantifiedPair(var, inExpr);
2435 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2436 quantifiedList.add(pair);
2437 }
2438 )*
2439 "satisfies" satisfiesExpr = Expression()
2440 {
2441 qc.setSatisfiesExpr(satisfiesExpr);
2442 qc.setQuantifiedList(quantifiedList);
2443 removeCurrentScope();
2444 return qc;
2445 }
2446}
2447
2448TOKEN_MGR_DECLS:
2449{
2450 public int commentDepth = 0;
2451}
2452
2453<DEFAULT>
2454TOKEN :
2455{
2456 <CARET : "^" >
2457}
2458
2459<DEFAULT>
2460TOKEN :
2461{
2462 <DATASET : "dataset" >
2463}
2464
2465<DEFAULT>
2466TOKEN :
2467{
2468 <LEFTPAREN : "(" >
2469}
2470
2471<DEFAULT>
2472TOKEN :
2473{
2474 <RIGHTPAREN : ")" >
2475}
2476
2477
2478<DEFAULT>
2479TOKEN :
2480{
2481 <INTEGER_LITERAL : (<DIGIT>)+ >
2482}
2483
2484
2485<DEFAULT>
2486TOKEN :
2487{
2488 <NULL : "null">
2489}
2490
2491<DEFAULT>
2492TOKEN :
2493{
2494 <TRUE : "true">
2495}
2496
2497<DEFAULT>
2498TOKEN :
2499{
2500 <FALSE : "false">
2501}
2502
2503<DEFAULT>
2504TOKEN :
2505{
2506 <#DIGIT : ["0" - "9"]>
2507}
2508
2509
2510TOKEN:
2511{
2512 < DOUBLE_LITERAL: <INTEGER>
2513 | <INTEGER> ( "." <INTEGER> )?
2514 | "." <INTEGER>
2515 >
2516 |
2517 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2518 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2519 | "." <INTEGER> ( "f" | "F" )
2520 >
2521 |
2522 <INTEGER : (<DIGIT>)+ >
2523}
2524
2525<DEFAULT>
2526TOKEN :
2527{
2528 <#LETTER : ["A" - "Z", "a" - "z"]>
2529}
2530
2531<DEFAULT>
2532TOKEN :
2533{
2534 <SPECIALCHARS : ["$", "_", "-"] >
2535}
2536
2537<DEFAULT>
2538TOKEN :
2539{
2540 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2541 |
2542 < #EscapeQuot: "\\\"" >
2543 |
2544 < #EscapeApos: "\\\'" >
2545}
2546
2547<DEFAULT>
2548TOKEN :
2549{
2550 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2551}
2552
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002553
vinayakb38b7ca42012-03-05 05:44:15 +00002554<DEFAULT>
2555TOKEN :
2556{
2557 <VARIABLE : "$" <IDENTIFIER> >
2558}
2559
2560SKIP:
2561{
2562 " "
2563| "\t"
2564| "\r"
2565| "\n"
2566}
2567
2568SKIP:
2569{
2570 <"//" (~["\n"])* "\n">
2571}
2572
2573SKIP:
2574{
2575 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2576}
2577
2578
2579SKIP:
2580{
2581 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2582}
2583
2584<INSIDE_COMMENT>
2585SPECIAL_TOKEN:
2586{
2587 <"+"(" ")*(~["*"])*>
2588}
2589
2590<INSIDE_COMMENT>
2591SKIP:
2592{
2593 <"/*"> {commentDepth++;}
2594}
2595
2596<INSIDE_COMMENT>
2597SKIP:
2598{
2599 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2600| <~[]>
2601}