blob: 430ea7d34bc52c9347bc7c8143c206f95bc80c99 [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;
salsubaieea5af4e02014-07-08 15:20:02 -0700317 String filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700318}
319{
320 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700321 "external" <DATASET> nameComponents = QualifiedName()
322 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
323 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700324 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700325 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700326 ( "hints" hints = Properties() )?
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700327 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700328 {
329 ExternalDetailsDecl edd = new ExternalDetailsDecl();
330 edd.setAdapter(adapterName);
331 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700332 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
333 edd.setCompactionPolicy(compactionPolicy);
334 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700335 dsetDecl = new DatasetDecl(nameComponents.first,
336 nameComponents.second,
337 new Identifier(typeName),
338 hints,
339 DatasetType.EXTERNAL,
340 edd,
341 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700342 }
343
Till Westmannd7dcb122013-05-16 13:19:09 -0700344 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700345 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
346 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700347 primaryKeyFields = PrimaryKey()
348 ("autogenerated" { autogenerated = true; } )?
349 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700350 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700351 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
salsubaieea5af4e02014-07-08 15:20:02 -0700352 ( "with filter on" filterField = FilterField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700353 {
Till Westmann14a20a72013-05-09 00:06:24 -0700354 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
355 ? new Identifier(nodeGroupName)
356 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700357 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700358 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700359 compactionPolicy,
salsubaieea5af4e02014-07-08 15:20:02 -0700360 compactionPolicyProperties,
361 filterField);
Till Westmann14a20a72013-05-09 00:06:24 -0700362 dsetDecl = new DatasetDecl(nameComponents.first,
363 nameComponents.second,
364 new Identifier(typeName),
365 hints,
366 DatasetType.INTERNAL,
367 idd,
368 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700369 }
370 )
371 {
372 return dsetDecl;
373 }
374}
375
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700376RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
377{
378 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
379 Pair<Identifier,Identifier> nameComponents = null;
380 String datasetName = null;
381}
382{
383 "refresh external" <DATASET> nameComponents = QualifiedName()
384 {
385 redss.setDataverseName(nameComponents.first);
386 redss.setDatasetName(nameComponents.second);
387 return redss;
388 }
389}
390
Till Westmann31c21f92013-05-08 09:21:53 -0700391CreateIndexStatement IndexSpecification() throws ParseException:
392{
393 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700394 String indexName = null;
395 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700396 boolean ifNotExists = false;
397 Pair<Identifier,Identifier> nameComponents = null;
398 IndexParams indexType = null;
399}
400{
Till Westmanna4242bc2013-05-08 17:49:55 -0700401 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700402 ifNotExists = IfNotExists()
403 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700404 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700405 {
Till Westmann14a20a72013-05-09 00:06:24 -0700406 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700407 }
Till Westmann96c1f172013-08-01 02:05:48 -0700408 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700409 {
Till Westmann14a20a72013-05-09 00:06:24 -0700410 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700411 }
412 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
413 {
Till Westmann14a20a72013-05-09 00:06:24 -0700414 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700415 cis.setIfNotExists(ifNotExists);
416 cis.setDataverseName(nameComponents.first);
417 cis.setDatasetName(nameComponents.second);
418 if (indexType != null) {
419 cis.setIndexType(indexType.type);
420 cis.setGramLength(indexType.gramLength);
421 }
422 return cis;
423 }
424}
425
salsubaiee0b423fa2013-09-19 19:16:48 -0700426String CompactionPolicy() throws ParseException :
427{
428 String compactionPolicy = null;
429}
430{
431 compactionPolicy = Identifier()
432 {
433 return compactionPolicy;
434 }
435}
436
salsubaieea5af4e02014-07-08 15:20:02 -0700437String FilterField() throws ParseException :
438{
439 String filterField = null;
440}
441{
442 filterField = Identifier()
443 {
444 return filterField;
445 }
446}
447
Till Westmann31c21f92013-05-08 09:21:53 -0700448IndexParams IndexType() throws ParseException:
449{
450 IndexType type = null;
451 int gramLength = 0;
452}
453{
454 ("btree"
455 {
456 type = IndexType.BTREE;
457 }
458 | "rtree"
459 {
460 type = IndexType.RTREE;
461 }
462 | "keyword"
463 {
JIMAHNb75446d2013-06-03 08:35:27 -0700464 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700465 }
466 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
467 {
JIMAHNb75446d2013-06-03 08:35:27 -0700468 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700469 gramLength = Integer.valueOf(token.image);
470 }
471 <RIGHTPAREN>)
472 {
473 return new IndexParams(type, gramLength);
474 }
475}
476
477CreateDataverseStatement DataverseSpecification() throws ParseException :
478{
Till Westmann14a20a72013-05-09 00:06:24 -0700479 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700480 boolean ifNotExists = false;
481 String format = null;
482}
483{
Till Westmanna4242bc2013-05-08 17:49:55 -0700484 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700485 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700486 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700487 {
Till Westmann14a20a72013-05-09 00:06:24 -0700488 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700489 }
490}
491
492CreateFunctionStatement FunctionSpecification() throws ParseException:
493{
494 FunctionSignature signature;
495 boolean ifNotExists = false;
496 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
497 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700498 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700499 Expression functionBodyExpr;
500 Token beginPos;
501 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700502 FunctionName fctName = null;
503
Till Westmann31c21f92013-05-08 09:21:53 -0700504 createNewScope();
505}
506{
ramangrover299f76a5e2013-06-18 10:25:17 -0700507 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700508 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700509 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700510 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530511 {
512 beginPos = token;
513 }
Till Westmann96c1f172013-08-01 02:05:48 -0700514 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700515 {
516 endPos = token;
517 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700518 // TODO use fctName.library
519 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700520 getCurrentScope().addFunctionDescriptor(signature, false);
521 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
522 }
523}
524
ramangrover29a774ef22013-07-17 09:29:18 -0700525CreateFeedStatement FeedSpecification() throws ParseException:
526{
527 Pair<Identifier,Identifier> nameComponents = null;
528 boolean ifNotExists = false;
529 String adaptorName = null;
530 Map<String,String> properties = null;
531 FunctionSignature appliedFunction = null;
532 CreateFeedStatement cfs = null;
533}
534{
535 (
536 "feed" nameComponents = QualifiedName()
537 ifNotExists = IfNotExists()
538 "using" adaptorName = AdapterName() properties = Configuration()
539 (appliedFunction = ApplyFunction())?
540 {
541 cfs = new CreateFeedStatement(nameComponents.first,
542 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
543 }
544
545 )
546 {
547 return cfs;
548 }
549}
550
551
552
Till Westmannd7dcb122013-05-16 13:19:09 -0700553List<VarIdentifier> ParameterList() throws ParseException:
554{
555 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
556 VarIdentifier var = null;
557}
558{
Till Westmann31c21f92013-05-08 09:21:53 -0700559 <LEFTPAREN> (<VARIABLE>
560 {
561 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700562 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700563 paramList.add(var);
564 getCurrentScope().addNewVarSymbolToScope(var);
565 }
Till Westmann96c1f172013-08-01 02:05:48 -0700566 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700567 {
568 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700569 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700570 paramList.add(var);
571 getCurrentScope().addNewVarSymbolToScope(var);
572 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700573 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700574 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700575 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700576 }
577}
578
579boolean IfNotExists() throws ParseException:
580{
581}
582{
583 ( "if not exists"
584 {
585 return true;
586 }
587 )?
588 {
589 return false;
590 }
591}
592
593FunctionSignature ApplyFunction() throws ParseException:
594{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530595 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700596 FunctionSignature funcSig = null;
597}
598{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530599 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700600 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530601 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
602 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700603 }
604}
605
ramangrover29566b3a92013-05-28 09:07:10 -0700606String GetPolicy() throws ParseException:
607{
608 String policy = null;
609}
610{
611 "using" "policy" policy = Identifier()
612 {
613 return policy;
614 }
615
616}
617
Till Westmann31c21f92013-05-08 09:21:53 -0700618FunctionSignature FunctionSignature() throws ParseException:
619{
ramangrover299f76a5e2013-06-18 10:25:17 -0700620 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700621 int arity = 0;
622}
623{
ramangrover299f76a5e2013-06-18 10:25:17 -0700624 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700625 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700626 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700627 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
628 throw new ParseException(" invalid arity:" + arity);
629 }
630
ramangrover299f76a5e2013-06-18 10:25:17 -0700631 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700632 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
633 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700634 }
635}
636
637List<String> PrimaryKey() throws ParseException:
638{
Till Westmann14a20a72013-05-09 00:06:24 -0700639 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700640 List<String> primaryKeyFields = new ArrayList<String>();
641}
642{
Till Westmann14a20a72013-05-09 00:06:24 -0700643 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700644 {
Till Westmann14a20a72013-05-09 00:06:24 -0700645 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700646 }
Till Westmann96c1f172013-08-01 02:05:48 -0700647 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700648 {
Till Westmann14a20a72013-05-09 00:06:24 -0700649 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700650 }
651 )*
652 {
653 return primaryKeyFields;
654 }
655}
656
657Statement DropStatement() throws ParseException:
658{
Till Westmann14a20a72013-05-09 00:06:24 -0700659 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700660 Pair<Identifier,Identifier> pairId = null;
661 Triple<Identifier,Identifier,Identifier> tripleId = null;
662 FunctionSignature funcSig = null;
663 boolean ifExists = false;
664 Statement stmt = null;
665}
666{
667 "drop"
668 (
669 <DATASET> pairId = QualifiedName() ifExists = IfExists()
670 {
671 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
672 }
673 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
674 {
675 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
676 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700677 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700678 {
Till Westmann14a20a72013-05-09 00:06:24 -0700679 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700680 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700681 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700682 {
683 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
684 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700685 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700686 {
Till Westmann14a20a72013-05-09 00:06:24 -0700687 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700688 }
689 | "function" funcSig = FunctionSignature() ifExists = IfExists()
690 {
691 stmt = new FunctionDropStatement(funcSig, ifExists);
692 }
ramangrover29a774ef22013-07-17 09:29:18 -0700693 | "feed" pairId = QualifiedName() ifExists = IfExists()
694 {
695 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
696 }
Till Westmann31c21f92013-05-08 09:21:53 -0700697 )
698 {
699 return stmt;
700 }
701}
702
703boolean IfExists() throws ParseException :
704{
705}
706{
Till Westmann96c1f172013-08-01 02:05:48 -0700707 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700708 {
709 return true;
710 }
711 )?
712 {
713 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000714 }
715}
716
717InsertStatement InsertStatement() throws ParseException:
718{
Till Westmann31c21f92013-05-08 09:21:53 -0700719 Pair<Identifier,Identifier> nameComponents = null;
720 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000721}
722{
Till Westmann31c21f92013-05-08 09:21:53 -0700723 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
724 {
725 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
726 }
vinayakb38b7ca42012-03-05 05:44:15 +0000727}
728
729DeleteStatement DeleteStatement() throws ParseException:
730{
Till Westmann31c21f92013-05-08 09:21:53 -0700731 VariableExpr var = null;
732 Expression condition = null;
733 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000734}
735{
Till Westmann31c21f92013-05-08 09:21:53 -0700736 "delete" var = Variable()
737 {
738 getCurrentScope().addNewVarSymbolToScope(var.getVar());
739 }
salsubaieedf89fbc2013-12-21 19:51:42 -0800740 "from" <DATASET> nameComponents = QualifiedName()
741 (<WHERE> condition = Expression())?
742 {
743 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700744 }
vinayakb38b7ca42012-03-05 05:44:15 +0000745}
746
747UpdateStatement UpdateStatement() throws ParseException:
748{
Till Westmann31c21f92013-05-08 09:21:53 -0700749 VariableExpr vars;
750 Expression target;
751 Expression condition;
752 UpdateClause uc;
753 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000754}
755{
Till Westmann96c1f172013-08-01 02:05:48 -0700756 "update" vars = Variable() <IN> target = Expression()
757 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700758 <LEFTPAREN> (uc = UpdateClause()
759 {
760 ucs.add(uc);
761 }
Till Westmann96c1f172013-08-01 02:05:48 -0700762 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700763 {
764 ucs.add(uc);
765 }
766 )*) <RIGHTPAREN>
767 {
768 return new UpdateStatement(vars, target, condition, ucs);
769 }
vinayakb38b7ca42012-03-05 05:44:15 +0000770}
771
vinayakb38b7ca42012-03-05 05:44:15 +0000772UpdateClause UpdateClause() throws ParseException:
773{
Till Westmann31c21f92013-05-08 09:21:53 -0700774 Expression target = null;
775 Expression value = null ;
776 InsertStatement is = null;
777 DeleteStatement ds = null;
778 UpdateStatement us = null;
779 Expression condition = null;
780 UpdateClause ifbranch = null;
781 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000782}
783{
Till Westmann96c1f172013-08-01 02:05:48 -0700784 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700785 | is = InsertStatement()
786 | ds = DeleteStatement()
787 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700788 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
789 <THEN> ifbranch = UpdateClause()
790 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700791 {
792 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
793 }
vinayakb38b7ca42012-03-05 05:44:15 +0000794}
795
vinayakb38b7ca42012-03-05 05:44:15 +0000796Statement SetStatement() throws ParseException:
797{
798 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700799 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000800}
801{
Till Westmann7d535322013-05-09 00:40:02 -0700802 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700803 {
Till Westmann31c21f92013-05-08 09:21:53 -0700804 return new SetStatement(pn, pv);
805 }
vinayakb38b7ca42012-03-05 05:44:15 +0000806}
807
808Statement WriteStatement() throws ParseException:
809{
Till Westmann14a20a72013-05-09 00:06:24 -0700810 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000811 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000812 Query query;
813 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000814 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000815}
816{
Till Westmann96c1f172013-08-01 02:05:48 -0700817 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700818 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700819 {
820 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000821 }
822}
823
zheilbron28e026f2013-11-20 10:15:15 -0800824LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000825{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000826 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000827 Identifier datasetName = null;
828 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000829 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000830 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000831 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000832}
833{
Till Westmann31c21f92013-05-08 09:21:53 -0700834 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000835 {
Till Westmann31c21f92013-05-08 09:21:53 -0700836 dataverseName = nameComponents.first;
837 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000838 }
Till Westmann31c21f92013-05-08 09:21:53 -0700839 "using" adapterName = AdapterName() properties = Configuration()
840 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000841 {
Till Westmann31c21f92013-05-08 09:21:53 -0700842 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000843 }
844 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700845 {
zheilbron28e026f2013-11-20 10:15:15 -0800846 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Till Westmann31c21f92013-05-08 09:21:53 -0700847 }
vinayakb38b7ca42012-03-05 05:44:15 +0000848}
849
vinayakb38b7ca42012-03-05 05:44:15 +0000850
Till Westmann31c21f92013-05-08 09:21:53 -0700851String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000852{
ramangrover29669d8f62013-02-11 06:03:32 +0000853 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000854}
855{
Till Westmann68d99652013-05-09 11:15:21 -0700856 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000857 {
Till Westmann7d535322013-05-09 00:40:02 -0700858 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000859 }
vinayakb38b7ca42012-03-05 05:44:15 +0000860}
861
salsubaiee0b423fa2013-09-19 19:16:48 -0700862Statement CompactStatement() throws ParseException:
863{
864 Pair<Identifier,Identifier> nameComponents = null;
865 Statement stmt = null;
866}
867{
868 "compact" <DATASET> nameComponents = QualifiedName()
869 {
870 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
871 }
872 {
873 return stmt;
874 }
875}
876
Till Westmann31c21f92013-05-08 09:21:53 -0700877Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000878{
ramangrover29a774ef22013-07-17 09:29:18 -0700879 Pair<Identifier,Identifier> feedNameComponents = null;
880 Pair<Identifier,Identifier> datasetNameComponents = null;
881
Till Westmann31c21f92013-05-08 09:21:53 -0700882 Map<String,String> configuration = null;
883 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700884 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000885}
886{
Till Westmann31c21f92013-05-08 09:21:53 -0700887 (
ramangrover29a774ef22013-07-17 09:29:18 -0700888 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700889 {
ramangrover29a774ef22013-07-17 09:29:18 -0700890 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700891 }
ramangrover29a774ef22013-07-17 09:29:18 -0700892 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700893 {
ramangrover29a774ef22013-07-17 09:29:18 -0700894 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700895 }
896 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000897 {
Till Westmann31c21f92013-05-08 09:21:53 -0700898 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000899 }
900}
901
Till Westmann31c21f92013-05-08 09:21:53 -0700902Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000903{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000904 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700905 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000906}
907{
Till Westmann31c21f92013-05-08 09:21:53 -0700908 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000909 {
Till Westmann31c21f92013-05-08 09:21:53 -0700910 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000911 }
Till Westmann96c1f172013-08-01 02:05:48 -0700912 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000913 {
Till Westmann31c21f92013-05-08 09:21:53 -0700914 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000915 }
Till Westmann31c21f92013-05-08 09:21:53 -0700916 )* )? <RIGHTPAREN>
917 {
918 return configuration;
919 }
920}
921
922Pair<String, String> KeyValuePair() throws ParseException:
923{
924 String key;
925 String value;
926}
927{
Till Westmann96c1f172013-08-01 02:05:48 -0700928 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700929 {
930 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000931 }
Till Westmann31c21f92013-05-08 09:21:53 -0700932}
933
934Map<String,String> Properties() throws ParseException:
935{
936 Map<String,String> properties = new HashMap<String,String>();
937 Pair<String, String> property;
938}
939{
940 ( <LEFTPAREN> property = Property()
941 {
942 properties.put(property.first, property.second);
943 }
Till Westmann96c1f172013-08-01 02:05:48 -0700944 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700945 {
946 properties.put(property.first, property.second);
947 }
948 )* <RIGHTPAREN> )?
949 {
950 return properties;
951 }
952}
953
954Pair<String, String> Property() throws ParseException:
955{
956 String key;
957 String value;
958}
959{
Till Westmann96c1f172013-08-01 02:05:48 -0700960 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700961 {
962 try {
963 value = "" + Long.valueOf(token.image);
964 } catch (NumberFormatException nfe) {
965 throw new ParseException("inapproriate value: " + token.image);
966 }
967 }
968 )
969 {
970 return new Pair<String, String>(key.toUpperCase(), value);
971 }
vinayakb38b7ca42012-03-05 05:44:15 +0000972}
973
974TypeExpression TypeExpr() throws ParseException:
975{
976 TypeExpression typeExpr = null;
977}
978{
979 (
980 typeExpr = RecordTypeDef()
981 | typeExpr = TypeReference()
982 | typeExpr = OrderedListTypeDef()
983 | typeExpr = UnorderedListTypeDef()
984 )
985 {
986 return typeExpr;
987 }
988}
989
990RecordTypeDefinition RecordTypeDef() throws ParseException:
991{
992 RecordTypeDefinition recType = new RecordTypeDefinition();
993 RecordTypeDefinition.RecordKind recordKind = null;
994}
995{
996 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
997 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700998 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000999 {
1000 String hint = getHint(token);
1001 if (hint != null) {
1002 String splits[] = hint.split(" +");
1003 if (splits[0].equals(GEN_FIELDS_HINT)) {
1004 if (splits.length != 5) {
1005 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1006 }
1007 if (!splits[1].equals("int")) {
1008 throw new ParseException("The only supported type for gen-fields is int.");
1009 }
1010 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1011 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1012 recType.setUndeclaredFieldsDataGen(ufdg);
1013 }
1014 }
1015
1016 }
1017 (
1018 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -07001019 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +00001020 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001021 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001022 {
1023 if (recordKind == null) {
1024 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1025 }
1026 recType.setRecordKind(recordKind);
1027 return recType;
1028 }
1029}
1030
1031void RecordField(RecordTypeDefinition recType) throws ParseException:
1032{
Till Westmann77cb2f42013-07-15 16:44:19 -07001033 String fieldName;
1034 TypeExpression type = null;
1035 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001036}
1037{
Till Westmann77cb2f42013-07-15 16:44:19 -07001038 fieldName = Identifier()
1039 {
1040 String hint = getHint(token);
1041 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1042 }
Till Westmann96c1f172013-08-01 02:05:48 -07001043 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001044 {
1045 recType.addField(fieldName, type, nullable, rfdg);
1046 }
vinayakb38b7ca42012-03-05 05:44:15 +00001047}
1048
1049TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001050{
Till Westmann14a20a72013-05-09 00:06:24 -07001051 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001052}
1053{
1054 id = Identifier()
1055 {
Till Westmann14a20a72013-05-09 00:06:24 -07001056 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001057 }
vinayakb38b7ca42012-03-05 05:44:15 +00001058}
1059
1060OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1061{
1062 TypeExpression type = null;
1063}
1064{
Till Westmann96c1f172013-08-01 02:05:48 -07001065 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001066 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001067 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001068 {
1069 return new OrderedListTypeDefinition(type);
1070 }
1071}
1072
1073
1074UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1075{
1076 TypeExpression type = null;
1077}
1078{
Till Westmann96c1f172013-08-01 02:05:48 -07001079 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001080 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001081 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001082 {
1083 return new UnorderedListTypeDefinition(type);
1084 }
1085}
1086
ramangrover299f76a5e2013-06-18 10:25:17 -07001087FunctionName FunctionName() throws ParseException:
1088{
1089 String first = null;
1090 String second = null;
1091 String third = null;
1092 boolean secondAfterDot = false;
1093}
1094{
zheilbron555dc9d2013-08-14 19:58:00 -07001095 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001096 {
1097 secondAfterDot = true;
1098 }
1099 ("#" third = Identifier())? | "#" second = Identifier() )?
1100 {
1101 FunctionName result = new FunctionName();
1102 if (second == null) {
1103 result.dataverse = defaultDataverse;
1104 result.library = null;
1105 result.function = first;
1106 } else if (third == null) {
1107 if (secondAfterDot) {
1108 result.dataverse = first;
1109 result.library = null;
1110 result.function = second;
1111 } else {
1112 result.dataverse = defaultDataverse;
1113 result.library = first;
1114 result.function = second;
1115 }
1116 } else {
1117 result.dataverse = first;
1118 result.library = second;
1119 result.function = third;
1120 }
1121 return result;
1122 }
1123}
Till Westmann31c21f92013-05-08 09:21:53 -07001124
ramangrover299f76a5e2013-06-18 10:25:17 -07001125
1126Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001127{
Till Westmann31c21f92013-05-08 09:21:53 -07001128 Pair<Identifier,Identifier> name = null;
1129}
1130{
1131 name = QualifiedName()
1132 {
1133 if (name.first == null) {
1134 name.first = new Identifier(defaultDataverse);
1135 }
1136 return name;
1137 }
1138}
1139
Till Westmann14a20a72013-05-09 00:06:24 -07001140String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001141{
Till Westmann68d99652013-05-09 11:15:21 -07001142 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001143}
1144{
1145 <IDENTIFIER>
1146 {
Till Westmann14a20a72013-05-09 00:06:24 -07001147 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001148 }
Till Westmann68d99652013-05-09 11:15:21 -07001149 | lit = StringLiteral()
1150 {
1151 return lit;
1152 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001153}
1154
Till Westmann7d535322013-05-09 00:40:02 -07001155String StringLiteral() throws ParseException:
1156{
1157}
1158{
1159 <STRING_LITERAL>
1160 {
1161 return removeQuotesAndEscapes(token.image);
1162 }
1163}
1164
Till Westmann31c21f92013-05-08 09:21:53 -07001165Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1166{
Till Westmann14a20a72013-05-09 00:06:24 -07001167 String first = null;
1168 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001169}
1170{
Till Westmann96c1f172013-08-01 02:05:48 -07001171 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001172 {
Till Westmann14a20a72013-05-09 00:06:24 -07001173 Identifier id1 = null;
1174 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001175 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001176 id2 = new Identifier(first);
1177 } else
1178 {
1179 id1 = new Identifier(first);
1180 id2 = new Identifier(second);
1181 }
1182 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001183 }
1184}
1185
Till Westmann31c21f92013-05-08 09:21:53 -07001186Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001187{
Till Westmann14a20a72013-05-09 00:06:24 -07001188 String first = null;
1189 String second = null;
1190 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001191}
1192{
Till Westmann96c1f172013-08-01 02:05:48 -07001193 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001194 {
Till Westmann14a20a72013-05-09 00:06:24 -07001195 Identifier id1 = null;
1196 Identifier id2 = null;
1197 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001198 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001199 id2 = new Identifier(first);
1200 id3 = new Identifier(second);
1201 } else {
1202 id1 = new Identifier(first);
1203 id2 = new Identifier(second);
1204 id3 = new Identifier(third);
1205 }
1206 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001207 }
1208}
1209
vinayakb38b7ca42012-03-05 05:44:15 +00001210FunctionDecl FunctionDeclaration() throws ParseException:
1211{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001212 FunctionDecl funcDecl;
1213 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001214 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001215 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1216 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001217 createNewScope();
1218}
1219{
Till Westmannd7dcb122013-05-16 13:19:09 -07001220 "declare" "function" functionName = Identifier()
1221 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001222 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001223 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001224 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001225 getCurrentScope().addFunctionDescriptor(signature, false);
1226 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001227 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001228 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001229 }
1230}
1231
vinayakb38b7ca42012-03-05 05:44:15 +00001232
Till Westmann31c21f92013-05-08 09:21:53 -07001233Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001234{
1235 Query query = new Query();
1236 Expression expr;
1237}
1238{
Till Westmann31c21f92013-05-08 09:21:53 -07001239 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001240 {
1241 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001242 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001243 return query;
1244 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001245
vinayakb38b7ca42012-03-05 05:44:15 +00001246}
1247
1248
1249
1250Expression Expression():
1251{
1252 Expression expr = null;
1253 Expression exprP = null;
1254}
1255{
1256(
1257
1258//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1259 expr = OperatorExpr()
1260 | expr = IfThenElse()
1261 | expr = FLWOGR()
1262 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001263
vinayakb38b7ca42012-03-05 05:44:15 +00001264
1265)
1266 {
1267 return (exprP==null) ? expr : exprP;
1268 }
1269}
1270
1271
1272
1273Expression OperatorExpr()throws ParseException:
1274{
1275 OperatorExpr op = null;
1276 Expression operand = null;
1277}
1278{
1279 operand = AndExpr()
1280 (
1281
Till Westmann96c1f172013-08-01 02:05:48 -07001282 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001283 {
1284 if (op == null) {
1285 op = new OperatorExpr();
1286 op.addOperand(operand);
1287 op.setCurrentop(true);
1288 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001289 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001290 }
1291
1292 operand = AndExpr()
1293 {
1294 op.addOperand(operand);
1295 }
1296
1297 )*
1298
1299 {
1300 return op==null? operand: op;
1301 }
1302}
1303
1304Expression AndExpr()throws ParseException:
1305{
1306 OperatorExpr op = null;
1307 Expression operand = null;
1308}
1309{
1310 operand = RelExpr()
1311 (
1312
Till Westmann96c1f172013-08-01 02:05:48 -07001313 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001314 {
1315 if (op == null) {
1316 op = new OperatorExpr();
1317 op.addOperand(operand);
1318 op.setCurrentop(true);
1319 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001320 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001321 }
1322
1323 operand = RelExpr()
1324 {
1325 op.addOperand(operand);
1326 }
1327
1328 )*
1329
1330 {
1331 return op==null? operand: op;
1332 }
1333}
1334
1335
1336
1337Expression RelExpr()throws ParseException:
1338{
1339 OperatorExpr op = null;
1340 Expression operand = null;
1341 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001342 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001343}
1344{
1345 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001346 {
1347 if (operand instanceof VariableExpr) {
1348 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001349 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001350 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001351 }
1352 }
1353 }
1354
1355 (
Till Westmann96c1f172013-08-01 02:05:48 -07001356 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001357 {
alexander.behm07617fd2012-07-25 10:13:50 +00001358 String mhint = getHint(token);
salsubaieedf89fbc2013-12-21 19:51:42 -08001359 if (mhint != null) {
1360 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1361 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1362 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1363 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1364 }
alexander.behm07617fd2012-07-25 10:13:50 +00001365 }
vinayakb38b7ca42012-03-05 05:44:15 +00001366 if (op == null) {
1367 op = new OperatorExpr();
1368 op.addOperand(operand, broadcast);
1369 op.setCurrentop(true);
1370 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001371 }
1372 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001373 }
1374
1375 operand = AddExpr()
1376 {
alexander.behm07617fd2012-07-25 10:13:50 +00001377 broadcast = false;
1378 if (operand instanceof VariableExpr) {
1379 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001380 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1381 broadcast = true;
1382 }
alexander.behm07617fd2012-07-25 10:13:50 +00001383 }
vinayakb38b7ca42012-03-05 05:44:15 +00001384 op.addOperand(operand, broadcast);
1385 }
1386 )?
1387
1388 {
alexander.behm07617fd2012-07-25 10:13:50 +00001389 if (annotation != null) {
1390 op.addHint(annotation);
1391 }
vinayakb38b7ca42012-03-05 05:44:15 +00001392 return op==null? operand: op;
1393 }
1394}
1395
1396Expression AddExpr()throws ParseException:
1397{
1398 OperatorExpr op = null;
1399 Expression operand = null;
1400}
1401{
1402 operand = MultExpr()
1403
Till Westmann96c1f172013-08-01 02:05:48 -07001404 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001405 {
1406 if (op == null) {
1407 op = new OperatorExpr();
1408 op.addOperand(operand);
1409 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001410 }
1411 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001412 }
1413
1414 operand = MultExpr()
1415 {
1416 op.addOperand(operand);
1417 }
1418 )*
1419
1420 {
1421 return op==null? operand: op;
1422 }
1423}
1424
1425Expression MultExpr()throws ParseException:
1426{
1427 OperatorExpr op = null;
1428 Expression operand = null;
1429}
1430{
1431 operand = UnionExpr()
1432
Till Westmann96c1f172013-08-01 02:05:48 -07001433 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001434 {
1435 if (op == null) {
1436 op = new OperatorExpr();
1437 op.addOperand(operand);
1438 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001439 }
1440 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001441 }
1442 operand = UnionExpr()
1443 {
1444 op.addOperand(operand);
1445 }
1446 )*
1447
1448 {
1449 return op==null?operand:op;
1450 }
1451}
1452
1453Expression UnionExpr() throws ParseException:
1454{
1455 UnionExpr union = null;
1456 Expression operand1 = null;
1457 Expression operand2 = null;
1458}
1459{
1460 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001461 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001462 (operand2 = UnaryExpr()) {
1463 if (union == null) {
1464 union = new UnionExpr();
1465 union.addExpr(operand1);
1466 }
1467 union.addExpr(operand2);
1468 } )*
1469 {
1470 return (union == null)? operand1: union;
1471 }
1472}
1473
1474Expression UnaryExpr() throws ParseException:
1475{
1476 Expression uexpr = null;
1477 Expression expr = null;
1478}
1479{
Till Westmann96c1f172013-08-01 02:05:48 -07001480 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001481 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001482 uexpr = new UnaryExpr();
1483 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001484 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001485 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001486 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1487 else
1488 throw new ParseException();
1489 }
1490 )?
1491
1492 expr = ValueExpr()
1493 {
1494 if(uexpr!=null){
1495 ((UnaryExpr)uexpr).setExpr(expr);
1496 return uexpr;
1497 }
1498 else{
1499 return expr;
1500 }
1501 }
1502}
1503
Till Westmann04478e72013-05-13 23:01:34 -07001504Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001505{
1506 Expression expr = null;
1507 Identifier ident = null;
1508 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001509 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001510}
1511{
Till Westmann04478e72013-05-13 23:01:34 -07001512 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001513 {
Till Westmann04478e72013-05-13 23:01:34 -07001514 fa = (fa == null ? new FieldAccessor(expr, ident)
1515 : new FieldAccessor(fa, ident));
1516 }
icetindila611ac72014-05-16 10:10:11 -07001517 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001518 {
icetindila611ac72014-05-16 10:10:11 -07001519 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1520 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001521 }
1522 )*
1523 {
1524 return fa == null ? expr : fa;
1525 }
vinayakb38b7ca42012-03-05 05:44:15 +00001526}
1527
1528Identifier Field() throws ParseException:
1529{
Till Westmann14a20a72013-05-09 00:06:24 -07001530 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001531}
1532{
Till Westmann96c1f172013-08-01 02:05:48 -07001533 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001534 {
Till Westmann14a20a72013-05-09 00:06:24 -07001535 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001536 }
vinayakb38b7ca42012-03-05 05:44:15 +00001537}
1538
icetindila611ac72014-05-16 10:10:11 -07001539Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001540{
1541 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001542}
1543{
Till Westmann96c1f172013-08-01 02:05:48 -07001544 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001545 {
1546 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1547 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001548 Literal lit = ((LiteralExpr)expr).getValue();
icetindila611ac72014-05-16 10:10:11 -07001549 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1550 lit.getLiteralType() != Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001551 throw new ParseException("Index should be an INTEGER");
1552 }
1553 }
vinayakb38b7ca42012-03-05 05:44:15 +00001554 }
1555
icetindil5860fb92014-05-16 11:22:15 -07001556 | <QUES> // ANY
vinayakb38b7ca42012-03-05 05:44:15 +00001557
1558 )
1559
Till Westmann96c1f172013-08-01 02:05:48 -07001560 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001561 {
icetindila611ac72014-05-16 10:10:11 -07001562 return expr;
vinayakb38b7ca42012-03-05 05:44:15 +00001563 }
1564}
1565
1566
1567Expression PrimaryExpr()throws ParseException:
1568{
1569 Expression expr = null;
1570}
1571{
Till Westmann68d99652013-05-09 11:15:21 -07001572 ( LOOKAHEAD(2)
1573 expr = FunctionCallExpr()
1574 | expr = Literal()
1575 | expr = DatasetAccessExpression()
1576 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001577 {
1578 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001579 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001580 }
Till Westmann68d99652013-05-09 11:15:21 -07001581 | expr = ListConstructor()
1582 | expr = RecordConstructor()
1583 | expr = ParenthesizedExpression()
1584 )
1585 {
1586 return expr;
1587 }
vinayakb38b7ca42012-03-05 05:44:15 +00001588}
1589
1590Expression Literal() throws ParseException:
1591{
vinayakb38b7ca42012-03-05 05:44:15 +00001592 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001593 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001594}
1595{
Till Westmann7d535322013-05-09 00:40:02 -07001596 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001597 {
Till Westmann7d535322013-05-09 00:40:02 -07001598 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001599 }
1600 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001601 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001602 try {
1603 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1604 } catch(NumberFormatException ex) {
1605 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1606 }
1607 }
1608 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001609 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001610 lit.setValue(new FloatLiteral(new Float(token.image)));
1611 }
1612 | <DOUBLE_LITERAL>
1613 {
1614 lit.setValue(new DoubleLiteral(new Double(token.image)));
1615 }
1616 | <NULL>
1617 {
1618 lit.setValue(NullLiteral.INSTANCE);
1619 }
1620 | <TRUE>
1621 {
1622 lit.setValue(TrueLiteral.INSTANCE);
1623 }
1624 | <FALSE>
1625 {
1626 lit.setValue(FalseLiteral.INSTANCE);
1627 }
1628 )
vinayakb38b7ca42012-03-05 05:44:15 +00001629 {
1630 return lit;
1631 }
1632}
1633
1634
1635VariableExpr VariableRef() throws ParseException:
1636{
1637 VariableExpr varExp = new VariableExpr();
1638 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001639}
1640{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001641 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001642 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001643 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001644 Identifier ident = lookupSymbol(varName);
1645 if (isInForbiddenScopes(varName)) {
1646 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.");
1647 }
1648 if(ident != null) { // exist such ident
1649 varExp.setIsNewVar(false);
1650 varExp.setVar((VarIdentifier)ident);
1651 } else {
1652 varExp.setVar(var);
1653 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001654 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001655 return varExp;
1656 }
1657}
1658
1659
1660VariableExpr Variable() throws ParseException:
1661{
1662 VariableExpr varExp = new VariableExpr();
1663 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001664}
1665{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001666 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001667 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001668 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001669 if(ident != null) { // exist such ident
1670 varExp.setIsNewVar(false);
1671 }
1672 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001673 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001674 return varExp;
1675 }
1676}
1677
1678Expression ListConstructor() throws ParseException:
1679{
1680 Expression expr = null;
1681}
1682{
1683 (
1684 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1685 )
1686
1687 {
1688 return expr;
1689 }
1690}
1691
1692
1693ListConstructor OrderedListConstructor() throws ParseException:
1694{
1695 ListConstructor expr = new ListConstructor();
1696 Expression tmp = null;
1697 List<Expression> exprList = new ArrayList<Expression>();
1698 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1699}
1700{
1701
Till Westmann96c1f172013-08-01 02:05:48 -07001702 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001703 ( tmp = Expression()
1704 {
1705 exprList.add(tmp);
1706 }
1707
Till Westmann96c1f172013-08-01 02:05:48 -07001708 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001709 )?
1710
Till Westmann96c1f172013-08-01 02:05:48 -07001711 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001712
1713 {
1714 expr.setExprList(exprList);
1715 return expr;
1716 }
1717}
1718
1719ListConstructor UnorderedListConstructor() throws ParseException:
1720{
1721 ListConstructor expr = new ListConstructor();
1722 Expression tmp = null;
1723 List<Expression> exprList = new ArrayList<Expression>();
1724 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1725}
1726{
1727
Till Westmann96c1f172013-08-01 02:05:48 -07001728 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001729 {
1730 exprList.add(tmp);
1731 }
Till Westmann96c1f172013-08-01 02:05:48 -07001732 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001733 {
1734 expr.setExprList(exprList);
1735 return expr;
1736 }
1737}
1738
1739RecordConstructor RecordConstructor() throws ParseException:
1740{
1741 RecordConstructor expr = new RecordConstructor();
1742 FieldBinding tmp = null;
1743 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1744}
1745{
Till Westmann96c1f172013-08-01 02:05:48 -07001746 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001747 {
1748 fbList.add(tmp);
1749 }
Till Westmann96c1f172013-08-01 02:05:48 -07001750 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001751 {
1752 expr.setFbList(fbList);
1753 return expr;
1754 }
1755}
1756
1757FieldBinding FieldBinding() throws ParseException:
1758{
1759 FieldBinding fb = new FieldBinding();
1760 Expression left, right;
1761}
1762{
Till Westmann96c1f172013-08-01 02:05:48 -07001763 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001764 {
1765 fb.setLeftExpr(left);
1766 fb.setRightExpr(right);
1767 return fb;
1768 }
1769}
1770
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001771
vinayakb38b7ca42012-03-05 05:44:15 +00001772Expression FunctionCallExpr() throws ParseException:
1773{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001774 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001775 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001776 Expression tmp;
1777 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001778 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001779 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001780}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001781{
ramangrover299f76a5e2013-06-18 10:25:17 -07001782 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001783 {
Till Westmann31c21f92013-05-08 09:21:53 -07001784 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001785 }
Till Westmann31c21f92013-05-08 09:21:53 -07001786 <LEFTPAREN> (tmp = Expression()
1787 {
1788 argList.add(tmp);
1789 arity ++;
1790 }
Till Westmann96c1f172013-08-01 02:05:48 -07001791 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001792 {
1793 argList.add(tmp);
1794 arity++;
1795 }
1796 )*)? <RIGHTPAREN>
1797 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001798 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001799 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001800 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001801 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001802 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001803 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001804 }
1805 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001806 if (hint != null) {
1807 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1808 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1809 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1810 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1811 }
Till Westmann31c21f92013-05-08 09:21:53 -07001812 }
1813 return callExpr;
1814 }
vinayakb38b7ca42012-03-05 05:44:15 +00001815}
1816
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001817
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001818Expression DatasetAccessExpression() throws ParseException:
1819{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001820 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001821 String arg1 = null;
1822 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001823 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001824}
1825{
Till Westmann14a20a72013-05-09 00:06:24 -07001826 <DATASET>
1827 {
Till Westmann14a20a72013-05-09 00:06:24 -07001828 funcName = token.image;
1829 }
Till Westmann96c1f172013-08-01 02:05:48 -07001830 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001831 {
1832 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001833 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001834 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001835 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001836 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001837 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001838 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001839 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1840 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1841 if (signature == null) {
1842 signature = new FunctionSignature(dataverse, funcName, 1);
1843 }
1844 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001845 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001846 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001847 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001848}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001849
vinayakb38b7ca42012-03-05 05:44:15 +00001850Expression ParenthesizedExpression() throws ParseException:
1851{
1852 Expression expr;
1853}
1854{
1855 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1856 {
1857 return expr;
1858 }
1859}
1860
1861Expression IfThenElse() throws ParseException:
1862{
1863 Expression condExpr;
1864 Expression thenExpr;
1865 Expression elseExpr;
1866 IfExpr ifExpr = new IfExpr();
1867}
1868{
Till Westmann96c1f172013-08-01 02:05:48 -07001869 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001870
1871 {
1872 ifExpr.setCondExpr(condExpr);
1873 ifExpr.setThenExpr(thenExpr);
1874 ifExpr.setElseExpr(elseExpr);
1875 return ifExpr;
1876 }
1877}
1878
1879Expression FLWOGR() throws ParseException:
1880{
1881 FLWOGRExpression flworg = new FLWOGRExpression();
1882 List<Clause> clauseList = new ArrayList<Clause>();
1883 Expression returnExpr;
1884 Clause tmp;
1885 createNewScope();
1886}
1887{
1888 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001889 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001890
1891 {
1892 flworg.setClauseList(clauseList);
1893 flworg.setReturnExpr(returnExpr);
1894 removeCurrentScope();
1895 return flworg;
1896 }
1897}
1898
1899Clause Clause()throws ParseException :
1900{
1901 Clause clause;
1902}
1903{
1904 (
1905 clause = ForClause()
1906 | clause = LetClause()
1907 | clause = WhereClause()
1908 | clause = OrderbyClause()
1909 | clause = GroupClause()
1910 | clause = LimitClause()
1911 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001912 )
1913 {
1914 return clause;
1915 }
1916}
1917
1918Clause ForClause()throws ParseException :
1919{
1920 ForClause fc = new ForClause();
1921 VariableExpr varExp;
1922 VariableExpr varPos = null;
1923 Expression inExp;
1924 extendCurrentScope();
1925}
1926{
Till Westmann96c1f172013-08-01 02:05:48 -07001927 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001928 {
1929 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001930 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001931 fc.setInExpr(inExp);
1932 if (varPos != null) {
1933 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001934 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001935 }
1936 return fc;
1937 }
1938}
1939
1940Clause LetClause() throws ParseException:
1941{
1942 LetClause lc = new LetClause();
1943 VariableExpr varExp;
1944 Expression beExp;
1945 extendCurrentScope();
1946}
1947{
Till Westmann96c1f172013-08-01 02:05:48 -07001948 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001949 {
1950 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001951 lc.setVarExpr(varExp);
1952 lc.setBeExpr(beExp);
1953 return lc;
1954 }
1955}
1956
1957Clause WhereClause()throws ParseException :
1958{
1959 WhereClause wc = new WhereClause();
1960 Expression whereExpr;
1961}
1962{
salsubaieedf89fbc2013-12-21 19:51:42 -08001963 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001964 {
1965 wc.setWhereExpr(whereExpr);
1966 return wc;
1967 }
1968}
1969
1970Clause OrderbyClause()throws ParseException :
1971{
1972 OrderbyClause oc = new OrderbyClause();
1973 Expression orderbyExpr;
1974 List<Expression> orderbyList = new ArrayList<Expression>();
1975 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1976 int numOfOrderby = 0;
1977}
1978{
1979 (
Till Westmann96c1f172013-08-01 02:05:48 -07001980 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001981 {
1982 String hint = getHint(token);
1983 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1984 String splits[] = hint.split(" +");
1985 int numFrames = Integer.parseInt(splits[1]);
1986 int numTuples = Integer.parseInt(splits[2]);
1987 oc.setNumFrames(numFrames);
1988 oc.setNumTuples(numTuples);
1989 }
1990 }
Till Westmann96c1f172013-08-01 02:05:48 -07001991 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001992 {
1993 orderbyList.add(orderbyExpr);
1994 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1995 }
Till Westmann96c1f172013-08-01 02:05:48 -07001996 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1997 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001998 {
1999 modifierList.add(modif);
2000 }
2001
Till Westmann96c1f172013-08-01 02:05:48 -07002002 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002003 {
2004 orderbyList.add(orderbyExpr);
2005 modif = OrderbyClause.OrderModifier.ASC;
2006 }
Till Westmann96c1f172013-08-01 02:05:48 -07002007 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2008 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002009 {
2010 modifierList.add(modif);
2011 }
2012 )*
2013)
2014 {
2015 oc.setModifierList(modifierList);
2016 oc.setOrderbyList(orderbyList);
2017 return oc;
2018 }
2019}
2020Clause GroupClause()throws ParseException :
2021{
2022 GroupbyClause gbc = new GroupbyClause();
2023 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2024 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2025 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2026 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2027 VariableExpr var = null;
2028 VariableExpr withVar = null;
2029 Expression expr = null;
2030 VariableExpr decorVar = null;
2031 Expression decorExpr = null;
2032}
2033{
2034 {
2035 Scope newScope = extendCurrentScopeNoPush(true);
2036 // extendCurrentScope(true);
2037 }
Till Westmann96c1f172013-08-01 02:05:48 -07002038 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002039 {
2040 String hint = getHint(token);
2041 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2042 gbc.setHashGroupByHint(true);
2043 }
2044 }
Till Westmann96c1f172013-08-01 02:05:48 -07002045 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002046 {
2047 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002048 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002049 expr = Expression()
2050 {
2051 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2052 vePairList.add(pair1);
2053 }
Till Westmann96c1f172013-08-01 02:05:48 -07002054 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002055 {
2056 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002057 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002058 expr = Expression()
2059 {
2060 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2061 vePairList.add(pair2);
2062 }
2063 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002064 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002065 {
2066 newScope.addNewVarSymbolToScope(decorVar.getVar());
2067 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2068 decorPairList.add(pair3);
2069 }
Till Westmann96c1f172013-08-01 02:05:48 -07002070 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002071 {
2072 newScope.addNewVarSymbolToScope(decorVar.getVar());
2073 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2074 decorPairList.add(pair4);
2075 }
2076 )*
2077 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002078 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002079 {
2080 if(withVar.getIsNewVar()==true)
2081 throw new ParseException("can't find variable " + withVar.getVar());
2082 withVarList.add(withVar);
2083 newScope.addNewVarSymbolToScope(withVar.getVar());
2084 }
Till Westmann96c1f172013-08-01 02:05:48 -07002085 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002086 {
2087 if(withVar.getIsNewVar()==true)
2088 throw new ParseException("can't find variable " + withVar.getVar());
2089 withVarList.add(withVar);
2090 newScope.addNewVarSymbolToScope(withVar.getVar());
2091 })*
2092 {
2093 gbc.setGbyPairList(vePairList);
2094 gbc.setDecorPairList(decorPairList);
2095 gbc.setWithVarList(withVarList);
2096 replaceCurrentScope(newScope);
2097 return gbc;
2098 }
2099}
2100
2101
2102LimitClause LimitClause() throws ParseException:
2103{
2104 LimitClause lc = new LimitClause();
2105 Expression expr;
2106 pushForbiddenScope(getCurrentScope());
2107}
2108{
Till Westmann96c1f172013-08-01 02:05:48 -07002109 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2110 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002111
2112 {
2113 popForbiddenScope();
2114 return lc;
2115 }
2116}
2117
2118DistinctClause DistinctClause() throws ParseException:
2119{
2120 List<Expression> exprs = new ArrayList<Expression>();
2121 Expression expr;
2122}
2123{
Till Westmann96c1f172013-08-01 02:05:48 -07002124 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002125 {
2126 exprs.add(expr);
2127 }
Till Westmann96c1f172013-08-01 02:05:48 -07002128 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002129 {
2130 exprs.add(expr);
2131 }
2132 )*
2133 {
2134 return new DistinctClause(exprs);
2135 }
2136}
2137
vinayakb38b7ca42012-03-05 05:44:15 +00002138QuantifiedExpression QuantifiedExpression()throws ParseException:
2139{
2140 QuantifiedExpression qc = new QuantifiedExpression();
2141 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2142 Expression satisfiesExpr;
2143 VariableExpr var;
2144 Expression inExpr;
2145 QuantifiedPair pair;
2146}
2147{
2148 {
2149 createNewScope();
2150 }
2151
Till Westmann96c1f172013-08-01 02:05:48 -07002152 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2153 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2154 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002155 {
2156 pair = new QuantifiedPair(var, inExpr);
2157 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2158 quantifiedList.add(pair);
2159 }
2160 (
Till Westmann96c1f172013-08-01 02:05:48 -07002161 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002162 {
2163 pair = new QuantifiedPair(var, inExpr);
2164 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2165 quantifiedList.add(pair);
2166 }
2167 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002168 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002169 {
2170 qc.setSatisfiesExpr(satisfiesExpr);
2171 qc.setQuantifiedList(quantifiedList);
2172 removeCurrentScope();
2173 return qc;
2174 }
2175}
2176
2177TOKEN_MGR_DECLS:
2178{
Till Westmann96c1f172013-08-01 02:05:48 -07002179 public int commentDepth = 0;
2180 public IntStack lexerStateStack = new IntStack();
2181
2182 public void pushState() {
2183 lexerStateStack.push( curLexState );
2184 }
2185
Till Westmannfd733ee2014-07-10 00:57:37 -07002186 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002187 if (lexerStateStack.size() > 0) {
2188 SwitchTo( lexerStateStack.pop() );
2189 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002190 int errorLine = input_stream.getEndLine();
2191 int errorColumn = input_stream.getEndColumn();
2192 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2193 + "\" but state stack is empty.";
2194 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002195 }
2196 }
vinayakb38b7ca42012-03-05 05:44:15 +00002197}
2198
Till Westmann96c1f172013-08-01 02:05:48 -07002199<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002200TOKEN :
2201{
Till Westmann5df7b452013-08-02 13:07:16 -07002202 <ASC : "asc">
2203 | <AT : "at">
2204 | <BY : "by">
2205 | <DATASET : "dataset">
2206 | <DECOR : "decor">
2207 | <DESC : "desc">
2208 | <DISTINCT : "distinct">
2209 | <ELSE : "else">
2210 | <EVERY : "every">
2211 | <FOR : "for">
2212 | <GROUP : "group">
2213 | <IF : "if">
2214 | <IN : "in">
2215 | <LET : "let">
2216 | <LIMIT : "limit">
2217 | <OFFSET : "offset">
2218 | <ORDER : "order">
2219 | <RETURN : "return">
2220 | <SATISFIES : "satisfies">
2221 | <SOME : "some">
2222 | <THEN : "then">
2223 | <UNION : "union">
2224 | <WHERE : "where">
2225 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002226}
2227
Till Westmann96c1f172013-08-01 02:05:48 -07002228<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002229TOKEN :
2230{
Till Westmann5df7b452013-08-02 13:07:16 -07002231 <CARET : "^">
2232 | <DIV : "/">
2233 | <IDIV : "idiv">
2234 | <MINUS : "-">
2235 | <MOD : "%">
2236 | <MUL : "*">
2237 | <PLUS : "+">
2238
2239 | <LEFTPAREN : "(">
2240 | <RIGHTPAREN : ")">
2241 | <LEFTBRACKET : "[">
2242 | <RIGHTBRACKET : "]">
2243
2244 | <COLON : ":">
2245 | <COMMA : ",">
2246 | <DOT : ".">
2247 | <QUES : "?">
2248
2249 | <LT : "<">
2250 | <GT : ">">
2251 | <LE : "<=">
2252 | <GE : ">=">
2253 | <EQ : "=">
2254 | <NE : "!=">
2255 | <SIMILAR : "~=">
2256 | <ASSIGN : ":=">
2257
2258 | <AND : "and">
2259 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002260}
2261
Till Westmann96c1f172013-08-01 02:05:48 -07002262<DEFAULT,IN_DBL_BRACE>
2263TOKEN :
2264{
Till Westmann5df7b452013-08-02 13:07:16 -07002265 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002266}
2267
2268<DEFAULT>
2269TOKEN :
2270{
Till Westmannfd733ee2014-07-10 00:57:37 -07002271 <RIGHTBRACE : "}"> { popState("}"); }
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 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002278}
2279
Till Westmann96c1f172013-08-01 02:05:48 -07002280<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002281TOKEN :
2282{
Till Westmannfd733ee2014-07-10 00:57:37 -07002283 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002284}
2285
Till Westmann96c1f172013-08-01 02:05:48 -07002286<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002287TOKEN :
2288{
Till Westmann5df7b452013-08-02 13:07:16 -07002289 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002290}
2291
Till Westmann96c1f172013-08-01 02:05:48 -07002292<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002293TOKEN :
2294{
Till Westmann5df7b452013-08-02 13:07:16 -07002295 <NULL : "null">
2296 | <TRUE : "true">
2297 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002298}
2299
Till Westmann96c1f172013-08-01 02:05:48 -07002300<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002301TOKEN :
2302{
Till Westmann5df7b452013-08-02 13:07:16 -07002303 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002304}
2305
Till Westmann96c1f172013-08-01 02:05:48 -07002306<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002307TOKEN:
2308{
Till Westmann5df7b452013-08-02 13:07:16 -07002309 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002310 | <DIGITS> ( "." <DIGITS> )?
2311 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002312 >
2313 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002314 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2315 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002316 >
2317 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002318}
2319
Till Westmann96c1f172013-08-01 02:05:48 -07002320<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002321TOKEN :
2322{
Till Westmann5df7b452013-08-02 13:07:16 -07002323 <#LETTER : ["A" - "Z", "a" - "z"]>
2324 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002325}
2326
Till Westmann96c1f172013-08-01 02:05:48 -07002327<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002328TOKEN :
2329{
Till Westmanne0cc01c2014-03-31 10:26:10 -07002330 <STRING_LITERAL : ("\"" (<EscapeQuot> | <EscapeBslash> | ~["\"","\\"])* "\"")
2331 | ("\'"(<EscapeApos> | <EscapeBslash> | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002332 | < #EscapeQuot: "\\\"" >
2333 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002334 | < #EscapeBslash: "\\\\" >
vinayakb38b7ca42012-03-05 05:44:15 +00002335}
2336
Till Westmann96c1f172013-08-01 02:05:48 -07002337<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002338TOKEN :
2339{
Till Westmann5df7b452013-08-02 13:07:16 -07002340 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002341}
2342
Till Westmann96c1f172013-08-01 02:05:48 -07002343<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002344TOKEN :
2345{
Till Westmann5df7b452013-08-02 13:07:16 -07002346 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002347}
2348
Till Westmann96c1f172013-08-01 02:05:48 -07002349<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002350SKIP:
2351{
2352 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002353 | "\t"
2354 | "\r"
2355 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002356}
2357
Till Westmann96c1f172013-08-01 02:05:48 -07002358<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002359SKIP:
2360{
Till Westmann5df7b452013-08-02 13:07:16 -07002361 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002362}
2363
Till Westmann96c1f172013-08-01 02:05:48 -07002364<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002365SKIP:
2366{
Till Westmann5df7b452013-08-02 13:07:16 -07002367 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002368}
2369
Till Westmann96c1f172013-08-01 02:05:48 -07002370<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002371SKIP:
2372{
Till Westmann96c1f172013-08-01 02:05:48 -07002373 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002374}
2375
2376<INSIDE_COMMENT>
2377SPECIAL_TOKEN:
2378{
Till Westmann5df7b452013-08-02 13:07:16 -07002379 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002380}
2381
2382<INSIDE_COMMENT>
2383SKIP:
2384{
Till Westmann96c1f172013-08-01 02:05:48 -07002385 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002386}
2387
2388<INSIDE_COMMENT>
2389SKIP:
2390{
Till Westmannfd733ee2014-07-10 00:57:37 -07002391 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002392 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002393}