blob: be7d954f464dcb5e7662cf3997c456a6dbaa5f54 [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;
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"
alexander.behmb742e092012-11-24 11:54:56 +0000402 ("btree" { cis.setIndexType(IndexType.BTREE); }
alexander.behmc576c602012-07-06 02:41:15 +0000403 | "rtree" { cis.setIndexType(IndexType.RTREE); }
alexander.behmb742e092012-11-24 11:54:56 +0000404 | "keyword" { cis.setIndexType(IndexType.WORD_INVIX); }
405 | "fuzzy keyword" { cis.setIndexType(IndexType.FUZZY_WORD_INVIX); }
alexander.behmc576c602012-07-06 02:41:15 +0000406 | "ngram"
407 <LEFTPAREN>
408 (<INTEGER_LITERAL>
409 {
410 cis.setIndexType(IndexType.NGRAM_INVIX);
411 cis.setGramLength(Integer.valueOf(token.image));
412 }
413 )
alexander.behmb742e092012-11-24 11:54:56 +0000414 <RIGHTPAREN>
415 | "fuzzy ngram"
416 <LEFTPAREN>
417 (<INTEGER_LITERAL>
418 {
419 cis.setIndexType(IndexType.FUZZY_NGRAM_INVIX);
420 cis.setGramLength(Integer.valueOf(token.image));
421 }
422 )
423 <RIGHTPAREN>
alexander.behmc576c602012-07-06 02:41:15 +0000424 )
vinayakb38b7ca42012-03-05 05:44:15 +0000425 ";"
426 | ";"
427 )
428 {
429 return cis;
430 }
431}
432
433DataverseDecl DataverseDeclaration() throws ParseException:
434{
435 Identifier dvName = null;
436}
437{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000438 "dataverse" <IDENTIFIER> { defaultDataverse = token.image;}
vinayakb38b7ca42012-03-05 05:44:15 +0000439 ";"
440 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000441 return new DataverseDecl(new Identifier(defaultDataverse));
vinayakb38b7ca42012-03-05 05:44:15 +0000442 }
443}
444
445DropStatement DropStatement() throws ParseException :
446{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000447 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000448 Identifier datasetName = null;
449 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000450 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000451}
452{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000453 {
454 nameComponents = getDotSeparatedPair();
455 dataverseName = nameComponents.first;
456 datasetName = nameComponents.second;
457 }
458
459
vinayakb38b7ca42012-03-05 05:44:15 +0000460 (
461 "if exists"
462 {
463 ifExists = true;
464 }
465 )? ";"
466 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000467 return new DropStatement(dataverseName, datasetName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000468 }
469}
470
471IndexDropStatement IndexDropStatement() throws ParseException :
472{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000473 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000474 Identifier datasetName = null;
475 Identifier indexName = null;
476 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000477 Triple<Identifier,Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000478}
479{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000480
vinayakb38b7ca42012-03-05 05:44:15 +0000481 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000482 nameComponents = getDotSeparatedTriple();
483 dataverseName = nameComponents.first;
484 datasetName = nameComponents.second;
485 indexName = nameComponents.third;
486 }
487
vinayakb38b7ca42012-03-05 05:44:15 +0000488 (
489 "if exists"
490 {
491 ifExists = true;
492 }
493 )? ";"
494 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000495 return new IndexDropStatement(dataverseName, datasetName, indexName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000496 }
497}
498
499NodeGroupDropStatement NodeGroupDropStatement() throws ParseException :
500{
501 Identifier groupName = null;
502 boolean ifExists = false;
503}
504{
505 < IDENTIFIER >
506 {
507 groupName = new Identifier(token.image);
508 }
509 (
510 "if exists"
511 {
512 ifExists = true;
513 }
514 )? ";"
515 {
516 return new NodeGroupDropStatement(groupName, ifExists);
517 }
518}
519
520TypeDropStatement TypeDropStatement() throws ParseException :
521{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000522 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000523 Identifier typeName = null;
524 boolean ifExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000525 Pair<Identifier,Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000526}
527{
vinayakb38b7ca42012-03-05 05:44:15 +0000528 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000529 nameComponents = getDotSeparatedPair();
530 dataverseName = nameComponents.first == null ? new Identifier(defaultDataverse) : nameComponents.first;
531 typeName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000532 }
533 (
534 "if exists"
535 {
536 ifExists = true;
537 }
538 )? ";"
539 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000540 return new TypeDropStatement(dataverseName, typeName, ifExists);
vinayakb38b7ca42012-03-05 05:44:15 +0000541 }
542}
543
544DataverseDropStatement DataverseDropStatement() throws ParseException :
545{
546 Identifier dataverseName = null;
547 boolean ifExists = false;
548}
549{
550 < IDENTIFIER >
551 {
552 dataverseName = new Identifier(token.image);
553 }
554 (
555 "if exists"
556 {
557 ifExists = true;
558 }
559 )? ";"
560 {
561 return new DataverseDropStatement(dataverseName, ifExists);
562 }
563}
564
565CreateDataverseStatement CreateDataverseStatement() throws ParseException :
566{
567 Identifier dvName = null;
568 boolean ifNotExists = false;
569 String format = null;
570}
571{
572 < IDENTIFIER >
573 {
574 dvName = new Identifier(token.image);
575 }
576 (
577 "if not exists"
578 {
579 ifNotExists = true;
580 }
581 )?
582 (
583 "with format" < STRING_LITERAL >
584 {
585 format = removeQuotesAndEscapes(token.image);
586 }
587 )?
588 ";"
589 {
590 return new CreateDataverseStatement(dvName, format, ifNotExists);
591 }
592}
593
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000594
595FunctionDropStatement FunctionDropStatement() throws ParseException :
596{
597 String dataverse;
598 String functionName;
599 int arity=0;
600 boolean ifExists = false;
601 Pair<Identifier, Identifier> nameComponents=null;
602}
603{
604 {
605 nameComponents = getDotSeparatedPair();
606 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
607 functionName = nameComponents.second.getValue();
608 }
609
610 "@"
611 <INTEGER_LITERAL>
612 {
613 Token t= getToken(0);
614 arity = new Integer(t.image);
615 if( arity < 0 && arity != FunctionIdentifier.VARARGS){
616 throw new ParseException(" invalid arity:" + arity);
617 }
618 }
619
620 (
621 "if exists"
622 {
623 ifExists = true;
624 }
625 )? ";"
626 {
627 return new FunctionDropStatement(new FunctionSignature(dataverse, functionName, arity), ifExists);
628 }
629}
630
631
vinayakb38b7ca42012-03-05 05:44:15 +0000632LoadFromFileStatement LoadStatement() throws ParseException:
633{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000634 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000635 Identifier datasetName = null;
636 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000637 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000638 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000639 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000640}
641{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000642 <DATASET>
643 {
644 nameComponents = getDotSeparatedPair();
645 dataverseName = nameComponents.first;
646 datasetName = nameComponents.second;
647 }
648
vinayakb38b7ca42012-03-05 05:44:15 +0000649 "using"
ramangrover29669d8f62013-02-11 06:03:32 +0000650
vinayakb38b7ca42012-03-05 05:44:15 +0000651 {
ramangrover29669d8f62013-02-11 06:03:32 +0000652 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000653 }
ramangrover29669d8f62013-02-11 06:03:32 +0000654
vinayakb38b7ca42012-03-05 05:44:15 +0000655 {
656 properties = getConfiguration();
657 }
658
659 ("pre-sorted"
660 { alreadySorted = true; }
661 )?
662
663 ";"
664 {
ramangrover29669d8f62013-02-11 06:03:32 +0000665 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
vinayakb38b7ca42012-03-05 05:44:15 +0000666 }
667}
668
669
ramangrover29669d8f62013-02-11 06:03:32 +0000670String getAdapterName() throws ParseException :
671{
672 String adapterName = null;
673}
674{
675 (
676 <IDENTIFIER> {
677 adapterName = (new Identifier(token.image)).getValue();;
678 }
679 |
680 <STRING_LITERAL>
681 {
682 adapterName = removeQuotesAndEscapes(token.image);
683 }
684 )
685 {
686 return adapterName;
687 }
688}
689
vinayakb38b7ca42012-03-05 05:44:15 +0000690
691DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException :
692{
693 DatasetDecl dd = null;
694 Identifier datasetName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000695 Identifier dataverseName = null;
696 Identifier itemDataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000697 Identifier itemTypeName = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000698 String nameComponentFirst = null;
699 String nameComponentSecond = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000700 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000701 IDatasetDetailsDecl datasetDetails = null;
ramangrover2971e5c6a2013-01-30 05:30:12 +0000702 Pair<Identifier,Identifier> nameComponents = null;
703 Map<String,String> hints = new HashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000704}
705{
vinayakb38b7ca42012-03-05 05:44:15 +0000706 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000707 nameComponents = getDotSeparatedPair();
708 dataverseName = nameComponents.first;
709 datasetName = nameComponents.second;
710 }
711
vinayakb38b7ca42012-03-05 05:44:15 +0000712 (
713 "if not exists"
714 {
715 ifNotExists = true;
716 }
717 )?
718 (
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000719 < LEFTPAREN > <IDENTIFIER>
vinayakb38b7ca42012-03-05 05:44:15 +0000720 {
721 itemTypeName = new Identifier(token.image);
722 }
723 < RIGHTPAREN >
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +0000724 )
vinayakb38b7ca42012-03-05 05:44:15 +0000725 {
726 if(datasetType == DatasetType.INTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000727 datasetDetails = InternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000728 }
729 else if(datasetType == DatasetType.EXTERNAL) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000730 datasetDetails = ExternalDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000731 }
732 else if(datasetType == DatasetType.FEED) {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000733 datasetDetails = FeedDatasetDeclaration();
vinayakb38b7ca42012-03-05 05:44:15 +0000734 }
vinayakb38b7ca42012-03-05 05:44:15 +0000735 }
ramangrover2971e5c6a2013-01-30 05:30:12 +0000736
737 (
738 "hints"
vinayakb38b7ca42012-03-05 05:44:15 +0000739 {
ramangrover2971e5c6a2013-01-30 05:30:12 +0000740 initProperties(hints);
741 }
742 )?
743 ";"
744
745 {
746 dd = new DatasetDecl(dataverseName, datasetName, itemTypeName, hints, datasetType, datasetDetails,ifNotExists);
747 return dd;
vinayakb38b7ca42012-03-05 05:44:15 +0000748 }
749}
750
751InternalDetailsDecl InternalDatasetDeclaration() throws ParseException :
752{
753 InternalDetailsDecl idd = null;
ramangrover292f199b02013-02-13 05:32:01 +0000754 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000755 Identifier nodeGroupName=null;
vinayakb38b7ca42012-03-05 05:44:15 +0000756}
757{
vinayakb38b7ca42012-03-05 05:44:15 +0000758 (
vinayakb38b7ca42012-03-05 05:44:15 +0000759 {
ramangrover292f199b02013-02-13 05:32:01 +0000760 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000761 }
ramangrover29669d8f62013-02-11 06:03:32 +0000762 )
763
vinayakb38b7ca42012-03-05 05:44:15 +0000764 (
765 "on" < IDENTIFIER >
766 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000767 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000768 }
769 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000770
vinayakb38b7ca42012-03-05 05:44:15 +0000771 {
ramangrover292f199b02013-02-13 05:32:01 +0000772 idd = new InternalDetailsDecl(nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000773 return idd;
774 }
775}
776
777ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException :
778{
779 ExternalDetailsDecl edd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000780 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000781 Map < String, String > properties;
782}
783{
784 {
785 edd = new ExternalDetailsDecl();
786 }
787
788 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000789 {
ramangrover29669d8f62013-02-11 06:03:32 +0000790 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000791 }
792
793 {
794 properties = getConfiguration();
795 }
796
797 {
798 edd = new ExternalDetailsDecl();
ramangrover29669d8f62013-02-11 06:03:32 +0000799 edd.setAdapter(adapterName);
vinayakb38b7ca42012-03-05 05:44:15 +0000800 edd.setProperties(properties);
801 }
vinayakb38b7ca42012-03-05 05:44:15 +0000802
803 {
804 return edd;
805 }
806}
807
808FeedDetailsDecl FeedDatasetDeclaration() throws ParseException :
809{
810 FeedDetailsDecl fdd = null;
ramangrover29669d8f62013-02-11 06:03:32 +0000811 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000812 Map < String, String > properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000813 Pair<Identifier,Identifier> nameComponents;
ramangrover292f199b02013-02-13 05:32:01 +0000814 List<String> primaryKeyFields = new ArrayList<String>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000815 Identifier nodeGroupName=null;
816 FunctionSignature appliedFunction=null;
817 String dataverse;
818 String functionName;
819 int arity;
vinayakb38b7ca42012-03-05 05:44:15 +0000820}
821{
vinayakb38b7ca42012-03-05 05:44:15 +0000822 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000823 {
ramangrover29669d8f62013-02-11 06:03:32 +0000824 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000825 }
826
827 {
828 properties = getConfiguration();
829 }
830
831 ("apply" "function"
vinayakb38b7ca42012-03-05 05:44:15 +0000832 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000833 nameComponents = getDotSeparatedPair();
834 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
835 functionName = nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +0000836 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000837 ("@" <INTEGER_LITERAL>
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000838 {
839 arity = Integer.parseInt(token.image);
840 }
841 )
842
843 {
844 appliedFunction = new FunctionSignature(dataverse, functionName, arity);
845 }
vinayakb38b7ca42012-03-05 05:44:15 +0000846 )?
847
vinayakb38b7ca42012-03-05 05:44:15 +0000848 (
vinayakb38b7ca42012-03-05 05:44:15 +0000849 {
ramangrover292f199b02013-02-13 05:32:01 +0000850 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000851 }
ramangrover29669d8f62013-02-11 06:03:32 +0000852 )
853
vinayakb38b7ca42012-03-05 05:44:15 +0000854 (
855 "on" < IDENTIFIER >
856 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000857 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000858 }
859 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000860
vinayakb38b7ca42012-03-05 05:44:15 +0000861 {
ramangrover292f199b02013-02-13 05:32:01 +0000862 fdd = new FeedDetailsDecl(adapterName, properties, appliedFunction, nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000863 return fdd;
864 }
865}
866
ramangrover292f199b02013-02-13 05:32:01 +0000867List<String> getPrimaryKeyFields() throws ParseException :
ramangrover29669d8f62013-02-11 06:03:32 +0000868{
ramangrover292f199b02013-02-13 05:32:01 +0000869 List<String> primaryKeyFields = new ArrayList<String>();
ramangrover29669d8f62013-02-11 06:03:32 +0000870}
871{
872
873 "primary" "key"
874 < IDENTIFIER >
875 {
ramangrover292f199b02013-02-13 05:32:01 +0000876 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000877 }
878 (
879 "," < IDENTIFIER >
880 {
ramangrover292f199b02013-02-13 05:32:01 +0000881 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000882 }
883 )*
884 {
ramangrover292f199b02013-02-13 05:32:01 +0000885 return primaryKeyFields;
ramangrover29669d8f62013-02-11 06:03:32 +0000886 }
887
888}
889
890
891
892
893
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000894ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000895{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000896 Pair<Identifier,Identifier> nameComponents = null;
897}
898{
899 {
900 nameComponents = getDotSeparatedPair();
901 return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second);
902 }
903}
904
905
906ControlFeedStatement AlterFeedDeclaration() throws ParseException :
907{
908 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000909 Map < String, String > configuration = new HashMap < String, String > ();
910}
911{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000912 {
913 nameComponents = getDotSeparatedPair();
914 }
915
vinayakb38b7ca42012-03-05 05:44:15 +0000916 "set"
917 {
918 configuration = getConfiguration();
919 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000920
vinayakb38b7ca42012-03-05 05:44:15 +0000921 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000922 return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
vinayakb38b7ca42012-03-05 05:44:15 +0000923 }
924}
925
926Map<String,String> getConfiguration() throws ParseException :
927{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000928 Map<String,String> configuration = new LinkedHashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000929 String key;
930 String value;
931}
932{
933
934<LEFTPAREN>
935 (
936 (
937 <LEFTPAREN>
938 (
939 <STRING_LITERAL>
940 {
941 key = removeQuotesAndEscapes(token.image);
942 }
943 "=" <STRING_LITERAL>
944 {
945 value = removeQuotesAndEscapes(token.image);
946 }
947 )
948 <RIGHTPAREN>
949 {
950 configuration.put(key, value);
951 }
952 )
953 (
954 "," <LEFTPAREN>
955 (
956 <STRING_LITERAL>
957 {
958 key = removeQuotesAndEscapes(token.image);
959 }
960 "=" <STRING_LITERAL>
961 {
962 value = removeQuotesAndEscapes(token.image);
963 }
964 )
965 <RIGHTPAREN>
966 {
967 configuration.put(key, value);
968 }
969 )*
970 )?
971 <RIGHTPAREN>
972 {
973 return configuration;
974 }
975}
976
ramangrover2971e5c6a2013-01-30 05:30:12 +0000977void initProperties(Map<String,String> properties) throws ParseException :
978{
979 String key;
980 String value;
981}
982{
983 (
984 <LEFTPAREN>
985 (
986 <IDENTIFIER>
987 {
988 key = (new Identifier(token.image)).getValue();
989 }
990 "="
991 (
992 (<STRING_LITERAL>
993 {
994 value = removeQuotesAndEscapes(token.image);
995 }
996 ) |
997 (<INTEGER_LITERAL>
998 {
999 try{
ramangrover2921b88182013-01-31 00:51:19 +00001000 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001001 } catch (NumberFormatException nfe){
1002 throw new ParseException("inapproriate value: " + token.image);
1003 }
1004 }
1005 )
1006 )
1007 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001008 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001009 }
1010 (
1011 ","
1012 (
1013 <IDENTIFIER>
1014 {
1015 key = (new Identifier(token.image)).getValue();
1016 }
1017 "="
1018 (
1019 (<STRING_LITERAL>
1020 {
1021 value = removeQuotesAndEscapes(token.image);
1022 }
1023 ) |
1024 (<INTEGER_LITERAL>
1025 {
1026 try{
ramangrover2921b88182013-01-31 00:51:19 +00001027 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001028 } catch (NumberFormatException nfe){
1029 throw new ParseException("inapproriate value: " + token.image);
1030 }
1031 }
1032 )
1033 )
1034 )
1035 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001036 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001037 }
1038
1039 )*
1040 )
1041 <RIGHTPAREN>
1042 )?
1043}
1044
1045
vinayakb38b7ca42012-03-05 05:44:15 +00001046
1047NodegroupDecl NodegroupDeclaration() throws ParseException :
1048{
1049 Identifier name = null;
1050 List < Identifier > ncNames = new ArrayList < Identifier > ();
1051 boolean ifNotExists = false;
1052}
1053{
1054 < IDENTIFIER >
1055 {
1056 name = new Identifier(token.image);
1057 }
1058 (
1059 "if not exists"
1060 {
1061 ifNotExists = true;
1062 }
1063 )?
1064 "on" < IDENTIFIER >
1065 {
1066 ncNames.add(new Identifier(token.image));
1067 }
1068 (
1069 "," < IDENTIFIER >
1070 {
1071 ncNames.add(new Identifier(token.image));
1072 }
1073 )*
1074 ";"
1075 {
1076 return new NodegroupDecl(name, ncNames, ifNotExists);
1077 }
1078}
1079
1080
1081TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException:
1082{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001083 Identifier dataverse;
vinayakb38b7ca42012-03-05 05:44:15 +00001084 Identifier ident;
1085 TypeExpression typeExpr;
1086 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001087 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001088}
1089{
vinayakb38b7ca42012-03-05 05:44:15 +00001090 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001091 nameComponents = getDotSeparatedPair();
1092 dataverse = nameComponents.first;
1093 ident = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001094 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001095
vinayakb38b7ca42012-03-05 05:44:15 +00001096 (
1097 "if not exists"
1098 {
1099 ifNotExists = true;
1100 }
1101 )?
1102 "as"
1103 ( typeExpr = TypeExpr() )
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001104 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001105 {
1106 long numValues = -1;
1107 String filename = null;
1108 if (dgen) {
1109 String splits[] = hint.split(" +");
1110 if (splits.length != 3) {
1111 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
1112 }
1113 filename = splits[1];
1114 numValues = Long.parseLong(splits[2]);
1115 }
1116 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001117 return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001118 }
1119}
1120
1121TypeExpression TypeExpr() throws ParseException:
1122{
1123 TypeExpression typeExpr = null;
1124}
1125{
1126 (
1127 typeExpr = RecordTypeDef()
1128 | typeExpr = TypeReference()
1129 | typeExpr = OrderedListTypeDef()
1130 | typeExpr = UnorderedListTypeDef()
1131 )
1132 {
1133 return typeExpr;
1134 }
1135}
1136
1137RecordTypeDefinition RecordTypeDef() throws ParseException:
1138{
1139 RecordTypeDefinition recType = new RecordTypeDefinition();
1140 RecordTypeDefinition.RecordKind recordKind = null;
1141}
1142{
1143 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1144 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1145 "{"
1146 {
1147 String hint = getHint(token);
1148 if (hint != null) {
1149 String splits[] = hint.split(" +");
1150 if (splits[0].equals(GEN_FIELDS_HINT)) {
1151 if (splits.length != 5) {
1152 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1153 }
1154 if (!splits[1].equals("int")) {
1155 throw new ParseException("The only supported type for gen-fields is int.");
1156 }
1157 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1158 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1159 recType.setUndeclaredFieldsDataGen(ufdg);
1160 }
1161 }
1162
1163 }
1164 (
1165 RecordField(recType)
1166 ( "," RecordField(recType) )*
1167 )?
1168 "}"
1169 {
1170 if (recordKind == null) {
1171 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1172 }
1173 recType.setRecordKind(recordKind);
1174 return recType;
1175 }
1176}
1177
1178void RecordField(RecordTypeDefinition recType) throws ParseException:
1179{
1180 String fieldName;
1181 TypeExpression type = null;
1182 boolean nullable = false;
1183}
1184{
1185 <IDENTIFIER>
1186 {
1187 Token t = getToken(0);
1188 fieldName = t.toString();
1189 String hint = getHint(t);
1190 IRecordFieldDataGen rfdg = null;
1191 if (hint != null) {
1192 String splits[] = hint.split(" +");
1193 if (splits[0].equals(VAL_FILE_HINT)) {
1194 File[] valFiles = new File[splits.length - 1];
1195 for (int k=1; k<splits.length; k++) {
1196 valFiles[k-1] = new File(splits[k]);
1197 }
1198 rfdg = new FieldValFileDataGen(valFiles);
1199 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
1200 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
1201 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
1202 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
1203 } else if (splits[0].equals(LIST_HINT)) {
1204 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1205 } else if (splits[0].equals(INTERVAL_HINT)) {
1206 FieldIntervalDataGen.ValueType vt;
1207 if (splits[1].equals("int")) {
1208 vt = FieldIntervalDataGen.ValueType.INT;
1209 } else if (splits[1].equals("long")) {
1210 vt = FieldIntervalDataGen.ValueType.LONG;
1211 } else if (splits[1].equals("float")) {
1212 vt = FieldIntervalDataGen.ValueType.FLOAT;
1213 } else if (splits[1].equals("double")) {
1214 vt = FieldIntervalDataGen.ValueType.DOUBLE;
1215 } else {
1216 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
1217 }
1218 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
1219 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
1220 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
1221 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
1222 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1223 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
1224 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1225 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
1226 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
1227 } else if (splits[0].equals(AUTO_HINT)) {
1228 rfdg = new AutoDataGen(splits[1]);
1229 }
1230 }
1231 }
1232 ":"
1233 ( type = TypeExpr() )
1234 ("?" { nullable = true; } )?
1235 {
1236 recType.addField(fieldName, type, nullable, rfdg);
1237 }
1238}
1239
1240TypeReferenceExpression TypeReference() throws ParseException:
1241{}
1242{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001243 <IDENTIFIER>
1244 {
1245 Token t = getToken(0);
1246 Identifier id = new Identifier(t.toString());
1247 return new TypeReferenceExpression(id);
1248 }
vinayakb38b7ca42012-03-05 05:44:15 +00001249}
1250
1251OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1252{
1253 TypeExpression type = null;
1254}
1255{
1256 "["
1257 ( type = TypeExpr() )
1258 "]"
1259 {
1260 return new OrderedListTypeDefinition(type);
1261 }
1262}
1263
1264
1265UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1266{
1267 TypeExpression type = null;
1268}
1269{
1270 "{{"
1271 ( type = TypeExpr() )
1272 "}}"
1273 {
1274 return new UnorderedListTypeDefinition(type);
1275 }
1276}
1277
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001278Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException:
1279{
1280 Identifier first = null;
1281 Identifier second = null;
1282}
1283{
1284 < IDENTIFIER >
1285 {
1286 first = new Identifier(token.image);
1287 }
1288 ("." <IDENTIFIER>
1289 {
1290 second = new Identifier(token.image);
1291 }
1292 )?
1293
1294 {
1295 if(second == null){
1296 second = first;
1297 first = null;
1298 }
1299
1300 return new Pair<Identifier,Identifier>(first,second);
1301 }
1302}
1303
1304Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException:
1305{
1306 Identifier first = null;
1307 Identifier second = null;
1308 Identifier third = null;
1309}
1310{
1311 < IDENTIFIER >
1312 {
1313 first = new Identifier(token.image);
1314 }
1315 "." <IDENTIFIER>
1316 {
1317 second = new Identifier(token.image);
1318 }
1319 (
1320 "." <IDENTIFIER>
1321 {
1322 third = new Identifier(token.image);
1323 }
1324 )?
1325
1326 {
1327 if(third == null){
1328 third = second;
1329 second = first;
1330 first = null;
1331 }
1332
1333 return new Triple<Identifier,Identifier,Identifier>(first,second,third);
1334 }
1335}
1336
1337
1338
vinayakb38b7ca42012-03-05 05:44:15 +00001339
1340FunctionDecl FunctionDeclaration() throws ParseException:
1341{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001342 FunctionDecl funcDecl;
1343 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001344 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001345 int arity = 0;
1346 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1347 Expression funcBody;
1348 VarIdentifier var = null;
1349 createNewScope();
1350}
1351{
1352
1353 <IDENTIFIER>
1354 {
1355 Token t = getToken(0);
ramangrover29a13f2422012-03-15 23:01:27 +00001356 functionName = t.toString();
vinayakb38b7ca42012-03-05 05:44:15 +00001357 }
1358 <LEFTPAREN> (<VARIABLE>
1359 {
1360 var = new VarIdentifier();
1361 var.setValue(getToken(0).toString());
1362 paramList.add(var);
1363 getCurrentScope().addNewVarSymbolToScope(var);
1364 arity++;
1365 }
1366 ("," <VARIABLE>
1367 {
1368 var = new VarIdentifier();
1369 var.setValue(getToken(0).toString());
1370 paramList.add(var);
1371 getCurrentScope().addNewVarSymbolToScope(var);
1372 arity++;
1373 })*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001374 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001375 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001376 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1377 getCurrentScope().addFunctionDescriptor(signature, false);
1378 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1379 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001380 }
1381}
1382
1383CreateFunctionStatement FunctionCreation() throws ParseException:
1384{
1385 CreateFunctionStatement cfs = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001386 FunctionSignature signature;
1387 String dataverse;
ramangrover29a13f2422012-03-15 23:01:27 +00001388 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001389 boolean ifNotExists = false;
1390 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001391 String functionBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001392 VarIdentifier var = null;
1393 createNewScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001394 Expression functionBodyExpr;
1395 Token beginPos;
1396 Token endPos;
1397 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001398}
1399{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001400 {
1401 nameComponents = getDotSeparatedPair();
1402 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
1403 functionName= nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +00001404 }
1405
1406 (
1407 "if not exists"
1408 {
1409 ifNotExists = true;
1410 }
1411 )?
1412
1413 <LEFTPAREN> (<VARIABLE>
1414 {
1415 var = new VarIdentifier();
1416 var.setValue(getToken(0).toString());
1417 paramList.add(var);
1418 getCurrentScope().addNewVarSymbolToScope(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001419 }
1420 ("," <VARIABLE>
1421 {
1422 var = new VarIdentifier();
1423 var.setValue(getToken(0).toString());
1424 paramList.add(var);
1425 getCurrentScope().addNewVarSymbolToScope(var);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001426 })*)? <RIGHTPAREN> "{"
vinayakb38b7ca42012-03-05 05:44:15 +00001427 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001428 beginPos = getToken(0);
1429 }
1430 functionBodyExpr = Expression()
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001431 "}"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001432 {
1433 endPos = getToken(0);
1434 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
1435 }
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001436 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001437 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001438 signature = new FunctionSignature(dataverse, functionName, paramList.size());
1439 getCurrentScope().addFunctionDescriptor(signature, false);
1440 cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001441 return cfs;
1442 }
1443}
1444
1445
1446
1447Query Query()throws ParseException:
1448{
1449 Query query = new Query();
1450 Expression expr;
1451}
1452{
1453 expr = Expression()
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001454 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001455 {
1456 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001457 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001458 return query;
1459 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001460
vinayakb38b7ca42012-03-05 05:44:15 +00001461}
1462
1463
1464
1465Expression Expression():
1466{
1467 Expression expr = null;
1468 Expression exprP = null;
1469}
1470{
1471(
1472
1473//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1474 expr = OperatorExpr()
1475 | expr = IfThenElse()
1476 | expr = FLWOGR()
1477 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001478
vinayakb38b7ca42012-03-05 05:44:15 +00001479
1480)
1481 {
1482 return (exprP==null) ? expr : exprP;
1483 }
1484}
1485
1486
1487
1488Expression OperatorExpr()throws ParseException:
1489{
1490 OperatorExpr op = null;
1491 Expression operand = null;
1492}
1493{
1494 operand = AndExpr()
1495 (
1496
1497 "or"
1498 {
1499 if (op == null) {
1500 op = new OperatorExpr();
1501 op.addOperand(operand);
1502 op.setCurrentop(true);
1503 }
1504 Token t = getToken(0);
1505 op.addOperator(t.toString());
1506 }
1507
1508 operand = AndExpr()
1509 {
1510 op.addOperand(operand);
1511 }
1512
1513 )*
1514
1515 {
1516 return op==null? operand: op;
1517 }
1518}
1519
1520Expression AndExpr()throws ParseException:
1521{
1522 OperatorExpr op = null;
1523 Expression operand = null;
1524}
1525{
1526 operand = RelExpr()
1527 (
1528
1529 "and"
1530 {
1531 if (op == null) {
1532 op = new OperatorExpr();
1533 op.addOperand(operand);
1534 op.setCurrentop(true);
1535 }
1536 Token t = getToken(0);
1537 op.addOperator(t.toString());
1538 }
1539
1540 operand = RelExpr()
1541 {
1542 op.addOperand(operand);
1543 }
1544
1545 )*
1546
1547 {
1548 return op==null? operand: op;
1549 }
1550}
1551
1552
1553
1554Expression RelExpr()throws ParseException:
1555{
1556 OperatorExpr op = null;
1557 Expression operand = null;
1558 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001559 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001560}
1561{
1562 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001563 {
1564 if (operand instanceof VariableExpr) {
1565 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001566 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001567 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001568 }
1569 }
1570 }
1571
1572 (
1573 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1574 {
alexander.behm07617fd2012-07-25 10:13:50 +00001575 String mhint = getHint(token);
1576 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1577 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1578 }
vinayakb38b7ca42012-03-05 05:44:15 +00001579 if (op == null) {
1580 op = new OperatorExpr();
1581 op.addOperand(operand, broadcast);
1582 op.setCurrentop(true);
1583 broadcast = false;
1584 }
1585 Token t = getToken(0);
1586 op.addOperator(t.toString());
1587 }
1588
1589 operand = AddExpr()
1590 {
alexander.behm07617fd2012-07-25 10:13:50 +00001591 broadcast = false;
1592 if (operand instanceof VariableExpr) {
1593 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001594 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1595 broadcast = true;
1596 }
alexander.behm07617fd2012-07-25 10:13:50 +00001597 }
vinayakb38b7ca42012-03-05 05:44:15 +00001598 op.addOperand(operand, broadcast);
1599 }
1600 )?
1601
1602 {
alexander.behm07617fd2012-07-25 10:13:50 +00001603 if (annotation != null) {
1604 op.addHint(annotation);
1605 }
vinayakb38b7ca42012-03-05 05:44:15 +00001606 return op==null? operand: op;
1607 }
1608}
1609
1610Expression AddExpr()throws ParseException:
1611{
1612 OperatorExpr op = null;
1613 Expression operand = null;
1614}
1615{
1616 operand = MultExpr()
1617
1618 ( ("+" | "-")
1619 {
1620 if (op == null) {
1621 op = new OperatorExpr();
1622 op.addOperand(operand);
1623 op.setCurrentop(true);
1624 }
1625 Token t = getToken(0);
1626 ((OperatorExpr)op).addOperator(t.toString());
1627 }
1628
1629 operand = MultExpr()
1630 {
1631 op.addOperand(operand);
1632 }
1633 )*
1634
1635 {
1636 return op==null? operand: op;
1637 }
1638}
1639
1640Expression MultExpr()throws ParseException:
1641{
1642 OperatorExpr op = null;
1643 Expression operand = null;
1644}
1645{
1646 operand = UnionExpr()
1647
1648 (( "*" | "/" | "%" | <CARET> | "idiv")
1649 {
1650 if (op == null) {
1651 op = new OperatorExpr();
1652 op.addOperand(operand);
1653 op.setCurrentop(true);
1654 }
1655 Token t = getToken(0);
1656 op.addOperator(t.toString());
1657 }
1658 operand = UnionExpr()
1659 {
1660 op.addOperand(operand);
1661 }
1662 )*
1663
1664 {
1665 return op==null?operand:op;
1666 }
1667}
1668
1669Expression UnionExpr() throws ParseException:
1670{
1671 UnionExpr union = null;
1672 Expression operand1 = null;
1673 Expression operand2 = null;
1674}
1675{
1676 operand1 = UnaryExpr()
1677 ("union"
1678 (operand2 = UnaryExpr()) {
1679 if (union == null) {
1680 union = new UnionExpr();
1681 union.addExpr(operand1);
1682 }
1683 union.addExpr(operand2);
1684 } )*
1685 {
1686 return (union == null)? operand1: union;
1687 }
1688}
1689
1690Expression UnaryExpr() throws ParseException:
1691{
1692 Expression uexpr = null;
1693 Expression expr = null;
1694}
1695{
1696 (( "+"|"-")
1697 {
1698 uexpr = new UnaryExpr();
1699 Token t = getToken(0);
1700 if("+".equals(t.toString()))
1701 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1702 else if("-".equals(t.toString()))
1703 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1704 else
1705 throw new ParseException();
1706 }
1707 )?
1708
1709 expr = ValueExpr()
1710 {
1711 if(uexpr!=null){
1712 ((UnaryExpr)uexpr).setExpr(expr);
1713 return uexpr;
1714 }
1715 else{
1716 return expr;
1717 }
1718 }
1719}
1720
1721Expression ValueExpr() throws ParseException:
1722{
1723 Expression expr;
1724}
1725{
1726 expr = FieldOrIndexAccessor()
1727 {
1728 return expr;
1729 }
1730}
1731
1732
1733Expression FieldOrIndexAccessor()throws ParseException:
1734{
1735 Expression expr = null;
1736 Identifier ident = null;
1737 AbstractAccessor fa = null;
1738 int index;
1739
1740}
1741{
1742 ( expr = PrimaryExpr()
1743
1744 )
1745
1746
1747 (
1748 (
1749 ident = Field()
1750 {
1751 if(fa == null)
1752 fa = new FieldAccessor(expr, ident);
1753 else
1754 fa = new FieldAccessor(fa, ident);
1755 }
1756 )
1757 | (
1758 index = Index()
1759 {
1760 if(fa == null)
1761 fa = new IndexAccessor(expr, index);
1762 else
1763 fa = new IndexAccessor(fa, index);
1764 }
1765 )
1766 )*
1767
1768
1769 {
1770 return fa==null?expr:fa;
1771 }
1772}
1773
1774Identifier Field() throws ParseException:
1775{
1776 Identifier ident = null;
1777
1778}
1779{
1780 "." < IDENTIFIER >
1781 {
1782
1783 ident = new Identifier();
1784 ident.setValue(getToken(0).toString());
1785
1786 return ident;
1787 }
1788}
1789
1790int Index() throws ParseException:
1791{
1792 Expression expr = null;
1793 int idx = -2;
1794}
1795{
1796 "[" ( expr = Expression()
1797 {
1798 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1799 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001800 Literal lit = ((LiteralExpr)expr).getValue();
1801 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1802 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001803 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001804 }
vinayakb38b7ca42012-03-05 05:44:15 +00001805 else {
1806 throw new ParseException("Index should be an INTEGER");
1807 }
1808 }
1809
1810 }
1811
1812 | "?"
1813 {
1814 idx = IndexAccessor.ANY;
1815 // ANY
1816 }
1817
1818 )
1819
1820 "]"
1821 {
1822 return idx;
1823 }
1824}
1825
1826
1827Expression PrimaryExpr()throws ParseException:
1828{
1829 Expression expr = null;
1830}
1831{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001832 //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | DatasetAccessExpression | ParenthesizedExpression
vinayakb38b7ca42012-03-05 05:44:15 +00001833 (
1834 expr =Literal()
1835 | expr = FunctionCallExpr()
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001836 | expr = DatasetAccessExpression()
vinayakb38b7ca42012-03-05 05:44:15 +00001837 | expr =VariableRef()
1838
1839 {
1840 if(((VariableExpr)expr).getIsNewVar() == true)
1841 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
1842 }
1843 | expr = ListConstructor()
1844 | expr = RecordConstructor()
1845 | expr = ParenthesizedExpression()
1846 )
1847 {
1848 return expr;
1849 }
1850}
1851
1852Expression Literal() throws ParseException:
1853{
1854
1855 LiteralExpr lit = new LiteralExpr();
1856 Token t;
1857}
1858{
1859(
1860 <STRING_LITERAL>
1861 {
1862 t= getToken(0);
1863 lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image)));
1864 }
1865
1866 | <INTEGER_LITERAL>
1867 {
1868 t= getToken(0);
ilovesoupc9fef1d2012-07-08 19:30:42 +00001869 try {
1870 lit.setValue(new IntegerLiteral(new Integer(t.image)));
1871 } catch(NumberFormatException ex) {
1872 lit.setValue(new LongIntegerLiteral(new Long(t.image)));
1873 }
vinayakb38b7ca42012-03-05 05:44:15 +00001874 }
1875 | < FLOAT_LITERAL >
1876 {
1877 t= getToken(0);
1878 lit.setValue(new FloatLiteral(new Float(t.image)));
1879 }
1880 | < DOUBLE_LITERAL >
1881 {
1882 t= getToken(0);
1883 lit.setValue(new DoubleLiteral(new Double(t.image)));
1884 }
1885 | <NULL>
1886 {
1887 t= getToken(0);
1888 lit.setValue(NullLiteral.INSTANCE);
1889 }
1890 | <TRUE>
1891 {
1892 t= getToken(0);
1893 lit.setValue(TrueLiteral.INSTANCE);
1894 }
1895 | <FALSE>
1896 {
1897 t= getToken(0);
1898 lit.setValue(FalseLiteral.INSTANCE);
1899 }
1900)
1901 {
1902 return lit;
1903 }
1904}
1905
1906
1907VariableExpr VariableRef() throws ParseException:
1908{
1909 VariableExpr varExp = new VariableExpr();
1910 VarIdentifier var = new VarIdentifier();
1911 Token t;
1912}
1913{
1914 <VARIABLE>
1915 {
1916 t = getToken(0);//get current token
1917 String varName = t.toString();
1918 Identifier ident = lookupSymbol(varName);
1919 if (isInForbiddenScopes(varName)) {
1920 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.");
1921 }
1922 if(ident != null) { // exist such ident
1923 varExp.setIsNewVar(false);
1924 varExp.setVar((VarIdentifier)ident);
1925 } else {
1926 varExp.setVar(var);
1927 }
1928 var.setValue(t.toString());
1929 return varExp;
1930 }
1931}
1932
1933
1934VariableExpr Variable() throws ParseException:
1935{
1936 VariableExpr varExp = new VariableExpr();
1937 VarIdentifier var = new VarIdentifier();
1938 Token t;
1939}
1940{
1941 <VARIABLE>
1942 {
1943 t = getToken(0);//get current token
1944 Identifier ident = lookupSymbol(t.toString());
1945 if(ident != null) { // exist such ident
1946 varExp.setIsNewVar(false);
1947 }
1948 varExp.setVar(var);
1949 var.setValue(t.toString());
1950 return varExp;
1951 }
1952}
1953
1954Expression ListConstructor() throws ParseException:
1955{
1956 Expression expr = null;
1957}
1958{
1959 (
1960 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1961 )
1962
1963 {
1964 return expr;
1965 }
1966}
1967
1968
1969ListConstructor OrderedListConstructor() throws ParseException:
1970{
1971 ListConstructor expr = new ListConstructor();
1972 Expression tmp = null;
1973 List<Expression> exprList = new ArrayList<Expression>();
1974 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1975}
1976{
1977
1978 "["
1979 ( tmp = Expression()
1980 {
1981 exprList.add(tmp);
1982 }
1983
1984 ("," tmp = Expression() { exprList.add(tmp); })*
1985 )?
1986
1987 "]"
1988
1989 {
1990 expr.setExprList(exprList);
1991 return expr;
1992 }
1993}
1994
1995ListConstructor UnorderedListConstructor() throws ParseException:
1996{
1997 ListConstructor expr = new ListConstructor();
1998 Expression tmp = null;
1999 List<Expression> exprList = new ArrayList<Expression>();
2000 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2001}
2002{
2003
2004 "{{" ( tmp = Expression()
2005 {
2006 exprList.add(tmp);
2007 }
2008 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
2009 {
2010 expr.setExprList(exprList);
2011 return expr;
2012 }
2013}
2014
2015RecordConstructor RecordConstructor() throws ParseException:
2016{
2017 RecordConstructor expr = new RecordConstructor();
2018 FieldBinding tmp = null;
2019 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2020}
2021{
2022 "{" (tmp = FieldBinding()
2023 {
2024 fbList.add(tmp);
2025 }
2026 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
2027 {
2028 expr.setFbList(fbList);
2029 return expr;
2030 }
2031}
2032
2033FieldBinding FieldBinding() throws ParseException:
2034{
2035 FieldBinding fb = new FieldBinding();
2036 Expression left, right;
2037}
2038{
2039 left = Expression() ":" right = Expression()
2040 {
2041 fb.setLeftExpr(left);
2042 fb.setRightExpr(right);
2043 return fb;
2044 }
2045}
2046
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002047
vinayakb38b7ca42012-03-05 05:44:15 +00002048Expression FunctionCallExpr() throws ParseException:
2049{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002050 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002051 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002052 Expression tmp;
2053 int arity = 0;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002054 String funcName;
2055 String dataverse;
2056 String hint=null;
2057 String id1=null;
2058 String id2=null;
vinayakb38b7ca42012-03-05 05:44:15 +00002059}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002060{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002061
2062 <IDENTIFIER> { dataverse = defaultDataverse; funcName = token.image;} ("." <IDENTIFIER> { dataverse = funcName; funcName = token.image;})?
vinayakb38b7ca42012-03-05 05:44:15 +00002063 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002064 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002065 }
2066 <LEFTPAREN> (tmp = Expression()
2067 {
2068 argList.add(tmp);
2069 arity ++;
2070 } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
2071
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002072 {
2073 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2074 if(signature == null)
2075 {
2076 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2077 }
2078 callExpr = new CallExpr(signature,argList);
2079 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2080 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2081 }
2082 return callExpr;
vinayakb38b7ca42012-03-05 05:44:15 +00002083 }
2084}
2085
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002086Expression DatasetAccessExpression() throws ParseException:
2087{
2088 CallExpr callExpr;
2089 List<Expression> argList = new ArrayList<Expression>();
2090 String funcName;
2091 String dataverse;
2092 LiteralExpr ds;
2093 LiteralExpr dvds;
2094 Expression nameArg;
2095 int arity = 0;
2096}
2097{
2098 <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();}
2099 (
2100 (<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);})? ) |
2101 (<LEFTPAREN> nameArg = Expression() {argList.add(nameArg); arity ++;} ("," nameArg = Expression() { argList.add(nameArg); arity++; })* <RIGHTPAREN>)
2102 )
2103
2104 {
2105 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2106 if(signature == null)
2107 {
2108 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2109 }
2110 callExpr = new CallExpr(signature,argList);
2111 return callExpr;
2112 }
2113}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002114
vinayakb38b7ca42012-03-05 05:44:15 +00002115Expression ParenthesizedExpression() throws ParseException:
2116{
2117 Expression expr;
2118}
2119{
2120 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2121 {
2122 return expr;
2123 }
2124}
2125
2126Expression IfThenElse() throws ParseException:
2127{
2128 Expression condExpr;
2129 Expression thenExpr;
2130 Expression elseExpr;
2131 IfExpr ifExpr = new IfExpr();
2132}
2133{
2134 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
2135
2136 {
2137 ifExpr.setCondExpr(condExpr);
2138 ifExpr.setThenExpr(thenExpr);
2139 ifExpr.setElseExpr(elseExpr);
2140 return ifExpr;
2141 }
2142}
2143
2144Expression FLWOGR() throws ParseException:
2145{
2146 FLWOGRExpression flworg = new FLWOGRExpression();
2147 List<Clause> clauseList = new ArrayList<Clause>();
2148 Expression returnExpr;
2149 Clause tmp;
2150 createNewScope();
2151}
2152{
2153 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2154 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
2155
2156 {
2157 flworg.setClauseList(clauseList);
2158 flworg.setReturnExpr(returnExpr);
2159 removeCurrentScope();
2160 return flworg;
2161 }
2162}
2163
2164Clause Clause()throws ParseException :
2165{
2166 Clause clause;
2167}
2168{
2169 (
2170 clause = ForClause()
2171 | clause = LetClause()
2172 | clause = WhereClause()
2173 | clause = OrderbyClause()
2174 | clause = GroupClause()
2175 | clause = LimitClause()
2176 | clause = DistinctClause()
2177 | clause = DieClause()
2178 )
2179 {
2180 return clause;
2181 }
2182}
2183
2184Clause ForClause()throws ParseException :
2185{
2186 ForClause fc = new ForClause();
2187 VariableExpr varExp;
2188 VariableExpr varPos = null;
2189 Expression inExp;
2190 extendCurrentScope();
2191}
2192{
2193 "for" varExp = Variable()
2194 {
2195 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2196 }
2197 ("at" varPos = Variable()
2198 {
2199 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2200 }
2201 )?
2202 "in" ( inExp = Expression() )
2203 {
2204 fc.setVarExpr(varExp);
2205 fc.setInExpr(inExp);
2206 if (varPos != null) {
2207 fc.setPosExpr(varPos);
2208 }
2209 return fc;
2210 }
2211}
2212
2213Clause LetClause() throws ParseException:
2214{
2215 LetClause lc = new LetClause();
2216 VariableExpr varExp;
2217 Expression beExp;
2218 extendCurrentScope();
2219}
2220{
ilovesoupb2527c12012-07-12 03:21:13 +00002221 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002222 {
2223 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002224 lc.setVarExpr(varExp);
2225 lc.setBeExpr(beExp);
2226 return lc;
2227 }
2228}
2229
2230Clause WhereClause()throws ParseException :
2231{
2232 WhereClause wc = new WhereClause();
2233 Expression whereExpr;
2234}
2235{
2236 "where" whereExpr = Expression()
2237 {
2238 wc.setWhereExpr(whereExpr);
2239 return wc;
2240 }
2241}
2242
2243Clause OrderbyClause()throws ParseException :
2244{
2245 OrderbyClause oc = new OrderbyClause();
2246 Expression orderbyExpr;
2247 List<Expression> orderbyList = new ArrayList<Expression>();
2248 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2249 int numOfOrderby = 0;
2250}
2251{
2252 (
2253 "order"
2254 {
2255 String hint = getHint(token);
2256 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2257 String splits[] = hint.split(" +");
2258 int numFrames = Integer.parseInt(splits[1]);
2259 int numTuples = Integer.parseInt(splits[2]);
2260 oc.setNumFrames(numFrames);
2261 oc.setNumTuples(numTuples);
2262 }
2263 }
2264 "by" orderbyExpr = Expression()
2265 {
2266 orderbyList.add(orderbyExpr);
2267 OrderbyClause.OrderModifier 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 ("," orderbyExpr = Expression()
2276 {
2277 orderbyList.add(orderbyExpr);
2278 modif = OrderbyClause.OrderModifier.ASC;
2279 }
2280 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2281 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2282 {
2283 modifierList.add(modif);
2284 }
2285 )*
2286)
2287 {
2288 oc.setModifierList(modifierList);
2289 oc.setOrderbyList(orderbyList);
2290 return oc;
2291 }
2292}
2293Clause GroupClause()throws ParseException :
2294{
2295 GroupbyClause gbc = new GroupbyClause();
2296 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2297 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2298 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2299 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2300 VariableExpr var = null;
2301 VariableExpr withVar = null;
2302 Expression expr = null;
2303 VariableExpr decorVar = null;
2304 Expression decorExpr = null;
2305}
2306{
2307 {
2308 Scope newScope = extendCurrentScopeNoPush(true);
2309 // extendCurrentScope(true);
2310 }
2311 "group"
2312 {
2313 String hint = getHint(token);
2314 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2315 gbc.setHashGroupByHint(true);
2316 }
2317 }
2318 "by" (LOOKAHEAD(2) var = Variable()
2319 {
2320 newScope.addNewVarSymbolToScope(var.getVar());
2321 } ":=")?
2322 expr = Expression()
2323 {
2324 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2325 vePairList.add(pair1);
2326 }
2327 ("," ( LOOKAHEAD(2) var = Variable()
2328 {
2329 newScope.addNewVarSymbolToScope(var.getVar());
2330 } ":=")?
2331 expr = Expression()
2332 {
2333 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2334 vePairList.add(pair2);
2335 }
2336 )*
2337 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2338 {
2339 newScope.addNewVarSymbolToScope(decorVar.getVar());
2340 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2341 decorPairList.add(pair3);
2342 }
2343 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2344 {
2345 newScope.addNewVarSymbolToScope(decorVar.getVar());
2346 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2347 decorPairList.add(pair4);
2348 }
2349 )*
2350 )?
2351 "with" withVar = VariableRef()
2352 {
2353 if(withVar.getIsNewVar()==true)
2354 throw new ParseException("can't find variable " + withVar.getVar());
2355 withVarList.add(withVar);
2356 newScope.addNewVarSymbolToScope(withVar.getVar());
2357 }
2358 ("," withVar = VariableRef()
2359 {
2360 if(withVar.getIsNewVar()==true)
2361 throw new ParseException("can't find variable " + withVar.getVar());
2362 withVarList.add(withVar);
2363 newScope.addNewVarSymbolToScope(withVar.getVar());
2364 })*
2365 {
2366 gbc.setGbyPairList(vePairList);
2367 gbc.setDecorPairList(decorPairList);
2368 gbc.setWithVarList(withVarList);
2369 replaceCurrentScope(newScope);
2370 return gbc;
2371 }
2372}
2373
2374
2375LimitClause LimitClause() throws ParseException:
2376{
2377 LimitClause lc = new LimitClause();
2378 Expression expr;
2379 pushForbiddenScope(getCurrentScope());
2380}
2381{
2382 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2383 ("offset" expr = Expression() { lc.setOffset(expr); })?
2384
2385 {
2386 popForbiddenScope();
2387 return lc;
2388 }
2389}
2390
2391DistinctClause DistinctClause() throws ParseException:
2392{
2393 List<Expression> exprs = new ArrayList<Expression>();
2394 Expression expr;
2395}
2396{
2397 "distinct" "by" expr = Expression()
2398 {
2399 exprs.add(expr);
2400 }
2401 ("," expr = Expression()
2402 {
2403 exprs.add(expr);
2404 }
2405 )*
2406 {
2407 return new DistinctClause(exprs);
2408 }
2409}
2410
2411DieClause DieClause() throws ParseException:
2412{
2413 DieClause lc = new DieClause();
2414 Expression expr;
2415 pushForbiddenScope(getCurrentScope());
2416}
2417{
2418 "die" "after" expr = Expression() { lc.setDieExpr(expr); }
2419 {
2420 popForbiddenScope();
2421 return lc;
2422 }
2423}
2424
2425
2426QuantifiedExpression QuantifiedExpression()throws ParseException:
2427{
2428 QuantifiedExpression qc = new QuantifiedExpression();
2429 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2430 Expression satisfiesExpr;
2431 VariableExpr var;
2432 Expression inExpr;
2433 QuantifiedPair pair;
2434}
2435{
2436 {
2437 createNewScope();
2438 }
2439
2440 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2441 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2442 var = Variable() "in" inExpr = Expression()
2443 {
2444 pair = new QuantifiedPair(var, inExpr);
2445 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2446 quantifiedList.add(pair);
2447 }
2448 (
2449 "," var = Variable() "in" inExpr = Expression()
2450 {
2451 pair = new QuantifiedPair(var, inExpr);
2452 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2453 quantifiedList.add(pair);
2454 }
2455 )*
2456 "satisfies" satisfiesExpr = Expression()
2457 {
2458 qc.setSatisfiesExpr(satisfiesExpr);
2459 qc.setQuantifiedList(quantifiedList);
2460 removeCurrentScope();
2461 return qc;
2462 }
2463}
2464
2465TOKEN_MGR_DECLS:
2466{
2467 public int commentDepth = 0;
2468}
2469
2470<DEFAULT>
2471TOKEN :
2472{
2473 <CARET : "^" >
2474}
2475
2476<DEFAULT>
2477TOKEN :
2478{
2479 <DATASET : "dataset" >
2480}
2481
2482<DEFAULT>
2483TOKEN :
2484{
2485 <LEFTPAREN : "(" >
2486}
2487
2488<DEFAULT>
2489TOKEN :
2490{
2491 <RIGHTPAREN : ")" >
2492}
2493
2494
2495<DEFAULT>
2496TOKEN :
2497{
2498 <INTEGER_LITERAL : (<DIGIT>)+ >
2499}
2500
2501
2502<DEFAULT>
2503TOKEN :
2504{
2505 <NULL : "null">
2506}
2507
2508<DEFAULT>
2509TOKEN :
2510{
2511 <TRUE : "true">
2512}
2513
2514<DEFAULT>
2515TOKEN :
2516{
2517 <FALSE : "false">
2518}
2519
2520<DEFAULT>
2521TOKEN :
2522{
2523 <#DIGIT : ["0" - "9"]>
2524}
2525
2526
2527TOKEN:
2528{
2529 < DOUBLE_LITERAL: <INTEGER>
2530 | <INTEGER> ( "." <INTEGER> )?
2531 | "." <INTEGER>
2532 >
2533 |
2534 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2535 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2536 | "." <INTEGER> ( "f" | "F" )
2537 >
2538 |
2539 <INTEGER : (<DIGIT>)+ >
2540}
2541
2542<DEFAULT>
2543TOKEN :
2544{
2545 <#LETTER : ["A" - "Z", "a" - "z"]>
2546}
2547
2548<DEFAULT>
2549TOKEN :
2550{
2551 <SPECIALCHARS : ["$", "_", "-"] >
2552}
2553
2554<DEFAULT>
2555TOKEN :
2556{
2557 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2558 |
2559 < #EscapeQuot: "\\\"" >
2560 |
2561 < #EscapeApos: "\\\'" >
2562}
2563
2564<DEFAULT>
2565TOKEN :
2566{
2567 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2568}
2569
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002570
vinayakb38b7ca42012-03-05 05:44:15 +00002571<DEFAULT>
2572TOKEN :
2573{
2574 <VARIABLE : "$" <IDENTIFIER> >
2575}
2576
2577SKIP:
2578{
2579 " "
2580| "\t"
2581| "\r"
2582| "\n"
2583}
2584
2585SKIP:
2586{
2587 <"//" (~["\n"])* "\n">
2588}
2589
2590SKIP:
2591{
2592 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2593}
2594
2595
2596SKIP:
2597{
2598 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2599}
2600
2601<INSIDE_COMMENT>
2602SPECIAL_TOKEN:
2603{
2604 <"+"(" ")*(~["*"])*>
2605}
2606
2607<INSIDE_COMMENT>
2608SKIP:
2609{
2610 <"/*"> {commentDepth++;}
2611}
2612
2613<INSIDE_COMMENT>
2614SKIP:
2615{
2616 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2617| <~[]>
2618}