blob: 4fdae83b2f503d66f4bd7f518f518af277a5a477 [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
ramangrover299f76a5e2013-06-18 10:25:17 -070088 private static class FunctionName {
89 public String dataverse = null;
90 public String library = null;
91 public String function = null;
92 }
93
vinayakb38b7ca42012-03-05 05:44:15 +000094 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070095 if (t.specialToken == null) {
96 return null;
97 }
98 String s = t.specialToken.image;
99 int n = s.length();
100 if (n < 2) {
101 return null;
102 }
103 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000104 }
105
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000106 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700107 this(new StringReader(s));
108 super.setInput(s);
109 }
vinayakb38b7ca42012-03-05 05:44:15 +0000110
Till Westmann31c21f92013-05-08 09:21:53 -0700111 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
112 File file = new File(args[0]);
113 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
114 AQLParser parser = new AQLParser(fis);
115 List<Statement> st = parser.Statement();
116 //st.accept(new AQLPrintVisitor(), 0);
117 }
vinayakb38b7ca42012-03-05 05:44:15 +0000118}
119
120PARSER_END(AQLParser)
121
122
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000123List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000124{
vinayakb38b7ca42012-03-05 05:44:15 +0000125 scopeStack.push(RootScopeFactory.createRootScope(this));
126 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700127 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000128}
129{
Till Westmann31c21f92013-05-08 09:21:53 -0700130 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000131 {
Till Westmann31c21f92013-05-08 09:21:53 -0700132 decls.add(stmt);
133 }
134 )*
135 <EOF>
136 {
137 return decls;
138 }
139}
140
141Statement SingleStatement() throws ParseException:
142{
143 Statement stmt = null;
144}
145{
146 (
147 stmt = DataverseDeclaration()
148 | stmt = FunctionDeclaration()
149 | stmt = CreateStatement()
150 | stmt = LoadStatement()
151 | stmt = DropStatement()
152 | stmt = WriteStatement()
153 | stmt = SetStatement()
154 | stmt = InsertStatement()
155 | stmt = DeleteStatement()
156 | stmt = UpdateStatement()
157 | stmt = FeedStatement()
158 | stmt = Query()
159 )
160 {
161 return stmt;
162 }
163}
164
165DataverseDecl DataverseDeclaration() throws ParseException:
166{
Till Westmann14a20a72013-05-09 00:06:24 -0700167 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700168}
169{
Till Westmanna4242bc2013-05-08 17:49:55 -0700170 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700171 {
Till Westmann14a20a72013-05-09 00:06:24 -0700172 defaultDataverse = dvName;
173 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700174 }
175}
176
177Statement CreateStatement() throws ParseException:
178{
179 String hint = null;
180 boolean dgen = false;
181 Statement stmt = null;
182}
183{
184 "create"
185 (
186 {
187 hint = getHint(token);
188 if (hint != null && hint.startsWith(DGEN_HINT)) {
189 dgen = true;
190 }
191 }
192 stmt = TypeSpecification(hint, dgen)
193 | stmt = NodegroupSpecification()
194 | stmt = DatasetSpecification()
195 | stmt = IndexSpecification()
196 | stmt = DataverseSpecification()
197 | stmt = FunctionSpecification()
198 )
199 {
200 return stmt;
201 }
202}
203
204TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
205{
206 Pair<Identifier,Identifier> nameComponents = null;
207 boolean ifNotExists = false;
208 TypeExpression typeExpr = null;
209}
210{
ramangrover299f76a5e2013-06-18 10:25:17 -0700211 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700212 "as" typeExpr = TypeExpr()
213 {
214 long numValues = -1;
215 String filename = null;
216 if (dgen) {
217 String splits[] = hint.split(" +");
218 if (splits.length != 3) {
219 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
220 }
221 filename = splits[1];
222 numValues = Long.parseLong(splits[2]);
223 }
224 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
225 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
226 }
227}
228
229
230NodegroupDecl NodegroupSpecification() throws ParseException:
231{
Till Westmann14a20a72013-05-09 00:06:24 -0700232 String name = null;
233 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700234 boolean ifNotExists = false;
235 List<Identifier>ncNames = null;
236}
237{
Till Westmanna4242bc2013-05-08 17:49:55 -0700238 "nodegroup" name = Identifier()
239 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700240 {
241 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700242 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700243 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700244 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700245 {
Till Westmann14a20a72013-05-09 00:06:24 -0700246 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700247 }
248 )*
249 {
Till Westmann14a20a72013-05-09 00:06:24 -0700250 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700251 }
252}
253
254DatasetDecl DatasetSpecification() throws ParseException:
255{
256 Pair<Identifier,Identifier> nameComponents = null;
257 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700258 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700259 String adapterName = null;
260 Map<String,String> properties = null;
261 FunctionSignature appliedFunction = null;
262 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700263 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700264 Map<String,String> hints = new HashMap<String,String>();
265 DatasetDecl dsetDecl = null;
266}
267{
268 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700269 "external" <DATASET> nameComponents = QualifiedName()
270 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
271 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700272 "using" adapterName = AdapterName() properties = Configuration()
273 ( "hints" hints = Properties() )?
274 {
275 ExternalDetailsDecl edd = new ExternalDetailsDecl();
276 edd.setAdapter(adapterName);
277 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700278 dsetDecl = new DatasetDecl(nameComponents.first,
279 nameComponents.second,
280 new Identifier(typeName),
281 hints,
282 DatasetType.EXTERNAL,
283 edd,
284 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700285 }
286
Till Westmanna4242bc2013-05-08 17:49:55 -0700287 | "feed" <DATASET> nameComponents = QualifiedName()
288 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
289 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700290 "using" adapterName = AdapterName() properties = Configuration()
291 (appliedFunction = ApplyFunction())? primaryKeyFields = PrimaryKey()
Till Westmanna4242bc2013-05-08 17:49:55 -0700292 ( "on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700293 ( "hints" hints = Properties() )?
294 {
Till Westmann14a20a72013-05-09 00:06:24 -0700295 FeedDetailsDecl fdd = new FeedDetailsDecl(adapterName,
296 properties,
297 appliedFunction,
298 nodeGroupName != null
299 ? new Identifier(nodeGroupName)
300 : null,
301 primaryKeyFields);
302 dsetDecl = new DatasetDecl(nameComponents.first,
303 nameComponents.second,
304 new Identifier(typeName),
305 hints,
306 DatasetType.FEED,
307 fdd,
308 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700309 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700310 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700311 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
312 ifNotExists = IfNotExists()
313 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700314 ( "hints" hints = Properties() )?
315 {
Till Westmann14a20a72013-05-09 00:06:24 -0700316 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
317 ? new Identifier(nodeGroupName)
318 : null,
319 primaryKeyFields);
320 dsetDecl = new DatasetDecl(nameComponents.first,
321 nameComponents.second,
322 new Identifier(typeName),
323 hints,
324 DatasetType.INTERNAL,
325 idd,
326 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700327 }
328 )
329 {
330 return dsetDecl;
331 }
332}
333
334CreateIndexStatement IndexSpecification() throws ParseException:
335{
336 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700337 String indexName = null;
338 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700339 boolean ifNotExists = false;
340 Pair<Identifier,Identifier> nameComponents = null;
341 IndexParams indexType = null;
342}
343{
Till Westmanna4242bc2013-05-08 17:49:55 -0700344 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700345 ifNotExists = IfNotExists()
346 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700347 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700348 {
Till Westmann14a20a72013-05-09 00:06:24 -0700349 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700350 }
Till Westmann14a20a72013-05-09 00:06:24 -0700351 ) ("," fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700352 {
Till Westmann14a20a72013-05-09 00:06:24 -0700353 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700354 }
355 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
356 {
Till Westmann14a20a72013-05-09 00:06:24 -0700357 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700358 cis.setIfNotExists(ifNotExists);
359 cis.setDataverseName(nameComponents.first);
360 cis.setDatasetName(nameComponents.second);
361 if (indexType != null) {
362 cis.setIndexType(indexType.type);
363 cis.setGramLength(indexType.gramLength);
364 }
365 return cis;
366 }
367}
368
369IndexParams IndexType() throws ParseException:
370{
371 IndexType type = null;
372 int gramLength = 0;
373}
374{
375 ("btree"
376 {
377 type = IndexType.BTREE;
378 }
379 | "rtree"
380 {
381 type = IndexType.RTREE;
382 }
383 | "keyword"
384 {
Till Westmann31c21f92013-05-08 09:21:53 -0700385 type = IndexType.FUZZY_WORD_INVIX;
386 }
387 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
388 {
Till Westmann31c21f92013-05-08 09:21:53 -0700389 type = IndexType.FUZZY_NGRAM_INVIX;
390 gramLength = Integer.valueOf(token.image);
391 }
392 <RIGHTPAREN>)
393 {
394 return new IndexParams(type, gramLength);
395 }
396}
397
398CreateDataverseStatement DataverseSpecification() throws ParseException :
399{
Till Westmann14a20a72013-05-09 00:06:24 -0700400 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700401 boolean ifNotExists = false;
402 String format = null;
403}
404{
Till Westmanna4242bc2013-05-08 17:49:55 -0700405 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700406 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700407 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700408 {
Till Westmann14a20a72013-05-09 00:06:24 -0700409 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700410 }
411}
412
413CreateFunctionStatement FunctionSpecification() throws ParseException:
414{
415 FunctionSignature signature;
416 boolean ifNotExists = false;
417 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
418 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700419 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700420 Expression functionBodyExpr;
421 Token beginPos;
422 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700423 FunctionName fctName = null;
424
Till Westmann31c21f92013-05-08 09:21:53 -0700425 createNewScope();
426}
427{
ramangrover299f76a5e2013-06-18 10:25:17 -0700428 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700429 ifNotExists = IfNotExists()
ramangrover299f76a5e2013-06-18 10:25:17 -0700430 <LEFTPAREN> (<VARIABLE>
431 {
432 var = new VarIdentifier();
433 var.setValue(token.image);
434 paramList.add(var);
435 getCurrentScope().addNewVarSymbolToScope(var);
436 }
437 ("," <VARIABLE>
438 {
439 var = new VarIdentifier();
440 var.setValue(token.image);
441 paramList.add(var);
442 getCurrentScope().addNewVarSymbolToScope(var);
443 }
444 )*)? <RIGHTPAREN> "{"
Till Westmannd7dcb122013-05-16 13:19:09 -0700445 {
446 beginPos = token;
447 }
448 functionBodyExpr = Expression() "}"
449 {
450 endPos = token;
451 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700452 // TODO use fctName.library
453 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700454 getCurrentScope().addFunctionDescriptor(signature, false);
455 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
456 }
457}
458
459List<VarIdentifier> ParameterList() throws ParseException:
460{
461 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
462 VarIdentifier var = null;
463}
464{
Till Westmann31c21f92013-05-08 09:21:53 -0700465 <LEFTPAREN> (<VARIABLE>
466 {
467 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700468 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700469 paramList.add(var);
470 getCurrentScope().addNewVarSymbolToScope(var);
471 }
472 ("," <VARIABLE>
473 {
474 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700475 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700476 paramList.add(var);
477 getCurrentScope().addNewVarSymbolToScope(var);
478 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700479 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700480 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700481 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700482 }
483}
484
485boolean IfNotExists() throws ParseException:
486{
487}
488{
489 ( "if not exists"
490 {
491 return true;
492 }
493 )?
494 {
495 return false;
496 }
497}
498
499FunctionSignature ApplyFunction() throws ParseException:
500{
501 FunctionSignature funcSig = null;
502}
503{
504 "apply" "function" funcSig = FunctionSignature()
505 {
506 return funcSig;
507 }
508}
509
ramangrover29566b3a92013-05-28 09:07:10 -0700510String GetPolicy() throws ParseException:
511{
512 String policy = null;
513}
514{
515 "using" "policy" policy = Identifier()
516 {
517 return policy;
518 }
519
520}
521
Till Westmann31c21f92013-05-08 09:21:53 -0700522FunctionSignature FunctionSignature() throws ParseException:
523{
ramangrover299f76a5e2013-06-18 10:25:17 -0700524 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700525 int arity = 0;
526}
527{
ramangrover299f76a5e2013-06-18 10:25:17 -0700528 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700529 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700530 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700531 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
532 throw new ParseException(" invalid arity:" + arity);
533 }
534
ramangrover299f76a5e2013-06-18 10:25:17 -0700535 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700536 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
537 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700538 }
539}
540
541List<String> PrimaryKey() throws ParseException:
542{
Till Westmann14a20a72013-05-09 00:06:24 -0700543 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700544 List<String> primaryKeyFields = new ArrayList<String>();
545}
546{
Till Westmann14a20a72013-05-09 00:06:24 -0700547 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700548 {
Till Westmann14a20a72013-05-09 00:06:24 -0700549 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700550 }
Till Westmann14a20a72013-05-09 00:06:24 -0700551 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700552 {
Till Westmann14a20a72013-05-09 00:06:24 -0700553 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700554 }
555 )*
556 {
557 return primaryKeyFields;
558 }
559}
560
561Statement DropStatement() throws ParseException:
562{
Till Westmann14a20a72013-05-09 00:06:24 -0700563 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700564 Pair<Identifier,Identifier> pairId = null;
565 Triple<Identifier,Identifier,Identifier> tripleId = null;
566 FunctionSignature funcSig = null;
567 boolean ifExists = false;
568 Statement stmt = null;
569}
570{
571 "drop"
572 (
573 <DATASET> pairId = QualifiedName() ifExists = IfExists()
574 {
575 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
576 }
577 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
578 {
579 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
580 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700581 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700582 {
Till Westmann14a20a72013-05-09 00:06:24 -0700583 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700584 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700585 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700586 {
587 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
588 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700589 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700590 {
Till Westmann14a20a72013-05-09 00:06:24 -0700591 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700592 }
593 | "function" funcSig = FunctionSignature() ifExists = IfExists()
594 {
595 stmt = new FunctionDropStatement(funcSig, ifExists);
596 }
597 )
598 {
599 return stmt;
600 }
601}
602
603boolean IfExists() throws ParseException :
604{
605}
606{
607 ( "if" "exists"
608 {
609 return true;
610 }
611 )?
612 {
613 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000614 }
615}
616
617InsertStatement InsertStatement() throws ParseException:
618{
Till Westmann31c21f92013-05-08 09:21:53 -0700619 Pair<Identifier,Identifier> nameComponents = null;
620 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000621}
622{
Till Westmann31c21f92013-05-08 09:21:53 -0700623 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
624 {
625 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
626 }
vinayakb38b7ca42012-03-05 05:44:15 +0000627}
628
629DeleteStatement DeleteStatement() throws ParseException:
630{
Till Westmann31c21f92013-05-08 09:21:53 -0700631 VariableExpr var = null;
632 Expression condition = null;
633 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000634}
635{
Till Westmann31c21f92013-05-08 09:21:53 -0700636 "delete" var = Variable()
637 {
638 getCurrentScope().addNewVarSymbolToScope(var.getVar());
639 }
640 "from" <DATASET> nameComponents = QualifiedName()
641 ("where" condition = Expression())?
642 {
643 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
644 }
vinayakb38b7ca42012-03-05 05:44:15 +0000645}
646
647UpdateStatement UpdateStatement() throws ParseException:
648{
Till Westmann31c21f92013-05-08 09:21:53 -0700649 VariableExpr vars;
650 Expression target;
651 Expression condition;
652 UpdateClause uc;
653 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000654}
655{
Till Westmann31c21f92013-05-08 09:21:53 -0700656 "update" vars = Variable() "in" target = Expression()
657 "where" condition = Expression()
658 <LEFTPAREN> (uc = UpdateClause()
659 {
660 ucs.add(uc);
661 }
662 ("," uc = UpdateClause()
663 {
664 ucs.add(uc);
665 }
666 )*) <RIGHTPAREN>
667 {
668 return new UpdateStatement(vars, target, condition, ucs);
669 }
vinayakb38b7ca42012-03-05 05:44:15 +0000670}
671
vinayakb38b7ca42012-03-05 05:44:15 +0000672UpdateClause UpdateClause() throws ParseException:
673{
Till Westmann31c21f92013-05-08 09:21:53 -0700674 Expression target = null;
675 Expression value = null ;
676 InsertStatement is = null;
677 DeleteStatement ds = null;
678 UpdateStatement us = null;
679 Expression condition = null;
680 UpdateClause ifbranch = null;
681 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000682}
683{
684 "set" target = Expression() ":=" value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700685 | is = InsertStatement()
686 | ds = DeleteStatement()
687 | us = UpdateStatement()
688 | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN>
689 "then" ifbranch = UpdateClause()
690 [LOOKAHEAD(1) "else" elsebranch = UpdateClause()]
691 {
692 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
693 }
vinayakb38b7ca42012-03-05 05:44:15 +0000694}
695
vinayakb38b7ca42012-03-05 05:44:15 +0000696Statement SetStatement() throws ParseException:
697{
698 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700699 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000700}
701{
Till Westmann7d535322013-05-09 00:40:02 -0700702 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700703 {
Till Westmann31c21f92013-05-08 09:21:53 -0700704 return new SetStatement(pn, pv);
705 }
vinayakb38b7ca42012-03-05 05:44:15 +0000706}
707
708Statement WriteStatement() throws ParseException:
709{
Till Westmann14a20a72013-05-09 00:06:24 -0700710 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000711 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000712 Statement stmt = null;
713 Query query;
714 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000715 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000716}
717{
Till Westmann31c21f92013-05-08 09:21:53 -0700718 "write" ((
Till Westmann7d535322013-05-09 00:40:02 -0700719 "output" "to" nodeName = Identifier() ":" fileName = StringLiteral()
720 ( "using" writerClass = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700721 {
Till Westmann14a20a72013-05-09 00:06:24 -0700722 stmt = new WriteStatement(new Identifier(nodeName), fileName, writerClass);
Till Westmann31c21f92013-05-08 09:21:53 -0700723 }
724 ) | (
725 "into" <DATASET>
726 {
727 nameComponents = QualifiedName();
728 }
729 <LEFTPAREN> query = Query() <RIGHTPAREN>
730 {
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000731 stmt = new WriteFromQueryResultStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700732 }
733 ))
vinayakb38b7ca42012-03-05 05:44:15 +0000734 {
735 return stmt;
736 }
737}
738
vinayakb38b7ca42012-03-05 05:44:15 +0000739LoadFromFileStatement LoadStatement() throws ParseException:
740{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000741 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000742 Identifier datasetName = null;
743 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000744 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000745 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000746 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000747}
748{
Till Westmann31c21f92013-05-08 09:21:53 -0700749 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000750 {
Till Westmann31c21f92013-05-08 09:21:53 -0700751 dataverseName = nameComponents.first;
752 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000753 }
Till Westmann31c21f92013-05-08 09:21:53 -0700754 "using" adapterName = AdapterName() properties = Configuration()
755 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000756 {
Till Westmann31c21f92013-05-08 09:21:53 -0700757 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000758 }
759 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700760 {
761 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
762 }
vinayakb38b7ca42012-03-05 05:44:15 +0000763}
764
vinayakb38b7ca42012-03-05 05:44:15 +0000765
Till Westmann31c21f92013-05-08 09:21:53 -0700766String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000767{
ramangrover29669d8f62013-02-11 06:03:32 +0000768 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000769}
770{
Till Westmann68d99652013-05-09 11:15:21 -0700771 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000772 {
Till Westmann7d535322013-05-09 00:40:02 -0700773 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000774 }
vinayakb38b7ca42012-03-05 05:44:15 +0000775}
776
Till Westmann31c21f92013-05-08 09:21:53 -0700777Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000778{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000779 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700780 Map<String,String> configuration = null;
781 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700782 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000783}
784{
Till Westmann31c21f92013-05-08 09:21:53 -0700785 (
ramangrover29566b3a92013-05-28 09:07:10 -0700786 "begin" "feed" nameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700787 {
ramangrover29566b3a92013-05-28 09:07:10 -0700788 stmt = new BeginFeedStatement(nameComponents.first, nameComponents.second, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700789 }
790 | "suspend" "feed" nameComponents = QualifiedName()
791 {
792 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, nameComponents.first, nameComponents.second);
793 }
794 | "resume" "feed" nameComponents = QualifiedName()
795 {
796 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, nameComponents.first, nameComponents.second);
797 }
798 | "end" "feed" nameComponents = QualifiedName()
799 {
800 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.END, nameComponents.first, nameComponents.second);
801 }
802 | "alter" "feed" nameComponents = QualifiedName() "set" configuration = Configuration()
803 {
804 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
805 }
806 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000807 {
Till Westmann31c21f92013-05-08 09:21:53 -0700808 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000809 }
810}
811
Till Westmann31c21f92013-05-08 09:21:53 -0700812Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000813{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000814 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700815 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000816}
817{
Till Westmann31c21f92013-05-08 09:21:53 -0700818 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000819 {
Till Westmann31c21f92013-05-08 09:21:53 -0700820 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000821 }
Till Westmann31c21f92013-05-08 09:21:53 -0700822 ( "," keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000823 {
Till Westmann31c21f92013-05-08 09:21:53 -0700824 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000825 }
Till Westmann31c21f92013-05-08 09:21:53 -0700826 )* )? <RIGHTPAREN>
827 {
828 return configuration;
829 }
830}
831
832Pair<String, String> KeyValuePair() throws ParseException:
833{
834 String key;
835 String value;
836}
837{
Till Westmann7d535322013-05-09 00:40:02 -0700838 <LEFTPAREN> key = StringLiteral() "=" value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700839 {
840 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000841 }
Till Westmann31c21f92013-05-08 09:21:53 -0700842}
843
844Map<String,String> Properties() throws ParseException:
845{
846 Map<String,String> properties = new HashMap<String,String>();
847 Pair<String, String> property;
848}
849{
850 ( <LEFTPAREN> property = Property()
851 {
852 properties.put(property.first, property.second);
853 }
854 ( "," property = Property()
855 {
856 properties.put(property.first, property.second);
857 }
858 )* <RIGHTPAREN> )?
859 {
860 return properties;
861 }
862}
863
864Pair<String, String> Property() throws ParseException:
865{
866 String key;
867 String value;
868}
869{
Till Westmann7d535322013-05-09 00:40:02 -0700870 key = Identifier() "=" ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700871 {
872 try {
873 value = "" + Long.valueOf(token.image);
874 } catch (NumberFormatException nfe) {
875 throw new ParseException("inapproriate value: " + token.image);
876 }
877 }
878 )
879 {
880 return new Pair<String, String>(key.toUpperCase(), value);
881 }
vinayakb38b7ca42012-03-05 05:44:15 +0000882}
883
884TypeExpression TypeExpr() throws ParseException:
885{
886 TypeExpression typeExpr = null;
887}
888{
889 (
890 typeExpr = RecordTypeDef()
891 | typeExpr = TypeReference()
892 | typeExpr = OrderedListTypeDef()
893 | typeExpr = UnorderedListTypeDef()
894 )
895 {
896 return typeExpr;
897 }
898}
899
900RecordTypeDefinition RecordTypeDef() throws ParseException:
901{
902 RecordTypeDefinition recType = new RecordTypeDefinition();
903 RecordTypeDefinition.RecordKind recordKind = null;
904}
905{
906 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
907 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
908 "{"
909 {
910 String hint = getHint(token);
911 if (hint != null) {
912 String splits[] = hint.split(" +");
913 if (splits[0].equals(GEN_FIELDS_HINT)) {
914 if (splits.length != 5) {
915 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
916 }
917 if (!splits[1].equals("int")) {
918 throw new ParseException("The only supported type for gen-fields is int.");
919 }
920 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
921 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
922 recType.setUndeclaredFieldsDataGen(ufdg);
923 }
924 }
925
926 }
927 (
928 RecordField(recType)
929 ( "," RecordField(recType) )*
930 )?
931 "}"
932 {
933 if (recordKind == null) {
934 recordKind = RecordTypeDefinition.RecordKind.OPEN;
935 }
936 recType.setRecordKind(recordKind);
937 return recType;
938 }
939}
940
941void RecordField(RecordTypeDefinition recType) throws ParseException:
942{
943 String fieldName;
944 TypeExpression type = null;
945 boolean nullable = false;
946}
947{
Till Westmann14a20a72013-05-09 00:06:24 -0700948 fieldName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000949 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700950 fieldName = token.image;
951 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +0000952 IRecordFieldDataGen rfdg = null;
953 if (hint != null) {
954 String splits[] = hint.split(" +");
955 if (splits[0].equals(VAL_FILE_HINT)) {
956 File[] valFiles = new File[splits.length - 1];
957 for (int k=1; k<splits.length; k++) {
958 valFiles[k-1] = new File(splits[k]);
959 }
960 rfdg = new FieldValFileDataGen(valFiles);
961 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
962 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
963 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
964 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
965 } else if (splits[0].equals(LIST_HINT)) {
966 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
967 } else if (splits[0].equals(INTERVAL_HINT)) {
968 FieldIntervalDataGen.ValueType vt;
969 if (splits[1].equals("int")) {
970 vt = FieldIntervalDataGen.ValueType.INT;
971 } else if (splits[1].equals("long")) {
972 vt = FieldIntervalDataGen.ValueType.LONG;
973 } else if (splits[1].equals("float")) {
974 vt = FieldIntervalDataGen.ValueType.FLOAT;
975 } else if (splits[1].equals("double")) {
976 vt = FieldIntervalDataGen.ValueType.DOUBLE;
977 } else {
978 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
979 }
980 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
981 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
982 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
983 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
984 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
985 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
986 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
987 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
988 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
989 } else if (splits[0].equals(AUTO_HINT)) {
990 rfdg = new AutoDataGen(splits[1]);
991 }
992 }
993 }
994 ":"
995 ( type = TypeExpr() )
996 ("?" { nullable = true; } )?
997 {
998 recType.addField(fieldName, type, nullable, rfdg);
999 }
1000}
1001
1002TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001003{
Till Westmann14a20a72013-05-09 00:06:24 -07001004 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001005}
1006{
1007 id = Identifier()
1008 {
Till Westmann14a20a72013-05-09 00:06:24 -07001009 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001010 }
vinayakb38b7ca42012-03-05 05:44:15 +00001011}
1012
1013OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1014{
1015 TypeExpression type = null;
1016}
1017{
1018 "["
1019 ( type = TypeExpr() )
1020 "]"
1021 {
1022 return new OrderedListTypeDefinition(type);
1023 }
1024}
1025
1026
1027UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1028{
1029 TypeExpression type = null;
1030}
1031{
1032 "{{"
1033 ( type = TypeExpr() )
1034 "}}"
1035 {
1036 return new UnorderedListTypeDefinition(type);
1037 }
1038}
1039
ramangrover299f76a5e2013-06-18 10:25:17 -07001040FunctionName FunctionName() throws ParseException:
1041{
1042 String first = null;
1043 String second = null;
1044 String third = null;
1045 boolean secondAfterDot = false;
1046}
1047{
1048 first = Identifier() ( "." second = Identifier()
1049 {
1050 secondAfterDot = true;
1051 }
1052 ("#" third = Identifier())? | "#" second = Identifier() )?
1053 {
1054 FunctionName result = new FunctionName();
1055 if (second == null) {
1056 result.dataverse = defaultDataverse;
1057 result.library = null;
1058 result.function = first;
1059 } else if (third == null) {
1060 if (secondAfterDot) {
1061 result.dataverse = first;
1062 result.library = null;
1063 result.function = second;
1064 } else {
1065 result.dataverse = defaultDataverse;
1066 result.library = first;
1067 result.function = second;
1068 }
1069 } else {
1070 result.dataverse = first;
1071 result.library = second;
1072 result.function = third;
1073 }
1074 return result;
1075 }
1076}
Till Westmann31c21f92013-05-08 09:21:53 -07001077
ramangrover299f76a5e2013-06-18 10:25:17 -07001078
1079Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001080{
Till Westmann31c21f92013-05-08 09:21:53 -07001081 Pair<Identifier,Identifier> name = null;
1082}
1083{
1084 name = QualifiedName()
1085 {
1086 if (name.first == null) {
1087 name.first = new Identifier(defaultDataverse);
1088 }
1089 return name;
1090 }
1091}
1092
Till Westmann14a20a72013-05-09 00:06:24 -07001093String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001094{
Till Westmann68d99652013-05-09 11:15:21 -07001095 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001096}
1097{
1098 <IDENTIFIER>
1099 {
Till Westmann14a20a72013-05-09 00:06:24 -07001100 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001101 }
Till Westmann68d99652013-05-09 11:15:21 -07001102 | lit = StringLiteral()
1103 {
1104 return lit;
1105 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001106}
1107
Till Westmann7d535322013-05-09 00:40:02 -07001108String StringLiteral() throws ParseException:
1109{
1110}
1111{
1112 <STRING_LITERAL>
1113 {
1114 return removeQuotesAndEscapes(token.image);
1115 }
1116}
1117
Till Westmann31c21f92013-05-08 09:21:53 -07001118Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1119{
Till Westmann14a20a72013-05-09 00:06:24 -07001120 String first = null;
1121 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001122}
1123{
Till Westmanna4242bc2013-05-08 17:49:55 -07001124 first = Identifier() ("." second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001125 {
Till Westmann14a20a72013-05-09 00:06:24 -07001126 Identifier id1 = null;
1127 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001128 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001129 id2 = new Identifier(first);
1130 } else
1131 {
1132 id1 = new Identifier(first);
1133 id2 = new Identifier(second);
1134 }
1135 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001136 }
1137}
1138
Till Westmann31c21f92013-05-08 09:21:53 -07001139Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001140{
Till Westmann14a20a72013-05-09 00:06:24 -07001141 String first = null;
1142 String second = null;
1143 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001144}
1145{
Till Westmanna4242bc2013-05-08 17:49:55 -07001146 first = Identifier() "." second = Identifier() ("." third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001147 {
Till Westmann14a20a72013-05-09 00:06:24 -07001148 Identifier id1 = null;
1149 Identifier id2 = null;
1150 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001151 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001152 id2 = new Identifier(first);
1153 id3 = new Identifier(second);
1154 } else {
1155 id1 = new Identifier(first);
1156 id2 = new Identifier(second);
1157 id3 = new Identifier(third);
1158 }
1159 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001160 }
1161}
1162
vinayakb38b7ca42012-03-05 05:44:15 +00001163FunctionDecl FunctionDeclaration() throws ParseException:
1164{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001165 FunctionDecl funcDecl;
1166 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001167 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001168 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1169 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001170 createNewScope();
1171}
1172{
Till Westmannd7dcb122013-05-16 13:19:09 -07001173 "declare" "function" functionName = Identifier()
1174 paramList = ParameterList()
1175 "{" funcBody = Expression() "}"
vinayakb38b7ca42012-03-05 05:44:15 +00001176 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001177 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001178 getCurrentScope().addFunctionDescriptor(signature, false);
1179 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001180 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001181 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001182 }
1183}
1184
vinayakb38b7ca42012-03-05 05:44:15 +00001185
Till Westmann31c21f92013-05-08 09:21:53 -07001186Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001187{
1188 Query query = new Query();
1189 Expression expr;
1190}
1191{
Till Westmann31c21f92013-05-08 09:21:53 -07001192 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001193 {
1194 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001195 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001196 return query;
1197 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001198
vinayakb38b7ca42012-03-05 05:44:15 +00001199}
1200
1201
1202
1203Expression Expression():
1204{
1205 Expression expr = null;
1206 Expression exprP = null;
1207}
1208{
1209(
1210
1211//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1212 expr = OperatorExpr()
1213 | expr = IfThenElse()
1214 | expr = FLWOGR()
1215 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001216
vinayakb38b7ca42012-03-05 05:44:15 +00001217
1218)
1219 {
1220 return (exprP==null) ? expr : exprP;
1221 }
1222}
1223
1224
1225
1226Expression OperatorExpr()throws ParseException:
1227{
1228 OperatorExpr op = null;
1229 Expression operand = null;
1230}
1231{
1232 operand = AndExpr()
1233 (
1234
1235 "or"
1236 {
1237 if (op == null) {
1238 op = new OperatorExpr();
1239 op.addOperand(operand);
1240 op.setCurrentop(true);
1241 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001242 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001243 }
1244
1245 operand = AndExpr()
1246 {
1247 op.addOperand(operand);
1248 }
1249
1250 )*
1251
1252 {
1253 return op==null? operand: op;
1254 }
1255}
1256
1257Expression AndExpr()throws ParseException:
1258{
1259 OperatorExpr op = null;
1260 Expression operand = null;
1261}
1262{
1263 operand = RelExpr()
1264 (
1265
1266 "and"
1267 {
1268 if (op == null) {
1269 op = new OperatorExpr();
1270 op.addOperand(operand);
1271 op.setCurrentop(true);
1272 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001273 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001274 }
1275
1276 operand = RelExpr()
1277 {
1278 op.addOperand(operand);
1279 }
1280
1281 )*
1282
1283 {
1284 return op==null? operand: op;
1285 }
1286}
1287
1288
1289
1290Expression RelExpr()throws ParseException:
1291{
1292 OperatorExpr op = null;
1293 Expression operand = null;
1294 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001295 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001296}
1297{
1298 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001299 {
1300 if (operand instanceof VariableExpr) {
1301 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001302 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001303 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001304 }
1305 }
1306 }
1307
1308 (
1309 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1310 {
alexander.behm07617fd2012-07-25 10:13:50 +00001311 String mhint = getHint(token);
1312 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1313 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1314 }
vinayakb38b7ca42012-03-05 05:44:15 +00001315 if (op == null) {
1316 op = new OperatorExpr();
1317 op.addOperand(operand, broadcast);
1318 op.setCurrentop(true);
1319 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001320 }
1321 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001322 }
1323
1324 operand = AddExpr()
1325 {
alexander.behm07617fd2012-07-25 10:13:50 +00001326 broadcast = false;
1327 if (operand instanceof VariableExpr) {
1328 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001329 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1330 broadcast = true;
1331 }
alexander.behm07617fd2012-07-25 10:13:50 +00001332 }
vinayakb38b7ca42012-03-05 05:44:15 +00001333 op.addOperand(operand, broadcast);
1334 }
1335 )?
1336
1337 {
alexander.behm07617fd2012-07-25 10:13:50 +00001338 if (annotation != null) {
1339 op.addHint(annotation);
1340 }
vinayakb38b7ca42012-03-05 05:44:15 +00001341 return op==null? operand: op;
1342 }
1343}
1344
1345Expression AddExpr()throws ParseException:
1346{
1347 OperatorExpr op = null;
1348 Expression operand = null;
1349}
1350{
1351 operand = MultExpr()
1352
1353 ( ("+" | "-")
1354 {
1355 if (op == null) {
1356 op = new OperatorExpr();
1357 op.addOperand(operand);
1358 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001359 }
1360 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001361 }
1362
1363 operand = MultExpr()
1364 {
1365 op.addOperand(operand);
1366 }
1367 )*
1368
1369 {
1370 return op==null? operand: op;
1371 }
1372}
1373
1374Expression MultExpr()throws ParseException:
1375{
1376 OperatorExpr op = null;
1377 Expression operand = null;
1378}
1379{
1380 operand = UnionExpr()
1381
1382 (( "*" | "/" | "%" | <CARET> | "idiv")
1383 {
1384 if (op == null) {
1385 op = new OperatorExpr();
1386 op.addOperand(operand);
1387 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001388 }
1389 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001390 }
1391 operand = UnionExpr()
1392 {
1393 op.addOperand(operand);
1394 }
1395 )*
1396
1397 {
1398 return op==null?operand:op;
1399 }
1400}
1401
1402Expression UnionExpr() throws ParseException:
1403{
1404 UnionExpr union = null;
1405 Expression operand1 = null;
1406 Expression operand2 = null;
1407}
1408{
1409 operand1 = UnaryExpr()
1410 ("union"
1411 (operand2 = UnaryExpr()) {
1412 if (union == null) {
1413 union = new UnionExpr();
1414 union.addExpr(operand1);
1415 }
1416 union.addExpr(operand2);
1417 } )*
1418 {
1419 return (union == null)? operand1: union;
1420 }
1421}
1422
1423Expression UnaryExpr() throws ParseException:
1424{
1425 Expression uexpr = null;
1426 Expression expr = null;
1427}
1428{
1429 (( "+"|"-")
1430 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001431 uexpr = new UnaryExpr();
1432 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001433 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001434 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001435 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1436 else
1437 throw new ParseException();
1438 }
1439 )?
1440
1441 expr = ValueExpr()
1442 {
1443 if(uexpr!=null){
1444 ((UnaryExpr)uexpr).setExpr(expr);
1445 return uexpr;
1446 }
1447 else{
1448 return expr;
1449 }
1450 }
1451}
1452
Till Westmann04478e72013-05-13 23:01:34 -07001453Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001454{
1455 Expression expr = null;
1456 Identifier ident = null;
1457 AbstractAccessor fa = null;
1458 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001459}
1460{
Till Westmann04478e72013-05-13 23:01:34 -07001461 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001462 {
Till Westmann04478e72013-05-13 23:01:34 -07001463 fa = (fa == null ? new FieldAccessor(expr, ident)
1464 : new FieldAccessor(fa, ident));
1465 }
1466 | index = Index()
1467 {
1468 fa = (fa == null ? new IndexAccessor(expr, index)
1469 : new IndexAccessor(fa, index));
1470 }
1471 )*
1472 {
1473 return fa == null ? expr : fa;
1474 }
vinayakb38b7ca42012-03-05 05:44:15 +00001475}
1476
1477Identifier Field() throws ParseException:
1478{
Till Westmann14a20a72013-05-09 00:06:24 -07001479 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001480}
1481{
Till Westmanna4242bc2013-05-08 17:49:55 -07001482 "." ident = Identifier()
1483 {
Till Westmann14a20a72013-05-09 00:06:24 -07001484 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001485 }
vinayakb38b7ca42012-03-05 05:44:15 +00001486}
1487
1488int Index() throws ParseException:
1489{
1490 Expression expr = null;
1491 int idx = -2;
1492}
1493{
1494 "[" ( expr = Expression()
1495 {
1496 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1497 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001498 Literal lit = ((LiteralExpr)expr).getValue();
1499 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1500 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001501 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001502 }
vinayakb38b7ca42012-03-05 05:44:15 +00001503 else {
1504 throw new ParseException("Index should be an INTEGER");
1505 }
1506 }
1507
1508 }
1509
1510 | "?"
1511 {
1512 idx = IndexAccessor.ANY;
1513 // ANY
1514 }
1515
1516 )
1517
1518 "]"
1519 {
1520 return idx;
1521 }
1522}
1523
1524
1525Expression PrimaryExpr()throws ParseException:
1526{
1527 Expression expr = null;
1528}
1529{
Till Westmann68d99652013-05-09 11:15:21 -07001530 ( LOOKAHEAD(2)
1531 expr = FunctionCallExpr()
1532 | expr = Literal()
1533 | expr = DatasetAccessExpression()
1534 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001535 {
1536 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001537 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001538 }
Till Westmann68d99652013-05-09 11:15:21 -07001539 | expr = ListConstructor()
1540 | expr = RecordConstructor()
1541 | expr = ParenthesizedExpression()
1542 )
1543 {
1544 return expr;
1545 }
vinayakb38b7ca42012-03-05 05:44:15 +00001546}
1547
1548Expression Literal() throws ParseException:
1549{
vinayakb38b7ca42012-03-05 05:44:15 +00001550 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001551 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001552}
1553{
Till Westmann7d535322013-05-09 00:40:02 -07001554 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001555 {
Till Westmann7d535322013-05-09 00:40:02 -07001556 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001557 }
1558 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001559 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001560 try {
1561 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1562 } catch(NumberFormatException ex) {
1563 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1564 }
1565 }
1566 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001567 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001568 lit.setValue(new FloatLiteral(new Float(token.image)));
1569 }
1570 | <DOUBLE_LITERAL>
1571 {
1572 lit.setValue(new DoubleLiteral(new Double(token.image)));
1573 }
1574 | <NULL>
1575 {
1576 lit.setValue(NullLiteral.INSTANCE);
1577 }
1578 | <TRUE>
1579 {
1580 lit.setValue(TrueLiteral.INSTANCE);
1581 }
1582 | <FALSE>
1583 {
1584 lit.setValue(FalseLiteral.INSTANCE);
1585 }
1586 )
vinayakb38b7ca42012-03-05 05:44:15 +00001587 {
1588 return lit;
1589 }
1590}
1591
1592
1593VariableExpr VariableRef() throws ParseException:
1594{
1595 VariableExpr varExp = new VariableExpr();
1596 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001597}
1598{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001599 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001600 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001601 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001602 Identifier ident = lookupSymbol(varName);
1603 if (isInForbiddenScopes(varName)) {
1604 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.");
1605 }
1606 if(ident != null) { // exist such ident
1607 varExp.setIsNewVar(false);
1608 varExp.setVar((VarIdentifier)ident);
1609 } else {
1610 varExp.setVar(var);
1611 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001612 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001613 return varExp;
1614 }
1615}
1616
1617
1618VariableExpr Variable() throws ParseException:
1619{
1620 VariableExpr varExp = new VariableExpr();
1621 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001622}
1623{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001624 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001625 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001626 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001627 if(ident != null) { // exist such ident
1628 varExp.setIsNewVar(false);
1629 }
1630 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001631 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001632 return varExp;
1633 }
1634}
1635
1636Expression ListConstructor() throws ParseException:
1637{
1638 Expression expr = null;
1639}
1640{
1641 (
1642 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1643 )
1644
1645 {
1646 return expr;
1647 }
1648}
1649
1650
1651ListConstructor OrderedListConstructor() throws ParseException:
1652{
1653 ListConstructor expr = new ListConstructor();
1654 Expression tmp = null;
1655 List<Expression> exprList = new ArrayList<Expression>();
1656 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1657}
1658{
1659
1660 "["
1661 ( tmp = Expression()
1662 {
1663 exprList.add(tmp);
1664 }
1665
1666 ("," tmp = Expression() { exprList.add(tmp); })*
1667 )?
1668
1669 "]"
1670
1671 {
1672 expr.setExprList(exprList);
1673 return expr;
1674 }
1675}
1676
1677ListConstructor UnorderedListConstructor() throws ParseException:
1678{
1679 ListConstructor expr = new ListConstructor();
1680 Expression tmp = null;
1681 List<Expression> exprList = new ArrayList<Expression>();
1682 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1683}
1684{
1685
1686 "{{" ( tmp = Expression()
1687 {
1688 exprList.add(tmp);
1689 }
1690 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1691 {
1692 expr.setExprList(exprList);
1693 return expr;
1694 }
1695}
1696
1697RecordConstructor RecordConstructor() throws ParseException:
1698{
1699 RecordConstructor expr = new RecordConstructor();
1700 FieldBinding tmp = null;
1701 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1702}
1703{
1704 "{" (tmp = FieldBinding()
1705 {
1706 fbList.add(tmp);
1707 }
1708 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
1709 {
1710 expr.setFbList(fbList);
1711 return expr;
1712 }
1713}
1714
1715FieldBinding FieldBinding() throws ParseException:
1716{
1717 FieldBinding fb = new FieldBinding();
1718 Expression left, right;
1719}
1720{
1721 left = Expression() ":" right = Expression()
1722 {
1723 fb.setLeftExpr(left);
1724 fb.setRightExpr(right);
1725 return fb;
1726 }
1727}
1728
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001729
vinayakb38b7ca42012-03-05 05:44:15 +00001730Expression FunctionCallExpr() throws ParseException:
1731{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001732 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001733 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001734 Expression tmp;
1735 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001736 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001737 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001738}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001739{
ramangrover299f76a5e2013-06-18 10:25:17 -07001740 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001741 {
Till Westmann31c21f92013-05-08 09:21:53 -07001742 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001743 }
Till Westmann31c21f92013-05-08 09:21:53 -07001744 <LEFTPAREN> (tmp = Expression()
1745 {
1746 argList.add(tmp);
1747 arity ++;
1748 }
1749 ("," tmp = Expression()
1750 {
1751 argList.add(tmp);
1752 arity++;
1753 }
1754 )*)? <RIGHTPAREN>
1755 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001756 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001757 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001758 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001759 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001760 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001761 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001762 }
1763 callExpr = new CallExpr(signature,argList);
1764 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1765 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1766 }
1767 return callExpr;
1768 }
vinayakb38b7ca42012-03-05 05:44:15 +00001769}
1770
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001771
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001772Expression DatasetAccessExpression() throws ParseException:
1773{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001774 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001775 String arg1 = null;
1776 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001777 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001778}
1779{
Till Westmann14a20a72013-05-09 00:06:24 -07001780 <DATASET>
1781 {
Till Westmann14a20a72013-05-09 00:06:24 -07001782 funcName = token.image;
1783 }
1784 ( ( arg1 = Identifier() ( "." arg2 = Identifier() )? )
1785 {
1786 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001787 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001788 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001789 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001790 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001791 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001792 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001793 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1794 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1795 if (signature == null) {
1796 signature = new FunctionSignature(dataverse, funcName, 1);
1797 }
1798 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001799 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001800 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001801 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001802}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001803
vinayakb38b7ca42012-03-05 05:44:15 +00001804Expression ParenthesizedExpression() throws ParseException:
1805{
1806 Expression expr;
1807}
1808{
1809 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1810 {
1811 return expr;
1812 }
1813}
1814
1815Expression IfThenElse() throws ParseException:
1816{
1817 Expression condExpr;
1818 Expression thenExpr;
1819 Expression elseExpr;
1820 IfExpr ifExpr = new IfExpr();
1821}
1822{
1823 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
1824
1825 {
1826 ifExpr.setCondExpr(condExpr);
1827 ifExpr.setThenExpr(thenExpr);
1828 ifExpr.setElseExpr(elseExpr);
1829 return ifExpr;
1830 }
1831}
1832
1833Expression FLWOGR() throws ParseException:
1834{
1835 FLWOGRExpression flworg = new FLWOGRExpression();
1836 List<Clause> clauseList = new ArrayList<Clause>();
1837 Expression returnExpr;
1838 Clause tmp;
1839 createNewScope();
1840}
1841{
1842 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
1843 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
1844
1845 {
1846 flworg.setClauseList(clauseList);
1847 flworg.setReturnExpr(returnExpr);
1848 removeCurrentScope();
1849 return flworg;
1850 }
1851}
1852
1853Clause Clause()throws ParseException :
1854{
1855 Clause clause;
1856}
1857{
1858 (
1859 clause = ForClause()
1860 | clause = LetClause()
1861 | clause = WhereClause()
1862 | clause = OrderbyClause()
1863 | clause = GroupClause()
1864 | clause = LimitClause()
1865 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001866 )
1867 {
1868 return clause;
1869 }
1870}
1871
1872Clause ForClause()throws ParseException :
1873{
1874 ForClause fc = new ForClause();
1875 VariableExpr varExp;
1876 VariableExpr varPos = null;
1877 Expression inExp;
1878 extendCurrentScope();
1879}
1880{
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001881 "for" varExp = Variable() ("at" varPos = Variable())? "in" ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001882 {
1883 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001884 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001885 fc.setInExpr(inExp);
1886 if (varPos != null) {
1887 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001888 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001889 }
1890 return fc;
1891 }
1892}
1893
1894Clause LetClause() throws ParseException:
1895{
1896 LetClause lc = new LetClause();
1897 VariableExpr varExp;
1898 Expression beExp;
1899 extendCurrentScope();
1900}
1901{
ilovesoupb2527c12012-07-12 03:21:13 +00001902 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001903 {
1904 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001905 lc.setVarExpr(varExp);
1906 lc.setBeExpr(beExp);
1907 return lc;
1908 }
1909}
1910
1911Clause WhereClause()throws ParseException :
1912{
1913 WhereClause wc = new WhereClause();
1914 Expression whereExpr;
1915}
1916{
1917 "where" whereExpr = Expression()
1918 {
1919 wc.setWhereExpr(whereExpr);
1920 return wc;
1921 }
1922}
1923
1924Clause OrderbyClause()throws ParseException :
1925{
1926 OrderbyClause oc = new OrderbyClause();
1927 Expression orderbyExpr;
1928 List<Expression> orderbyList = new ArrayList<Expression>();
1929 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1930 int numOfOrderby = 0;
1931}
1932{
1933 (
1934 "order"
1935 {
1936 String hint = getHint(token);
1937 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1938 String splits[] = hint.split(" +");
1939 int numFrames = Integer.parseInt(splits[1]);
1940 int numTuples = Integer.parseInt(splits[2]);
1941 oc.setNumFrames(numFrames);
1942 oc.setNumTuples(numTuples);
1943 }
1944 }
1945 "by" orderbyExpr = Expression()
1946 {
1947 orderbyList.add(orderbyExpr);
1948 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1949 }
1950 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1951 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1952 {
1953 modifierList.add(modif);
1954 }
1955
1956 ("," orderbyExpr = Expression()
1957 {
1958 orderbyList.add(orderbyExpr);
1959 modif = OrderbyClause.OrderModifier.ASC;
1960 }
1961 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1962 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1963 {
1964 modifierList.add(modif);
1965 }
1966 )*
1967)
1968 {
1969 oc.setModifierList(modifierList);
1970 oc.setOrderbyList(orderbyList);
1971 return oc;
1972 }
1973}
1974Clause GroupClause()throws ParseException :
1975{
1976 GroupbyClause gbc = new GroupbyClause();
1977 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1978 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1979 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1980 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1981 VariableExpr var = null;
1982 VariableExpr withVar = null;
1983 Expression expr = null;
1984 VariableExpr decorVar = null;
1985 Expression decorExpr = null;
1986}
1987{
1988 {
1989 Scope newScope = extendCurrentScopeNoPush(true);
1990 // extendCurrentScope(true);
1991 }
1992 "group"
1993 {
1994 String hint = getHint(token);
1995 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1996 gbc.setHashGroupByHint(true);
1997 }
1998 }
1999 "by" (LOOKAHEAD(2) var = Variable()
2000 {
2001 newScope.addNewVarSymbolToScope(var.getVar());
2002 } ":=")?
2003 expr = Expression()
2004 {
2005 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2006 vePairList.add(pair1);
2007 }
2008 ("," ( LOOKAHEAD(2) var = Variable()
2009 {
2010 newScope.addNewVarSymbolToScope(var.getVar());
2011 } ":=")?
2012 expr = Expression()
2013 {
2014 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2015 vePairList.add(pair2);
2016 }
2017 )*
2018 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2019 {
2020 newScope.addNewVarSymbolToScope(decorVar.getVar());
2021 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2022 decorPairList.add(pair3);
2023 }
2024 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2025 {
2026 newScope.addNewVarSymbolToScope(decorVar.getVar());
2027 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2028 decorPairList.add(pair4);
2029 }
2030 )*
2031 )?
2032 "with" withVar = VariableRef()
2033 {
2034 if(withVar.getIsNewVar()==true)
2035 throw new ParseException("can't find variable " + withVar.getVar());
2036 withVarList.add(withVar);
2037 newScope.addNewVarSymbolToScope(withVar.getVar());
2038 }
2039 ("," withVar = VariableRef()
2040 {
2041 if(withVar.getIsNewVar()==true)
2042 throw new ParseException("can't find variable " + withVar.getVar());
2043 withVarList.add(withVar);
2044 newScope.addNewVarSymbolToScope(withVar.getVar());
2045 })*
2046 {
2047 gbc.setGbyPairList(vePairList);
2048 gbc.setDecorPairList(decorPairList);
2049 gbc.setWithVarList(withVarList);
2050 replaceCurrentScope(newScope);
2051 return gbc;
2052 }
2053}
2054
2055
2056LimitClause LimitClause() throws ParseException:
2057{
2058 LimitClause lc = new LimitClause();
2059 Expression expr;
2060 pushForbiddenScope(getCurrentScope());
2061}
2062{
2063 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2064 ("offset" expr = Expression() { lc.setOffset(expr); })?
2065
2066 {
2067 popForbiddenScope();
2068 return lc;
2069 }
2070}
2071
2072DistinctClause DistinctClause() throws ParseException:
2073{
2074 List<Expression> exprs = new ArrayList<Expression>();
2075 Expression expr;
2076}
2077{
2078 "distinct" "by" expr = Expression()
2079 {
2080 exprs.add(expr);
2081 }
2082 ("," expr = Expression()
2083 {
2084 exprs.add(expr);
2085 }
2086 )*
2087 {
2088 return new DistinctClause(exprs);
2089 }
2090}
2091
vinayakb38b7ca42012-03-05 05:44:15 +00002092QuantifiedExpression QuantifiedExpression()throws ParseException:
2093{
2094 QuantifiedExpression qc = new QuantifiedExpression();
2095 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2096 Expression satisfiesExpr;
2097 VariableExpr var;
2098 Expression inExpr;
2099 QuantifiedPair pair;
2100}
2101{
2102 {
2103 createNewScope();
2104 }
2105
2106 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2107 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2108 var = Variable() "in" inExpr = Expression()
2109 {
2110 pair = new QuantifiedPair(var, inExpr);
2111 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2112 quantifiedList.add(pair);
2113 }
2114 (
2115 "," var = Variable() "in" inExpr = Expression()
2116 {
2117 pair = new QuantifiedPair(var, inExpr);
2118 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2119 quantifiedList.add(pair);
2120 }
2121 )*
2122 "satisfies" satisfiesExpr = Expression()
2123 {
2124 qc.setSatisfiesExpr(satisfiesExpr);
2125 qc.setQuantifiedList(quantifiedList);
2126 removeCurrentScope();
2127 return qc;
2128 }
2129}
2130
2131TOKEN_MGR_DECLS:
2132{
2133 public int commentDepth = 0;
2134}
2135
2136<DEFAULT>
2137TOKEN :
2138{
2139 <CARET : "^" >
2140}
2141
2142<DEFAULT>
2143TOKEN :
2144{
2145 <DATASET : "dataset" >
2146}
2147
2148<DEFAULT>
2149TOKEN :
2150{
2151 <LEFTPAREN : "(" >
2152}
2153
2154<DEFAULT>
2155TOKEN :
2156{
2157 <RIGHTPAREN : ")" >
2158}
2159
2160
2161<DEFAULT>
2162TOKEN :
2163{
2164 <INTEGER_LITERAL : (<DIGIT>)+ >
2165}
2166
2167
2168<DEFAULT>
2169TOKEN :
2170{
2171 <NULL : "null">
2172}
2173
2174<DEFAULT>
2175TOKEN :
2176{
2177 <TRUE : "true">
2178}
2179
2180<DEFAULT>
2181TOKEN :
2182{
2183 <FALSE : "false">
2184}
2185
2186<DEFAULT>
2187TOKEN :
2188{
2189 <#DIGIT : ["0" - "9"]>
2190}
2191
2192
2193TOKEN:
2194{
2195 < DOUBLE_LITERAL: <INTEGER>
2196 | <INTEGER> ( "." <INTEGER> )?
2197 | "." <INTEGER>
2198 >
2199 |
2200 < FLOAT_LITERAL: <INTEGER> ( "f" | "F" )
2201 | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )?
2202 | "." <INTEGER> ( "f" | "F" )
2203 >
2204 |
2205 <INTEGER : (<DIGIT>)+ >
2206}
2207
2208<DEFAULT>
2209TOKEN :
2210{
2211 <#LETTER : ["A" - "Z", "a" - "z"]>
2212}
2213
2214<DEFAULT>
2215TOKEN :
2216{
2217 <SPECIALCHARS : ["$", "_", "-"] >
2218}
2219
2220<DEFAULT>
2221TOKEN :
2222{
2223 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2224 |
2225 < #EscapeQuot: "\\\"" >
2226 |
2227 < #EscapeApos: "\\\'" >
2228}
2229
2230<DEFAULT>
2231TOKEN :
2232{
2233 <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2234}
2235
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002236
vinayakb38b7ca42012-03-05 05:44:15 +00002237<DEFAULT>
2238TOKEN :
2239{
Till Westmann4f58e1a2013-05-20 18:29:54 -07002240 <VARIABLE : "$" (<LETTER>)+ (<LETTER> | <DIGIT> | "_")* >
vinayakb38b7ca42012-03-05 05:44:15 +00002241}
2242
2243SKIP:
2244{
2245 " "
2246| "\t"
2247| "\r"
2248| "\n"
2249}
2250
2251SKIP:
2252{
2253 <"//" (~["\n"])* "\n">
2254}
2255
2256SKIP:
2257{
2258 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2259}
2260
2261
2262SKIP:
2263{
2264 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2265}
2266
2267<INSIDE_COMMENT>
2268SPECIAL_TOKEN:
2269{
2270 <"+"(" ")*(~["*"])*>
2271}
2272
2273<INSIDE_COMMENT>
2274SKIP:
2275{
2276 <"/*"> {commentDepth++;}
2277}
2278
2279<INSIDE_COMMENT>
2280SKIP:
2281{
2282 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2283| <~[]>
2284}