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