blob: cc542ff5484c74744810bde93a8386d6fec2130e [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";
Till Westmann31c21f92013-05-08 09:21:53 -070077
78 private static class IndexParams {
79 public IndexType type;
80 public int gramLength;
81
82 public IndexParams(IndexType type, int gramLength) {
83 this.type = type;
84 this.gramLength = gramLength;
85 }
86 };
vinayakb38b7ca42012-03-05 05:44:15 +000087
88 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070089 if (t.specialToken == null) {
90 return null;
91 }
92 String s = t.specialToken.image;
93 int n = s.length();
94 if (n < 2) {
95 return null;
96 }
97 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +000098 }
99
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000100 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700101 this(new StringReader(s));
102 super.setInput(s);
103 }
vinayakb38b7ca42012-03-05 05:44:15 +0000104
Till Westmann31c21f92013-05-08 09:21:53 -0700105 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
106 File file = new File(args[0]);
107 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
108 AQLParser parser = new AQLParser(fis);
109 List<Statement> st = parser.Statement();
110 //st.accept(new AQLPrintVisitor(), 0);
111 }
vinayakb38b7ca42012-03-05 05:44:15 +0000112}
113
114PARSER_END(AQLParser)
115
116
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000117List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000118{
vinayakb38b7ca42012-03-05 05:44:15 +0000119 scopeStack.push(RootScopeFactory.createRootScope(this));
120 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700121 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000122}
123{
Till Westmann31c21f92013-05-08 09:21:53 -0700124 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000125 {
Till Westmann31c21f92013-05-08 09:21:53 -0700126 decls.add(stmt);
127 }
128 )*
129 <EOF>
130 {
131 return decls;
132 }
133}
134
135Statement SingleStatement() throws ParseException:
136{
137 Statement stmt = null;
138}
139{
140 (
141 stmt = DataverseDeclaration()
142 | stmt = FunctionDeclaration()
143 | stmt = CreateStatement()
144 | stmt = LoadStatement()
145 | stmt = DropStatement()
146 | stmt = WriteStatement()
147 | stmt = SetStatement()
148 | stmt = InsertStatement()
149 | stmt = DeleteStatement()
150 | stmt = UpdateStatement()
151 | stmt = FeedStatement()
152 | stmt = Query()
153 )
154 {
155 return stmt;
156 }
157}
158
159DataverseDecl DataverseDeclaration() throws ParseException:
160{
Till Westmann14a20a72013-05-09 00:06:24 -0700161 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700162}
163{
Till Westmanna4242bc2013-05-08 17:49:55 -0700164 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700165 {
Till Westmann14a20a72013-05-09 00:06:24 -0700166 defaultDataverse = dvName;
167 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700168 }
169}
170
171Statement CreateStatement() throws ParseException:
172{
173 String hint = null;
174 boolean dgen = false;
175 Statement stmt = null;
176}
177{
178 "create"
179 (
180 {
181 hint = getHint(token);
182 if (hint != null && hint.startsWith(DGEN_HINT)) {
183 dgen = true;
184 }
185 }
186 stmt = TypeSpecification(hint, dgen)
187 | stmt = NodegroupSpecification()
188 | stmt = DatasetSpecification()
189 | stmt = IndexSpecification()
190 | stmt = DataverseSpecification()
191 | stmt = FunctionSpecification()
192 )
193 {
194 return stmt;
195 }
196}
197
198TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
199{
200 Pair<Identifier,Identifier> nameComponents = null;
201 boolean ifNotExists = false;
202 TypeExpression typeExpr = null;
203}
204{
205 "type" nameComponents = FunctionOrTypeName() ifNotExists = IfNotExists()
206 "as" typeExpr = TypeExpr()
207 {
208 long numValues = -1;
209 String filename = null;
210 if (dgen) {
211 String splits[] = hint.split(" +");
212 if (splits.length != 3) {
213 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
214 }
215 filename = splits[1];
216 numValues = Long.parseLong(splits[2]);
217 }
218 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
219 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
220 }
221}
222
223
224NodegroupDecl NodegroupSpecification() throws ParseException:
225{
Till Westmann14a20a72013-05-09 00:06:24 -0700226 String name = null;
227 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700228 boolean ifNotExists = false;
229 List<Identifier>ncNames = null;
230}
231{
Till Westmanna4242bc2013-05-08 17:49:55 -0700232 "nodegroup" name = Identifier()
233 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700234 {
235 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700236 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700237 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700238 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700239 {
Till Westmann14a20a72013-05-09 00:06:24 -0700240 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700241 }
242 )*
243 {
Till Westmann14a20a72013-05-09 00:06:24 -0700244 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700245 }
246}
247
248DatasetDecl DatasetSpecification() throws ParseException:
249{
250 Pair<Identifier,Identifier> nameComponents = null;
251 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700252 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700253 String adapterName = null;
254 Map<String,String> properties = null;
255 FunctionSignature appliedFunction = null;
256 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700257 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700258 Map<String,String> hints = new HashMap<String,String>();
259 DatasetDecl dsetDecl = null;
260}
261{
262 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700263 "external" <DATASET> nameComponents = QualifiedName()
264 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
265 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700266 "using" adapterName = AdapterName() properties = Configuration()
267 ( "hints" hints = Properties() )?
268 {
269 ExternalDetailsDecl edd = new ExternalDetailsDecl();
270 edd.setAdapter(adapterName);
271 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700272 dsetDecl = new DatasetDecl(nameComponents.first,
273 nameComponents.second,
274 new Identifier(typeName),
275 hints,
276 DatasetType.EXTERNAL,
277 edd,
278 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700279 }
280
Till Westmanna4242bc2013-05-08 17:49:55 -0700281 | "feed" <DATASET> nameComponents = QualifiedName()
282 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
283 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700284 "using" adapterName = AdapterName() properties = Configuration()
285 (appliedFunction = ApplyFunction())? primaryKeyFields = PrimaryKey()
Till Westmanna4242bc2013-05-08 17:49:55 -0700286 ( "on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700287 ( "hints" hints = Properties() )?
288 {
Till Westmann14a20a72013-05-09 00:06:24 -0700289 FeedDetailsDecl fdd = new FeedDetailsDecl(adapterName,
290 properties,
291 appliedFunction,
292 nodeGroupName != null
293 ? new Identifier(nodeGroupName)
294 : null,
295 primaryKeyFields);
296 dsetDecl = new DatasetDecl(nameComponents.first,
297 nameComponents.second,
298 new Identifier(typeName),
299 hints,
300 DatasetType.FEED,
301 fdd,
302 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700303 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700304 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700305 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
306 ifNotExists = IfNotExists()
307 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700308 ( "hints" hints = Properties() )?
309 {
Till Westmann14a20a72013-05-09 00:06:24 -0700310 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
311 ? new Identifier(nodeGroupName)
312 : null,
313 primaryKeyFields);
314 dsetDecl = new DatasetDecl(nameComponents.first,
315 nameComponents.second,
316 new Identifier(typeName),
317 hints,
318 DatasetType.INTERNAL,
319 idd,
320 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700321 }
322 )
323 {
324 return dsetDecl;
325 }
326}
327
328CreateIndexStatement IndexSpecification() throws ParseException:
329{
330 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700331 String indexName = null;
332 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700333 boolean ifNotExists = false;
334 Pair<Identifier,Identifier> nameComponents = null;
335 IndexParams indexType = null;
336}
337{
Till Westmanna4242bc2013-05-08 17:49:55 -0700338 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700339 ifNotExists = IfNotExists()
340 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700341 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700342 {
Till Westmann14a20a72013-05-09 00:06:24 -0700343 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700344 }
Till Westmann14a20a72013-05-09 00:06:24 -0700345 ) ("," fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700346 {
Till Westmann14a20a72013-05-09 00:06:24 -0700347 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700348 }
349 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
350 {
Till Westmann14a20a72013-05-09 00:06:24 -0700351 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700352 cis.setIfNotExists(ifNotExists);
353 cis.setDataverseName(nameComponents.first);
354 cis.setDatasetName(nameComponents.second);
355 if (indexType != null) {
356 cis.setIndexType(indexType.type);
357 cis.setGramLength(indexType.gramLength);
358 }
359 return cis;
360 }
361}
362
363IndexParams IndexType() throws ParseException:
364{
365 IndexType type = null;
366 int gramLength = 0;
367}
368{
369 ("btree"
370 {
371 type = IndexType.BTREE;
372 }
373 | "rtree"
374 {
375 type = IndexType.RTREE;
376 }
377 | "keyword"
378 {
Till Westmann31c21f92013-05-08 09:21:53 -0700379 type = IndexType.FUZZY_WORD_INVIX;
380 }
381 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
382 {
Till Westmann31c21f92013-05-08 09:21:53 -0700383 type = IndexType.FUZZY_NGRAM_INVIX;
384 gramLength = Integer.valueOf(token.image);
385 }
386 <RIGHTPAREN>)
387 {
388 return new IndexParams(type, gramLength);
389 }
390}
391
392CreateDataverseStatement DataverseSpecification() throws ParseException :
393{
Till Westmann14a20a72013-05-09 00:06:24 -0700394 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700395 boolean ifNotExists = false;
396 String format = null;
397}
398{
Till Westmanna4242bc2013-05-08 17:49:55 -0700399 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700400 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700401 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700402 {
Till Westmann14a20a72013-05-09 00:06:24 -0700403 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700404 }
405}
406
407CreateFunctionStatement FunctionSpecification() throws ParseException:
408{
409 FunctionSignature signature;
410 boolean ifNotExists = false;
411 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
412 String functionBody;
Till Westmann31c21f92013-05-08 09:21:53 -0700413 Expression functionBodyExpr;
414 Token beginPos;
415 Token endPos;
416 Pair<Identifier,Identifier> nameComponents=null;
417
418 createNewScope();
419}
420{
421 "function" nameComponents = FunctionOrTypeName()
422 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700423 paramList = ParameterList()
424 "{"
425 {
426 beginPos = token;
427 }
428 functionBodyExpr = Expression() "}"
429 {
430 endPos = token;
431 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
432 String dataverse = nameComponents.first.getValue();
433 String functionName = nameComponents.second.getValue();
434 signature = new FunctionSignature(dataverse, functionName, paramList.size());
435 getCurrentScope().addFunctionDescriptor(signature, false);
436 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
437 }
438}
439
440List<VarIdentifier> ParameterList() throws ParseException:
441{
442 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
443 VarIdentifier var = null;
444}
445{
Till Westmann31c21f92013-05-08 09:21:53 -0700446 <LEFTPAREN> (<VARIABLE>
447 {
448 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700449 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700450 paramList.add(var);
451 getCurrentScope().addNewVarSymbolToScope(var);
452 }
453 ("," <VARIABLE>
454 {
455 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700456 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700457 paramList.add(var);
458 getCurrentScope().addNewVarSymbolToScope(var);
459 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700460 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700461 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700462 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700463 }
464}
465
466boolean IfNotExists() throws ParseException:
467{
468}
469{
470 ( "if not exists"
471 {
472 return true;
473 }
474 )?
475 {
476 return false;
477 }
478}
479
480FunctionSignature ApplyFunction() throws ParseException:
481{
482 FunctionSignature funcSig = null;
483}
484{
485 "apply" "function" funcSig = FunctionSignature()
486 {
487 return funcSig;
488 }
489}
490
ramangrover29566b3a92013-05-28 09:07:10 -0700491String GetPolicy() throws ParseException:
492{
493 String policy = null;
494}
495{
496 "using" "policy" policy = Identifier()
497 {
498 return policy;
499 }
500
501}
502
Till Westmann31c21f92013-05-08 09:21:53 -0700503FunctionSignature FunctionSignature() throws ParseException:
504{
505 Pair<Identifier,Identifier> pairId = null;
506 int arity = 0;
507}
508{
509 pairId = FunctionOrTypeName() "@" <INTEGER_LITERAL>
510 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700511 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700512 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
513 throw new ParseException(" invalid arity:" + arity);
514 }
515
516 String dataverse = pairId.first.getValue();
517 String functionName = pairId.second.getValue();
518 return new FunctionSignature(dataverse, functionName, arity);
519 }
520}
521
522List<String> PrimaryKey() throws ParseException:
523{
Till Westmann14a20a72013-05-09 00:06:24 -0700524 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700525 List<String> primaryKeyFields = new ArrayList<String>();
526}
527{
Till Westmann14a20a72013-05-09 00:06:24 -0700528 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700529 {
Till Westmann14a20a72013-05-09 00:06:24 -0700530 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700531 }
Till Westmann14a20a72013-05-09 00:06:24 -0700532 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700533 {
Till Westmann14a20a72013-05-09 00:06:24 -0700534 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700535 }
536 )*
537 {
538 return primaryKeyFields;
539 }
540}
541
542Statement DropStatement() throws ParseException:
543{
Till Westmann14a20a72013-05-09 00:06:24 -0700544 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700545 Pair<Identifier,Identifier> pairId = null;
546 Triple<Identifier,Identifier,Identifier> tripleId = null;
547 FunctionSignature funcSig = null;
548 boolean ifExists = false;
549 Statement stmt = null;
550}
551{
552 "drop"
553 (
554 <DATASET> pairId = QualifiedName() ifExists = IfExists()
555 {
556 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
557 }
558 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
559 {
560 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
561 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700562 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700563 {
Till Westmann14a20a72013-05-09 00:06:24 -0700564 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700565 }
566 | "type" pairId = FunctionOrTypeName() ifExists = IfExists()
567 {
568 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
569 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700570 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700571 {
Till Westmann14a20a72013-05-09 00:06:24 -0700572 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700573 }
574 | "function" funcSig = FunctionSignature() ifExists = IfExists()
575 {
576 stmt = new FunctionDropStatement(funcSig, ifExists);
577 }
578 )
579 {
580 return stmt;
581 }
582}
583
584boolean IfExists() throws ParseException :
585{
586}
587{
588 ( "if" "exists"
589 {
590 return true;
591 }
592 )?
593 {
594 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000595 }
596}
597
598InsertStatement InsertStatement() throws ParseException:
599{
Till Westmann31c21f92013-05-08 09:21:53 -0700600 Pair<Identifier,Identifier> nameComponents = null;
601 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000602}
603{
Till Westmann31c21f92013-05-08 09:21:53 -0700604 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
605 {
606 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
607 }
vinayakb38b7ca42012-03-05 05:44:15 +0000608}
609
610DeleteStatement DeleteStatement() throws ParseException:
611{
Till Westmann31c21f92013-05-08 09:21:53 -0700612 VariableExpr var = null;
613 Expression condition = null;
614 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000615}
616{
Till Westmann31c21f92013-05-08 09:21:53 -0700617 "delete" var = Variable()
618 {
619 getCurrentScope().addNewVarSymbolToScope(var.getVar());
620 }
621 "from" <DATASET> nameComponents = QualifiedName()
622 ("where" condition = Expression())?
623 {
624 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
625 }
vinayakb38b7ca42012-03-05 05:44:15 +0000626}
627
628UpdateStatement UpdateStatement() throws ParseException:
629{
Till Westmann31c21f92013-05-08 09:21:53 -0700630 VariableExpr vars;
631 Expression target;
632 Expression condition;
633 UpdateClause uc;
634 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000635}
636{
Till Westmann31c21f92013-05-08 09:21:53 -0700637 "update" vars = Variable() "in" target = Expression()
638 "where" condition = Expression()
639 <LEFTPAREN> (uc = UpdateClause()
640 {
641 ucs.add(uc);
642 }
643 ("," uc = UpdateClause()
644 {
645 ucs.add(uc);
646 }
647 )*) <RIGHTPAREN>
648 {
649 return new UpdateStatement(vars, target, condition, ucs);
650 }
vinayakb38b7ca42012-03-05 05:44:15 +0000651}
652
vinayakb38b7ca42012-03-05 05:44:15 +0000653UpdateClause UpdateClause() throws ParseException:
654{
Till Westmann31c21f92013-05-08 09:21:53 -0700655 Expression target = null;
656 Expression value = null ;
657 InsertStatement is = null;
658 DeleteStatement ds = null;
659 UpdateStatement us = null;
660 Expression condition = null;
661 UpdateClause ifbranch = null;
662 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000663}
664{
665 "set" target = Expression() ":=" value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700666 | is = InsertStatement()
667 | ds = DeleteStatement()
668 | us = UpdateStatement()
669 | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN>
670 "then" ifbranch = UpdateClause()
671 [LOOKAHEAD(1) "else" elsebranch = UpdateClause()]
672 {
673 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
674 }
vinayakb38b7ca42012-03-05 05:44:15 +0000675}
676
vinayakb38b7ca42012-03-05 05:44:15 +0000677Statement SetStatement() throws ParseException:
678{
679 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700680 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000681}
682{
Till Westmann7d535322013-05-09 00:40:02 -0700683 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700684 {
Till Westmann31c21f92013-05-08 09:21:53 -0700685 return new SetStatement(pn, pv);
686 }
vinayakb38b7ca42012-03-05 05:44:15 +0000687}
688
689Statement WriteStatement() throws ParseException:
690{
Till Westmann14a20a72013-05-09 00:06:24 -0700691 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000692 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000693 Statement stmt = null;
694 Query query;
695 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000696 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000697}
698{
Till Westmann31c21f92013-05-08 09:21:53 -0700699 "write" ((
Till Westmann7d535322013-05-09 00:40:02 -0700700 "output" "to" nodeName = Identifier() ":" fileName = StringLiteral()
701 ( "using" writerClass = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700702 {
Till Westmann14a20a72013-05-09 00:06:24 -0700703 stmt = new WriteStatement(new Identifier(nodeName), fileName, writerClass);
Till Westmann31c21f92013-05-08 09:21:53 -0700704 }
705 ) | (
706 "into" <DATASET>
707 {
708 nameComponents = QualifiedName();
709 }
710 <LEFTPAREN> query = Query() <RIGHTPAREN>
711 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000712 stmt = new WriteFromQueryResultStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700713 }
714 ))
vinayakb38b7ca42012-03-05 05:44:15 +0000715 {
716 return stmt;
717 }
718}
719
vinayakb38b7ca42012-03-05 05:44:15 +0000720LoadFromFileStatement LoadStatement() throws ParseException:
721{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000722 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000723 Identifier datasetName = null;
724 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000725 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000726 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000727 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000728}
729{
Till Westmann31c21f92013-05-08 09:21:53 -0700730 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000731 {
Till Westmann31c21f92013-05-08 09:21:53 -0700732 dataverseName = nameComponents.first;
733 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000734 }
Till Westmann31c21f92013-05-08 09:21:53 -0700735 "using" adapterName = AdapterName() properties = Configuration()
736 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000737 {
Till Westmann31c21f92013-05-08 09:21:53 -0700738 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000739 }
740 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700741 {
742 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
743 }
vinayakb38b7ca42012-03-05 05:44:15 +0000744}
745
vinayakb38b7ca42012-03-05 05:44:15 +0000746
Till Westmann31c21f92013-05-08 09:21:53 -0700747String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000748{
ramangrover29669d8f62013-02-11 06:03:32 +0000749 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000750}
751{
Till Westmann68d99652013-05-09 11:15:21 -0700752 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000753 {
Till Westmann7d535322013-05-09 00:40:02 -0700754 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000755 }
vinayakb38b7ca42012-03-05 05:44:15 +0000756}
757
Till Westmann31c21f92013-05-08 09:21:53 -0700758Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000759{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000760 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700761 Map<String,String> configuration = null;
762 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700763 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000764}
765{
Till Westmann31c21f92013-05-08 09:21:53 -0700766 (
ramangrover29566b3a92013-05-28 09:07:10 -0700767 "begin" "feed" nameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700768 {
ramangrover29566b3a92013-05-28 09:07:10 -0700769 stmt = new BeginFeedStatement(nameComponents.first, nameComponents.second, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700770 }
771 | "suspend" "feed" nameComponents = QualifiedName()
772 {
773 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, nameComponents.first, nameComponents.second);
774 }
775 | "resume" "feed" nameComponents = QualifiedName()
776 {
777 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, nameComponents.first, nameComponents.second);
778 }
779 | "end" "feed" nameComponents = QualifiedName()
780 {
781 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.END, nameComponents.first, nameComponents.second);
782 }
783 | "alter" "feed" nameComponents = QualifiedName() "set" configuration = Configuration()
784 {
785 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
786 }
787 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000788 {
Till Westmann31c21f92013-05-08 09:21:53 -0700789 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000790 }
791}
792
Till Westmann31c21f92013-05-08 09:21:53 -0700793Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000794{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000795 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700796 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000797}
798{
Till Westmann31c21f92013-05-08 09:21:53 -0700799 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000800 {
Till Westmann31c21f92013-05-08 09:21:53 -0700801 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000802 }
Till Westmann31c21f92013-05-08 09:21:53 -0700803 ( "," keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000804 {
Till Westmann31c21f92013-05-08 09:21:53 -0700805 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000806 }
Till Westmann31c21f92013-05-08 09:21:53 -0700807 )* )? <RIGHTPAREN>
808 {
809 return configuration;
810 }
811}
812
813Pair<String, String> KeyValuePair() throws ParseException:
814{
815 String key;
816 String value;
817}
818{
Till Westmann7d535322013-05-09 00:40:02 -0700819 <LEFTPAREN> key = StringLiteral() "=" value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700820 {
821 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000822 }
Till Westmann31c21f92013-05-08 09:21:53 -0700823}
824
825Map<String,String> Properties() throws ParseException:
826{
827 Map<String,String> properties = new HashMap<String,String>();
828 Pair<String, String> property;
829}
830{
831 ( <LEFTPAREN> property = Property()
832 {
833 properties.put(property.first, property.second);
834 }
835 ( "," property = Property()
836 {
837 properties.put(property.first, property.second);
838 }
839 )* <RIGHTPAREN> )?
840 {
841 return properties;
842 }
843}
844
845Pair<String, String> Property() throws ParseException:
846{
847 String key;
848 String value;
849}
850{
Till Westmann7d535322013-05-09 00:40:02 -0700851 key = Identifier() "=" ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700852 {
853 try {
854 value = "" + Long.valueOf(token.image);
855 } catch (NumberFormatException nfe) {
856 throw new ParseException("inapproriate value: " + token.image);
857 }
858 }
859 )
860 {
861 return new Pair<String, String>(key.toUpperCase(), value);
862 }
vinayakb38b7ca42012-03-05 05:44:15 +0000863}
864
865TypeExpression TypeExpr() throws ParseException:
866{
867 TypeExpression typeExpr = null;
868}
869{
870 (
871 typeExpr = RecordTypeDef()
872 | typeExpr = TypeReference()
873 | typeExpr = OrderedListTypeDef()
874 | typeExpr = UnorderedListTypeDef()
875 )
876 {
877 return typeExpr;
878 }
879}
880
881RecordTypeDefinition RecordTypeDef() throws ParseException:
882{
883 RecordTypeDefinition recType = new RecordTypeDefinition();
884 RecordTypeDefinition.RecordKind recordKind = null;
885}
886{
887 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
888 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
889 "{"
890 {
891 String hint = getHint(token);
892 if (hint != null) {
893 String splits[] = hint.split(" +");
894 if (splits[0].equals(GEN_FIELDS_HINT)) {
895 if (splits.length != 5) {
896 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
897 }
898 if (!splits[1].equals("int")) {
899 throw new ParseException("The only supported type for gen-fields is int.");
900 }
901 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
902 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
903 recType.setUndeclaredFieldsDataGen(ufdg);
904 }
905 }
906
907 }
908 (
909 RecordField(recType)
910 ( "," RecordField(recType) )*
911 )?
912 "}"
913 {
914 if (recordKind == null) {
915 recordKind = RecordTypeDefinition.RecordKind.OPEN;
916 }
917 recType.setRecordKind(recordKind);
918 return recType;
919 }
920}
921
922void RecordField(RecordTypeDefinition recType) throws ParseException:
923{
924 String fieldName;
925 TypeExpression type = null;
926 boolean nullable = false;
927}
928{
Till Westmann14a20a72013-05-09 00:06:24 -0700929 fieldName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000930 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700931 fieldName = token.image;
932 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +0000933 IRecordFieldDataGen rfdg = null;
934 if (hint != null) {
935 String splits[] = hint.split(" +");
936 if (splits[0].equals(VAL_FILE_HINT)) {
937 File[] valFiles = new File[splits.length - 1];
938 for (int k=1; k<splits.length; k++) {
939 valFiles[k-1] = new File(splits[k]);
940 }
941 rfdg = new FieldValFileDataGen(valFiles);
942 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
943 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
944 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
945 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
946 } else if (splits[0].equals(LIST_HINT)) {
947 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
948 } else if (splits[0].equals(INTERVAL_HINT)) {
949 FieldIntervalDataGen.ValueType vt;
950 if (splits[1].equals("int")) {
951 vt = FieldIntervalDataGen.ValueType.INT;
952 } else if (splits[1].equals("long")) {
953 vt = FieldIntervalDataGen.ValueType.LONG;
954 } else if (splits[1].equals("float")) {
955 vt = FieldIntervalDataGen.ValueType.FLOAT;
956 } else if (splits[1].equals("double")) {
957 vt = FieldIntervalDataGen.ValueType.DOUBLE;
958 } else {
959 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
960 }
961 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
962 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
963 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
964 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
965 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
966 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
967 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
968 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
969 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
970 } else if (splits[0].equals(AUTO_HINT)) {
971 rfdg = new AutoDataGen(splits[1]);
972 }
973 }
974 }
975 ":"
976 ( type = TypeExpr() )
977 ("?" { nullable = true; } )?
978 {
979 recType.addField(fieldName, type, nullable, rfdg);
980 }
981}
982
983TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000984{
Till Westmann14a20a72013-05-09 00:06:24 -0700985 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700986}
987{
988 id = Identifier()
989 {
Till Westmann14a20a72013-05-09 00:06:24 -0700990 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700991 }
vinayakb38b7ca42012-03-05 05:44:15 +0000992}
993
994OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
995{
996 TypeExpression type = null;
997}
998{
999 "["
1000 ( type = TypeExpr() )
1001 "]"
1002 {
1003 return new OrderedListTypeDefinition(type);
1004 }
1005}
1006
1007
1008UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1009{
1010 TypeExpression type = null;
1011}
1012{
1013 "{{"
1014 ( type = TypeExpr() )
1015 "}}"
1016 {
1017 return new UnorderedListTypeDefinition(type);
1018 }
1019}
1020
Till Westmann31c21f92013-05-08 09:21:53 -07001021
1022Pair<Identifier,Identifier> FunctionOrTypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001023{
Till Westmann31c21f92013-05-08 09:21:53 -07001024 Pair<Identifier,Identifier> name = null;
1025}
1026{
1027 name = QualifiedName()
1028 {
1029 if (name.first == null) {
1030 name.first = new Identifier(defaultDataverse);
1031 }
1032 return name;
1033 }
1034}
1035
Till Westmann14a20a72013-05-09 00:06:24 -07001036String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001037{
Till Westmann68d99652013-05-09 11:15:21 -07001038 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001039}
1040{
1041 <IDENTIFIER>
1042 {
Till Westmann14a20a72013-05-09 00:06:24 -07001043 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001044 }
Till Westmann68d99652013-05-09 11:15:21 -07001045 | lit = StringLiteral()
1046 {
1047 return lit;
1048 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001049}
1050
Till Westmann7d535322013-05-09 00:40:02 -07001051String StringLiteral() throws ParseException:
1052{
1053}
1054{
1055 <STRING_LITERAL>
1056 {
1057 return removeQuotesAndEscapes(token.image);
1058 }
1059}
1060
Till Westmann31c21f92013-05-08 09:21:53 -07001061Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1062{
Till Westmann14a20a72013-05-09 00:06:24 -07001063 String first = null;
1064 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001065}
1066{
Till Westmanna4242bc2013-05-08 17:49:55 -07001067 first = Identifier() ("." second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001068 {
Till Westmann14a20a72013-05-09 00:06:24 -07001069 Identifier id1 = null;
1070 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001071 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001072 id2 = new Identifier(first);
1073 } else
1074 {
1075 id1 = new Identifier(first);
1076 id2 = new Identifier(second);
1077 }
1078 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001079 }
1080}
1081
Till Westmann31c21f92013-05-08 09:21:53 -07001082Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001083{
Till Westmann14a20a72013-05-09 00:06:24 -07001084 String first = null;
1085 String second = null;
1086 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001087}
1088{
Till Westmanna4242bc2013-05-08 17:49:55 -07001089 first = Identifier() "." second = Identifier() ("." third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001090 {
Till Westmann14a20a72013-05-09 00:06:24 -07001091 Identifier id1 = null;
1092 Identifier id2 = null;
1093 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001094 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001095 id2 = new Identifier(first);
1096 id3 = new Identifier(second);
1097 } else {
1098 id1 = new Identifier(first);
1099 id2 = new Identifier(second);
1100 id3 = new Identifier(third);
1101 }
1102 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001103 }
1104}
1105
vinayakb38b7ca42012-03-05 05:44:15 +00001106FunctionDecl FunctionDeclaration() throws ParseException:
1107{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001108 FunctionDecl funcDecl;
1109 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001110 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001111 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1112 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001113 createNewScope();
1114}
1115{
Till Westmannd7dcb122013-05-16 13:19:09 -07001116 "declare" "function" functionName = Identifier()
1117 paramList = ParameterList()
1118 "{" funcBody = Expression() "}"
vinayakb38b7ca42012-03-05 05:44:15 +00001119 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001120 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001121 getCurrentScope().addFunctionDescriptor(signature, false);
1122 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001123 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001124 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001125 }
1126}
1127
vinayakb38b7ca42012-03-05 05:44:15 +00001128
Till Westmann31c21f92013-05-08 09:21:53 -07001129Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001130{
1131 Query query = new Query();
1132 Expression expr;
1133}
1134{
Till Westmann31c21f92013-05-08 09:21:53 -07001135 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001136 {
1137 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001138 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001139 return query;
1140 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001141
vinayakb38b7ca42012-03-05 05:44:15 +00001142}
1143
1144
1145
1146Expression Expression():
1147{
1148 Expression expr = null;
1149 Expression exprP = null;
1150}
1151{
1152(
1153
1154//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1155 expr = OperatorExpr()
1156 | expr = IfThenElse()
1157 | expr = FLWOGR()
1158 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001159
vinayakb38b7ca42012-03-05 05:44:15 +00001160
1161)
1162 {
1163 return (exprP==null) ? expr : exprP;
1164 }
1165}
1166
1167
1168
1169Expression OperatorExpr()throws ParseException:
1170{
1171 OperatorExpr op = null;
1172 Expression operand = null;
1173}
1174{
1175 operand = AndExpr()
1176 (
1177
1178 "or"
1179 {
1180 if (op == null) {
1181 op = new OperatorExpr();
1182 op.addOperand(operand);
1183 op.setCurrentop(true);
1184 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001185 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001186 }
1187
1188 operand = AndExpr()
1189 {
1190 op.addOperand(operand);
1191 }
1192
1193 )*
1194
1195 {
1196 return op==null? operand: op;
1197 }
1198}
1199
1200Expression AndExpr()throws ParseException:
1201{
1202 OperatorExpr op = null;
1203 Expression operand = null;
1204}
1205{
1206 operand = RelExpr()
1207 (
1208
1209 "and"
1210 {
1211 if (op == null) {
1212 op = new OperatorExpr();
1213 op.addOperand(operand);
1214 op.setCurrentop(true);
1215 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001216 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001217 }
1218
1219 operand = RelExpr()
1220 {
1221 op.addOperand(operand);
1222 }
1223
1224 )*
1225
1226 {
1227 return op==null? operand: op;
1228 }
1229}
1230
1231
1232
1233Expression RelExpr()throws ParseException:
1234{
1235 OperatorExpr op = null;
1236 Expression operand = null;
1237 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001238 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001239}
1240{
1241 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001242 {
1243 if (operand instanceof VariableExpr) {
1244 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001245 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001246 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001247 }
1248 }
1249 }
1250
1251 (
1252 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1253 {
alexander.behm07617fd2012-07-25 10:13:50 +00001254 String mhint = getHint(token);
1255 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1256 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1257 }
vinayakb38b7ca42012-03-05 05:44:15 +00001258 if (op == null) {
1259 op = new OperatorExpr();
1260 op.addOperand(operand, broadcast);
1261 op.setCurrentop(true);
1262 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001263 }
1264 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001265 }
1266
1267 operand = AddExpr()
1268 {
alexander.behm07617fd2012-07-25 10:13:50 +00001269 broadcast = false;
1270 if (operand instanceof VariableExpr) {
1271 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001272 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1273 broadcast = true;
1274 }
alexander.behm07617fd2012-07-25 10:13:50 +00001275 }
vinayakb38b7ca42012-03-05 05:44:15 +00001276 op.addOperand(operand, broadcast);
1277 }
1278 )?
1279
1280 {
alexander.behm07617fd2012-07-25 10:13:50 +00001281 if (annotation != null) {
1282 op.addHint(annotation);
1283 }
vinayakb38b7ca42012-03-05 05:44:15 +00001284 return op==null? operand: op;
1285 }
1286}
1287
1288Expression AddExpr()throws ParseException:
1289{
1290 OperatorExpr op = null;
1291 Expression operand = null;
1292}
1293{
1294 operand = MultExpr()
1295
1296 ( ("+" | "-")
1297 {
1298 if (op == null) {
1299 op = new OperatorExpr();
1300 op.addOperand(operand);
1301 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001302 }
1303 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001304 }
1305
1306 operand = MultExpr()
1307 {
1308 op.addOperand(operand);
1309 }
1310 )*
1311
1312 {
1313 return op==null? operand: op;
1314 }
1315}
1316
1317Expression MultExpr()throws ParseException:
1318{
1319 OperatorExpr op = null;
1320 Expression operand = null;
1321}
1322{
1323 operand = UnionExpr()
1324
1325 (( "*" | "/" | "%" | <CARET> | "idiv")
1326 {
1327 if (op == null) {
1328 op = new OperatorExpr();
1329 op.addOperand(operand);
1330 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001331 }
1332 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001333 }
1334 operand = UnionExpr()
1335 {
1336 op.addOperand(operand);
1337 }
1338 )*
1339
1340 {
1341 return op==null?operand:op;
1342 }
1343}
1344
1345Expression UnionExpr() throws ParseException:
1346{
1347 UnionExpr union = null;
1348 Expression operand1 = null;
1349 Expression operand2 = null;
1350}
1351{
1352 operand1 = UnaryExpr()
1353 ("union"
1354 (operand2 = UnaryExpr()) {
1355 if (union == null) {
1356 union = new UnionExpr();
1357 union.addExpr(operand1);
1358 }
1359 union.addExpr(operand2);
1360 } )*
1361 {
1362 return (union == null)? operand1: union;
1363 }
1364}
1365
1366Expression UnaryExpr() throws ParseException:
1367{
1368 Expression uexpr = null;
1369 Expression expr = null;
1370}
1371{
1372 (( "+"|"-")
1373 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001374 uexpr = new UnaryExpr();
1375 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001376 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001377 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001378 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1379 else
1380 throw new ParseException();
1381 }
1382 )?
1383
1384 expr = ValueExpr()
1385 {
1386 if(uexpr!=null){
1387 ((UnaryExpr)uexpr).setExpr(expr);
1388 return uexpr;
1389 }
1390 else{
1391 return expr;
1392 }
1393 }
1394}
1395
Till Westmann04478e72013-05-13 23:01:34 -07001396Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001397{
1398 Expression expr = null;
1399 Identifier ident = null;
1400 AbstractAccessor fa = null;
1401 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001402}
1403{
Till Westmann04478e72013-05-13 23:01:34 -07001404 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001405 {
Till Westmann04478e72013-05-13 23:01:34 -07001406 fa = (fa == null ? new FieldAccessor(expr, ident)
1407 : new FieldAccessor(fa, ident));
1408 }
1409 | index = Index()
1410 {
1411 fa = (fa == null ? new IndexAccessor(expr, index)
1412 : new IndexAccessor(fa, index));
1413 }
1414 )*
1415 {
1416 return fa == null ? expr : fa;
1417 }
vinayakb38b7ca42012-03-05 05:44:15 +00001418}
1419
1420Identifier Field() throws ParseException:
1421{
Till Westmann14a20a72013-05-09 00:06:24 -07001422 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001423}
1424{
Till Westmanna4242bc2013-05-08 17:49:55 -07001425 "." ident = Identifier()
1426 {
Till Westmann14a20a72013-05-09 00:06:24 -07001427 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001428 }
vinayakb38b7ca42012-03-05 05:44:15 +00001429}
1430
1431int Index() throws ParseException:
1432{
1433 Expression expr = null;
1434 int idx = -2;
1435}
1436{
1437 "[" ( expr = Expression()
1438 {
1439 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1440 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001441 Literal lit = ((LiteralExpr)expr).getValue();
1442 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1443 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001444 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001445 }
vinayakb38b7ca42012-03-05 05:44:15 +00001446 else {
1447 throw new ParseException("Index should be an INTEGER");
1448 }
1449 }
1450
1451 }
1452
1453 | "?"
1454 {
1455 idx = IndexAccessor.ANY;
1456 // ANY
1457 }
1458
1459 )
1460
1461 "]"
1462 {
1463 return idx;
1464 }
1465}
1466
1467
1468Expression PrimaryExpr()throws ParseException:
1469{
1470 Expression expr = null;
1471}
1472{
Till Westmann68d99652013-05-09 11:15:21 -07001473 ( LOOKAHEAD(2)
1474 expr = FunctionCallExpr()
1475 | expr = Literal()
1476 | expr = DatasetAccessExpression()
1477 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001478 {
1479 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001480 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001481 }
Till Westmann68d99652013-05-09 11:15:21 -07001482 | expr = ListConstructor()
1483 | expr = RecordConstructor()
1484 | expr = ParenthesizedExpression()
1485 )
1486 {
1487 return expr;
1488 }
vinayakb38b7ca42012-03-05 05:44:15 +00001489}
1490
1491Expression Literal() throws ParseException:
1492{
vinayakb38b7ca42012-03-05 05:44:15 +00001493 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001494 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001495}
1496{
Till Westmann7d535322013-05-09 00:40:02 -07001497 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001498 {
Till Westmann7d535322013-05-09 00:40:02 -07001499 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001500 }
1501 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001502 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001503 try {
1504 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1505 } catch(NumberFormatException ex) {
1506 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1507 }
1508 }
1509 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001510 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001511 lit.setValue(new FloatLiteral(new Float(token.image)));
1512 }
1513 | <DOUBLE_LITERAL>
1514 {
1515 lit.setValue(new DoubleLiteral(new Double(token.image)));
1516 }
1517 | <NULL>
1518 {
1519 lit.setValue(NullLiteral.INSTANCE);
1520 }
1521 | <TRUE>
1522 {
1523 lit.setValue(TrueLiteral.INSTANCE);
1524 }
1525 | <FALSE>
1526 {
1527 lit.setValue(FalseLiteral.INSTANCE);
1528 }
1529 )
vinayakb38b7ca42012-03-05 05:44:15 +00001530 {
1531 return lit;
1532 }
1533}
1534
1535
1536VariableExpr VariableRef() throws ParseException:
1537{
1538 VariableExpr varExp = new VariableExpr();
1539 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001540}
1541{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001542 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001543 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001544 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001545 Identifier ident = lookupSymbol(varName);
1546 if (isInForbiddenScopes(varName)) {
1547 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.");
1548 }
1549 if(ident != null) { // exist such ident
1550 varExp.setIsNewVar(false);
1551 varExp.setVar((VarIdentifier)ident);
1552 } else {
1553 varExp.setVar(var);
1554 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001555 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001556 return varExp;
1557 }
1558}
1559
1560
1561VariableExpr Variable() throws ParseException:
1562{
1563 VariableExpr varExp = new VariableExpr();
1564 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001565}
1566{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001567 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001568 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001569 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001570 if(ident != null) { // exist such ident
1571 varExp.setIsNewVar(false);
1572 }
1573 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001574 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001575 return varExp;
1576 }
1577}
1578
1579Expression ListConstructor() throws ParseException:
1580{
1581 Expression expr = null;
1582}
1583{
1584 (
1585 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1586 )
1587
1588 {
1589 return expr;
1590 }
1591}
1592
1593
1594ListConstructor OrderedListConstructor() throws ParseException:
1595{
1596 ListConstructor expr = new ListConstructor();
1597 Expression tmp = null;
1598 List<Expression> exprList = new ArrayList<Expression>();
1599 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1600}
1601{
1602
1603 "["
1604 ( tmp = Expression()
1605 {
1606 exprList.add(tmp);
1607 }
1608
1609 ("," tmp = Expression() { exprList.add(tmp); })*
1610 )?
1611
1612 "]"
1613
1614 {
1615 expr.setExprList(exprList);
1616 return expr;
1617 }
1618}
1619
1620ListConstructor UnorderedListConstructor() throws ParseException:
1621{
1622 ListConstructor expr = new ListConstructor();
1623 Expression tmp = null;
1624 List<Expression> exprList = new ArrayList<Expression>();
1625 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1626}
1627{
1628
1629 "{{" ( tmp = Expression()
1630 {
1631 exprList.add(tmp);
1632 }
1633 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1634 {
1635 expr.setExprList(exprList);
1636 return expr;
1637 }
1638}
1639
1640RecordConstructor RecordConstructor() throws ParseException:
1641{
1642 RecordConstructor expr = new RecordConstructor();
1643 FieldBinding tmp = null;
1644 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1645}
1646{
1647 "{" (tmp = FieldBinding()
1648 {
1649 fbList.add(tmp);
1650 }
1651 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
1652 {
1653 expr.setFbList(fbList);
1654 return expr;
1655 }
1656}
1657
1658FieldBinding FieldBinding() throws ParseException:
1659{
1660 FieldBinding fb = new FieldBinding();
1661 Expression left, right;
1662}
1663{
1664 left = Expression() ":" right = Expression()
1665 {
1666 fb.setLeftExpr(left);
1667 fb.setRightExpr(right);
1668 return fb;
1669 }
1670}
1671
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001672
vinayakb38b7ca42012-03-05 05:44:15 +00001673Expression FunctionCallExpr() throws ParseException:
1674{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001675 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001676 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001677 Expression tmp;
1678 int arity = 0;
Till Westmann31c21f92013-05-08 09:21:53 -07001679 Pair<Identifier,Identifier> funcId = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001680 String funcName;
1681 String dataverse;
Till Westmann31c21f92013-05-08 09:21:53 -07001682 String hint = null;
1683 String id1 = null;
1684 String id2 = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001685}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001686{
Till Westmann31c21f92013-05-08 09:21:53 -07001687 funcId = FunctionOrTypeName()
vinayakb38b7ca42012-03-05 05:44:15 +00001688 {
Till Westmann31c21f92013-05-08 09:21:53 -07001689 dataverse = funcId.first.getValue();
1690 funcName = funcId.second.getValue();
1691 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001692 }
Till Westmann31c21f92013-05-08 09:21:53 -07001693 <LEFTPAREN> (tmp = Expression()
1694 {
1695 argList.add(tmp);
1696 arity ++;
1697 }
1698 ("," tmp = Expression()
1699 {
1700 argList.add(tmp);
1701 arity++;
1702 }
1703 )*)? <RIGHTPAREN>
1704 {
1705 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity);
1706 if (signature == null) {
1707 signature = new FunctionSignature(dataverse, funcName, arity);
1708 }
1709 callExpr = new CallExpr(signature,argList);
1710 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1711 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1712 }
1713 return callExpr;
1714 }
vinayakb38b7ca42012-03-05 05:44:15 +00001715}
1716
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001717Expression DatasetAccessExpression() throws ParseException:
1718{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001719 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001720 String arg1 = null;
1721 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001722 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001723}
1724{
Till Westmann14a20a72013-05-09 00:06:24 -07001725 <DATASET>
1726 {
Till Westmann14a20a72013-05-09 00:06:24 -07001727 funcName = token.image;
1728 }
1729 ( ( arg1 = Identifier() ( "." arg2 = Identifier() )? )
1730 {
1731 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001732 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001733 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001734 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001735 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001736 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001737 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001738 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1739 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1740 if (signature == null) {
1741 signature = new FunctionSignature(dataverse, funcName, 1);
1742 }
1743 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001744 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001745 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001746 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001747}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001748
vinayakb38b7ca42012-03-05 05:44:15 +00001749Expression ParenthesizedExpression() throws ParseException:
1750{
1751 Expression expr;
1752}
1753{
1754 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1755 {
1756 return expr;
1757 }
1758}
1759
1760Expression IfThenElse() throws ParseException:
1761{
1762 Expression condExpr;
1763 Expression thenExpr;
1764 Expression elseExpr;
1765 IfExpr ifExpr = new IfExpr();
1766}
1767{
1768 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
1769
1770 {
1771 ifExpr.setCondExpr(condExpr);
1772 ifExpr.setThenExpr(thenExpr);
1773 ifExpr.setElseExpr(elseExpr);
1774 return ifExpr;
1775 }
1776}
1777
1778Expression FLWOGR() throws ParseException:
1779{
1780 FLWOGRExpression flworg = new FLWOGRExpression();
1781 List<Clause> clauseList = new ArrayList<Clause>();
1782 Expression returnExpr;
1783 Clause tmp;
1784 createNewScope();
1785}
1786{
1787 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
1788 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
1789
1790 {
1791 flworg.setClauseList(clauseList);
1792 flworg.setReturnExpr(returnExpr);
1793 removeCurrentScope();
1794 return flworg;
1795 }
1796}
1797
1798Clause Clause()throws ParseException :
1799{
1800 Clause clause;
1801}
1802{
1803 (
1804 clause = ForClause()
1805 | clause = LetClause()
1806 | clause = WhereClause()
1807 | clause = OrderbyClause()
1808 | clause = GroupClause()
1809 | clause = LimitClause()
1810 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001811 )
1812 {
1813 return clause;
1814 }
1815}
1816
1817Clause ForClause()throws ParseException :
1818{
1819 ForClause fc = new ForClause();
1820 VariableExpr varExp;
1821 VariableExpr varPos = null;
1822 Expression inExp;
1823 extendCurrentScope();
1824}
1825{
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001826 "for" varExp = Variable() ("at" varPos = Variable())? "in" ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001827 {
1828 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001829 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001830 fc.setInExpr(inExp);
1831 if (varPos != null) {
1832 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001833 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001834 }
1835 return fc;
1836 }
1837}
1838
1839Clause LetClause() throws ParseException:
1840{
1841 LetClause lc = new LetClause();
1842 VariableExpr varExp;
1843 Expression beExp;
1844 extendCurrentScope();
1845}
1846{
ilovesoupb2527c12012-07-12 03:21:13 +00001847 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001848 {
1849 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001850 lc.setVarExpr(varExp);
1851 lc.setBeExpr(beExp);
1852 return lc;
1853 }
1854}
1855
1856Clause WhereClause()throws ParseException :
1857{
1858 WhereClause wc = new WhereClause();
1859 Expression whereExpr;
1860}
1861{
1862 "where" whereExpr = Expression()
1863 {
1864 wc.setWhereExpr(whereExpr);
1865 return wc;
1866 }
1867}
1868
1869Clause OrderbyClause()throws ParseException :
1870{
1871 OrderbyClause oc = new OrderbyClause();
1872 Expression orderbyExpr;
1873 List<Expression> orderbyList = new ArrayList<Expression>();
1874 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1875 int numOfOrderby = 0;
1876}
1877{
1878 (
1879 "order"
1880 {
1881 String hint = getHint(token);
1882 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1883 String splits[] = hint.split(" +");
1884 int numFrames = Integer.parseInt(splits[1]);
1885 int numTuples = Integer.parseInt(splits[2]);
1886 oc.setNumFrames(numFrames);
1887 oc.setNumTuples(numTuples);
1888 }
1889 }
1890 "by" orderbyExpr = Expression()
1891 {
1892 orderbyList.add(orderbyExpr);
1893 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1894 }
1895 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1896 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1897 {
1898 modifierList.add(modif);
1899 }
1900
1901 ("," orderbyExpr = Expression()
1902 {
1903 orderbyList.add(orderbyExpr);
1904 modif = OrderbyClause.OrderModifier.ASC;
1905 }
1906 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1907 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1908 {
1909 modifierList.add(modif);
1910 }
1911 )*
1912)
1913 {
1914 oc.setModifierList(modifierList);
1915 oc.setOrderbyList(orderbyList);
1916 return oc;
1917 }
1918}
1919Clause GroupClause()throws ParseException :
1920{
1921 GroupbyClause gbc = new GroupbyClause();
1922 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1923 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1924 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1925 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1926 VariableExpr var = null;
1927 VariableExpr withVar = null;
1928 Expression expr = null;
1929 VariableExpr decorVar = null;
1930 Expression decorExpr = null;
1931}
1932{
1933 {
1934 Scope newScope = extendCurrentScopeNoPush(true);
1935 // extendCurrentScope(true);
1936 }
1937 "group"
1938 {
1939 String hint = getHint(token);
1940 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1941 gbc.setHashGroupByHint(true);
1942 }
1943 }
1944 "by" (LOOKAHEAD(2) var = Variable()
1945 {
1946 newScope.addNewVarSymbolToScope(var.getVar());
1947 } ":=")?
1948 expr = Expression()
1949 {
1950 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1951 vePairList.add(pair1);
1952 }
1953 ("," ( LOOKAHEAD(2) var = Variable()
1954 {
1955 newScope.addNewVarSymbolToScope(var.getVar());
1956 } ":=")?
1957 expr = Expression()
1958 {
1959 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
1960 vePairList.add(pair2);
1961 }
1962 )*
1963 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
1964 {
1965 newScope.addNewVarSymbolToScope(decorVar.getVar());
1966 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
1967 decorPairList.add(pair3);
1968 }
1969 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
1970 {
1971 newScope.addNewVarSymbolToScope(decorVar.getVar());
1972 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
1973 decorPairList.add(pair4);
1974 }
1975 )*
1976 )?
1977 "with" withVar = VariableRef()
1978 {
1979 if(withVar.getIsNewVar()==true)
1980 throw new ParseException("can't find variable " + withVar.getVar());
1981 withVarList.add(withVar);
1982 newScope.addNewVarSymbolToScope(withVar.getVar());
1983 }
1984 ("," withVar = VariableRef()
1985 {
1986 if(withVar.getIsNewVar()==true)
1987 throw new ParseException("can't find variable " + withVar.getVar());
1988 withVarList.add(withVar);
1989 newScope.addNewVarSymbolToScope(withVar.getVar());
1990 })*
1991 {
1992 gbc.setGbyPairList(vePairList);
1993 gbc.setDecorPairList(decorPairList);
1994 gbc.setWithVarList(withVarList);
1995 replaceCurrentScope(newScope);
1996 return gbc;
1997 }
1998}
1999
2000
2001LimitClause LimitClause() throws ParseException:
2002{
2003 LimitClause lc = new LimitClause();
2004 Expression expr;
2005 pushForbiddenScope(getCurrentScope());
2006}
2007{
2008 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2009 ("offset" expr = Expression() { lc.setOffset(expr); })?
2010
2011 {
2012 popForbiddenScope();
2013 return lc;
2014 }
2015}
2016
2017DistinctClause DistinctClause() throws ParseException:
2018{
2019 List<Expression> exprs = new ArrayList<Expression>();
2020 Expression expr;
2021}
2022{
2023 "distinct" "by" expr = Expression()
2024 {
2025 exprs.add(expr);
2026 }
2027 ("," expr = Expression()
2028 {
2029 exprs.add(expr);
2030 }
2031 )*
2032 {
2033 return new DistinctClause(exprs);
2034 }
2035}
2036
vinayakb38b7ca42012-03-05 05:44:15 +00002037QuantifiedExpression QuantifiedExpression()throws ParseException:
2038{
2039 QuantifiedExpression qc = new QuantifiedExpression();
2040 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2041 Expression satisfiesExpr;
2042 VariableExpr var;
2043 Expression inExpr;
2044 QuantifiedPair pair;
2045}
2046{
2047 {
2048 createNewScope();
2049 }
2050
2051 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2052 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2053 var = Variable() "in" inExpr = Expression()
2054 {
2055 pair = new QuantifiedPair(var, inExpr);
2056 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2057 quantifiedList.add(pair);
2058 }
2059 (
2060 "," var = Variable() "in" inExpr = Expression()
2061 {
2062 pair = new QuantifiedPair(var, inExpr);
2063 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2064 quantifiedList.add(pair);
2065 }
2066 )*
2067 "satisfies" satisfiesExpr = Expression()
2068 {
2069 qc.setSatisfiesExpr(satisfiesExpr);
2070 qc.setQuantifiedList(quantifiedList);
2071 removeCurrentScope();
2072 return qc;
2073 }
2074}
2075
2076TOKEN_MGR_DECLS:
2077{
2078 public int commentDepth = 0;
2079}
2080
2081<DEFAULT>
2082TOKEN :
2083{
2084 <CARET : "^" >
2085}
2086
2087<DEFAULT>
2088TOKEN :
2089{
2090 <DATASET : "dataset" >
2091}
2092
2093<DEFAULT>
2094TOKEN :
2095{
2096 <LEFTPAREN : "(" >
2097}
2098
2099<DEFAULT>
2100TOKEN :
2101{
2102 <RIGHTPAREN : ")" >
2103}
2104
2105
2106<DEFAULT>
2107TOKEN :
2108{
2109 <INTEGER_LITERAL : (<DIGIT>)+ >
2110}
2111
2112
2113<DEFAULT>
2114TOKEN :
2115{
2116 <NULL : "null">
2117}
2118
2119<DEFAULT>
2120TOKEN :
2121{
2122 <TRUE : "true">
2123}
2124
2125<DEFAULT>
2126TOKEN :
2127{
2128 <FALSE : "false">
2129}
2130
2131<DEFAULT>
2132TOKEN :
2133{
2134 <#DIGIT : ["0" - "9"]>
2135}
2136
2137
2138TOKEN:
2139{
2140 < DOUBLE_LITERAL: <INTEGER>
2141 | <INTEGER> ( "." <INTEGER> )?
2142 | "." <INTEGER>
2143 >
2144 |
2145 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2146 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2147 | "." <INTEGER> ( "f" | "F" )
2148 >
2149 |
2150 <INTEGER : (<DIGIT>)+ >
2151}
2152
2153<DEFAULT>
2154TOKEN :
2155{
2156 <#LETTER : ["A" - "Z", "a" - "z"]>
2157}
2158
2159<DEFAULT>
2160TOKEN :
2161{
2162 <SPECIALCHARS : ["$", "_", "-"] >
2163}
2164
2165<DEFAULT>
2166TOKEN :
2167{
2168 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2169 |
2170 < #EscapeQuot: "\\\"" >
2171 |
2172 < #EscapeApos: "\\\'" >
2173}
2174
2175<DEFAULT>
2176TOKEN :
2177{
2178 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2179}
2180
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002181
vinayakb38b7ca42012-03-05 05:44:15 +00002182<DEFAULT>
2183TOKEN :
2184{
Till Westmann4f58e1a2013-05-20 18:29:54 -07002185 <VARIABLE : "$" (<LETTER>)+ (<LETTER> | <DIGIT> | "_")* >
vinayakb38b7ca42012-03-05 05:44:15 +00002186}
2187
2188SKIP:
2189{
2190 " "
2191| "\t"
2192| "\r"
2193| "\n"
2194}
2195
2196SKIP:
2197{
2198 <"//" (~["\n"])* "\n">
2199}
2200
2201SKIP:
2202{
2203 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2204}
2205
2206
2207SKIP:
2208{
2209 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2210}
2211
2212<INSIDE_COMMENT>
2213SPECIAL_TOKEN:
2214{
2215 <"+"(" ")*(~["*"])*>
2216}
2217
2218<INSIDE_COMMENT>
2219SKIP:
2220{
2221 <"/*"> {commentDepth++;}
2222}
2223
2224<INSIDE_COMMENT>
2225SKIP:
2226{
2227 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2228| <~[]>
2229}