blob: 46e4f6402bd01ad9201679754f9e060a078e6c38 [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 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700105
106 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
107 IRecordFieldDataGen rfdg = null;
108 String splits[] = hint.split(" +");
109 if (splits[0].equals(VAL_FILE_HINT)) {
110 File[] valFiles = new File[splits.length - 1];
111 for (int k=1; k<splits.length; k++) {
112 valFiles[k-1] = new File(splits[k]);
113 }
114 rfdg = new FieldValFileDataGen(valFiles);
115 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
116 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
117 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
118 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
119 } else if (splits[0].equals(LIST_HINT)) {
120 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
121 } else if (splits[0].equals(INTERVAL_HINT)) {
122 FieldIntervalDataGen.ValueType vt;
123 if (splits[1].equals("int")) {
124 vt = FieldIntervalDataGen.ValueType.INT;
125 } else if (splits[1].equals("long")) {
126 vt = FieldIntervalDataGen.ValueType.LONG;
127 } else if (splits[1].equals("float")) {
128 vt = FieldIntervalDataGen.ValueType.FLOAT;
129 } else if (splits[1].equals("double")) {
130 vt = FieldIntervalDataGen.ValueType.DOUBLE;
131 } else {
132 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
133 }
134 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
135 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
136 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
137 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
138 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
139 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
140 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
141 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
142 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
143 } else if (splits[0].equals(AUTO_HINT)) {
144 rfdg = new AutoDataGen(splits[1]);
145 }
146 return rfdg;
147 }
vinayakb38b7ca42012-03-05 05:44:15 +0000148
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000149 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700150 this(new StringReader(s));
151 super.setInput(s);
152 }
vinayakb38b7ca42012-03-05 05:44:15 +0000153
Till Westmann31c21f92013-05-08 09:21:53 -0700154 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
155 File file = new File(args[0]);
156 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
157 AQLParser parser = new AQLParser(fis);
158 List<Statement> st = parser.Statement();
159 //st.accept(new AQLPrintVisitor(), 0);
160 }
vinayakb38b7ca42012-03-05 05:44:15 +0000161}
162
163PARSER_END(AQLParser)
164
165
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000166List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000167{
vinayakb38b7ca42012-03-05 05:44:15 +0000168 scopeStack.push(RootScopeFactory.createRootScope(this));
169 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700170 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000171}
172{
Till Westmann31c21f92013-05-08 09:21:53 -0700173 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000174 {
Till Westmann31c21f92013-05-08 09:21:53 -0700175 decls.add(stmt);
176 }
177 )*
178 <EOF>
179 {
180 return decls;
181 }
182}
183
184Statement SingleStatement() throws ParseException:
185{
186 Statement stmt = null;
187}
188{
189 (
190 stmt = DataverseDeclaration()
191 | stmt = FunctionDeclaration()
192 | stmt = CreateStatement()
193 | stmt = LoadStatement()
194 | stmt = DropStatement()
195 | stmt = WriteStatement()
196 | stmt = SetStatement()
197 | stmt = InsertStatement()
198 | stmt = DeleteStatement()
199 | stmt = UpdateStatement()
200 | stmt = FeedStatement()
201 | stmt = Query()
202 )
203 {
204 return stmt;
205 }
206}
207
208DataverseDecl DataverseDeclaration() throws ParseException:
209{
Till Westmann14a20a72013-05-09 00:06:24 -0700210 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700211}
212{
Till Westmanna4242bc2013-05-08 17:49:55 -0700213 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700214 {
Till Westmann14a20a72013-05-09 00:06:24 -0700215 defaultDataverse = dvName;
216 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700217 }
218}
219
220Statement CreateStatement() throws ParseException:
221{
222 String hint = null;
223 boolean dgen = false;
224 Statement stmt = null;
225}
226{
227 "create"
228 (
229 {
230 hint = getHint(token);
231 if (hint != null && hint.startsWith(DGEN_HINT)) {
232 dgen = true;
233 }
234 }
235 stmt = TypeSpecification(hint, dgen)
236 | stmt = NodegroupSpecification()
237 | stmt = DatasetSpecification()
238 | stmt = IndexSpecification()
239 | stmt = DataverseSpecification()
240 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700241 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700242 )
243 {
244 return stmt;
245 }
246}
247
248TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
249{
250 Pair<Identifier,Identifier> nameComponents = null;
251 boolean ifNotExists = false;
252 TypeExpression typeExpr = null;
253}
254{
ramangrover299f76a5e2013-06-18 10:25:17 -0700255 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700256 "as" typeExpr = TypeExpr()
257 {
258 long numValues = -1;
259 String filename = null;
260 if (dgen) {
261 String splits[] = hint.split(" +");
262 if (splits.length != 3) {
263 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
264 }
265 filename = splits[1];
266 numValues = Long.parseLong(splits[2]);
267 }
268 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
269 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
270 }
271}
272
273
274NodegroupDecl NodegroupSpecification() throws ParseException:
275{
Till Westmann14a20a72013-05-09 00:06:24 -0700276 String name = null;
277 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700278 boolean ifNotExists = false;
279 List<Identifier>ncNames = null;
280}
281{
Till Westmanna4242bc2013-05-08 17:49:55 -0700282 "nodegroup" name = Identifier()
283 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700284 {
285 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700286 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700287 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700288 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700289 {
Till Westmann14a20a72013-05-09 00:06:24 -0700290 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700291 }
292 )*
293 {
Till Westmann14a20a72013-05-09 00:06:24 -0700294 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700295 }
296}
297
298DatasetDecl DatasetSpecification() throws ParseException:
299{
300 Pair<Identifier,Identifier> nameComponents = null;
301 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700302 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700303 String adapterName = null;
304 Map<String,String> properties = null;
305 FunctionSignature appliedFunction = null;
306 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700307 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700308 Map<String,String> hints = new HashMap<String,String>();
309 DatasetDecl dsetDecl = null;
310}
311{
312 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700313 "external" <DATASET> nameComponents = QualifiedName()
314 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
315 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700316 "using" adapterName = AdapterName() properties = Configuration()
317 ( "hints" hints = Properties() )?
318 {
319 ExternalDetailsDecl edd = new ExternalDetailsDecl();
320 edd.setAdapter(adapterName);
321 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700322 dsetDecl = new DatasetDecl(nameComponents.first,
323 nameComponents.second,
324 new Identifier(typeName),
325 hints,
326 DatasetType.EXTERNAL,
327 edd,
328 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700329 }
330
Till Westmannd7dcb122013-05-16 13:19:09 -0700331 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700332 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
333 ifNotExists = IfNotExists()
334 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700335 ( "hints" hints = Properties() )?
336 {
Till Westmann14a20a72013-05-09 00:06:24 -0700337 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
338 ? new Identifier(nodeGroupName)
339 : null,
340 primaryKeyFields);
341 dsetDecl = new DatasetDecl(nameComponents.first,
342 nameComponents.second,
343 new Identifier(typeName),
344 hints,
345 DatasetType.INTERNAL,
346 idd,
347 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700348 }
349 )
350 {
351 return dsetDecl;
352 }
353}
354
355CreateIndexStatement IndexSpecification() throws ParseException:
356{
357 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700358 String indexName = null;
359 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700360 boolean ifNotExists = false;
361 Pair<Identifier,Identifier> nameComponents = null;
362 IndexParams indexType = null;
363}
364{
Till Westmanna4242bc2013-05-08 17:49:55 -0700365 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700366 ifNotExists = IfNotExists()
367 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700368 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700369 {
Till Westmann14a20a72013-05-09 00:06:24 -0700370 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700371 }
Till Westmann14a20a72013-05-09 00:06:24 -0700372 ) ("," fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700373 {
Till Westmann14a20a72013-05-09 00:06:24 -0700374 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700375 }
376 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
377 {
Till Westmann14a20a72013-05-09 00:06:24 -0700378 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700379 cis.setIfNotExists(ifNotExists);
380 cis.setDataverseName(nameComponents.first);
381 cis.setDatasetName(nameComponents.second);
382 if (indexType != null) {
383 cis.setIndexType(indexType.type);
384 cis.setGramLength(indexType.gramLength);
385 }
386 return cis;
387 }
388}
389
390IndexParams IndexType() throws ParseException:
391{
392 IndexType type = null;
393 int gramLength = 0;
394}
395{
396 ("btree"
397 {
398 type = IndexType.BTREE;
399 }
400 | "rtree"
401 {
402 type = IndexType.RTREE;
403 }
404 | "keyword"
405 {
JIMAHNb75446d2013-06-03 08:35:27 -0700406 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700407 }
408 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
409 {
JIMAHNb75446d2013-06-03 08:35:27 -0700410 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700411 gramLength = Integer.valueOf(token.image);
412 }
413 <RIGHTPAREN>)
414 {
415 return new IndexParams(type, gramLength);
416 }
417}
418
419CreateDataverseStatement DataverseSpecification() throws ParseException :
420{
Till Westmann14a20a72013-05-09 00:06:24 -0700421 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700422 boolean ifNotExists = false;
423 String format = null;
424}
425{
Till Westmanna4242bc2013-05-08 17:49:55 -0700426 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700427 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700428 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700429 {
Till Westmann14a20a72013-05-09 00:06:24 -0700430 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700431 }
432}
433
434CreateFunctionStatement FunctionSpecification() throws ParseException:
435{
436 FunctionSignature signature;
437 boolean ifNotExists = false;
438 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
439 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700440 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700441 Expression functionBodyExpr;
442 Token beginPos;
443 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700444 FunctionName fctName = null;
445
Till Westmann31c21f92013-05-08 09:21:53 -0700446 createNewScope();
447}
448{
ramangrover299f76a5e2013-06-18 10:25:17 -0700449 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700450 ifNotExists = IfNotExists()
ramangrover299f76a5e2013-06-18 10:25:17 -0700451 <LEFTPAREN> (<VARIABLE>
452 {
453 var = new VarIdentifier();
454 var.setValue(token.image);
455 paramList.add(var);
456 getCurrentScope().addNewVarSymbolToScope(var);
457 }
458 ("," <VARIABLE>
459 {
460 var = new VarIdentifier();
461 var.setValue(token.image);
462 paramList.add(var);
463 getCurrentScope().addNewVarSymbolToScope(var);
464 }
465 )*)? <RIGHTPAREN> "{"
Till Westmannd7dcb122013-05-16 13:19:09 -0700466 {
467 beginPos = token;
468 }
469 functionBodyExpr = Expression() "}"
470 {
471 endPos = token;
472 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700473 // TODO use fctName.library
474 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700475 getCurrentScope().addFunctionDescriptor(signature, false);
476 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
477 }
478}
479
ramangrover29a774ef22013-07-17 09:29:18 -0700480CreateFeedStatement FeedSpecification() throws ParseException:
481{
482 Pair<Identifier,Identifier> nameComponents = null;
483 boolean ifNotExists = false;
484 String adaptorName = null;
485 Map<String,String> properties = null;
486 FunctionSignature appliedFunction = null;
487 CreateFeedStatement cfs = null;
488}
489{
490 (
491 "feed" nameComponents = QualifiedName()
492 ifNotExists = IfNotExists()
493 "using" adaptorName = AdapterName() properties = Configuration()
494 (appliedFunction = ApplyFunction())?
495 {
496 cfs = new CreateFeedStatement(nameComponents.first,
497 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
498 }
499
500 )
501 {
502 return cfs;
503 }
504}
505
506
507
Till Westmannd7dcb122013-05-16 13:19:09 -0700508List<VarIdentifier> ParameterList() throws ParseException:
509{
510 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
511 VarIdentifier var = null;
512}
513{
Till Westmann31c21f92013-05-08 09:21:53 -0700514 <LEFTPAREN> (<VARIABLE>
515 {
516 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700517 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700518 paramList.add(var);
519 getCurrentScope().addNewVarSymbolToScope(var);
520 }
521 ("," <VARIABLE>
522 {
523 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700524 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700525 paramList.add(var);
526 getCurrentScope().addNewVarSymbolToScope(var);
527 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700528 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700529 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700530 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700531 }
532}
533
534boolean IfNotExists() throws ParseException:
535{
536}
537{
538 ( "if not exists"
539 {
540 return true;
541 }
542 )?
543 {
544 return false;
545 }
546}
547
548FunctionSignature ApplyFunction() throws ParseException:
549{
550 FunctionSignature funcSig = null;
551}
552{
553 "apply" "function" funcSig = FunctionSignature()
554 {
555 return funcSig;
556 }
557}
558
ramangrover29566b3a92013-05-28 09:07:10 -0700559String GetPolicy() throws ParseException:
560{
561 String policy = null;
562}
563{
564 "using" "policy" policy = Identifier()
565 {
566 return policy;
567 }
568
569}
570
Till Westmann31c21f92013-05-08 09:21:53 -0700571FunctionSignature FunctionSignature() throws ParseException:
572{
ramangrover299f76a5e2013-06-18 10:25:17 -0700573 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700574 int arity = 0;
575}
576{
ramangrover299f76a5e2013-06-18 10:25:17 -0700577 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700578 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700579 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700580 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
581 throw new ParseException(" invalid arity:" + arity);
582 }
583
ramangrover299f76a5e2013-06-18 10:25:17 -0700584 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700585 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
586 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700587 }
588}
589
590List<String> PrimaryKey() throws ParseException:
591{
Till Westmann14a20a72013-05-09 00:06:24 -0700592 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700593 List<String> primaryKeyFields = new ArrayList<String>();
594}
595{
Till Westmann14a20a72013-05-09 00:06:24 -0700596 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700597 {
Till Westmann14a20a72013-05-09 00:06:24 -0700598 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700599 }
Till Westmann14a20a72013-05-09 00:06:24 -0700600 ( "," tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700601 {
Till Westmann14a20a72013-05-09 00:06:24 -0700602 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700603 }
604 )*
605 {
606 return primaryKeyFields;
607 }
608}
609
610Statement DropStatement() throws ParseException:
611{
Till Westmann14a20a72013-05-09 00:06:24 -0700612 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700613 Pair<Identifier,Identifier> pairId = null;
614 Triple<Identifier,Identifier,Identifier> tripleId = null;
615 FunctionSignature funcSig = null;
616 boolean ifExists = false;
617 Statement stmt = null;
618}
619{
620 "drop"
621 (
622 <DATASET> pairId = QualifiedName() ifExists = IfExists()
623 {
624 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
625 }
626 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
627 {
628 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
629 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700630 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700631 {
Till Westmann14a20a72013-05-09 00:06:24 -0700632 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700633 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700634 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700635 {
636 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
637 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700638 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700639 {
Till Westmann14a20a72013-05-09 00:06:24 -0700640 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700641 }
642 | "function" funcSig = FunctionSignature() ifExists = IfExists()
643 {
644 stmt = new FunctionDropStatement(funcSig, ifExists);
645 }
ramangrover29a774ef22013-07-17 09:29:18 -0700646 | "feed" pairId = QualifiedName() ifExists = IfExists()
647 {
648 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
649 }
Till Westmann31c21f92013-05-08 09:21:53 -0700650 )
651 {
652 return stmt;
653 }
654}
655
656boolean IfExists() throws ParseException :
657{
658}
659{
660 ( "if" "exists"
661 {
662 return true;
663 }
664 )?
665 {
666 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000667 }
668}
669
670InsertStatement InsertStatement() throws ParseException:
671{
Till Westmann31c21f92013-05-08 09:21:53 -0700672 Pair<Identifier,Identifier> nameComponents = null;
673 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000674}
675{
Till Westmann31c21f92013-05-08 09:21:53 -0700676 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
677 {
678 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
679 }
vinayakb38b7ca42012-03-05 05:44:15 +0000680}
681
682DeleteStatement DeleteStatement() throws ParseException:
683{
Till Westmann31c21f92013-05-08 09:21:53 -0700684 VariableExpr var = null;
685 Expression condition = null;
686 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000687}
688{
Till Westmann31c21f92013-05-08 09:21:53 -0700689 "delete" var = Variable()
690 {
691 getCurrentScope().addNewVarSymbolToScope(var.getVar());
692 }
693 "from" <DATASET> nameComponents = QualifiedName()
694 ("where" condition = Expression())?
695 {
696 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
697 }
vinayakb38b7ca42012-03-05 05:44:15 +0000698}
699
700UpdateStatement UpdateStatement() throws ParseException:
701{
Till Westmann31c21f92013-05-08 09:21:53 -0700702 VariableExpr vars;
703 Expression target;
704 Expression condition;
705 UpdateClause uc;
706 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000707}
708{
Till Westmann31c21f92013-05-08 09:21:53 -0700709 "update" vars = Variable() "in" target = Expression()
710 "where" condition = Expression()
711 <LEFTPAREN> (uc = UpdateClause()
712 {
713 ucs.add(uc);
714 }
715 ("," uc = UpdateClause()
716 {
717 ucs.add(uc);
718 }
719 )*) <RIGHTPAREN>
720 {
721 return new UpdateStatement(vars, target, condition, ucs);
722 }
vinayakb38b7ca42012-03-05 05:44:15 +0000723}
724
vinayakb38b7ca42012-03-05 05:44:15 +0000725UpdateClause UpdateClause() throws ParseException:
726{
Till Westmann31c21f92013-05-08 09:21:53 -0700727 Expression target = null;
728 Expression value = null ;
729 InsertStatement is = null;
730 DeleteStatement ds = null;
731 UpdateStatement us = null;
732 Expression condition = null;
733 UpdateClause ifbranch = null;
734 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000735}
736{
737 "set" target = Expression() ":=" value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700738 | is = InsertStatement()
739 | ds = DeleteStatement()
740 | us = UpdateStatement()
741 | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN>
742 "then" ifbranch = UpdateClause()
743 [LOOKAHEAD(1) "else" elsebranch = UpdateClause()]
744 {
745 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
746 }
vinayakb38b7ca42012-03-05 05:44:15 +0000747}
748
vinayakb38b7ca42012-03-05 05:44:15 +0000749Statement SetStatement() throws ParseException:
750{
751 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700752 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000753}
754{
Till Westmann7d535322013-05-09 00:40:02 -0700755 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700756 {
Till Westmann31c21f92013-05-08 09:21:53 -0700757 return new SetStatement(pn, pv);
758 }
vinayakb38b7ca42012-03-05 05:44:15 +0000759}
760
761Statement WriteStatement() throws ParseException:
762{
Till Westmann14a20a72013-05-09 00:06:24 -0700763 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000764 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000765 Query query;
766 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000767 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000768}
769{
Till Westmann35a0f702013-07-01 14:06:34 -0700770 "write" "output" "to" nodeName = Identifier() ":" fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700771 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700772 {
773 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000774 }
775}
776
vinayakb38b7ca42012-03-05 05:44:15 +0000777LoadFromFileStatement LoadStatement() throws ParseException:
778{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000779 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000780 Identifier datasetName = null;
781 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000782 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000783 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000784 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000785}
786{
Till Westmann31c21f92013-05-08 09:21:53 -0700787 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000788 {
Till Westmann31c21f92013-05-08 09:21:53 -0700789 dataverseName = nameComponents.first;
790 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000791 }
Till Westmann31c21f92013-05-08 09:21:53 -0700792 "using" adapterName = AdapterName() properties = Configuration()
793 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000794 {
Till Westmann31c21f92013-05-08 09:21:53 -0700795 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000796 }
797 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700798 {
799 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
800 }
vinayakb38b7ca42012-03-05 05:44:15 +0000801}
802
vinayakb38b7ca42012-03-05 05:44:15 +0000803
Till Westmann31c21f92013-05-08 09:21:53 -0700804String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000805{
ramangrover29669d8f62013-02-11 06:03:32 +0000806 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000807}
808{
Till Westmann68d99652013-05-09 11:15:21 -0700809 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000810 {
Till Westmann7d535322013-05-09 00:40:02 -0700811 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000812 }
vinayakb38b7ca42012-03-05 05:44:15 +0000813}
814
Till Westmann31c21f92013-05-08 09:21:53 -0700815Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000816{
ramangrover29a774ef22013-07-17 09:29:18 -0700817 Pair<Identifier,Identifier> feedNameComponents = null;
818 Pair<Identifier,Identifier> datasetNameComponents = null;
819
Till Westmann31c21f92013-05-08 09:21:53 -0700820 Map<String,String> configuration = null;
821 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700822 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000823}
824{
Till Westmann31c21f92013-05-08 09:21:53 -0700825 (
ramangrover29a774ef22013-07-17 09:29:18 -0700826 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700827 {
ramangrover29a774ef22013-07-17 09:29:18 -0700828 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700829 }
ramangrover29a774ef22013-07-17 09:29:18 -0700830 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700831 {
ramangrover29a774ef22013-07-17 09:29:18 -0700832 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700833 }
834 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000835 {
Till Westmann31c21f92013-05-08 09:21:53 -0700836 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000837 }
838}
839
Till Westmann31c21f92013-05-08 09:21:53 -0700840Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000841{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000842 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700843 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000844}
845{
Till Westmann31c21f92013-05-08 09:21:53 -0700846 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000847 {
Till Westmann31c21f92013-05-08 09:21:53 -0700848 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000849 }
Till Westmann31c21f92013-05-08 09:21:53 -0700850 ( "," keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000851 {
Till Westmann31c21f92013-05-08 09:21:53 -0700852 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000853 }
Till Westmann31c21f92013-05-08 09:21:53 -0700854 )* )? <RIGHTPAREN>
855 {
856 return configuration;
857 }
858}
859
860Pair<String, String> KeyValuePair() throws ParseException:
861{
862 String key;
863 String value;
864}
865{
Till Westmann7d535322013-05-09 00:40:02 -0700866 <LEFTPAREN> key = StringLiteral() "=" value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700867 {
868 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000869 }
Till Westmann31c21f92013-05-08 09:21:53 -0700870}
871
872Map<String,String> Properties() throws ParseException:
873{
874 Map<String,String> properties = new HashMap<String,String>();
875 Pair<String, String> property;
876}
877{
878 ( <LEFTPAREN> property = Property()
879 {
880 properties.put(property.first, property.second);
881 }
882 ( "," property = Property()
883 {
884 properties.put(property.first, property.second);
885 }
886 )* <RIGHTPAREN> )?
887 {
888 return properties;
889 }
890}
891
892Pair<String, String> Property() throws ParseException:
893{
894 String key;
895 String value;
896}
897{
Till Westmann7d535322013-05-09 00:40:02 -0700898 key = Identifier() "=" ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700899 {
900 try {
901 value = "" + Long.valueOf(token.image);
902 } catch (NumberFormatException nfe) {
903 throw new ParseException("inapproriate value: " + token.image);
904 }
905 }
906 )
907 {
908 return new Pair<String, String>(key.toUpperCase(), value);
909 }
vinayakb38b7ca42012-03-05 05:44:15 +0000910}
911
912TypeExpression TypeExpr() throws ParseException:
913{
914 TypeExpression typeExpr = null;
915}
916{
917 (
918 typeExpr = RecordTypeDef()
919 | typeExpr = TypeReference()
920 | typeExpr = OrderedListTypeDef()
921 | typeExpr = UnorderedListTypeDef()
922 )
923 {
924 return typeExpr;
925 }
926}
927
928RecordTypeDefinition RecordTypeDef() throws ParseException:
929{
930 RecordTypeDefinition recType = new RecordTypeDefinition();
931 RecordTypeDefinition.RecordKind recordKind = null;
932}
933{
934 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
935 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
936 "{"
937 {
938 String hint = getHint(token);
939 if (hint != null) {
940 String splits[] = hint.split(" +");
941 if (splits[0].equals(GEN_FIELDS_HINT)) {
942 if (splits.length != 5) {
943 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
944 }
945 if (!splits[1].equals("int")) {
946 throw new ParseException("The only supported type for gen-fields is int.");
947 }
948 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
949 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
950 recType.setUndeclaredFieldsDataGen(ufdg);
951 }
952 }
953
954 }
955 (
956 RecordField(recType)
957 ( "," RecordField(recType) )*
958 )?
959 "}"
960 {
961 if (recordKind == null) {
962 recordKind = RecordTypeDefinition.RecordKind.OPEN;
963 }
964 recType.setRecordKind(recordKind);
965 return recType;
966 }
967}
968
969void RecordField(RecordTypeDefinition recType) throws ParseException:
970{
Till Westmann77cb2f42013-07-15 16:44:19 -0700971 String fieldName;
972 TypeExpression type = null;
973 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000974}
975{
Till Westmann77cb2f42013-07-15 16:44:19 -0700976 fieldName = Identifier()
977 {
978 String hint = getHint(token);
979 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
980 }
981 ":" type = TypeExpr() ("?" { nullable = true; } )?
982 {
983 recType.addField(fieldName, type, nullable, rfdg);
984 }
vinayakb38b7ca42012-03-05 05:44:15 +0000985}
986
987TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000988{
Till Westmann14a20a72013-05-09 00:06:24 -0700989 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700990}
991{
992 id = Identifier()
993 {
Till Westmann14a20a72013-05-09 00:06:24 -0700994 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700995 }
vinayakb38b7ca42012-03-05 05:44:15 +0000996}
997
998OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
999{
1000 TypeExpression type = null;
1001}
1002{
1003 "["
1004 ( type = TypeExpr() )
1005 "]"
1006 {
1007 return new OrderedListTypeDefinition(type);
1008 }
1009}
1010
1011
1012UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1013{
1014 TypeExpression type = null;
1015}
1016{
1017 "{{"
1018 ( type = TypeExpr() )
1019 "}}"
1020 {
1021 return new UnorderedListTypeDefinition(type);
1022 }
1023}
1024
ramangrover299f76a5e2013-06-18 10:25:17 -07001025FunctionName FunctionName() throws ParseException:
1026{
1027 String first = null;
1028 String second = null;
1029 String third = null;
1030 boolean secondAfterDot = false;
1031}
1032{
1033 first = Identifier() ( "." second = Identifier()
1034 {
1035 secondAfterDot = true;
1036 }
1037 ("#" third = Identifier())? | "#" second = Identifier() )?
1038 {
1039 FunctionName result = new FunctionName();
1040 if (second == null) {
1041 result.dataverse = defaultDataverse;
1042 result.library = null;
1043 result.function = first;
1044 } else if (third == null) {
1045 if (secondAfterDot) {
1046 result.dataverse = first;
1047 result.library = null;
1048 result.function = second;
1049 } else {
1050 result.dataverse = defaultDataverse;
1051 result.library = first;
1052 result.function = second;
1053 }
1054 } else {
1055 result.dataverse = first;
1056 result.library = second;
1057 result.function = third;
1058 }
1059 return result;
1060 }
1061}
Till Westmann31c21f92013-05-08 09:21:53 -07001062
ramangrover299f76a5e2013-06-18 10:25:17 -07001063
1064Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001065{
Till Westmann31c21f92013-05-08 09:21:53 -07001066 Pair<Identifier,Identifier> name = null;
1067}
1068{
1069 name = QualifiedName()
1070 {
1071 if (name.first == null) {
1072 name.first = new Identifier(defaultDataverse);
1073 }
1074 return name;
1075 }
1076}
1077
Till Westmann14a20a72013-05-09 00:06:24 -07001078String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001079{
Till Westmann68d99652013-05-09 11:15:21 -07001080 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001081}
1082{
1083 <IDENTIFIER>
1084 {
Till Westmann14a20a72013-05-09 00:06:24 -07001085 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001086 }
Till Westmann68d99652013-05-09 11:15:21 -07001087 | lit = StringLiteral()
1088 {
1089 return lit;
1090 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001091}
1092
Till Westmann7d535322013-05-09 00:40:02 -07001093String StringLiteral() throws ParseException:
1094{
1095}
1096{
1097 <STRING_LITERAL>
1098 {
1099 return removeQuotesAndEscapes(token.image);
1100 }
1101}
1102
Till Westmann31c21f92013-05-08 09:21:53 -07001103Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1104{
Till Westmann14a20a72013-05-09 00:06:24 -07001105 String first = null;
1106 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001107}
1108{
Till Westmanna4242bc2013-05-08 17:49:55 -07001109 first = Identifier() ("." second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001110 {
Till Westmann14a20a72013-05-09 00:06:24 -07001111 Identifier id1 = null;
1112 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001113 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001114 id2 = new Identifier(first);
1115 } else
1116 {
1117 id1 = new Identifier(first);
1118 id2 = new Identifier(second);
1119 }
1120 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001121 }
1122}
1123
Till Westmann31c21f92013-05-08 09:21:53 -07001124Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001125{
Till Westmann14a20a72013-05-09 00:06:24 -07001126 String first = null;
1127 String second = null;
1128 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001129}
1130{
Till Westmanna4242bc2013-05-08 17:49:55 -07001131 first = Identifier() "." second = Identifier() ("." third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001132 {
Till Westmann14a20a72013-05-09 00:06:24 -07001133 Identifier id1 = null;
1134 Identifier id2 = null;
1135 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001136 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001137 id2 = new Identifier(first);
1138 id3 = new Identifier(second);
1139 } else {
1140 id1 = new Identifier(first);
1141 id2 = new Identifier(second);
1142 id3 = new Identifier(third);
1143 }
1144 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001145 }
1146}
1147
vinayakb38b7ca42012-03-05 05:44:15 +00001148FunctionDecl FunctionDeclaration() throws ParseException:
1149{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001150 FunctionDecl funcDecl;
1151 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001152 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001153 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1154 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001155 createNewScope();
1156}
1157{
Till Westmannd7dcb122013-05-16 13:19:09 -07001158 "declare" "function" functionName = Identifier()
1159 paramList = ParameterList()
1160 "{" funcBody = Expression() "}"
vinayakb38b7ca42012-03-05 05:44:15 +00001161 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001162 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001163 getCurrentScope().addFunctionDescriptor(signature, false);
1164 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001165 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001166 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001167 }
1168}
1169
vinayakb38b7ca42012-03-05 05:44:15 +00001170
Till Westmann31c21f92013-05-08 09:21:53 -07001171Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001172{
1173 Query query = new Query();
1174 Expression expr;
1175}
1176{
Till Westmann31c21f92013-05-08 09:21:53 -07001177 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001178 {
1179 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001180 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001181 return query;
1182 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001183
vinayakb38b7ca42012-03-05 05:44:15 +00001184}
1185
1186
1187
1188Expression Expression():
1189{
1190 Expression expr = null;
1191 Expression exprP = null;
1192}
1193{
1194(
1195
1196//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1197 expr = OperatorExpr()
1198 | expr = IfThenElse()
1199 | expr = FLWOGR()
1200 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001201
vinayakb38b7ca42012-03-05 05:44:15 +00001202
1203)
1204 {
1205 return (exprP==null) ? expr : exprP;
1206 }
1207}
1208
1209
1210
1211Expression OperatorExpr()throws ParseException:
1212{
1213 OperatorExpr op = null;
1214 Expression operand = null;
1215}
1216{
1217 operand = AndExpr()
1218 (
1219
1220 "or"
1221 {
1222 if (op == null) {
1223 op = new OperatorExpr();
1224 op.addOperand(operand);
1225 op.setCurrentop(true);
1226 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001227 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001228 }
1229
1230 operand = AndExpr()
1231 {
1232 op.addOperand(operand);
1233 }
1234
1235 )*
1236
1237 {
1238 return op==null? operand: op;
1239 }
1240}
1241
1242Expression AndExpr()throws ParseException:
1243{
1244 OperatorExpr op = null;
1245 Expression operand = null;
1246}
1247{
1248 operand = RelExpr()
1249 (
1250
1251 "and"
1252 {
1253 if (op == null) {
1254 op = new OperatorExpr();
1255 op.addOperand(operand);
1256 op.setCurrentop(true);
1257 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001258 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001259 }
1260
1261 operand = RelExpr()
1262 {
1263 op.addOperand(operand);
1264 }
1265
1266 )*
1267
1268 {
1269 return op==null? operand: op;
1270 }
1271}
1272
1273
1274
1275Expression RelExpr()throws ParseException:
1276{
1277 OperatorExpr op = null;
1278 Expression operand = null;
1279 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001280 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001281}
1282{
1283 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001284 {
1285 if (operand instanceof VariableExpr) {
1286 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001287 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001288 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001289 }
1290 }
1291 }
1292
1293 (
1294 LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=")
1295 {
alexander.behm07617fd2012-07-25 10:13:50 +00001296 String mhint = getHint(token);
1297 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1298 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1299 }
vinayakb38b7ca42012-03-05 05:44:15 +00001300 if (op == null) {
1301 op = new OperatorExpr();
1302 op.addOperand(operand, broadcast);
1303 op.setCurrentop(true);
1304 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001305 }
1306 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001307 }
1308
1309 operand = AddExpr()
1310 {
alexander.behm07617fd2012-07-25 10:13:50 +00001311 broadcast = false;
1312 if (operand instanceof VariableExpr) {
1313 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001314 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1315 broadcast = true;
1316 }
alexander.behm07617fd2012-07-25 10:13:50 +00001317 }
vinayakb38b7ca42012-03-05 05:44:15 +00001318 op.addOperand(operand, broadcast);
1319 }
1320 )?
1321
1322 {
alexander.behm07617fd2012-07-25 10:13:50 +00001323 if (annotation != null) {
1324 op.addHint(annotation);
1325 }
vinayakb38b7ca42012-03-05 05:44:15 +00001326 return op==null? operand: op;
1327 }
1328}
1329
1330Expression AddExpr()throws ParseException:
1331{
1332 OperatorExpr op = null;
1333 Expression operand = null;
1334}
1335{
1336 operand = MultExpr()
1337
1338 ( ("+" | "-")
1339 {
1340 if (op == null) {
1341 op = new OperatorExpr();
1342 op.addOperand(operand);
1343 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001344 }
1345 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001346 }
1347
1348 operand = MultExpr()
1349 {
1350 op.addOperand(operand);
1351 }
1352 )*
1353
1354 {
1355 return op==null? operand: op;
1356 }
1357}
1358
1359Expression MultExpr()throws ParseException:
1360{
1361 OperatorExpr op = null;
1362 Expression operand = null;
1363}
1364{
1365 operand = UnionExpr()
1366
1367 (( "*" | "/" | "%" | <CARET> | "idiv")
1368 {
1369 if (op == null) {
1370 op = new OperatorExpr();
1371 op.addOperand(operand);
1372 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001373 }
1374 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001375 }
1376 operand = UnionExpr()
1377 {
1378 op.addOperand(operand);
1379 }
1380 )*
1381
1382 {
1383 return op==null?operand:op;
1384 }
1385}
1386
1387Expression UnionExpr() throws ParseException:
1388{
1389 UnionExpr union = null;
1390 Expression operand1 = null;
1391 Expression operand2 = null;
1392}
1393{
1394 operand1 = UnaryExpr()
1395 ("union"
1396 (operand2 = UnaryExpr()) {
1397 if (union == null) {
1398 union = new UnionExpr();
1399 union.addExpr(operand1);
1400 }
1401 union.addExpr(operand2);
1402 } )*
1403 {
1404 return (union == null)? operand1: union;
1405 }
1406}
1407
1408Expression UnaryExpr() throws ParseException:
1409{
1410 Expression uexpr = null;
1411 Expression expr = null;
1412}
1413{
1414 (( "+"|"-")
1415 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001416 uexpr = new UnaryExpr();
1417 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001418 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001419 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001420 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1421 else
1422 throw new ParseException();
1423 }
1424 )?
1425
1426 expr = ValueExpr()
1427 {
1428 if(uexpr!=null){
1429 ((UnaryExpr)uexpr).setExpr(expr);
1430 return uexpr;
1431 }
1432 else{
1433 return expr;
1434 }
1435 }
1436}
1437
Till Westmann04478e72013-05-13 23:01:34 -07001438Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001439{
1440 Expression expr = null;
1441 Identifier ident = null;
1442 AbstractAccessor fa = null;
1443 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001444}
1445{
Till Westmann04478e72013-05-13 23:01:34 -07001446 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001447 {
Till Westmann04478e72013-05-13 23:01:34 -07001448 fa = (fa == null ? new FieldAccessor(expr, ident)
1449 : new FieldAccessor(fa, ident));
1450 }
1451 | index = Index()
1452 {
1453 fa = (fa == null ? new IndexAccessor(expr, index)
1454 : new IndexAccessor(fa, index));
1455 }
1456 )*
1457 {
1458 return fa == null ? expr : fa;
1459 }
vinayakb38b7ca42012-03-05 05:44:15 +00001460}
1461
1462Identifier Field() throws ParseException:
1463{
Till Westmann14a20a72013-05-09 00:06:24 -07001464 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001465}
1466{
Till Westmanna4242bc2013-05-08 17:49:55 -07001467 "." ident = Identifier()
1468 {
Till Westmann14a20a72013-05-09 00:06:24 -07001469 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001470 }
vinayakb38b7ca42012-03-05 05:44:15 +00001471}
1472
1473int Index() throws ParseException:
1474{
1475 Expression expr = null;
1476 int idx = -2;
1477}
1478{
1479 "[" ( expr = Expression()
1480 {
1481 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1482 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001483 Literal lit = ((LiteralExpr)expr).getValue();
1484 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1485 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001486 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001487 }
vinayakb38b7ca42012-03-05 05:44:15 +00001488 else {
1489 throw new ParseException("Index should be an INTEGER");
1490 }
1491 }
1492
1493 }
1494
1495 | "?"
1496 {
1497 idx = IndexAccessor.ANY;
1498 // ANY
1499 }
1500
1501 )
1502
1503 "]"
1504 {
1505 return idx;
1506 }
1507}
1508
1509
1510Expression PrimaryExpr()throws ParseException:
1511{
1512 Expression expr = null;
1513}
1514{
Till Westmann68d99652013-05-09 11:15:21 -07001515 ( LOOKAHEAD(2)
1516 expr = FunctionCallExpr()
1517 | expr = Literal()
1518 | expr = DatasetAccessExpression()
1519 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001520 {
1521 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001522 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001523 }
Till Westmann68d99652013-05-09 11:15:21 -07001524 | expr = ListConstructor()
1525 | expr = RecordConstructor()
1526 | expr = ParenthesizedExpression()
1527 )
1528 {
1529 return expr;
1530 }
vinayakb38b7ca42012-03-05 05:44:15 +00001531}
1532
1533Expression Literal() throws ParseException:
1534{
vinayakb38b7ca42012-03-05 05:44:15 +00001535 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001536 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001537}
1538{
Till Westmann7d535322013-05-09 00:40:02 -07001539 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001540 {
Till Westmann7d535322013-05-09 00:40:02 -07001541 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001542 }
1543 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001544 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001545 try {
1546 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1547 } catch(NumberFormatException ex) {
1548 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1549 }
1550 }
1551 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001552 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001553 lit.setValue(new FloatLiteral(new Float(token.image)));
1554 }
1555 | <DOUBLE_LITERAL>
1556 {
1557 lit.setValue(new DoubleLiteral(new Double(token.image)));
1558 }
1559 | <NULL>
1560 {
1561 lit.setValue(NullLiteral.INSTANCE);
1562 }
1563 | <TRUE>
1564 {
1565 lit.setValue(TrueLiteral.INSTANCE);
1566 }
1567 | <FALSE>
1568 {
1569 lit.setValue(FalseLiteral.INSTANCE);
1570 }
1571 )
vinayakb38b7ca42012-03-05 05:44:15 +00001572 {
1573 return lit;
1574 }
1575}
1576
1577
1578VariableExpr VariableRef() throws ParseException:
1579{
1580 VariableExpr varExp = new VariableExpr();
1581 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001582}
1583{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001584 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001585 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001586 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001587 Identifier ident = lookupSymbol(varName);
1588 if (isInForbiddenScopes(varName)) {
1589 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.");
1590 }
1591 if(ident != null) { // exist such ident
1592 varExp.setIsNewVar(false);
1593 varExp.setVar((VarIdentifier)ident);
1594 } else {
1595 varExp.setVar(var);
1596 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001597 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001598 return varExp;
1599 }
1600}
1601
1602
1603VariableExpr Variable() throws ParseException:
1604{
1605 VariableExpr varExp = new VariableExpr();
1606 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001607}
1608{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001609 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001610 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001611 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001612 if(ident != null) { // exist such ident
1613 varExp.setIsNewVar(false);
1614 }
1615 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001616 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001617 return varExp;
1618 }
1619}
1620
1621Expression ListConstructor() throws ParseException:
1622{
1623 Expression expr = null;
1624}
1625{
1626 (
1627 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1628 )
1629
1630 {
1631 return expr;
1632 }
1633}
1634
1635
1636ListConstructor OrderedListConstructor() throws ParseException:
1637{
1638 ListConstructor expr = new ListConstructor();
1639 Expression tmp = null;
1640 List<Expression> exprList = new ArrayList<Expression>();
1641 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1642}
1643{
1644
1645 "["
1646 ( tmp = Expression()
1647 {
1648 exprList.add(tmp);
1649 }
1650
1651 ("," tmp = Expression() { exprList.add(tmp); })*
1652 )?
1653
1654 "]"
1655
1656 {
1657 expr.setExprList(exprList);
1658 return expr;
1659 }
1660}
1661
1662ListConstructor UnorderedListConstructor() throws ParseException:
1663{
1664 ListConstructor expr = new ListConstructor();
1665 Expression tmp = null;
1666 List<Expression> exprList = new ArrayList<Expression>();
1667 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1668}
1669{
1670
1671 "{{" ( tmp = Expression()
1672 {
1673 exprList.add(tmp);
1674 }
1675 ("," tmp = Expression() { exprList.add(tmp); })*)? "}}"
1676 {
1677 expr.setExprList(exprList);
1678 return expr;
1679 }
1680}
1681
1682RecordConstructor RecordConstructor() throws ParseException:
1683{
1684 RecordConstructor expr = new RecordConstructor();
1685 FieldBinding tmp = null;
1686 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1687}
1688{
1689 "{" (tmp = FieldBinding()
1690 {
1691 fbList.add(tmp);
1692 }
1693 ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}"
1694 {
1695 expr.setFbList(fbList);
1696 return expr;
1697 }
1698}
1699
1700FieldBinding FieldBinding() throws ParseException:
1701{
1702 FieldBinding fb = new FieldBinding();
1703 Expression left, right;
1704}
1705{
1706 left = Expression() ":" right = Expression()
1707 {
1708 fb.setLeftExpr(left);
1709 fb.setRightExpr(right);
1710 return fb;
1711 }
1712}
1713
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001714
vinayakb38b7ca42012-03-05 05:44:15 +00001715Expression FunctionCallExpr() throws ParseException:
1716{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001717 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001718 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001719 Expression tmp;
1720 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001721 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001722 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001723}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001724{
ramangrover299f76a5e2013-06-18 10:25:17 -07001725 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001726 {
Till Westmann31c21f92013-05-08 09:21:53 -07001727 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001728 }
Till Westmann31c21f92013-05-08 09:21:53 -07001729 <LEFTPAREN> (tmp = Expression()
1730 {
1731 argList.add(tmp);
1732 arity ++;
1733 }
1734 ("," tmp = Expression()
1735 {
1736 argList.add(tmp);
1737 arity++;
1738 }
1739 )*)? <RIGHTPAREN>
1740 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001741 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001742 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001743 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001744 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001745 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001746 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001747 }
1748 callExpr = new CallExpr(signature,argList);
1749 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1750 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1751 }
1752 return callExpr;
1753 }
vinayakb38b7ca42012-03-05 05:44:15 +00001754}
1755
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001756
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001757Expression DatasetAccessExpression() throws ParseException:
1758{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001759 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001760 String arg1 = null;
1761 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001762 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001763}
1764{
Till Westmann14a20a72013-05-09 00:06:24 -07001765 <DATASET>
1766 {
Till Westmann14a20a72013-05-09 00:06:24 -07001767 funcName = token.image;
1768 }
1769 ( ( arg1 = Identifier() ( "." arg2 = Identifier() )? )
1770 {
1771 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001772 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001773 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001774 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001775 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001776 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001777 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001778 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1779 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1780 if (signature == null) {
1781 signature = new FunctionSignature(dataverse, funcName, 1);
1782 }
1783 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001784 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001785 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001786 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001787}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001788
vinayakb38b7ca42012-03-05 05:44:15 +00001789Expression ParenthesizedExpression() throws ParseException:
1790{
1791 Expression expr;
1792}
1793{
1794 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1795 {
1796 return expr;
1797 }
1798}
1799
1800Expression IfThenElse() throws ParseException:
1801{
1802 Expression condExpr;
1803 Expression thenExpr;
1804 Expression elseExpr;
1805 IfExpr ifExpr = new IfExpr();
1806}
1807{
1808 "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression()
1809
1810 {
1811 ifExpr.setCondExpr(condExpr);
1812 ifExpr.setThenExpr(thenExpr);
1813 ifExpr.setElseExpr(elseExpr);
1814 return ifExpr;
1815 }
1816}
1817
1818Expression FLWOGR() throws ParseException:
1819{
1820 FLWOGRExpression flworg = new FLWOGRExpression();
1821 List<Clause> clauseList = new ArrayList<Clause>();
1822 Expression returnExpr;
1823 Clause tmp;
1824 createNewScope();
1825}
1826{
1827 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
1828 (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression()
1829
1830 {
1831 flworg.setClauseList(clauseList);
1832 flworg.setReturnExpr(returnExpr);
1833 removeCurrentScope();
1834 return flworg;
1835 }
1836}
1837
1838Clause Clause()throws ParseException :
1839{
1840 Clause clause;
1841}
1842{
1843 (
1844 clause = ForClause()
1845 | clause = LetClause()
1846 | clause = WhereClause()
1847 | clause = OrderbyClause()
1848 | clause = GroupClause()
1849 | clause = LimitClause()
1850 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001851 )
1852 {
1853 return clause;
1854 }
1855}
1856
1857Clause ForClause()throws ParseException :
1858{
1859 ForClause fc = new ForClause();
1860 VariableExpr varExp;
1861 VariableExpr varPos = null;
1862 Expression inExp;
1863 extendCurrentScope();
1864}
1865{
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001866 "for" varExp = Variable() ("at" varPos = Variable())? "in" ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001867 {
1868 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001869 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001870 fc.setInExpr(inExp);
1871 if (varPos != null) {
1872 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001873 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001874 }
1875 return fc;
1876 }
1877}
1878
1879Clause LetClause() throws ParseException:
1880{
1881 LetClause lc = new LetClause();
1882 VariableExpr varExp;
1883 Expression beExp;
1884 extendCurrentScope();
1885}
1886{
ilovesoupb2527c12012-07-12 03:21:13 +00001887 "let" varExp = Variable() ":=" beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001888 {
1889 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001890 lc.setVarExpr(varExp);
1891 lc.setBeExpr(beExp);
1892 return lc;
1893 }
1894}
1895
1896Clause WhereClause()throws ParseException :
1897{
1898 WhereClause wc = new WhereClause();
1899 Expression whereExpr;
1900}
1901{
1902 "where" whereExpr = Expression()
1903 {
1904 wc.setWhereExpr(whereExpr);
1905 return wc;
1906 }
1907}
1908
1909Clause OrderbyClause()throws ParseException :
1910{
1911 OrderbyClause oc = new OrderbyClause();
1912 Expression orderbyExpr;
1913 List<Expression> orderbyList = new ArrayList<Expression>();
1914 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1915 int numOfOrderby = 0;
1916}
1917{
1918 (
1919 "order"
1920 {
1921 String hint = getHint(token);
1922 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1923 String splits[] = hint.split(" +");
1924 int numFrames = Integer.parseInt(splits[1]);
1925 int numTuples = Integer.parseInt(splits[2]);
1926 oc.setNumFrames(numFrames);
1927 oc.setNumTuples(numTuples);
1928 }
1929 }
1930 "by" orderbyExpr = Expression()
1931 {
1932 orderbyList.add(orderbyExpr);
1933 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1934 }
1935 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1936 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1937 {
1938 modifierList.add(modif);
1939 }
1940
1941 ("," orderbyExpr = Expression()
1942 {
1943 orderbyList.add(orderbyExpr);
1944 modif = OrderbyClause.OrderModifier.ASC;
1945 }
1946 ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; })
1947 | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))?
1948 {
1949 modifierList.add(modif);
1950 }
1951 )*
1952)
1953 {
1954 oc.setModifierList(modifierList);
1955 oc.setOrderbyList(orderbyList);
1956 return oc;
1957 }
1958}
1959Clause GroupClause()throws ParseException :
1960{
1961 GroupbyClause gbc = new GroupbyClause();
1962 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1963 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1964 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1965 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1966 VariableExpr var = null;
1967 VariableExpr withVar = null;
1968 Expression expr = null;
1969 VariableExpr decorVar = null;
1970 Expression decorExpr = null;
1971}
1972{
1973 {
1974 Scope newScope = extendCurrentScopeNoPush(true);
1975 // extendCurrentScope(true);
1976 }
1977 "group"
1978 {
1979 String hint = getHint(token);
1980 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1981 gbc.setHashGroupByHint(true);
1982 }
1983 }
1984 "by" (LOOKAHEAD(2) var = Variable()
1985 {
1986 newScope.addNewVarSymbolToScope(var.getVar());
1987 } ":=")?
1988 expr = Expression()
1989 {
1990 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1991 vePairList.add(pair1);
1992 }
1993 ("," ( LOOKAHEAD(2) var = Variable()
1994 {
1995 newScope.addNewVarSymbolToScope(var.getVar());
1996 } ":=")?
1997 expr = Expression()
1998 {
1999 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2000 vePairList.add(pair2);
2001 }
2002 )*
2003 ("decor" decorVar = Variable() ":=" decorExpr = Expression()
2004 {
2005 newScope.addNewVarSymbolToScope(decorVar.getVar());
2006 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2007 decorPairList.add(pair3);
2008 }
2009 ("," "decor" decorVar = Variable() ":=" decorExpr = Expression()
2010 {
2011 newScope.addNewVarSymbolToScope(decorVar.getVar());
2012 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2013 decorPairList.add(pair4);
2014 }
2015 )*
2016 )?
2017 "with" withVar = VariableRef()
2018 {
2019 if(withVar.getIsNewVar()==true)
2020 throw new ParseException("can't find variable " + withVar.getVar());
2021 withVarList.add(withVar);
2022 newScope.addNewVarSymbolToScope(withVar.getVar());
2023 }
2024 ("," withVar = VariableRef()
2025 {
2026 if(withVar.getIsNewVar()==true)
2027 throw new ParseException("can't find variable " + withVar.getVar());
2028 withVarList.add(withVar);
2029 newScope.addNewVarSymbolToScope(withVar.getVar());
2030 })*
2031 {
2032 gbc.setGbyPairList(vePairList);
2033 gbc.setDecorPairList(decorPairList);
2034 gbc.setWithVarList(withVarList);
2035 replaceCurrentScope(newScope);
2036 return gbc;
2037 }
2038}
2039
2040
2041LimitClause LimitClause() throws ParseException:
2042{
2043 LimitClause lc = new LimitClause();
2044 Expression expr;
2045 pushForbiddenScope(getCurrentScope());
2046}
2047{
2048 "limit" expr = Expression() { lc.setLimitExpr(expr); }
2049 ("offset" expr = Expression() { lc.setOffset(expr); })?
2050
2051 {
2052 popForbiddenScope();
2053 return lc;
2054 }
2055}
2056
2057DistinctClause DistinctClause() throws ParseException:
2058{
2059 List<Expression> exprs = new ArrayList<Expression>();
2060 Expression expr;
2061}
2062{
2063 "distinct" "by" expr = Expression()
2064 {
2065 exprs.add(expr);
2066 }
2067 ("," expr = Expression()
2068 {
2069 exprs.add(expr);
2070 }
2071 )*
2072 {
2073 return new DistinctClause(exprs);
2074 }
2075}
2076
vinayakb38b7ca42012-03-05 05:44:15 +00002077QuantifiedExpression QuantifiedExpression()throws ParseException:
2078{
2079 QuantifiedExpression qc = new QuantifiedExpression();
2080 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2081 Expression satisfiesExpr;
2082 VariableExpr var;
2083 Expression inExpr;
2084 QuantifiedPair pair;
2085}
2086{
2087 {
2088 createNewScope();
2089 }
2090
2091 ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2092 | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2093 var = Variable() "in" inExpr = Expression()
2094 {
2095 pair = new QuantifiedPair(var, inExpr);
2096 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2097 quantifiedList.add(pair);
2098 }
2099 (
2100 "," var = Variable() "in" inExpr = Expression()
2101 {
2102 pair = new QuantifiedPair(var, inExpr);
2103 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2104 quantifiedList.add(pair);
2105 }
2106 )*
2107 "satisfies" satisfiesExpr = Expression()
2108 {
2109 qc.setSatisfiesExpr(satisfiesExpr);
2110 qc.setQuantifiedList(quantifiedList);
2111 removeCurrentScope();
2112 return qc;
2113 }
2114}
2115
2116TOKEN_MGR_DECLS:
2117{
2118 public int commentDepth = 0;
2119}
2120
2121<DEFAULT>
2122TOKEN :
2123{
2124 <CARET : "^" >
2125}
2126
2127<DEFAULT>
2128TOKEN :
2129{
2130 <DATASET : "dataset" >
2131}
2132
2133<DEFAULT>
2134TOKEN :
2135{
2136 <LEFTPAREN : "(" >
2137}
2138
2139<DEFAULT>
2140TOKEN :
2141{
2142 <RIGHTPAREN : ")" >
2143}
2144
2145
2146<DEFAULT>
2147TOKEN :
2148{
2149 <INTEGER_LITERAL : (<DIGIT>)+ >
2150}
2151
2152
2153<DEFAULT>
2154TOKEN :
2155{
2156 <NULL : "null">
2157}
2158
2159<DEFAULT>
2160TOKEN :
2161{
2162 <TRUE : "true">
2163}
2164
2165<DEFAULT>
2166TOKEN :
2167{
2168 <FALSE : "false">
2169}
2170
2171<DEFAULT>
2172TOKEN :
2173{
2174 <#DIGIT : ["0" - "9"]>
2175}
2176
2177
2178TOKEN:
2179{
Till Westmannaf0551c2013-07-23 14:53:31 -07002180 < DOUBLE_LITERAL: <DIGITS>
2181 | <DIGITS> ( "." <DIGITS> )?
2182 | "." <DIGITS>
vinayakb38b7ca42012-03-05 05:44:15 +00002183 >
2184 |
Till Westmannaf0551c2013-07-23 14:53:31 -07002185 < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2186 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2187 | "." <DIGITS> ( "f" | "F" )
vinayakb38b7ca42012-03-05 05:44:15 +00002188 >
2189 |
Till Westmannaf0551c2013-07-23 14:53:31 -07002190 <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002191}
2192
2193<DEFAULT>
2194TOKEN :
2195{
2196 <#LETTER : ["A" - "Z", "a" - "z"]>
2197}
2198
2199<DEFAULT>
2200TOKEN :
2201{
2202 <SPECIALCHARS : ["$", "_", "-"] >
2203}
2204
2205<DEFAULT>
2206TOKEN :
2207{
2208 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2209 |
2210 < #EscapeQuot: "\\\"" >
2211 |
2212 < #EscapeApos: "\\\'" >
2213}
2214
2215<DEFAULT>
2216TOKEN :
2217{
Till Westmannaf0551c2013-07-23 14:53:31 -07002218 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002219}
2220
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002221
vinayakb38b7ca42012-03-05 05:44:15 +00002222<DEFAULT>
2223TOKEN :
2224{
Till Westmannaf0551c2013-07-23 14:53:31 -07002225 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002226}
2227
2228SKIP:
2229{
2230 " "
2231| "\t"
2232| "\r"
2233| "\n"
2234}
2235
2236SKIP:
2237{
2238 <"//" (~["\n"])* "\n">
2239}
2240
2241SKIP:
2242{
2243 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2244}
2245
2246
2247SKIP:
2248{
2249 <"/*"> {commentDepth=1;}: INSIDE_COMMENT
2250}
2251
2252<INSIDE_COMMENT>
2253SPECIAL_TOKEN:
2254{
2255 <"+"(" ")*(~["*"])*>
2256}
2257
2258<INSIDE_COMMENT>
2259SKIP:
2260{
2261 <"/*"> {commentDepth++;}
2262}
2263
2264<INSIDE_COMMENT>
2265SKIP:
2266{
2267 <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);}
2268| <~[]>
2269}