blob: e234bb8d45cb587ab6a5ecf9376f2ada3f22f165 [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;
ramangrover294369da82013-04-24 14:24:03 -0700819 String libraryName;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000820 int arity;
ramangrover294369da82013-04-24 14:24:03 -0700821 Triple<String,String,String> functionCallComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000822}
823{
vinayakb38b7ca42012-03-05 05:44:15 +0000824 "using"
vinayakb38b7ca42012-03-05 05:44:15 +0000825 {
ramangrover29669d8f62013-02-11 06:03:32 +0000826 adapterName = getAdapterName();
vinayakb38b7ca42012-03-05 05:44:15 +0000827 }
828
829 {
830 properties = getConfiguration();
831 }
832
833 ("apply" "function"
ramangrover294369da82013-04-24 14:24:03 -0700834 (
835 ( functionCallComponents = getFunctionCallComponents() )
836 {
837 dataverse = functionCallComponents.first == null ? defaultDataverse : functionCallComponents.first;
838 libraryName = functionCallComponents.second;
839 functionName = functionCallComponents.third;
840 if(libraryName != null){
841 functionName = libraryName + ":" + functionName;
842 }
843 }
844 )
845
ramangrover29fbaba5f2013-01-26 02:36:29 +0000846 ("@" <INTEGER_LITERAL>
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000847 {
848 arity = Integer.parseInt(token.image);
849 }
850 )
851
852 {
853 appliedFunction = new FunctionSignature(dataverse, functionName, arity);
854 }
vinayakb38b7ca42012-03-05 05:44:15 +0000855 )?
856
vinayakb38b7ca42012-03-05 05:44:15 +0000857 (
vinayakb38b7ca42012-03-05 05:44:15 +0000858 {
ramangrover292f199b02013-02-13 05:32:01 +0000859 primaryKeyFields = getPrimaryKeyFields();
vinayakb38b7ca42012-03-05 05:44:15 +0000860 }
ramangrover29669d8f62013-02-11 06:03:32 +0000861 )
862
vinayakb38b7ca42012-03-05 05:44:15 +0000863 (
864 "on" < IDENTIFIER >
865 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000866 nodeGroupName = new Identifier(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +0000867 }
868 )?
ramangrover2971e5c6a2013-01-30 05:30:12 +0000869
vinayakb38b7ca42012-03-05 05:44:15 +0000870 {
ramangrover292f199b02013-02-13 05:32:01 +0000871 fdd = new FeedDetailsDecl(adapterName, properties, appliedFunction, nodeGroupName, primaryKeyFields);
vinayakb38b7ca42012-03-05 05:44:15 +0000872 return fdd;
873 }
874}
875
ramangrover292f199b02013-02-13 05:32:01 +0000876List<String> getPrimaryKeyFields() throws ParseException :
ramangrover29669d8f62013-02-11 06:03:32 +0000877{
ramangrover292f199b02013-02-13 05:32:01 +0000878 List<String> primaryKeyFields = new ArrayList<String>();
ramangrover29669d8f62013-02-11 06:03:32 +0000879}
880{
881
882 "primary" "key"
883 < IDENTIFIER >
884 {
ramangrover292f199b02013-02-13 05:32:01 +0000885 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000886 }
887 (
888 "," < IDENTIFIER >
889 {
ramangrover292f199b02013-02-13 05:32:01 +0000890 primaryKeyFields.add(token.image);
ramangrover29669d8f62013-02-11 06:03:32 +0000891 }
892 )*
893 {
ramangrover292f199b02013-02-13 05:32:01 +0000894 return primaryKeyFields;
ramangrover29669d8f62013-02-11 06:03:32 +0000895 }
896
897}
898
899
900
901
902
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000903ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000904{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000905 Pair<Identifier,Identifier> nameComponents = null;
906}
907{
908 {
909 nameComponents = getDotSeparatedPair();
910 return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second);
911 }
912}
913
914
915ControlFeedStatement AlterFeedDeclaration() throws ParseException :
916{
917 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000918 Map < String, String > configuration = new HashMap < String, String > ();
919}
920{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000921 {
922 nameComponents = getDotSeparatedPair();
923 }
924
vinayakb38b7ca42012-03-05 05:44:15 +0000925 "set"
926 {
927 configuration = getConfiguration();
928 }
ramangrover29fbaba5f2013-01-26 02:36:29 +0000929
vinayakb38b7ca42012-03-05 05:44:15 +0000930 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000931 return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
vinayakb38b7ca42012-03-05 05:44:15 +0000932 }
933}
934
935Map<String,String> getConfiguration() throws ParseException :
936{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000937 Map<String,String> configuration = new LinkedHashMap<String,String>();
vinayakb38b7ca42012-03-05 05:44:15 +0000938 String key;
939 String value;
940}
941{
942
943<LEFTPAREN>
944 (
945 (
946 <LEFTPAREN>
947 (
948 <STRING_LITERAL>
949 {
950 key = removeQuotesAndEscapes(token.image);
951 }
952 "=" <STRING_LITERAL>
953 {
954 value = removeQuotesAndEscapes(token.image);
955 }
956 )
957 <RIGHTPAREN>
958 {
959 configuration.put(key, value);
960 }
961 )
962 (
963 "," <LEFTPAREN>
964 (
965 <STRING_LITERAL>
966 {
967 key = removeQuotesAndEscapes(token.image);
968 }
969 "=" <STRING_LITERAL>
970 {
971 value = removeQuotesAndEscapes(token.image);
972 }
973 )
974 <RIGHTPAREN>
975 {
976 configuration.put(key, value);
977 }
978 )*
979 )?
980 <RIGHTPAREN>
981 {
982 return configuration;
983 }
984}
985
ramangrover2971e5c6a2013-01-30 05:30:12 +0000986void initProperties(Map<String,String> properties) throws ParseException :
987{
988 String key;
989 String value;
990}
991{
992 (
993 <LEFTPAREN>
994 (
995 <IDENTIFIER>
996 {
997 key = (new Identifier(token.image)).getValue();
998 }
999 "="
1000 (
1001 (<STRING_LITERAL>
1002 {
1003 value = removeQuotesAndEscapes(token.image);
1004 }
1005 ) |
1006 (<INTEGER_LITERAL>
1007 {
1008 try{
ramangrover2921b88182013-01-31 00:51:19 +00001009 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001010 } catch (NumberFormatException nfe){
1011 throw new ParseException("inapproriate value: " + token.image);
1012 }
1013 }
1014 )
1015 )
1016 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001017 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001018 }
1019 (
1020 ","
1021 (
1022 <IDENTIFIER>
1023 {
1024 key = (new Identifier(token.image)).getValue();
1025 }
1026 "="
1027 (
1028 (<STRING_LITERAL>
1029 {
1030 value = removeQuotesAndEscapes(token.image);
1031 }
1032 ) |
1033 (<INTEGER_LITERAL>
1034 {
1035 try{
ramangrover2921b88182013-01-31 00:51:19 +00001036 value = "" + Long.valueOf(token.image);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001037 } catch (NumberFormatException nfe){
1038 throw new ParseException("inapproriate value: " + token.image);
1039 }
1040 }
1041 )
1042 )
1043 )
1044 {
ramangrover2954f1fc42013-02-09 00:46:26 +00001045 properties.put(key.toUpperCase(), value);
ramangrover2971e5c6a2013-01-30 05:30:12 +00001046 }
1047
1048 )*
1049 )
1050 <RIGHTPAREN>
1051 )?
1052}
1053
1054
vinayakb38b7ca42012-03-05 05:44:15 +00001055
1056NodegroupDecl NodegroupDeclaration() throws ParseException :
1057{
1058 Identifier name = null;
1059 List < Identifier > ncNames = new ArrayList < Identifier > ();
1060 boolean ifNotExists = false;
1061}
1062{
1063 < IDENTIFIER >
1064 {
1065 name = new Identifier(token.image);
1066 }
1067 (
1068 "if not exists"
1069 {
1070 ifNotExists = true;
1071 }
1072 )?
1073 "on" < IDENTIFIER >
1074 {
1075 ncNames.add(new Identifier(token.image));
1076 }
1077 (
1078 "," < IDENTIFIER >
1079 {
1080 ncNames.add(new Identifier(token.image));
1081 }
1082 )*
1083 ";"
1084 {
1085 return new NodegroupDecl(name, ncNames, ifNotExists);
1086 }
1087}
1088
1089
1090TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException:
1091{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001092 Identifier dataverse;
vinayakb38b7ca42012-03-05 05:44:15 +00001093 Identifier ident;
1094 TypeExpression typeExpr;
1095 boolean ifNotExists = false;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001096 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001097}
1098{
vinayakb38b7ca42012-03-05 05:44:15 +00001099 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001100 nameComponents = getDotSeparatedPair();
1101 dataverse = nameComponents.first;
1102 ident = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001103 }
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001104
vinayakb38b7ca42012-03-05 05:44:15 +00001105 (
1106 "if not exists"
1107 {
1108 ifNotExists = true;
1109 }
1110 )?
1111 "as"
1112 ( typeExpr = TypeExpr() )
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001113 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001114 {
1115 long numValues = -1;
1116 String filename = null;
1117 if (dgen) {
1118 String splits[] = hint.split(" +");
1119 if (splits.length != 3) {
1120 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
1121 }
1122 filename = splits[1];
1123 numValues = Long.parseLong(splits[2]);
1124 }
1125 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001126 return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001127 }
1128}
1129
1130TypeExpression TypeExpr() throws ParseException:
1131{
1132 TypeExpression typeExpr = null;
1133}
1134{
1135 (
1136 typeExpr = RecordTypeDef()
1137 | typeExpr = TypeReference()
1138 | typeExpr = OrderedListTypeDef()
1139 | typeExpr = UnorderedListTypeDef()
1140 )
1141 {
1142 return typeExpr;
1143 }
1144}
1145
1146RecordTypeDefinition RecordTypeDef() throws ParseException:
1147{
1148 RecordTypeDefinition recType = new RecordTypeDefinition();
1149 RecordTypeDefinition.RecordKind recordKind = null;
1150}
1151{
1152 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1153 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1154 "{"
1155 {
1156 String hint = getHint(token);
1157 if (hint != null) {
1158 String splits[] = hint.split(" +");
1159 if (splits[0].equals(GEN_FIELDS_HINT)) {
1160 if (splits.length != 5) {
1161 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1162 }
1163 if (!splits[1].equals("int")) {
1164 throw new ParseException("The only supported type for gen-fields is int.");
1165 }
1166 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1167 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1168 recType.setUndeclaredFieldsDataGen(ufdg);
1169 }
1170 }
1171
1172 }
1173 (
1174 RecordField(recType)
1175 ( "," RecordField(recType) )*
1176 )?
1177 "}"
1178 {
1179 if (recordKind == null) {
1180 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1181 }
1182 recType.setRecordKind(recordKind);
1183 return recType;
1184 }
1185}
1186
1187void RecordField(RecordTypeDefinition recType) throws ParseException:
1188{
1189 String fieldName;
1190 TypeExpression type = null;
1191 boolean nullable = false;
1192}
1193{
1194 <IDENTIFIER>
1195 {
1196 Token t = getToken(0);
1197 fieldName = t.toString();
1198 String hint = getHint(t);
1199 IRecordFieldDataGen rfdg = null;
1200 if (hint != null) {
1201 String splits[] = hint.split(" +");
1202 if (splits[0].equals(VAL_FILE_HINT)) {
1203 File[] valFiles = new File[splits.length - 1];
1204 for (int k=1; k<splits.length; k++) {
1205 valFiles[k-1] = new File(splits[k]);
1206 }
1207 rfdg = new FieldValFileDataGen(valFiles);
1208 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
1209 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
1210 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
1211 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
1212 } else if (splits[0].equals(LIST_HINT)) {
1213 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1214 } else if (splits[0].equals(INTERVAL_HINT)) {
1215 FieldIntervalDataGen.ValueType vt;
1216 if (splits[1].equals("int")) {
1217 vt = FieldIntervalDataGen.ValueType.INT;
1218 } else if (splits[1].equals("long")) {
1219 vt = FieldIntervalDataGen.ValueType.LONG;
1220 } else if (splits[1].equals("float")) {
1221 vt = FieldIntervalDataGen.ValueType.FLOAT;
1222 } else if (splits[1].equals("double")) {
1223 vt = FieldIntervalDataGen.ValueType.DOUBLE;
1224 } else {
1225 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
1226 }
1227 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
1228 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
1229 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
1230 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
1231 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1232 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
1233 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
1234 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
1235 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
1236 } else if (splits[0].equals(AUTO_HINT)) {
1237 rfdg = new AutoDataGen(splits[1]);
1238 }
1239 }
1240 }
1241 ":"
1242 ( type = TypeExpr() )
1243 ("?" { nullable = true; } )?
1244 {
1245 recType.addField(fieldName, type, nullable, rfdg);
1246 }
1247}
1248
1249TypeReferenceExpression TypeReference() throws ParseException:
1250{}
1251{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001252 <IDENTIFIER>
1253 {
1254 Token t = getToken(0);
1255 Identifier id = new Identifier(t.toString());
1256 return new TypeReferenceExpression(id);
1257 }
vinayakb38b7ca42012-03-05 05:44:15 +00001258}
1259
1260OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1261{
1262 TypeExpression type = null;
1263}
1264{
1265 "["
1266 ( type = TypeExpr() )
1267 "]"
1268 {
1269 return new OrderedListTypeDefinition(type);
1270 }
1271}
1272
1273
1274UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1275{
1276 TypeExpression type = null;
1277}
1278{
1279 "{{"
1280 ( type = TypeExpr() )
1281 "}}"
1282 {
1283 return new UnorderedListTypeDefinition(type);
1284 }
1285}
1286
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001287Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException:
1288{
1289 Identifier first = null;
1290 Identifier second = null;
1291}
1292{
1293 < IDENTIFIER >
1294 {
1295 first = new Identifier(token.image);
1296 }
1297 ("." <IDENTIFIER>
1298 {
1299 second = new Identifier(token.image);
1300 }
1301 )?
1302
1303 {
1304 if(second == null){
1305 second = first;
1306 first = null;
1307 }
1308
1309 return new Pair<Identifier,Identifier>(first,second);
1310 }
1311}
1312
1313Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException:
1314{
1315 Identifier first = null;
1316 Identifier second = null;
1317 Identifier third = null;
1318}
1319{
1320 < IDENTIFIER >
1321 {
1322 first = new Identifier(token.image);
1323 }
1324 "." <IDENTIFIER>
1325 {
1326 second = new Identifier(token.image);
1327 }
1328 (
1329 "." <IDENTIFIER>
1330 {
1331 third = new Identifier(token.image);
1332 }
1333 )?
1334
1335 {
1336 if(third == null){
1337 third = second;
1338 second = first;
1339 first = null;
1340 }
1341
1342 return new Triple<Identifier,Identifier,Identifier>(first,second,third);
1343 }
1344}
1345
1346
1347
vinayakb38b7ca42012-03-05 05:44:15 +00001348
1349FunctionDecl FunctionDeclaration() throws ParseException:
1350{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001351 FunctionDecl funcDecl;
1352 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001353 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001354 int arity = 0;
1355 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1356 Expression funcBody;
1357 VarIdentifier var = null;
1358 createNewScope();
1359}
1360{
1361
1362 <IDENTIFIER>
1363 {
1364 Token t = getToken(0);
ramangrover29a13f2422012-03-15 23:01:27 +00001365 functionName = t.toString();
vinayakb38b7ca42012-03-05 05:44:15 +00001366 }
1367 <LEFTPAREN> (<VARIABLE>
1368 {
1369 var = new VarIdentifier();
1370 var.setValue(getToken(0).toString());
1371 paramList.add(var);
1372 getCurrentScope().addNewVarSymbolToScope(var);
1373 arity++;
1374 }
1375 ("," <VARIABLE>
1376 {
1377 var = new VarIdentifier();
1378 var.setValue(getToken(0).toString());
1379 paramList.add(var);
1380 getCurrentScope().addNewVarSymbolToScope(var);
1381 arity++;
1382 })*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001383 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001384 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001385 signature = new FunctionSignature(defaultDataverse, functionName, arity);
1386 getCurrentScope().addFunctionDescriptor(signature, false);
1387 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1388 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001389 }
1390}
1391
1392CreateFunctionStatement FunctionCreation() throws ParseException:
1393{
1394 CreateFunctionStatement cfs = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001395 FunctionSignature signature;
1396 String dataverse;
ramangrover29a13f2422012-03-15 23:01:27 +00001397 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001398 boolean ifNotExists = false;
1399 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001400 String functionBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001401 VarIdentifier var = null;
1402 createNewScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001403 Expression functionBodyExpr;
1404 Token beginPos;
1405 Token endPos;
1406 Pair<Identifier,Identifier> nameComponents=null;
vinayakb38b7ca42012-03-05 05:44:15 +00001407}
1408{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001409 {
1410 nameComponents = getDotSeparatedPair();
1411 dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse;
1412 functionName= nameComponents.second.getValue();
vinayakb38b7ca42012-03-05 05:44:15 +00001413 }
1414
1415 (
1416 "if not exists"
1417 {
1418 ifNotExists = true;
1419 }
1420 )?
1421
1422 <LEFTPAREN> (<VARIABLE>
1423 {
1424 var = new VarIdentifier();
1425 var.setValue(getToken(0).toString());
1426 paramList.add(var);
1427 getCurrentScope().addNewVarSymbolToScope(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001428 }
1429 ("," <VARIABLE>
1430 {
1431 var = new VarIdentifier();
1432 var.setValue(getToken(0).toString());
1433 paramList.add(var);
1434 getCurrentScope().addNewVarSymbolToScope(var);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001435 })*)? <RIGHTPAREN> "{"
vinayakb38b7ca42012-03-05 05:44:15 +00001436 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001437 beginPos = getToken(0);
1438 }
1439 functionBodyExpr = Expression()
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001440 "}"
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001441 {
1442 endPos = getToken(0);
1443 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
1444 }
ramangrover29@gmail.comf18c14b2013-04-10 16:26:57 +00001445 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001446 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001447 signature = new FunctionSignature(dataverse, functionName, paramList.size());
1448 getCurrentScope().addFunctionDescriptor(signature, false);
1449 cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
vinayakb38b7ca42012-03-05 05:44:15 +00001450 return cfs;
1451 }
1452}
1453
1454
1455
1456Query Query()throws ParseException:
1457{
1458 Query query = new Query();
1459 Expression expr;
1460}
1461{
1462 expr = Expression()
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001463 (";")?
vinayakb38b7ca42012-03-05 05:44:15 +00001464 {
1465 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001466 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001467 return query;
1468 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001469
vinayakb38b7ca42012-03-05 05:44:15 +00001470}
1471
1472
1473
1474Expression Expression():
1475{
1476 Expression expr = null;
1477 Expression exprP = null;
1478}
1479{
1480(
1481
1482//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1483 expr = OperatorExpr()
1484 | expr = IfThenElse()
1485 | expr = FLWOGR()
1486 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001487
vinayakb38b7ca42012-03-05 05:44:15 +00001488
1489)
1490 {
1491 return (exprP==null) ? expr : exprP;
1492 }
1493}
1494
1495
1496
1497Expression OperatorExpr()throws ParseException:
1498{
1499 OperatorExpr op = null;
1500 Expression operand = null;
1501}
1502{
1503 operand = AndExpr()
1504 (
1505
1506 "or"
1507 {
1508 if (op == null) {
1509 op = new OperatorExpr();
1510 op.addOperand(operand);
1511 op.setCurrentop(true);
1512 }
1513 Token t = getToken(0);
1514 op.addOperator(t.toString());
1515 }
1516
1517 operand = AndExpr()
1518 {
1519 op.addOperand(operand);
1520 }
1521
1522 )*
1523
1524 {
1525 return op==null? operand: op;
1526 }
1527}
1528
1529Expression AndExpr()throws ParseException:
1530{
1531 OperatorExpr op = null;
1532 Expression operand = null;
1533}
1534{
1535 operand = RelExpr()
1536 (
1537
1538 "and"
1539 {
1540 if (op == null) {
1541 op = new OperatorExpr();
1542 op.addOperand(operand);
1543 op.setCurrentop(true);
1544 }
1545 Token t = getToken(0);
1546 op.addOperator(t.toString());
1547 }
1548
1549 operand = RelExpr()
1550 {
1551 op.addOperand(operand);
1552 }
1553
1554 )*
1555
1556 {
1557 return op==null? operand: op;
1558 }
1559}
1560
1561
1562
1563Expression RelExpr()throws ParseException:
1564{
1565 OperatorExpr op = null;
1566 Expression operand = null;
1567 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001568 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001569}
1570{
1571 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001572 {
1573 if (operand instanceof VariableExpr) {
1574 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001575 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001576 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001577 }
1578 }
1579 }
1580
1581 (
1582 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1583 {
alexander.behm07617fd2012-07-25 10:13:50 +00001584 String mhint = getHint(token);
1585 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1586 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1587 }
vinayakb38b7ca42012-03-05 05:44:15 +00001588 if (op == null) {
1589 op = new OperatorExpr();
1590 op.addOperand(operand, broadcast);
1591 op.setCurrentop(true);
1592 broadcast = false;
1593 }
1594 Token t = getToken(0);
1595 op.addOperator(t.toString());
1596 }
1597
1598 operand = AddExpr()
1599 {
alexander.behm07617fd2012-07-25 10:13:50 +00001600 broadcast = false;
1601 if (operand instanceof VariableExpr) {
1602 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001603 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1604 broadcast = true;
1605 }
alexander.behm07617fd2012-07-25 10:13:50 +00001606 }
vinayakb38b7ca42012-03-05 05:44:15 +00001607 op.addOperand(operand, broadcast);
1608 }
1609 )?
1610
1611 {
alexander.behm07617fd2012-07-25 10:13:50 +00001612 if (annotation != null) {
1613 op.addHint(annotation);
1614 }
vinayakb38b7ca42012-03-05 05:44:15 +00001615 return op==null? operand: op;
1616 }
1617}
1618
1619Expression AddExpr()throws ParseException:
1620{
1621 OperatorExpr op = null;
1622 Expression operand = null;
1623}
1624{
1625 operand = MultExpr()
1626
1627 ( ("+" | "-")
1628 {
1629 if (op == null) {
1630 op = new OperatorExpr();
1631 op.addOperand(operand);
1632 op.setCurrentop(true);
1633 }
1634 Token t = getToken(0);
1635 ((OperatorExpr)op).addOperator(t.toString());
1636 }
1637
1638 operand = MultExpr()
1639 {
1640 op.addOperand(operand);
1641 }
1642 )*
1643
1644 {
1645 return op==null? operand: op;
1646 }
1647}
1648
1649Expression MultExpr()throws ParseException:
1650{
1651 OperatorExpr op = null;
1652 Expression operand = null;
1653}
1654{
1655 operand = UnionExpr()
1656
1657 (( "*" | "/" | "%" | <CARET> | "idiv")
1658 {
1659 if (op == null) {
1660 op = new OperatorExpr();
1661 op.addOperand(operand);
1662 op.setCurrentop(true);
1663 }
1664 Token t = getToken(0);
1665 op.addOperator(t.toString());
1666 }
1667 operand = UnionExpr()
1668 {
1669 op.addOperand(operand);
1670 }
1671 )*
1672
1673 {
1674 return op==null?operand:op;
1675 }
1676}
1677
1678Expression UnionExpr() throws ParseException:
1679{
1680 UnionExpr union = null;
1681 Expression operand1 = null;
1682 Expression operand2 = null;
1683}
1684{
1685 operand1 = UnaryExpr()
1686 ("union"
1687 (operand2 = UnaryExpr()) {
1688 if (union == null) {
1689 union = new UnionExpr();
1690 union.addExpr(operand1);
1691 }
1692 union.addExpr(operand2);
1693 } )*
1694 {
1695 return (union == null)? operand1: union;
1696 }
1697}
1698
1699Expression UnaryExpr() throws ParseException:
1700{
1701 Expression uexpr = null;
1702 Expression expr = null;
1703}
1704{
1705 (( "+"|"-")
1706 {
1707 uexpr = new UnaryExpr();
1708 Token t = getToken(0);
1709 if("+".equals(t.toString()))
1710 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1711 else if("-".equals(t.toString()))
1712 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1713 else
1714 throw new ParseException();
1715 }
1716 )?
1717
1718 expr = ValueExpr()
1719 {
1720 if(uexpr!=null){
1721 ((UnaryExpr)uexpr).setExpr(expr);
1722 return uexpr;
1723 }
1724 else{
1725 return expr;
1726 }
1727 }
1728}
1729
1730Expression ValueExpr() throws ParseException:
1731{
1732 Expression expr;
1733}
1734{
1735 expr = FieldOrIndexAccessor()
1736 {
1737 return expr;
1738 }
1739}
1740
1741
1742Expression FieldOrIndexAccessor()throws ParseException:
1743{
1744 Expression expr = null;
1745 Identifier ident = null;
1746 AbstractAccessor fa = null;
1747 int index;
1748
1749}
1750{
1751 ( expr = PrimaryExpr()
1752
1753 )
1754
1755
1756 (
1757 (
1758 ident = Field()
1759 {
1760 if(fa == null)
1761 fa = new FieldAccessor(expr, ident);
1762 else
1763 fa = new FieldAccessor(fa, ident);
1764 }
1765 )
1766 | (
1767 index = Index()
1768 {
1769 if(fa == null)
1770 fa = new IndexAccessor(expr, index);
1771 else
1772 fa = new IndexAccessor(fa, index);
1773 }
1774 )
1775 )*
1776
1777
1778 {
1779 return fa==null?expr:fa;
1780 }
1781}
1782
1783Identifier Field() throws ParseException:
1784{
1785 Identifier ident = null;
1786
1787}
1788{
1789 "." < IDENTIFIER >
1790 {
1791
1792 ident = new Identifier();
1793 ident.setValue(getToken(0).toString());
1794
1795 return ident;
1796 }
1797}
1798
1799int Index() throws ParseException:
1800{
1801 Expression expr = null;
1802 int idx = -2;
1803}
1804{
1805 "[" ( expr = Expression()
1806 {
1807 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1808 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001809 Literal lit = ((LiteralExpr)expr).getValue();
1810 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1811 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001812 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001813 }
vinayakb38b7ca42012-03-05 05:44:15 +00001814 else {
1815 throw new ParseException("Index should be an INTEGER");
1816 }
1817 }
1818
1819 }
1820
1821 | "?"
1822 {
1823 idx = IndexAccessor.ANY;
1824 // ANY
1825 }
1826
1827 )
1828
1829 "]"
1830 {
1831 return idx;
1832 }
1833}
1834
1835
1836Expression PrimaryExpr()throws ParseException:
1837{
1838 Expression expr = null;
1839}
1840{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001841 //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | DatasetAccessExpression | ParenthesizedExpression
vinayakb38b7ca42012-03-05 05:44:15 +00001842 (
1843 expr =Literal()
1844 | expr = FunctionCallExpr()
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001845 | expr = DatasetAccessExpression()
vinayakb38b7ca42012-03-05 05:44:15 +00001846 | expr =VariableRef()
1847
1848 {
1849 if(((VariableExpr)expr).getIsNewVar() == true)
1850 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
1851 }
1852 | expr = ListConstructor()
1853 | expr = RecordConstructor()
1854 | expr = ParenthesizedExpression()
1855 )
1856 {
1857 return expr;
1858 }
1859}
1860
1861Expression Literal() throws ParseException:
1862{
1863
1864 LiteralExpr lit = new LiteralExpr();
1865 Token t;
1866}
1867{
1868(
1869 <STRING_LITERAL>
1870 {
1871 t= getToken(0);
1872 lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image)));
1873 }
1874
1875 | <INTEGER_LITERAL>
1876 {
1877 t= getToken(0);
ilovesoupc9fef1d2012-07-08 19:30:42 +00001878 try {
1879 lit.setValue(new IntegerLiteral(new Integer(t.image)));
1880 } catch(NumberFormatException ex) {
1881 lit.setValue(new LongIntegerLiteral(new Long(t.image)));
1882 }
vinayakb38b7ca42012-03-05 05:44:15 +00001883 }
1884 | < FLOAT_LITERAL >
1885 {
1886 t= getToken(0);
1887 lit.setValue(new FloatLiteral(new Float(t.image)));
1888 }
1889 | < DOUBLE_LITERAL >
1890 {
1891 t= getToken(0);
1892 lit.setValue(new DoubleLiteral(new Double(t.image)));
1893 }
1894 | <NULL>
1895 {
1896 t= getToken(0);
1897 lit.setValue(NullLiteral.INSTANCE);
1898 }
1899 | <TRUE>
1900 {
1901 t= getToken(0);
1902 lit.setValue(TrueLiteral.INSTANCE);
1903 }
1904 | <FALSE>
1905 {
1906 t= getToken(0);
1907 lit.setValue(FalseLiteral.INSTANCE);
1908 }
1909)
1910 {
1911 return lit;
1912 }
1913}
1914
1915
1916VariableExpr VariableRef() throws ParseException:
1917{
1918 VariableExpr varExp = new VariableExpr();
1919 VarIdentifier var = new VarIdentifier();
1920 Token t;
1921}
1922{
1923 <VARIABLE>
1924 {
1925 t = getToken(0);//get current token
1926 String varName = t.toString();
1927 Identifier ident = lookupSymbol(varName);
1928 if (isInForbiddenScopes(varName)) {
1929 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.");
1930 }
1931 if(ident != null) { // exist such ident
1932 varExp.setIsNewVar(false);
1933 varExp.setVar((VarIdentifier)ident);
1934 } else {
1935 varExp.setVar(var);
1936 }
1937 var.setValue(t.toString());
1938 return varExp;
1939 }
1940}
1941
1942
1943VariableExpr Variable() throws ParseException:
1944{
1945 VariableExpr varExp = new VariableExpr();
1946 VarIdentifier var = new VarIdentifier();
1947 Token t;
1948}
1949{
1950 <VARIABLE>
1951 {
1952 t = getToken(0);//get current token
1953 Identifier ident = lookupSymbol(t.toString());
1954 if(ident != null) { // exist such ident
1955 varExp.setIsNewVar(false);
1956 }
1957 varExp.setVar(var);
1958 var.setValue(t.toString());
1959 return varExp;
1960 }
1961}
1962
1963Expression ListConstructor() throws ParseException:
1964{
1965 Expression expr = null;
1966}
1967{
1968 (
1969 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1970 )
1971
1972 {
1973 return expr;
1974 }
1975}
1976
1977
1978ListConstructor OrderedListConstructor() throws ParseException:
1979{
1980 ListConstructor expr = new ListConstructor();
1981 Expression tmp = null;
1982 List<Expression> exprList = new ArrayList<Expression>();
1983 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1984}
1985{
1986
1987 "["
1988 ( tmp = Expression()
1989 {
1990 exprList.add(tmp);
1991 }
1992
1993 ("," tmp = Expression() { exprList.add(tmp); })*
1994 )?
1995
1996 "]"
1997
1998 {
1999 expr.setExprList(exprList);
2000 return expr;
2001 }
2002}
2003
2004ListConstructor UnorderedListConstructor() throws ParseException:
2005{
2006 ListConstructor expr = new ListConstructor();
2007 Expression tmp = null;
2008 List<Expression> exprList = new ArrayList<Expression>();
2009 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2010}
2011{
2012
2013 "{{" ( tmp = Expression()
2014 {
2015 exprList.add(tmp);
2016 }
2017 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
2018 {
2019 expr.setExprList(exprList);
2020 return expr;
2021 }
2022}
2023
2024RecordConstructor RecordConstructor() throws ParseException:
2025{
2026 RecordConstructor expr = new RecordConstructor();
2027 FieldBinding tmp = null;
2028 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2029}
2030{
2031 "{" (tmp = FieldBinding()
2032 {
2033 fbList.add(tmp);
2034 }
2035 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
2036 {
2037 expr.setFbList(fbList);
2038 return expr;
2039 }
2040}
2041
2042FieldBinding FieldBinding() throws ParseException:
2043{
2044 FieldBinding fb = new FieldBinding();
2045 Expression left, right;
2046}
2047{
2048 left = Expression() ":" right = Expression()
2049 {
2050 fb.setLeftExpr(left);
2051 fb.setRightExpr(right);
2052 return fb;
2053 }
2054}
2055
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002056
vinayakb38b7ca42012-03-05 05:44:15 +00002057Expression FunctionCallExpr() throws ParseException:
2058{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002059 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002060 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002061 Expression tmp;
2062 int arity = 0;
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002063 String funcName=null;
2064 String dataverse=null;
2065 String libraryName=null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002066 String hint=null;
2067 String id1=null;
2068 String id2=null;
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002069 String first = null;
2070 String second = null;
2071 String third = null;
2072 Triple<String,String,String> functionCallComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002073}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002074{
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002075 (
2076 ( functionCallComponents = getFunctionCallComponents() )
2077 {
2078 dataverse = functionCallComponents.first == null ? defaultDataverse : functionCallComponents.first;
2079 libraryName = functionCallComponents.second;
2080 funcName = functionCallComponents.third;
2081 if(libraryName != null){
2082 funcName = libraryName + ":" + funcName;
2083 }
2084 }
2085 )
2086
vinayakb38b7ca42012-03-05 05:44:15 +00002087 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002088 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002089 }
2090 <LEFTPAREN> (tmp = Expression()
2091 {
2092 argList.add(tmp);
2093 arity ++;
2094 } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
2095
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002096 {
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002097 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002098 if(signature == null)
2099 {
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002100 signature = new FunctionSignature(dataverse, funcName, arity);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002101 }
2102 callExpr = new CallExpr(signature,argList);
2103 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2104 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2105 }
2106 return callExpr;
vinayakb38b7ca42012-03-05 05:44:15 +00002107 }
2108}
2109
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002110Triple<String,String,String> getFunctionCallComponents() throws ParseException:
2111{
2112 String first = null;
2113 String second = null;
2114 String third = null;
2115}
2116{
2117 <IDENTIFIER>{
2118 first = token.image;
2119 }
2120 (
2121 ("." <IDENTIFIER> {
2122 second = token.image;
2123 }
2124 )?
2125 ( ":" <IDENTIFIER> {
2126 third = token.image;
2127 }
2128 )?
2129 )
2130 {
2131 if(second == null) {
2132 if(third!=null){
2133 second="" + first;
2134 } else {
2135 third = "" + first;
2136 }
2137 first = null;
2138 } else if (third == null) {
2139 third = "" + second;
2140 second = null;
2141 }
2142 return new Triple<String,String,String>(first,second,third);
2143 }
2144
2145}
2146
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002147Expression DatasetAccessExpression() throws ParseException:
2148{
2149 CallExpr callExpr;
2150 List<Expression> argList = new ArrayList<Expression>();
2151 String funcName;
2152 String dataverse;
2153 LiteralExpr ds;
2154 LiteralExpr dvds;
2155 Expression nameArg;
2156 int arity = 0;
2157}
2158{
2159 <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();}
2160 (
2161 (<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);})? ) |
2162 (<LEFTPAREN> nameArg = Expression() {argList.add(nameArg); arity ++;} ("," nameArg = Expression() { argList.add(nameArg); arity++; })* <RIGHTPAREN>)
2163 )
2164
2165 {
2166 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
2167 if(signature == null)
2168 {
2169 signature = new FunctionSignature(dataverse, funcName.toString(), arity);
2170 }
2171 callExpr = new CallExpr(signature,argList);
2172 return callExpr;
2173 }
2174}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002175
vinayakb38b7ca42012-03-05 05:44:15 +00002176Expression ParenthesizedExpression() throws ParseException:
2177{
2178 Expression expr;
2179}
2180{
2181 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2182 {
2183 return expr;
2184 }
2185}
2186
2187Expression IfThenElse() throws ParseException:
2188{
2189 Expression condExpr;
2190 Expression thenExpr;
2191 Expression elseExpr;
2192 IfExpr ifExpr = new IfExpr();
2193}
2194{
2195 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
2196
2197 {
2198 ifExpr.setCondExpr(condExpr);
2199 ifExpr.setThenExpr(thenExpr);
2200 ifExpr.setElseExpr(elseExpr);
2201 return ifExpr;
2202 }
2203}
2204
2205Expression FLWOGR() throws ParseException:
2206{
2207 FLWOGRExpression flworg = new FLWOGRExpression();
2208 List<Clause> clauseList = new ArrayList<Clause>();
2209 Expression returnExpr;
2210 Clause tmp;
2211 createNewScope();
2212}
2213{
2214 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2215 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
2216
2217 {
2218 flworg.setClauseList(clauseList);
2219 flworg.setReturnExpr(returnExpr);
2220 removeCurrentScope();
2221 return flworg;
2222 }
2223}
2224
2225Clause Clause()throws ParseException :
2226{
2227 Clause clause;
2228}
2229{
2230 (
2231 clause = ForClause()
2232 | clause = LetClause()
2233 | clause = WhereClause()
2234 | clause = OrderbyClause()
2235 | clause = GroupClause()
2236 | clause = LimitClause()
2237 | clause = DistinctClause()
2238 | clause = DieClause()
2239 )
2240 {
2241 return clause;
2242 }
2243}
2244
2245Clause ForClause()throws ParseException :
2246{
2247 ForClause fc = new ForClause();
2248 VariableExpr varExp;
2249 VariableExpr varPos = null;
2250 Expression inExp;
2251 extendCurrentScope();
2252}
2253{
2254 "for" varExp = Variable()
2255 {
2256 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2257 }
2258 ("at" varPos = Variable()
2259 {
2260 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2261 }
2262 )?
2263 "in" ( inExp = Expression() )
2264 {
2265 fc.setVarExpr(varExp);
2266 fc.setInExpr(inExp);
2267 if (varPos != null) {
2268 fc.setPosExpr(varPos);
2269 }
2270 return fc;
2271 }
2272}
2273
2274Clause LetClause() throws ParseException:
2275{
2276 LetClause lc = new LetClause();
2277 VariableExpr varExp;
2278 Expression beExp;
2279 extendCurrentScope();
2280}
2281{
ilovesoupb2527c12012-07-12 03:21:13 +00002282 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002283 {
2284 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002285 lc.setVarExpr(varExp);
2286 lc.setBeExpr(beExp);
2287 return lc;
2288 }
2289}
2290
2291Clause WhereClause()throws ParseException :
2292{
2293 WhereClause wc = new WhereClause();
2294 Expression whereExpr;
2295}
2296{
2297 "where" whereExpr = Expression()
2298 {
2299 wc.setWhereExpr(whereExpr);
2300 return wc;
2301 }
2302}
2303
2304Clause OrderbyClause()throws ParseException :
2305{
2306 OrderbyClause oc = new OrderbyClause();
2307 Expression orderbyExpr;
2308 List<Expression> orderbyList = new ArrayList<Expression>();
2309 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2310 int numOfOrderby = 0;
2311}
2312{
2313 (
2314 "order"
2315 {
2316 String hint = getHint(token);
2317 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2318 String splits[] = hint.split(" +");
2319 int numFrames = Integer.parseInt(splits[1]);
2320 int numTuples = Integer.parseInt(splits[2]);
2321 oc.setNumFrames(numFrames);
2322 oc.setNumTuples(numTuples);
2323 }
2324 }
2325 "by" orderbyExpr = Expression()
2326 {
2327 orderbyList.add(orderbyExpr);
2328 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2329 }
2330 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2331 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2332 {
2333 modifierList.add(modif);
2334 }
2335
2336 ("," orderbyExpr = Expression()
2337 {
2338 orderbyList.add(orderbyExpr);
2339 modif = OrderbyClause.OrderModifier.ASC;
2340 }
2341 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
2342 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
2343 {
2344 modifierList.add(modif);
2345 }
2346 )*
2347)
2348 {
2349 oc.setModifierList(modifierList);
2350 oc.setOrderbyList(orderbyList);
2351 return oc;
2352 }
2353}
2354Clause GroupClause()throws ParseException :
2355{
2356 GroupbyClause gbc = new GroupbyClause();
2357 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2358 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2359 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2360 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2361 VariableExpr var = null;
2362 VariableExpr withVar = null;
2363 Expression expr = null;
2364 VariableExpr decorVar = null;
2365 Expression decorExpr = null;
2366}
2367{
2368 {
2369 Scope newScope = extendCurrentScopeNoPush(true);
2370 // extendCurrentScope(true);
2371 }
2372 "group"
2373 {
2374 String hint = getHint(token);
2375 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2376 gbc.setHashGroupByHint(true);
2377 }
2378 }
2379 "by" (LOOKAHEAD(2) var = Variable()
2380 {
2381 newScope.addNewVarSymbolToScope(var.getVar());
2382 } ":=")?
2383 expr = Expression()
2384 {
2385 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2386 vePairList.add(pair1);
2387 }
2388 ("," ( LOOKAHEAD(2) var = Variable()
2389 {
2390 newScope.addNewVarSymbolToScope(var.getVar());
2391 } ":=")?
2392 expr = Expression()
2393 {
2394 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2395 vePairList.add(pair2);
2396 }
2397 )*
2398 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2399 {
2400 newScope.addNewVarSymbolToScope(decorVar.getVar());
2401 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2402 decorPairList.add(pair3);
2403 }
2404 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2405 {
2406 newScope.addNewVarSymbolToScope(decorVar.getVar());
2407 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2408 decorPairList.add(pair4);
2409 }
2410 )*
2411 )?
2412 "with" withVar = VariableRef()
2413 {
2414 if(withVar.getIsNewVar()==true)
2415 throw new ParseException("can't find variable " + withVar.getVar());
2416 withVarList.add(withVar);
2417 newScope.addNewVarSymbolToScope(withVar.getVar());
2418 }
2419 ("," withVar = VariableRef()
2420 {
2421 if(withVar.getIsNewVar()==true)
2422 throw new ParseException("can't find variable " + withVar.getVar());
2423 withVarList.add(withVar);
2424 newScope.addNewVarSymbolToScope(withVar.getVar());
2425 })*
2426 {
2427 gbc.setGbyPairList(vePairList);
2428 gbc.setDecorPairList(decorPairList);
2429 gbc.setWithVarList(withVarList);
2430 replaceCurrentScope(newScope);
2431 return gbc;
2432 }
2433}
2434
2435
2436LimitClause LimitClause() throws ParseException:
2437{
2438 LimitClause lc = new LimitClause();
2439 Expression expr;
2440 pushForbiddenScope(getCurrentScope());
2441}
2442{
2443 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2444 ("offset" expr = Expression() { lc.setOffset(expr); })?
2445
2446 {
2447 popForbiddenScope();
2448 return lc;
2449 }
2450}
2451
2452DistinctClause DistinctClause() throws ParseException:
2453{
2454 List<Expression> exprs = new ArrayList<Expression>();
2455 Expression expr;
2456}
2457{
2458 "distinct" "by" expr = Expression()
2459 {
2460 exprs.add(expr);
2461 }
2462 ("," expr = Expression()
2463 {
2464 exprs.add(expr);
2465 }
2466 )*
2467 {
2468 return new DistinctClause(exprs);
2469 }
2470}
2471
2472DieClause DieClause() throws ParseException:
2473{
2474 DieClause lc = new DieClause();
2475 Expression expr;
2476 pushForbiddenScope(getCurrentScope());
2477}
2478{
2479 "die" "after" expr = Expression() { lc.setDieExpr(expr); }
2480 {
2481 popForbiddenScope();
2482 return lc;
2483 }
2484}
2485
2486
2487QuantifiedExpression QuantifiedExpression()throws ParseException:
2488{
2489 QuantifiedExpression qc = new QuantifiedExpression();
2490 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2491 Expression satisfiesExpr;
2492 VariableExpr var;
2493 Expression inExpr;
2494 QuantifiedPair pair;
2495}
2496{
2497 {
2498 createNewScope();
2499 }
2500
2501 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2502 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2503 var = Variable() "in" inExpr = Expression()
2504 {
2505 pair = new QuantifiedPair(var, inExpr);
2506 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2507 quantifiedList.add(pair);
2508 }
2509 (
2510 "," var = Variable() "in" inExpr = Expression()
2511 {
2512 pair = new QuantifiedPair(var, inExpr);
2513 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2514 quantifiedList.add(pair);
2515 }
2516 )*
2517 "satisfies" satisfiesExpr = Expression()
2518 {
2519 qc.setSatisfiesExpr(satisfiesExpr);
2520 qc.setQuantifiedList(quantifiedList);
2521 removeCurrentScope();
2522 return qc;
2523 }
2524}
2525
2526TOKEN_MGR_DECLS:
2527{
2528 public int commentDepth = 0;
2529}
2530
2531<DEFAULT>
2532TOKEN :
2533{
2534 <CARET : "^" >
2535}
2536
2537<DEFAULT>
2538TOKEN :
2539{
2540 <DATASET : "dataset" >
2541}
2542
2543<DEFAULT>
2544TOKEN :
2545{
2546 <LEFTPAREN : "(" >
2547}
2548
2549<DEFAULT>
2550TOKEN :
2551{
2552 <RIGHTPAREN : ")" >
2553}
2554
2555
2556<DEFAULT>
2557TOKEN :
2558{
2559 <INTEGER_LITERAL : (<DIGIT>)+ >
2560}
2561
2562
2563<DEFAULT>
2564TOKEN :
2565{
2566 <NULL : "null">
2567}
2568
2569<DEFAULT>
2570TOKEN :
2571{
2572 <TRUE : "true">
2573}
2574
2575<DEFAULT>
2576TOKEN :
2577{
2578 <FALSE : "false">
2579}
2580
2581<DEFAULT>
2582TOKEN :
2583{
2584 <#DIGIT : ["0" - "9"]>
2585}
2586
2587
2588TOKEN:
2589{
2590 < DOUBLE_LITERAL: <INTEGER>
2591 | <INTEGER> ( "." <INTEGER> )?
2592 | "." <INTEGER>
2593 >
2594 |
2595 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2596 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2597 | "." <INTEGER> ( "f" | "F" )
2598 >
2599 |
2600 <INTEGER : (<DIGIT>)+ >
2601}
2602
2603<DEFAULT>
2604TOKEN :
2605{
2606 <#LETTER : ["A" - "Z", "a" - "z"]>
2607}
2608
2609<DEFAULT>
2610TOKEN :
2611{
2612 <SPECIALCHARS : ["$", "_", "-"] >
2613}
2614
2615<DEFAULT>
2616TOKEN :
2617{
2618 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2619 |
2620 < #EscapeQuot: "\\\"" >
2621 |
2622 < #EscapeApos: "\\\'" >
2623}
2624
2625<DEFAULT>
2626TOKEN :
2627{
2628 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2629}
2630
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002631
vinayakb38b7ca42012-03-05 05:44:15 +00002632<DEFAULT>
2633TOKEN :
2634{
2635 <VARIABLE : "$" <IDENTIFIER> >
2636}
2637
2638SKIP:
2639{
2640 " "
2641| "\t"
2642| "\r"
2643| "\n"
2644}
2645
2646SKIP:
2647{
2648 <"//" (~["\n"])* "\n">
2649}
2650
2651SKIP:
2652{
2653 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2654}
2655
2656
2657SKIP:
2658{
2659 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2660}
2661
2662<INSIDE_COMMENT>
2663SPECIAL_TOKEN:
2664{
2665 <"+"(" ")*(~["*"])*>
2666}
2667
2668<INSIDE_COMMENT>
2669SKIP:
2670{
2671 <"/*"> {commentDepth++;}
2672}
2673
2674<INSIDE_COMMENT>
2675SKIP:
2676{
2677 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2678| <~[]>
2679}