blob: ad868623ff7cba07c990f59ea06a7f6d4e81d1df [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;
vinayakb38b7ca42012-03-05 05:44:15 +000016import java.util.Map;
17import java.util.HashMap;
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +000018import java.util.LinkedHashMap;
Till Westmann96c1f172013-08-01 02:05:48 -070019
20import org.apache.xerces.util.IntStack;
21
vinayakb38b7ca42012-03-05 05:44:15 +000022import edu.uci.ics.asterix.aql.literal.FloatLiteral;
23import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
24import edu.uci.ics.asterix.aql.literal.FalseLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000025import edu.uci.ics.asterix.aql.base.Literal;
vinayakb38b7ca42012-03-05 05:44:15 +000026import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000027import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +000028import edu.uci.ics.asterix.aql.literal.NullLiteral;
29import edu.uci.ics.asterix.aql.literal.StringLiteral;
30import edu.uci.ics.asterix.aql.literal.TrueLiteral;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000031import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
vinayakb38b7ca42012-03-05 05:44:15 +000032
33import edu.uci.ics.asterix.aql.base.*;
34import edu.uci.ics.asterix.aql.expression.*;
35import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
36import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
37import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
38import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
39import edu.uci.ics.asterix.aql.base.Statement.Kind;
40import edu.uci.ics.asterix.aql.context.Scope;
41import edu.uci.ics.asterix.aql.context.RootScopeFactory;
42import edu.uci.ics.asterix.common.annotations.*;
43import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000044import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000045import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000046import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
47import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000048import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
49import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
50import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
51
52
vinayakb38b7ca42012-03-05 05:44:15 +000053
54
55public class AQLParser extends ScopeChecker {
56
vinayakb38b7ca42012-03-05 05:44:15 +000057 // optimizer hints
58 private static final String HASH_GROUP_BY_HINT = "hash";
salsubaieebb167912013-12-21 12:55:52 -080059 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
vinayakb38b7ca42012-03-05 05:44:15 +000060 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000061 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000062 private static final String INMEMORY_HINT = "inmem";
63 private static final String VAL_FILE_HINT = "val-files";
64 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
65 private static final String INTERVAL_HINT = "interval";
66 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
67 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
68 private static final String LIST_VAL_FILE_HINT = "list-val-file";
69 private static final String LIST_HINT = "list";
70 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
71 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
72 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
73 private static final String AUTO_HINT = "auto";
74
75 private static final String GEN_FIELDS_HINT = "gen-fields";
76
77 // data generator hints
78 private static final String DGEN_HINT = "dgen";
Till Westmann31c21f92013-05-08 09:21:53 -070079
80 private static class IndexParams {
81 public IndexType type;
82 public int gramLength;
83
84 public IndexParams(IndexType type, int gramLength) {
85 this.type = type;
86 this.gramLength = gramLength;
87 }
88 };
vinayakb38b7ca42012-03-05 05:44:15 +000089
ramangrover299f76a5e2013-06-18 10:25:17 -070090 private static class FunctionName {
91 public String dataverse = null;
92 public String library = null;
93 public String function = null;
94 }
95
vinayakb38b7ca42012-03-05 05:44:15 +000096 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070097 if (t.specialToken == null) {
98 return null;
99 }
100 String s = t.specialToken.image;
101 int n = s.length();
102 if (n < 2) {
103 return null;
104 }
105 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000106 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700107
108 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
109 IRecordFieldDataGen rfdg = null;
110 String splits[] = hint.split(" +");
111 if (splits[0].equals(VAL_FILE_HINT)) {
112 File[] valFiles = new File[splits.length - 1];
113 for (int k=1; k<splits.length; k++) {
114 valFiles[k-1] = new File(splits[k]);
115 }
116 rfdg = new FieldValFileDataGen(valFiles);
117 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
118 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
119 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
120 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
121 } else if (splits[0].equals(LIST_HINT)) {
122 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
123 } else if (splits[0].equals(INTERVAL_HINT)) {
124 FieldIntervalDataGen.ValueType vt;
125 if (splits[1].equals("int")) {
126 vt = FieldIntervalDataGen.ValueType.INT;
127 } else if (splits[1].equals("long")) {
128 vt = FieldIntervalDataGen.ValueType.LONG;
129 } else if (splits[1].equals("float")) {
130 vt = FieldIntervalDataGen.ValueType.FLOAT;
131 } else if (splits[1].equals("double")) {
132 vt = FieldIntervalDataGen.ValueType.DOUBLE;
133 } else {
134 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
135 }
136 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
137 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
138 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
139 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
140 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
141 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
142 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
143 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
144 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
145 } else if (splits[0].equals(AUTO_HINT)) {
146 rfdg = new AutoDataGen(splits[1]);
147 }
148 return rfdg;
149 }
vinayakb38b7ca42012-03-05 05:44:15 +0000150
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000151 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700152 this(new StringReader(s));
153 super.setInput(s);
154 }
vinayakb38b7ca42012-03-05 05:44:15 +0000155
Till Westmann31c21f92013-05-08 09:21:53 -0700156 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
157 File file = new File(args[0]);
158 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
159 AQLParser parser = new AQLParser(fis);
160 List<Statement> st = parser.Statement();
161 //st.accept(new AQLPrintVisitor(), 0);
162 }
vinayakb38b7ca42012-03-05 05:44:15 +0000163}
164
165PARSER_END(AQLParser)
166
167
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000168List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000169{
vinayakb38b7ca42012-03-05 05:44:15 +0000170 scopeStack.push(RootScopeFactory.createRootScope(this));
171 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700172 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000173}
174{
Till Westmann31c21f92013-05-08 09:21:53 -0700175 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000176 {
Till Westmann31c21f92013-05-08 09:21:53 -0700177 decls.add(stmt);
178 }
179 )*
180 <EOF>
181 {
182 return decls;
183 }
184}
185
186Statement SingleStatement() throws ParseException:
187{
188 Statement stmt = null;
189}
190{
191 (
192 stmt = DataverseDeclaration()
193 | stmt = FunctionDeclaration()
194 | stmt = CreateStatement()
195 | stmt = LoadStatement()
196 | stmt = DropStatement()
197 | stmt = WriteStatement()
198 | stmt = SetStatement()
199 | stmt = InsertStatement()
200 | stmt = DeleteStatement()
201 | stmt = UpdateStatement()
202 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700203 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700204 | stmt = Query()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700205 | stmt = RefreshExternalDatasetStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700206 )
207 {
208 return stmt;
209 }
210}
211
212DataverseDecl DataverseDeclaration() throws ParseException:
213{
Till Westmann14a20a72013-05-09 00:06:24 -0700214 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700215}
216{
Till Westmanna4242bc2013-05-08 17:49:55 -0700217 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700218 {
Till Westmann14a20a72013-05-09 00:06:24 -0700219 defaultDataverse = dvName;
220 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700221 }
222}
223
224Statement CreateStatement() throws ParseException:
225{
226 String hint = null;
227 boolean dgen = false;
228 Statement stmt = null;
229}
230{
231 "create"
232 (
233 {
234 hint = getHint(token);
235 if (hint != null && hint.startsWith(DGEN_HINT)) {
236 dgen = true;
237 }
238 }
239 stmt = TypeSpecification(hint, dgen)
240 | stmt = NodegroupSpecification()
241 | stmt = DatasetSpecification()
242 | stmt = IndexSpecification()
243 | stmt = DataverseSpecification()
244 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700245 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700246 )
247 {
248 return stmt;
249 }
250}
251
252TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
253{
254 Pair<Identifier,Identifier> nameComponents = null;
255 boolean ifNotExists = false;
256 TypeExpression typeExpr = null;
257}
258{
ramangrover299f76a5e2013-06-18 10:25:17 -0700259 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700260 "as" typeExpr = TypeExpr()
261 {
262 long numValues = -1;
263 String filename = null;
264 if (dgen) {
265 String splits[] = hint.split(" +");
266 if (splits.length != 3) {
267 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
268 }
269 filename = splits[1];
270 numValues = Long.parseLong(splits[2]);
271 }
272 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
273 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
274 }
275}
276
277
278NodegroupDecl NodegroupSpecification() throws ParseException:
279{
Till Westmann14a20a72013-05-09 00:06:24 -0700280 String name = null;
281 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700282 boolean ifNotExists = false;
283 List<Identifier>ncNames = null;
284}
285{
Till Westmanna4242bc2013-05-08 17:49:55 -0700286 "nodegroup" name = Identifier()
287 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700288 {
289 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700290 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700291 }
Till Westmann96c1f172013-08-01 02:05:48 -0700292 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700293 {
Till Westmann14a20a72013-05-09 00:06:24 -0700294 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700295 }
296 )*
297 {
Till Westmann14a20a72013-05-09 00:06:24 -0700298 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700299 }
300}
301
302DatasetDecl DatasetSpecification() throws ParseException:
303{
304 Pair<Identifier,Identifier> nameComponents = null;
305 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700306 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700307 String adapterName = null;
308 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700309 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700310 FunctionSignature appliedFunction = null;
311 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700312 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700313 Map<String,String> hints = new HashMap<String,String>();
314 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700315 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700316 String compactionPolicy = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700317}
318{
319 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700320 "external" <DATASET> nameComponents = QualifiedName()
321 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
322 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700323 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700324 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700325 ( "hints" hints = Properties() )?
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700326 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700327 {
328 ExternalDetailsDecl edd = new ExternalDetailsDecl();
329 edd.setAdapter(adapterName);
330 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700331 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
332 edd.setCompactionPolicy(compactionPolicy);
333 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700334 dsetDecl = new DatasetDecl(nameComponents.first,
335 nameComponents.second,
336 new Identifier(typeName),
337 hints,
338 DatasetType.EXTERNAL,
339 edd,
340 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700341 }
342
Till Westmannd7dcb122013-05-16 13:19:09 -0700343 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700344 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
345 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700346 primaryKeyFields = PrimaryKey()
347 ("autogenerated" { autogenerated = true; } )?
348 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700349 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700350 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700351 {
Till Westmann14a20a72013-05-09 00:06:24 -0700352 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
353 ? new Identifier(nodeGroupName)
354 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700355 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700356 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700357 compactionPolicy,
358 compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700359 dsetDecl = new DatasetDecl(nameComponents.first,
360 nameComponents.second,
361 new Identifier(typeName),
362 hints,
363 DatasetType.INTERNAL,
364 idd,
365 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700366 }
367 )
368 {
369 return dsetDecl;
370 }
371}
372
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700373RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
374{
375 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
376 Pair<Identifier,Identifier> nameComponents = null;
377 String datasetName = null;
378}
379{
380 "refresh external" <DATASET> nameComponents = QualifiedName()
381 {
382 redss.setDataverseName(nameComponents.first);
383 redss.setDatasetName(nameComponents.second);
384 return redss;
385 }
386}
387
Till Westmann31c21f92013-05-08 09:21:53 -0700388CreateIndexStatement IndexSpecification() throws ParseException:
389{
390 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700391 String indexName = null;
392 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700393 boolean ifNotExists = false;
394 Pair<Identifier,Identifier> nameComponents = null;
395 IndexParams indexType = null;
396}
397{
Till Westmanna4242bc2013-05-08 17:49:55 -0700398 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700399 ifNotExists = IfNotExists()
400 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700401 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700402 {
Till Westmann14a20a72013-05-09 00:06:24 -0700403 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700404 }
Till Westmann96c1f172013-08-01 02:05:48 -0700405 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700406 {
Till Westmann14a20a72013-05-09 00:06:24 -0700407 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700408 }
409 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
410 {
Till Westmann14a20a72013-05-09 00:06:24 -0700411 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700412 cis.setIfNotExists(ifNotExists);
413 cis.setDataverseName(nameComponents.first);
414 cis.setDatasetName(nameComponents.second);
415 if (indexType != null) {
416 cis.setIndexType(indexType.type);
417 cis.setGramLength(indexType.gramLength);
418 }
419 return cis;
420 }
421}
422
salsubaiee0b423fa2013-09-19 19:16:48 -0700423String CompactionPolicy() throws ParseException :
424{
425 String compactionPolicy = null;
426}
427{
428 compactionPolicy = Identifier()
429 {
430 return compactionPolicy;
431 }
432}
433
Till Westmann31c21f92013-05-08 09:21:53 -0700434IndexParams IndexType() throws ParseException:
435{
436 IndexType type = null;
437 int gramLength = 0;
438}
439{
440 ("btree"
441 {
442 type = IndexType.BTREE;
443 }
444 | "rtree"
445 {
446 type = IndexType.RTREE;
447 }
448 | "keyword"
449 {
JIMAHNb75446d2013-06-03 08:35:27 -0700450 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700451 }
452 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
453 {
JIMAHNb75446d2013-06-03 08:35:27 -0700454 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700455 gramLength = Integer.valueOf(token.image);
456 }
457 <RIGHTPAREN>)
458 {
459 return new IndexParams(type, gramLength);
460 }
461}
462
463CreateDataverseStatement DataverseSpecification() throws ParseException :
464{
Till Westmann14a20a72013-05-09 00:06:24 -0700465 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700466 boolean ifNotExists = false;
467 String format = null;
468}
469{
Till Westmanna4242bc2013-05-08 17:49:55 -0700470 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700471 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700472 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700473 {
Till Westmann14a20a72013-05-09 00:06:24 -0700474 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700475 }
476}
477
478CreateFunctionStatement FunctionSpecification() throws ParseException:
479{
480 FunctionSignature signature;
481 boolean ifNotExists = false;
482 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
483 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700484 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700485 Expression functionBodyExpr;
486 Token beginPos;
487 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700488 FunctionName fctName = null;
489
Till Westmann31c21f92013-05-08 09:21:53 -0700490 createNewScope();
491}
492{
ramangrover299f76a5e2013-06-18 10:25:17 -0700493 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700494 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700495 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700496 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530497 {
498 beginPos = token;
499 }
Till Westmann96c1f172013-08-01 02:05:48 -0700500 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700501 {
502 endPos = token;
503 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700504 // TODO use fctName.library
505 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700506 getCurrentScope().addFunctionDescriptor(signature, false);
507 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
508 }
509}
510
ramangrover29a774ef22013-07-17 09:29:18 -0700511CreateFeedStatement FeedSpecification() throws ParseException:
512{
513 Pair<Identifier,Identifier> nameComponents = null;
514 boolean ifNotExists = false;
515 String adaptorName = null;
516 Map<String,String> properties = null;
517 FunctionSignature appliedFunction = null;
518 CreateFeedStatement cfs = null;
519}
520{
521 (
522 "feed" nameComponents = QualifiedName()
523 ifNotExists = IfNotExists()
524 "using" adaptorName = AdapterName() properties = Configuration()
525 (appliedFunction = ApplyFunction())?
526 {
527 cfs = new CreateFeedStatement(nameComponents.first,
528 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
529 }
530
531 )
532 {
533 return cfs;
534 }
535}
536
537
538
Till Westmannd7dcb122013-05-16 13:19:09 -0700539List<VarIdentifier> ParameterList() throws ParseException:
540{
541 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
542 VarIdentifier var = null;
543}
544{
Till Westmann31c21f92013-05-08 09:21:53 -0700545 <LEFTPAREN> (<VARIABLE>
546 {
547 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700548 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700549 paramList.add(var);
550 getCurrentScope().addNewVarSymbolToScope(var);
551 }
Till Westmann96c1f172013-08-01 02:05:48 -0700552 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700553 {
554 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700555 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700556 paramList.add(var);
557 getCurrentScope().addNewVarSymbolToScope(var);
558 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700559 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700560 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700561 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700562 }
563}
564
565boolean IfNotExists() throws ParseException:
566{
567}
568{
569 ( "if not exists"
570 {
571 return true;
572 }
573 )?
574 {
575 return false;
576 }
577}
578
579FunctionSignature ApplyFunction() throws ParseException:
580{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530581 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700582 FunctionSignature funcSig = null;
583}
584{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530585 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700586 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530587 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
588 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700589 }
590}
591
ramangrover29566b3a92013-05-28 09:07:10 -0700592String GetPolicy() throws ParseException:
593{
594 String policy = null;
595}
596{
597 "using" "policy" policy = Identifier()
598 {
599 return policy;
600 }
601
602}
603
Till Westmann31c21f92013-05-08 09:21:53 -0700604FunctionSignature FunctionSignature() throws ParseException:
605{
ramangrover299f76a5e2013-06-18 10:25:17 -0700606 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700607 int arity = 0;
608}
609{
ramangrover299f76a5e2013-06-18 10:25:17 -0700610 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700611 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700612 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700613 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
614 throw new ParseException(" invalid arity:" + arity);
615 }
616
ramangrover299f76a5e2013-06-18 10:25:17 -0700617 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700618 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
619 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700620 }
621}
622
623List<String> PrimaryKey() throws ParseException:
624{
Till Westmann14a20a72013-05-09 00:06:24 -0700625 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700626 List<String> primaryKeyFields = new ArrayList<String>();
627}
628{
Till Westmann14a20a72013-05-09 00:06:24 -0700629 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700630 {
Till Westmann14a20a72013-05-09 00:06:24 -0700631 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700632 }
Till Westmann96c1f172013-08-01 02:05:48 -0700633 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700634 {
Till Westmann14a20a72013-05-09 00:06:24 -0700635 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700636 }
637 )*
638 {
639 return primaryKeyFields;
640 }
641}
642
643Statement DropStatement() throws ParseException:
644{
Till Westmann14a20a72013-05-09 00:06:24 -0700645 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700646 Pair<Identifier,Identifier> pairId = null;
647 Triple<Identifier,Identifier,Identifier> tripleId = null;
648 FunctionSignature funcSig = null;
649 boolean ifExists = false;
650 Statement stmt = null;
651}
652{
653 "drop"
654 (
655 <DATASET> pairId = QualifiedName() ifExists = IfExists()
656 {
657 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
658 }
659 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
660 {
661 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
662 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700663 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700664 {
Till Westmann14a20a72013-05-09 00:06:24 -0700665 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700666 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700667 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700668 {
669 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
670 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700671 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700672 {
Till Westmann14a20a72013-05-09 00:06:24 -0700673 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700674 }
675 | "function" funcSig = FunctionSignature() ifExists = IfExists()
676 {
677 stmt = new FunctionDropStatement(funcSig, ifExists);
678 }
ramangrover29a774ef22013-07-17 09:29:18 -0700679 | "feed" pairId = QualifiedName() ifExists = IfExists()
680 {
681 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
682 }
Till Westmann31c21f92013-05-08 09:21:53 -0700683 )
684 {
685 return stmt;
686 }
687}
688
689boolean IfExists() throws ParseException :
690{
691}
692{
Till Westmann96c1f172013-08-01 02:05:48 -0700693 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700694 {
695 return true;
696 }
697 )?
698 {
699 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000700 }
701}
702
703InsertStatement InsertStatement() throws ParseException:
704{
Till Westmann31c21f92013-05-08 09:21:53 -0700705 Pair<Identifier,Identifier> nameComponents = null;
706 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000707}
708{
Till Westmann31c21f92013-05-08 09:21:53 -0700709 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
710 {
711 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
712 }
vinayakb38b7ca42012-03-05 05:44:15 +0000713}
714
715DeleteStatement DeleteStatement() throws ParseException:
716{
Till Westmann31c21f92013-05-08 09:21:53 -0700717 VariableExpr var = null;
718 Expression condition = null;
719 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000720}
721{
Till Westmann31c21f92013-05-08 09:21:53 -0700722 "delete" var = Variable()
723 {
724 getCurrentScope().addNewVarSymbolToScope(var.getVar());
725 }
salsubaieedf89fbc2013-12-21 19:51:42 -0800726 "from" <DATASET> nameComponents = QualifiedName()
727 (<WHERE> condition = Expression())?
728 {
729 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700730 }
vinayakb38b7ca42012-03-05 05:44:15 +0000731}
732
733UpdateStatement UpdateStatement() throws ParseException:
734{
Till Westmann31c21f92013-05-08 09:21:53 -0700735 VariableExpr vars;
736 Expression target;
737 Expression condition;
738 UpdateClause uc;
739 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000740}
741{
Till Westmann96c1f172013-08-01 02:05:48 -0700742 "update" vars = Variable() <IN> target = Expression()
743 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700744 <LEFTPAREN> (uc = UpdateClause()
745 {
746 ucs.add(uc);
747 }
Till Westmann96c1f172013-08-01 02:05:48 -0700748 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700749 {
750 ucs.add(uc);
751 }
752 )*) <RIGHTPAREN>
753 {
754 return new UpdateStatement(vars, target, condition, ucs);
755 }
vinayakb38b7ca42012-03-05 05:44:15 +0000756}
757
vinayakb38b7ca42012-03-05 05:44:15 +0000758UpdateClause UpdateClause() throws ParseException:
759{
Till Westmann31c21f92013-05-08 09:21:53 -0700760 Expression target = null;
761 Expression value = null ;
762 InsertStatement is = null;
763 DeleteStatement ds = null;
764 UpdateStatement us = null;
765 Expression condition = null;
766 UpdateClause ifbranch = null;
767 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000768}
769{
Till Westmann96c1f172013-08-01 02:05:48 -0700770 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700771 | is = InsertStatement()
772 | ds = DeleteStatement()
773 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700774 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
775 <THEN> ifbranch = UpdateClause()
776 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700777 {
778 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
779 }
vinayakb38b7ca42012-03-05 05:44:15 +0000780}
781
vinayakb38b7ca42012-03-05 05:44:15 +0000782Statement SetStatement() throws ParseException:
783{
784 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700785 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000786}
787{
Till Westmann7d535322013-05-09 00:40:02 -0700788 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700789 {
Till Westmann31c21f92013-05-08 09:21:53 -0700790 return new SetStatement(pn, pv);
791 }
vinayakb38b7ca42012-03-05 05:44:15 +0000792}
793
794Statement WriteStatement() throws ParseException:
795{
Till Westmann14a20a72013-05-09 00:06:24 -0700796 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000797 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000798 Query query;
799 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000800 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000801}
802{
Till Westmann96c1f172013-08-01 02:05:48 -0700803 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700804 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700805 {
806 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000807 }
808}
809
zheilbron28e026f2013-11-20 10:15:15 -0800810LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000811{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000812 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000813 Identifier datasetName = null;
814 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000815 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000816 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000817 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000818}
819{
Till Westmann31c21f92013-05-08 09:21:53 -0700820 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000821 {
Till Westmann31c21f92013-05-08 09:21:53 -0700822 dataverseName = nameComponents.first;
823 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000824 }
Till Westmann31c21f92013-05-08 09:21:53 -0700825 "using" adapterName = AdapterName() properties = Configuration()
826 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000827 {
Till Westmann31c21f92013-05-08 09:21:53 -0700828 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000829 }
830 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700831 {
zheilbron28e026f2013-11-20 10:15:15 -0800832 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Till Westmann31c21f92013-05-08 09:21:53 -0700833 }
vinayakb38b7ca42012-03-05 05:44:15 +0000834}
835
vinayakb38b7ca42012-03-05 05:44:15 +0000836
Till Westmann31c21f92013-05-08 09:21:53 -0700837String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000838{
ramangrover29669d8f62013-02-11 06:03:32 +0000839 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000840}
841{
Till Westmann68d99652013-05-09 11:15:21 -0700842 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000843 {
Till Westmann7d535322013-05-09 00:40:02 -0700844 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000845 }
vinayakb38b7ca42012-03-05 05:44:15 +0000846}
847
salsubaiee0b423fa2013-09-19 19:16:48 -0700848Statement CompactStatement() throws ParseException:
849{
850 Pair<Identifier,Identifier> nameComponents = null;
851 Statement stmt = null;
852}
853{
854 "compact" <DATASET> nameComponents = QualifiedName()
855 {
856 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
857 }
858 {
859 return stmt;
860 }
861}
862
Till Westmann31c21f92013-05-08 09:21:53 -0700863Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000864{
ramangrover29a774ef22013-07-17 09:29:18 -0700865 Pair<Identifier,Identifier> feedNameComponents = null;
866 Pair<Identifier,Identifier> datasetNameComponents = null;
867
Till Westmann31c21f92013-05-08 09:21:53 -0700868 Map<String,String> configuration = null;
869 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700870 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000871}
872{
Till Westmann31c21f92013-05-08 09:21:53 -0700873 (
ramangrover29a774ef22013-07-17 09:29:18 -0700874 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700875 {
ramangrover29a774ef22013-07-17 09:29:18 -0700876 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700877 }
ramangrover29a774ef22013-07-17 09:29:18 -0700878 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700879 {
ramangrover29a774ef22013-07-17 09:29:18 -0700880 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700881 }
882 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000883 {
Till Westmann31c21f92013-05-08 09:21:53 -0700884 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000885 }
886}
887
Till Westmann31c21f92013-05-08 09:21:53 -0700888Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000889{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000890 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700891 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000892}
893{
Till Westmann31c21f92013-05-08 09:21:53 -0700894 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000895 {
Till Westmann31c21f92013-05-08 09:21:53 -0700896 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000897 }
Till Westmann96c1f172013-08-01 02:05:48 -0700898 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000899 {
Till Westmann31c21f92013-05-08 09:21:53 -0700900 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000901 }
Till Westmann31c21f92013-05-08 09:21:53 -0700902 )* )? <RIGHTPAREN>
903 {
904 return configuration;
905 }
906}
907
908Pair<String, String> KeyValuePair() throws ParseException:
909{
910 String key;
911 String value;
912}
913{
Till Westmann96c1f172013-08-01 02:05:48 -0700914 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700915 {
916 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000917 }
Till Westmann31c21f92013-05-08 09:21:53 -0700918}
919
920Map<String,String> Properties() throws ParseException:
921{
922 Map<String,String> properties = new HashMap<String,String>();
923 Pair<String, String> property;
924}
925{
926 ( <LEFTPAREN> property = Property()
927 {
928 properties.put(property.first, property.second);
929 }
Till Westmann96c1f172013-08-01 02:05:48 -0700930 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700931 {
932 properties.put(property.first, property.second);
933 }
934 )* <RIGHTPAREN> )?
935 {
936 return properties;
937 }
938}
939
940Pair<String, String> Property() throws ParseException:
941{
942 String key;
943 String value;
944}
945{
Till Westmann96c1f172013-08-01 02:05:48 -0700946 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700947 {
948 try {
949 value = "" + Long.valueOf(token.image);
950 } catch (NumberFormatException nfe) {
951 throw new ParseException("inapproriate value: " + token.image);
952 }
953 }
954 )
955 {
956 return new Pair<String, String>(key.toUpperCase(), value);
957 }
vinayakb38b7ca42012-03-05 05:44:15 +0000958}
959
960TypeExpression TypeExpr() throws ParseException:
961{
962 TypeExpression typeExpr = null;
963}
964{
965 (
966 typeExpr = RecordTypeDef()
967 | typeExpr = TypeReference()
968 | typeExpr = OrderedListTypeDef()
969 | typeExpr = UnorderedListTypeDef()
970 )
971 {
972 return typeExpr;
973 }
974}
975
976RecordTypeDefinition RecordTypeDef() throws ParseException:
977{
978 RecordTypeDefinition recType = new RecordTypeDefinition();
979 RecordTypeDefinition.RecordKind recordKind = null;
980}
981{
982 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
983 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700984 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000985 {
986 String hint = getHint(token);
987 if (hint != null) {
988 String splits[] = hint.split(" +");
989 if (splits[0].equals(GEN_FIELDS_HINT)) {
990 if (splits.length != 5) {
991 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
992 }
993 if (!splits[1].equals("int")) {
994 throw new ParseException("The only supported type for gen-fields is int.");
995 }
996 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
997 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
998 recType.setUndeclaredFieldsDataGen(ufdg);
999 }
1000 }
1001
1002 }
1003 (
1004 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -07001005 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +00001006 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001007 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001008 {
1009 if (recordKind == null) {
1010 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1011 }
1012 recType.setRecordKind(recordKind);
1013 return recType;
1014 }
1015}
1016
1017void RecordField(RecordTypeDefinition recType) throws ParseException:
1018{
Till Westmann77cb2f42013-07-15 16:44:19 -07001019 String fieldName;
1020 TypeExpression type = null;
1021 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001022}
1023{
Till Westmann77cb2f42013-07-15 16:44:19 -07001024 fieldName = Identifier()
1025 {
1026 String hint = getHint(token);
1027 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1028 }
Till Westmann96c1f172013-08-01 02:05:48 -07001029 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001030 {
1031 recType.addField(fieldName, type, nullable, rfdg);
1032 }
vinayakb38b7ca42012-03-05 05:44:15 +00001033}
1034
1035TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001036{
Till Westmann14a20a72013-05-09 00:06:24 -07001037 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001038}
1039{
1040 id = Identifier()
1041 {
Till Westmann14a20a72013-05-09 00:06:24 -07001042 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001043 }
vinayakb38b7ca42012-03-05 05:44:15 +00001044}
1045
1046OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1047{
1048 TypeExpression type = null;
1049}
1050{
Till Westmann96c1f172013-08-01 02:05:48 -07001051 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001052 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001053 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001054 {
1055 return new OrderedListTypeDefinition(type);
1056 }
1057}
1058
1059
1060UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1061{
1062 TypeExpression type = null;
1063}
1064{
Till Westmann96c1f172013-08-01 02:05:48 -07001065 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001066 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001067 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001068 {
1069 return new UnorderedListTypeDefinition(type);
1070 }
1071}
1072
ramangrover299f76a5e2013-06-18 10:25:17 -07001073FunctionName FunctionName() throws ParseException:
1074{
1075 String first = null;
1076 String second = null;
1077 String third = null;
1078 boolean secondAfterDot = false;
1079}
1080{
zheilbron555dc9d2013-08-14 19:58:00 -07001081 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001082 {
1083 secondAfterDot = true;
1084 }
1085 ("#" third = Identifier())? | "#" second = Identifier() )?
1086 {
1087 FunctionName result = new FunctionName();
1088 if (second == null) {
1089 result.dataverse = defaultDataverse;
1090 result.library = null;
1091 result.function = first;
1092 } else if (third == null) {
1093 if (secondAfterDot) {
1094 result.dataverse = first;
1095 result.library = null;
1096 result.function = second;
1097 } else {
1098 result.dataverse = defaultDataverse;
1099 result.library = first;
1100 result.function = second;
1101 }
1102 } else {
1103 result.dataverse = first;
1104 result.library = second;
1105 result.function = third;
1106 }
1107 return result;
1108 }
1109}
Till Westmann31c21f92013-05-08 09:21:53 -07001110
ramangrover299f76a5e2013-06-18 10:25:17 -07001111
1112Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001113{
Till Westmann31c21f92013-05-08 09:21:53 -07001114 Pair<Identifier,Identifier> name = null;
1115}
1116{
1117 name = QualifiedName()
1118 {
1119 if (name.first == null) {
1120 name.first = new Identifier(defaultDataverse);
1121 }
1122 return name;
1123 }
1124}
1125
Till Westmann14a20a72013-05-09 00:06:24 -07001126String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001127{
Till Westmann68d99652013-05-09 11:15:21 -07001128 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001129}
1130{
1131 <IDENTIFIER>
1132 {
Till Westmann14a20a72013-05-09 00:06:24 -07001133 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001134 }
Till Westmann68d99652013-05-09 11:15:21 -07001135 | lit = StringLiteral()
1136 {
1137 return lit;
1138 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001139}
1140
Till Westmann7d535322013-05-09 00:40:02 -07001141String StringLiteral() throws ParseException:
1142{
1143}
1144{
1145 <STRING_LITERAL>
1146 {
1147 return removeQuotesAndEscapes(token.image);
1148 }
1149}
1150
Till Westmann31c21f92013-05-08 09:21:53 -07001151Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1152{
Till Westmann14a20a72013-05-09 00:06:24 -07001153 String first = null;
1154 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001155}
1156{
Till Westmann96c1f172013-08-01 02:05:48 -07001157 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001158 {
Till Westmann14a20a72013-05-09 00:06:24 -07001159 Identifier id1 = null;
1160 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001161 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001162 id2 = new Identifier(first);
1163 } else
1164 {
1165 id1 = new Identifier(first);
1166 id2 = new Identifier(second);
1167 }
1168 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001169 }
1170}
1171
Till Westmann31c21f92013-05-08 09:21:53 -07001172Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001173{
Till Westmann14a20a72013-05-09 00:06:24 -07001174 String first = null;
1175 String second = null;
1176 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001177}
1178{
Till Westmann96c1f172013-08-01 02:05:48 -07001179 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001180 {
Till Westmann14a20a72013-05-09 00:06:24 -07001181 Identifier id1 = null;
1182 Identifier id2 = null;
1183 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001184 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001185 id2 = new Identifier(first);
1186 id3 = new Identifier(second);
1187 } else {
1188 id1 = new Identifier(first);
1189 id2 = new Identifier(second);
1190 id3 = new Identifier(third);
1191 }
1192 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001193 }
1194}
1195
vinayakb38b7ca42012-03-05 05:44:15 +00001196FunctionDecl FunctionDeclaration() throws ParseException:
1197{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001198 FunctionDecl funcDecl;
1199 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001200 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001201 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1202 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001203 createNewScope();
1204}
1205{
Till Westmannd7dcb122013-05-16 13:19:09 -07001206 "declare" "function" functionName = Identifier()
1207 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001208 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001209 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001210 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001211 getCurrentScope().addFunctionDescriptor(signature, false);
1212 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001213 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001214 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001215 }
1216}
1217
vinayakb38b7ca42012-03-05 05:44:15 +00001218
Till Westmann31c21f92013-05-08 09:21:53 -07001219Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001220{
1221 Query query = new Query();
1222 Expression expr;
1223}
1224{
Till Westmann31c21f92013-05-08 09:21:53 -07001225 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001226 {
1227 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001228 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001229 return query;
1230 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001231
vinayakb38b7ca42012-03-05 05:44:15 +00001232}
1233
1234
1235
1236Expression Expression():
1237{
1238 Expression expr = null;
1239 Expression exprP = null;
1240}
1241{
1242(
1243
1244//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1245 expr = OperatorExpr()
1246 | expr = IfThenElse()
1247 | expr = FLWOGR()
1248 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001249
vinayakb38b7ca42012-03-05 05:44:15 +00001250
1251)
1252 {
1253 return (exprP==null) ? expr : exprP;
1254 }
1255}
1256
1257
1258
1259Expression OperatorExpr()throws ParseException:
1260{
1261 OperatorExpr op = null;
1262 Expression operand = null;
1263}
1264{
1265 operand = AndExpr()
1266 (
1267
Till Westmann96c1f172013-08-01 02:05:48 -07001268 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001269 {
1270 if (op == null) {
1271 op = new OperatorExpr();
1272 op.addOperand(operand);
1273 op.setCurrentop(true);
1274 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001275 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001276 }
1277
1278 operand = AndExpr()
1279 {
1280 op.addOperand(operand);
1281 }
1282
1283 )*
1284
1285 {
1286 return op==null? operand: op;
1287 }
1288}
1289
1290Expression AndExpr()throws ParseException:
1291{
1292 OperatorExpr op = null;
1293 Expression operand = null;
1294}
1295{
1296 operand = RelExpr()
1297 (
1298
Till Westmann96c1f172013-08-01 02:05:48 -07001299 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001300 {
1301 if (op == null) {
1302 op = new OperatorExpr();
1303 op.addOperand(operand);
1304 op.setCurrentop(true);
1305 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001306 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001307 }
1308
1309 operand = RelExpr()
1310 {
1311 op.addOperand(operand);
1312 }
1313
1314 )*
1315
1316 {
1317 return op==null? operand: op;
1318 }
1319}
1320
1321
1322
1323Expression RelExpr()throws ParseException:
1324{
1325 OperatorExpr op = null;
1326 Expression operand = null;
1327 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001328 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001329}
1330{
1331 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001332 {
1333 if (operand instanceof VariableExpr) {
1334 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001335 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001336 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001337 }
1338 }
1339 }
1340
1341 (
Till Westmann96c1f172013-08-01 02:05:48 -07001342 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001343 {
alexander.behm07617fd2012-07-25 10:13:50 +00001344 String mhint = getHint(token);
salsubaieedf89fbc2013-12-21 19:51:42 -08001345 if (mhint != null) {
1346 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1347 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1348 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1349 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1350 }
alexander.behm07617fd2012-07-25 10:13:50 +00001351 }
vinayakb38b7ca42012-03-05 05:44:15 +00001352 if (op == null) {
1353 op = new OperatorExpr();
1354 op.addOperand(operand, broadcast);
1355 op.setCurrentop(true);
1356 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001357 }
1358 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001359 }
1360
1361 operand = AddExpr()
1362 {
alexander.behm07617fd2012-07-25 10:13:50 +00001363 broadcast = false;
1364 if (operand instanceof VariableExpr) {
1365 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001366 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1367 broadcast = true;
1368 }
alexander.behm07617fd2012-07-25 10:13:50 +00001369 }
vinayakb38b7ca42012-03-05 05:44:15 +00001370 op.addOperand(operand, broadcast);
1371 }
1372 )?
1373
1374 {
alexander.behm07617fd2012-07-25 10:13:50 +00001375 if (annotation != null) {
1376 op.addHint(annotation);
1377 }
vinayakb38b7ca42012-03-05 05:44:15 +00001378 return op==null? operand: op;
1379 }
1380}
1381
1382Expression AddExpr()throws ParseException:
1383{
1384 OperatorExpr op = null;
1385 Expression operand = null;
1386}
1387{
1388 operand = MultExpr()
1389
Till Westmann96c1f172013-08-01 02:05:48 -07001390 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001391 {
1392 if (op == null) {
1393 op = new OperatorExpr();
1394 op.addOperand(operand);
1395 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001396 }
1397 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001398 }
1399
1400 operand = MultExpr()
1401 {
1402 op.addOperand(operand);
1403 }
1404 )*
1405
1406 {
1407 return op==null? operand: op;
1408 }
1409}
1410
1411Expression MultExpr()throws ParseException:
1412{
1413 OperatorExpr op = null;
1414 Expression operand = null;
1415}
1416{
1417 operand = UnionExpr()
1418
Till Westmann96c1f172013-08-01 02:05:48 -07001419 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001420 {
1421 if (op == null) {
1422 op = new OperatorExpr();
1423 op.addOperand(operand);
1424 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001425 }
1426 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001427 }
1428 operand = UnionExpr()
1429 {
1430 op.addOperand(operand);
1431 }
1432 )*
1433
1434 {
1435 return op==null?operand:op;
1436 }
1437}
1438
1439Expression UnionExpr() throws ParseException:
1440{
1441 UnionExpr union = null;
1442 Expression operand1 = null;
1443 Expression operand2 = null;
1444}
1445{
1446 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001447 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001448 (operand2 = UnaryExpr()) {
1449 if (union == null) {
1450 union = new UnionExpr();
1451 union.addExpr(operand1);
1452 }
1453 union.addExpr(operand2);
1454 } )*
1455 {
1456 return (union == null)? operand1: union;
1457 }
1458}
1459
1460Expression UnaryExpr() throws ParseException:
1461{
1462 Expression uexpr = null;
1463 Expression expr = null;
1464}
1465{
Till Westmann96c1f172013-08-01 02:05:48 -07001466 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001467 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001468 uexpr = new UnaryExpr();
1469 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001470 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001471 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001472 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1473 else
1474 throw new ParseException();
1475 }
1476 )?
1477
1478 expr = ValueExpr()
1479 {
1480 if(uexpr!=null){
1481 ((UnaryExpr)uexpr).setExpr(expr);
1482 return uexpr;
1483 }
1484 else{
1485 return expr;
1486 }
1487 }
1488}
1489
Till Westmann04478e72013-05-13 23:01:34 -07001490Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001491{
1492 Expression expr = null;
1493 Identifier ident = null;
1494 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001495 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001496}
1497{
Till Westmann04478e72013-05-13 23:01:34 -07001498 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001499 {
Till Westmann04478e72013-05-13 23:01:34 -07001500 fa = (fa == null ? new FieldAccessor(expr, ident)
1501 : new FieldAccessor(fa, ident));
1502 }
icetindila611ac72014-05-16 10:10:11 -07001503 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001504 {
icetindila611ac72014-05-16 10:10:11 -07001505 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1506 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001507 }
1508 )*
1509 {
1510 return fa == null ? expr : fa;
1511 }
vinayakb38b7ca42012-03-05 05:44:15 +00001512}
1513
1514Identifier Field() throws ParseException:
1515{
Till Westmann14a20a72013-05-09 00:06:24 -07001516 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001517}
1518{
Till Westmann96c1f172013-08-01 02:05:48 -07001519 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001520 {
Till Westmann14a20a72013-05-09 00:06:24 -07001521 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001522 }
vinayakb38b7ca42012-03-05 05:44:15 +00001523}
1524
icetindila611ac72014-05-16 10:10:11 -07001525Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001526{
1527 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001528}
1529{
Till Westmann96c1f172013-08-01 02:05:48 -07001530 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001531 {
1532 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1533 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001534 Literal lit = ((LiteralExpr)expr).getValue();
icetindila611ac72014-05-16 10:10:11 -07001535 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1536 lit.getLiteralType() != Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001537 throw new ParseException("Index should be an INTEGER");
1538 }
1539 }
vinayakb38b7ca42012-03-05 05:44:15 +00001540 }
1541
icetindil5860fb92014-05-16 11:22:15 -07001542 | <QUES> // ANY
vinayakb38b7ca42012-03-05 05:44:15 +00001543
1544 )
1545
Till Westmann96c1f172013-08-01 02:05:48 -07001546 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001547 {
icetindila611ac72014-05-16 10:10:11 -07001548 return expr;
vinayakb38b7ca42012-03-05 05:44:15 +00001549 }
1550}
1551
1552
1553Expression PrimaryExpr()throws ParseException:
1554{
1555 Expression expr = null;
1556}
1557{
Till Westmann68d99652013-05-09 11:15:21 -07001558 ( LOOKAHEAD(2)
1559 expr = FunctionCallExpr()
1560 | expr = Literal()
1561 | expr = DatasetAccessExpression()
1562 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001563 {
1564 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001565 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001566 }
Till Westmann68d99652013-05-09 11:15:21 -07001567 | expr = ListConstructor()
1568 | expr = RecordConstructor()
1569 | expr = ParenthesizedExpression()
1570 )
1571 {
1572 return expr;
1573 }
vinayakb38b7ca42012-03-05 05:44:15 +00001574}
1575
1576Expression Literal() throws ParseException:
1577{
vinayakb38b7ca42012-03-05 05:44:15 +00001578 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001579 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001580}
1581{
Till Westmann7d535322013-05-09 00:40:02 -07001582 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001583 {
Till Westmann7d535322013-05-09 00:40:02 -07001584 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001585 }
1586 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001587 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001588 try {
1589 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1590 } catch(NumberFormatException ex) {
1591 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1592 }
1593 }
1594 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001595 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001596 lit.setValue(new FloatLiteral(new Float(token.image)));
1597 }
1598 | <DOUBLE_LITERAL>
1599 {
1600 lit.setValue(new DoubleLiteral(new Double(token.image)));
1601 }
1602 | <NULL>
1603 {
1604 lit.setValue(NullLiteral.INSTANCE);
1605 }
1606 | <TRUE>
1607 {
1608 lit.setValue(TrueLiteral.INSTANCE);
1609 }
1610 | <FALSE>
1611 {
1612 lit.setValue(FalseLiteral.INSTANCE);
1613 }
1614 )
vinayakb38b7ca42012-03-05 05:44:15 +00001615 {
1616 return lit;
1617 }
1618}
1619
1620
1621VariableExpr VariableRef() throws ParseException:
1622{
1623 VariableExpr varExp = new VariableExpr();
1624 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001625}
1626{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001627 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001628 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001629 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001630 Identifier ident = lookupSymbol(varName);
1631 if (isInForbiddenScopes(varName)) {
1632 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.");
1633 }
1634 if(ident != null) { // exist such ident
1635 varExp.setIsNewVar(false);
1636 varExp.setVar((VarIdentifier)ident);
1637 } else {
1638 varExp.setVar(var);
1639 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001640 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001641 return varExp;
1642 }
1643}
1644
1645
1646VariableExpr Variable() throws ParseException:
1647{
1648 VariableExpr varExp = new VariableExpr();
1649 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001650}
1651{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001652 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001653 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001654 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001655 if(ident != null) { // exist such ident
1656 varExp.setIsNewVar(false);
1657 }
1658 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001659 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001660 return varExp;
1661 }
1662}
1663
1664Expression ListConstructor() throws ParseException:
1665{
1666 Expression expr = null;
1667}
1668{
1669 (
1670 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1671 )
1672
1673 {
1674 return expr;
1675 }
1676}
1677
1678
1679ListConstructor OrderedListConstructor() throws ParseException:
1680{
1681 ListConstructor expr = new ListConstructor();
1682 Expression tmp = null;
1683 List<Expression> exprList = new ArrayList<Expression>();
1684 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1685}
1686{
1687
Till Westmann96c1f172013-08-01 02:05:48 -07001688 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001689 ( tmp = Expression()
1690 {
1691 exprList.add(tmp);
1692 }
1693
Till Westmann96c1f172013-08-01 02:05:48 -07001694 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001695 )?
1696
Till Westmann96c1f172013-08-01 02:05:48 -07001697 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001698
1699 {
1700 expr.setExprList(exprList);
1701 return expr;
1702 }
1703}
1704
1705ListConstructor UnorderedListConstructor() throws ParseException:
1706{
1707 ListConstructor expr = new ListConstructor();
1708 Expression tmp = null;
1709 List<Expression> exprList = new ArrayList<Expression>();
1710 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1711}
1712{
1713
Till Westmann96c1f172013-08-01 02:05:48 -07001714 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001715 {
1716 exprList.add(tmp);
1717 }
Till Westmann96c1f172013-08-01 02:05:48 -07001718 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001719 {
1720 expr.setExprList(exprList);
1721 return expr;
1722 }
1723}
1724
1725RecordConstructor RecordConstructor() throws ParseException:
1726{
1727 RecordConstructor expr = new RecordConstructor();
1728 FieldBinding tmp = null;
1729 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1730}
1731{
Till Westmann96c1f172013-08-01 02:05:48 -07001732 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001733 {
1734 fbList.add(tmp);
1735 }
Till Westmann96c1f172013-08-01 02:05:48 -07001736 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001737 {
1738 expr.setFbList(fbList);
1739 return expr;
1740 }
1741}
1742
1743FieldBinding FieldBinding() throws ParseException:
1744{
1745 FieldBinding fb = new FieldBinding();
1746 Expression left, right;
1747}
1748{
Till Westmann96c1f172013-08-01 02:05:48 -07001749 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001750 {
1751 fb.setLeftExpr(left);
1752 fb.setRightExpr(right);
1753 return fb;
1754 }
1755}
1756
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001757
vinayakb38b7ca42012-03-05 05:44:15 +00001758Expression FunctionCallExpr() throws ParseException:
1759{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001760 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001761 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001762 Expression tmp;
1763 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001764 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001765 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001766}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001767{
ramangrover299f76a5e2013-06-18 10:25:17 -07001768 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001769 {
Till Westmann31c21f92013-05-08 09:21:53 -07001770 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001771 }
Till Westmann31c21f92013-05-08 09:21:53 -07001772 <LEFTPAREN> (tmp = Expression()
1773 {
1774 argList.add(tmp);
1775 arity ++;
1776 }
Till Westmann96c1f172013-08-01 02:05:48 -07001777 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001778 {
1779 argList.add(tmp);
1780 arity++;
1781 }
1782 )*)? <RIGHTPAREN>
1783 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001784 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001785 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001786 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001787 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001788 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001789 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001790 }
1791 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001792 if (hint != null) {
1793 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1794 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1795 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1796 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1797 }
Till Westmann31c21f92013-05-08 09:21:53 -07001798 }
1799 return callExpr;
1800 }
vinayakb38b7ca42012-03-05 05:44:15 +00001801}
1802
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001803
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001804Expression DatasetAccessExpression() throws ParseException:
1805{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001806 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001807 String arg1 = null;
1808 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001809 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001810}
1811{
Till Westmann14a20a72013-05-09 00:06:24 -07001812 <DATASET>
1813 {
Till Westmann14a20a72013-05-09 00:06:24 -07001814 funcName = token.image;
1815 }
Till Westmann96c1f172013-08-01 02:05:48 -07001816 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001817 {
1818 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001819 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001820 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001821 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001822 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001823 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001824 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001825 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1826 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1827 if (signature == null) {
1828 signature = new FunctionSignature(dataverse, funcName, 1);
1829 }
1830 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001831 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001832 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001833 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001834}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001835
vinayakb38b7ca42012-03-05 05:44:15 +00001836Expression ParenthesizedExpression() throws ParseException:
1837{
1838 Expression expr;
1839}
1840{
1841 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1842 {
1843 return expr;
1844 }
1845}
1846
1847Expression IfThenElse() throws ParseException:
1848{
1849 Expression condExpr;
1850 Expression thenExpr;
1851 Expression elseExpr;
1852 IfExpr ifExpr = new IfExpr();
1853}
1854{
Till Westmann96c1f172013-08-01 02:05:48 -07001855 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001856
1857 {
1858 ifExpr.setCondExpr(condExpr);
1859 ifExpr.setThenExpr(thenExpr);
1860 ifExpr.setElseExpr(elseExpr);
1861 return ifExpr;
1862 }
1863}
1864
1865Expression FLWOGR() throws ParseException:
1866{
1867 FLWOGRExpression flworg = new FLWOGRExpression();
1868 List<Clause> clauseList = new ArrayList<Clause>();
1869 Expression returnExpr;
1870 Clause tmp;
1871 createNewScope();
1872}
1873{
1874 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001875 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001876
1877 {
1878 flworg.setClauseList(clauseList);
1879 flworg.setReturnExpr(returnExpr);
1880 removeCurrentScope();
1881 return flworg;
1882 }
1883}
1884
1885Clause Clause()throws ParseException :
1886{
1887 Clause clause;
1888}
1889{
1890 (
1891 clause = ForClause()
1892 | clause = LetClause()
1893 | clause = WhereClause()
1894 | clause = OrderbyClause()
1895 | clause = GroupClause()
1896 | clause = LimitClause()
1897 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001898 )
1899 {
1900 return clause;
1901 }
1902}
1903
1904Clause ForClause()throws ParseException :
1905{
1906 ForClause fc = new ForClause();
1907 VariableExpr varExp;
1908 VariableExpr varPos = null;
1909 Expression inExp;
1910 extendCurrentScope();
1911}
1912{
Till Westmann96c1f172013-08-01 02:05:48 -07001913 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001914 {
1915 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001916 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001917 fc.setInExpr(inExp);
1918 if (varPos != null) {
1919 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001920 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001921 }
1922 return fc;
1923 }
1924}
1925
1926Clause LetClause() throws ParseException:
1927{
1928 LetClause lc = new LetClause();
1929 VariableExpr varExp;
1930 Expression beExp;
1931 extendCurrentScope();
1932}
1933{
Till Westmann96c1f172013-08-01 02:05:48 -07001934 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001935 {
1936 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001937 lc.setVarExpr(varExp);
1938 lc.setBeExpr(beExp);
1939 return lc;
1940 }
1941}
1942
1943Clause WhereClause()throws ParseException :
1944{
1945 WhereClause wc = new WhereClause();
1946 Expression whereExpr;
1947}
1948{
salsubaieedf89fbc2013-12-21 19:51:42 -08001949 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001950 {
1951 wc.setWhereExpr(whereExpr);
1952 return wc;
1953 }
1954}
1955
1956Clause OrderbyClause()throws ParseException :
1957{
1958 OrderbyClause oc = new OrderbyClause();
1959 Expression orderbyExpr;
1960 List<Expression> orderbyList = new ArrayList<Expression>();
1961 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1962 int numOfOrderby = 0;
1963}
1964{
1965 (
Till Westmann96c1f172013-08-01 02:05:48 -07001966 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001967 {
1968 String hint = getHint(token);
1969 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1970 String splits[] = hint.split(" +");
1971 int numFrames = Integer.parseInt(splits[1]);
1972 int numTuples = Integer.parseInt(splits[2]);
1973 oc.setNumFrames(numFrames);
1974 oc.setNumTuples(numTuples);
1975 }
1976 }
Till Westmann96c1f172013-08-01 02:05:48 -07001977 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001978 {
1979 orderbyList.add(orderbyExpr);
1980 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1981 }
Till Westmann96c1f172013-08-01 02:05:48 -07001982 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1983 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001984 {
1985 modifierList.add(modif);
1986 }
1987
Till Westmann96c1f172013-08-01 02:05:48 -07001988 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001989 {
1990 orderbyList.add(orderbyExpr);
1991 modif = OrderbyClause.OrderModifier.ASC;
1992 }
Till Westmann96c1f172013-08-01 02:05:48 -07001993 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1994 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001995 {
1996 modifierList.add(modif);
1997 }
1998 )*
1999)
2000 {
2001 oc.setModifierList(modifierList);
2002 oc.setOrderbyList(orderbyList);
2003 return oc;
2004 }
2005}
2006Clause GroupClause()throws ParseException :
2007{
2008 GroupbyClause gbc = new GroupbyClause();
2009 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2010 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2011 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2012 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2013 VariableExpr var = null;
2014 VariableExpr withVar = null;
2015 Expression expr = null;
2016 VariableExpr decorVar = null;
2017 Expression decorExpr = null;
2018}
2019{
2020 {
2021 Scope newScope = extendCurrentScopeNoPush(true);
2022 // extendCurrentScope(true);
2023 }
Till Westmann96c1f172013-08-01 02:05:48 -07002024 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002025 {
2026 String hint = getHint(token);
2027 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2028 gbc.setHashGroupByHint(true);
2029 }
2030 }
Till Westmann96c1f172013-08-01 02:05:48 -07002031 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002032 {
2033 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002034 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002035 expr = Expression()
2036 {
2037 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2038 vePairList.add(pair1);
2039 }
Till Westmann96c1f172013-08-01 02:05:48 -07002040 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002041 {
2042 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002043 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002044 expr = Expression()
2045 {
2046 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2047 vePairList.add(pair2);
2048 }
2049 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002050 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002051 {
2052 newScope.addNewVarSymbolToScope(decorVar.getVar());
2053 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2054 decorPairList.add(pair3);
2055 }
Till Westmann96c1f172013-08-01 02:05:48 -07002056 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002057 {
2058 newScope.addNewVarSymbolToScope(decorVar.getVar());
2059 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2060 decorPairList.add(pair4);
2061 }
2062 )*
2063 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002064 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002065 {
2066 if(withVar.getIsNewVar()==true)
2067 throw new ParseException("can't find variable " + withVar.getVar());
2068 withVarList.add(withVar);
2069 newScope.addNewVarSymbolToScope(withVar.getVar());
2070 }
Till Westmann96c1f172013-08-01 02:05:48 -07002071 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002072 {
2073 if(withVar.getIsNewVar()==true)
2074 throw new ParseException("can't find variable " + withVar.getVar());
2075 withVarList.add(withVar);
2076 newScope.addNewVarSymbolToScope(withVar.getVar());
2077 })*
2078 {
2079 gbc.setGbyPairList(vePairList);
2080 gbc.setDecorPairList(decorPairList);
2081 gbc.setWithVarList(withVarList);
2082 replaceCurrentScope(newScope);
2083 return gbc;
2084 }
2085}
2086
2087
2088LimitClause LimitClause() throws ParseException:
2089{
2090 LimitClause lc = new LimitClause();
2091 Expression expr;
2092 pushForbiddenScope(getCurrentScope());
2093}
2094{
Till Westmann96c1f172013-08-01 02:05:48 -07002095 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2096 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002097
2098 {
2099 popForbiddenScope();
2100 return lc;
2101 }
2102}
2103
2104DistinctClause DistinctClause() throws ParseException:
2105{
2106 List<Expression> exprs = new ArrayList<Expression>();
2107 Expression expr;
2108}
2109{
Till Westmann96c1f172013-08-01 02:05:48 -07002110 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002111 {
2112 exprs.add(expr);
2113 }
Till Westmann96c1f172013-08-01 02:05:48 -07002114 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002115 {
2116 exprs.add(expr);
2117 }
2118 )*
2119 {
2120 return new DistinctClause(exprs);
2121 }
2122}
2123
vinayakb38b7ca42012-03-05 05:44:15 +00002124QuantifiedExpression QuantifiedExpression()throws ParseException:
2125{
2126 QuantifiedExpression qc = new QuantifiedExpression();
2127 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2128 Expression satisfiesExpr;
2129 VariableExpr var;
2130 Expression inExpr;
2131 QuantifiedPair pair;
2132}
2133{
2134 {
2135 createNewScope();
2136 }
2137
Till Westmann96c1f172013-08-01 02:05:48 -07002138 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2139 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2140 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002141 {
2142 pair = new QuantifiedPair(var, inExpr);
2143 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2144 quantifiedList.add(pair);
2145 }
2146 (
Till Westmann96c1f172013-08-01 02:05:48 -07002147 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002148 {
2149 pair = new QuantifiedPair(var, inExpr);
2150 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2151 quantifiedList.add(pair);
2152 }
2153 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002154 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002155 {
2156 qc.setSatisfiesExpr(satisfiesExpr);
2157 qc.setQuantifiedList(quantifiedList);
2158 removeCurrentScope();
2159 return qc;
2160 }
2161}
2162
2163TOKEN_MGR_DECLS:
2164{
Till Westmann96c1f172013-08-01 02:05:48 -07002165 public int commentDepth = 0;
2166 public IntStack lexerStateStack = new IntStack();
2167
2168 public void pushState() {
2169 lexerStateStack.push( curLexState );
2170 }
2171
2172 public void popState() {
2173 if (lexerStateStack.size() > 0) {
2174 SwitchTo( lexerStateStack.pop() );
2175 } else {
2176 throw new RuntimeException();
2177 }
2178 }
vinayakb38b7ca42012-03-05 05:44:15 +00002179}
2180
Till Westmann96c1f172013-08-01 02:05:48 -07002181<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002182TOKEN :
2183{
Till Westmann5df7b452013-08-02 13:07:16 -07002184 <ASC : "asc">
2185 | <AT : "at">
2186 | <BY : "by">
2187 | <DATASET : "dataset">
2188 | <DECOR : "decor">
2189 | <DESC : "desc">
2190 | <DISTINCT : "distinct">
2191 | <ELSE : "else">
2192 | <EVERY : "every">
2193 | <FOR : "for">
2194 | <GROUP : "group">
2195 | <IF : "if">
2196 | <IN : "in">
2197 | <LET : "let">
2198 | <LIMIT : "limit">
2199 | <OFFSET : "offset">
2200 | <ORDER : "order">
2201 | <RETURN : "return">
2202 | <SATISFIES : "satisfies">
2203 | <SOME : "some">
2204 | <THEN : "then">
2205 | <UNION : "union">
2206 | <WHERE : "where">
2207 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002208}
2209
Till Westmann96c1f172013-08-01 02:05:48 -07002210<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002211TOKEN :
2212{
Till Westmann5df7b452013-08-02 13:07:16 -07002213 <CARET : "^">
2214 | <DIV : "/">
2215 | <IDIV : "idiv">
2216 | <MINUS : "-">
2217 | <MOD : "%">
2218 | <MUL : "*">
2219 | <PLUS : "+">
2220
2221 | <LEFTPAREN : "(">
2222 | <RIGHTPAREN : ")">
2223 | <LEFTBRACKET : "[">
2224 | <RIGHTBRACKET : "]">
2225
2226 | <COLON : ":">
2227 | <COMMA : ",">
2228 | <DOT : ".">
2229 | <QUES : "?">
2230
2231 | <LT : "<">
2232 | <GT : ">">
2233 | <LE : "<=">
2234 | <GE : ">=">
2235 | <EQ : "=">
2236 | <NE : "!=">
2237 | <SIMILAR : "~=">
2238 | <ASSIGN : ":=">
2239
2240 | <AND : "and">
2241 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002242}
2243
Till Westmann96c1f172013-08-01 02:05:48 -07002244<DEFAULT,IN_DBL_BRACE>
2245TOKEN :
2246{
Till Westmann5df7b452013-08-02 13:07:16 -07002247 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002248}
2249
2250<DEFAULT>
2251TOKEN :
2252{
Till Westmann5df7b452013-08-02 13:07:16 -07002253 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002254}
2255
Till Westmann96c1f172013-08-01 02:05:48 -07002256<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002257TOKEN :
2258{
Till Westmann5df7b452013-08-02 13:07:16 -07002259 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002260}
2261
Till Westmann96c1f172013-08-01 02:05:48 -07002262<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002263TOKEN :
2264{
Till Westmann5df7b452013-08-02 13:07:16 -07002265 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002266}
2267
Till Westmann96c1f172013-08-01 02:05:48 -07002268<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002269TOKEN :
2270{
Till Westmann5df7b452013-08-02 13:07:16 -07002271 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002272}
2273
Till Westmann96c1f172013-08-01 02:05:48 -07002274<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002275TOKEN :
2276{
Till Westmann5df7b452013-08-02 13:07:16 -07002277 <NULL : "null">
2278 | <TRUE : "true">
2279 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002280}
2281
Till Westmann96c1f172013-08-01 02:05:48 -07002282<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002283TOKEN :
2284{
Till Westmann5df7b452013-08-02 13:07:16 -07002285 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002286}
2287
Till Westmann96c1f172013-08-01 02:05:48 -07002288<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002289TOKEN:
2290{
Till Westmann5df7b452013-08-02 13:07:16 -07002291 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002292 | <DIGITS> ( "." <DIGITS> )?
2293 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002294 >
2295 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002296 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2297 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002298 >
2299 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002300}
2301
Till Westmann96c1f172013-08-01 02:05:48 -07002302<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002303TOKEN :
2304{
Till Westmann5df7b452013-08-02 13:07:16 -07002305 <#LETTER : ["A" - "Z", "a" - "z"]>
2306 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002307}
2308
Till Westmann96c1f172013-08-01 02:05:48 -07002309<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002310TOKEN :
2311{
Till Westmanne0cc01c2014-03-31 10:26:10 -07002312 <STRING_LITERAL : ("\"" (<EscapeQuot> | <EscapeBslash> | ~["\"","\\"])* "\"")
2313 | ("\'"(<EscapeApos> | <EscapeBslash> | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002314 | < #EscapeQuot: "\\\"" >
2315 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002316 | < #EscapeBslash: "\\\\" >
vinayakb38b7ca42012-03-05 05:44:15 +00002317}
2318
Till Westmann96c1f172013-08-01 02:05:48 -07002319<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002320TOKEN :
2321{
Till Westmann5df7b452013-08-02 13:07:16 -07002322 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002323}
2324
Till Westmann96c1f172013-08-01 02:05:48 -07002325<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002326TOKEN :
2327{
Till Westmann5df7b452013-08-02 13:07:16 -07002328 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002329}
2330
Till Westmann96c1f172013-08-01 02:05:48 -07002331<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002332SKIP:
2333{
2334 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002335 | "\t"
2336 | "\r"
2337 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002338}
2339
Till Westmann96c1f172013-08-01 02:05:48 -07002340<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002341SKIP:
2342{
Till Westmann5df7b452013-08-02 13:07:16 -07002343 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002344}
2345
Till Westmann96c1f172013-08-01 02:05:48 -07002346<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002347SKIP:
2348{
Till Westmann5df7b452013-08-02 13:07:16 -07002349 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002350}
2351
Till Westmann96c1f172013-08-01 02:05:48 -07002352<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002353SKIP:
2354{
Till Westmann96c1f172013-08-01 02:05:48 -07002355 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002356}
2357
2358<INSIDE_COMMENT>
2359SPECIAL_TOKEN:
2360{
Till Westmann5df7b452013-08-02 13:07:16 -07002361 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002362}
2363
2364<INSIDE_COMMENT>
2365SKIP:
2366{
Till Westmann96c1f172013-08-01 02:05:48 -07002367 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002368}
2369
2370<INSIDE_COMMENT>
2371SKIP:
2372{
Till Westmann96c1f172013-08-01 02:05:48 -07002373 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002374 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002375}