blob: 6be8300c9719009003a0028d51509f2d0a25b87f [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() )?
salsubaiee661b9c72014-07-17 17:19:45 -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() )?
salsubaiee661b9c72014-07-17 17:19:45 -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
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300632 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700633 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;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300734 // This is related to the new metadata lock management
735 setDataverses(new ArrayList<String>());
736 setDatasets(new ArrayList<String>());
737
vinayakb38b7ca42012-03-05 05:44:15 +0000738}
739{
Till Westmann31c21f92013-05-08 09:21:53 -0700740 "delete" var = Variable()
741 {
742 getCurrentScope().addNewVarSymbolToScope(var.getVar());
743 }
salsubaieedf89fbc2013-12-21 19:51:42 -0800744 "from" <DATASET> nameComponents = QualifiedName()
745 (<WHERE> condition = Expression())?
746 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300747 // First we get the dataverses and datasets that we want to lock
748 List<String> dataverses = getDataverses();
749 List<String> datasets = getDatasets();
750 // we remove the pointer to the dataverses and datasets
751 setDataverses(null);
752 setDatasets(null);
753 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
754 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700755 }
vinayakb38b7ca42012-03-05 05:44:15 +0000756}
757
758UpdateStatement UpdateStatement() throws ParseException:
759{
Till Westmann31c21f92013-05-08 09:21:53 -0700760 VariableExpr vars;
761 Expression target;
762 Expression condition;
763 UpdateClause uc;
764 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000765}
766{
Till Westmann96c1f172013-08-01 02:05:48 -0700767 "update" vars = Variable() <IN> target = Expression()
768 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700769 <LEFTPAREN> (uc = UpdateClause()
770 {
771 ucs.add(uc);
772 }
Till Westmann96c1f172013-08-01 02:05:48 -0700773 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700774 {
775 ucs.add(uc);
776 }
777 )*) <RIGHTPAREN>
778 {
779 return new UpdateStatement(vars, target, condition, ucs);
780 }
vinayakb38b7ca42012-03-05 05:44:15 +0000781}
782
vinayakb38b7ca42012-03-05 05:44:15 +0000783UpdateClause UpdateClause() throws ParseException:
784{
Till Westmann31c21f92013-05-08 09:21:53 -0700785 Expression target = null;
786 Expression value = null ;
787 InsertStatement is = null;
788 DeleteStatement ds = null;
789 UpdateStatement us = null;
790 Expression condition = null;
791 UpdateClause ifbranch = null;
792 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000793}
794{
Till Westmann96c1f172013-08-01 02:05:48 -0700795 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700796 | is = InsertStatement()
797 | ds = DeleteStatement()
798 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700799 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
800 <THEN> ifbranch = UpdateClause()
801 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700802 {
803 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
804 }
vinayakb38b7ca42012-03-05 05:44:15 +0000805}
806
vinayakb38b7ca42012-03-05 05:44:15 +0000807Statement SetStatement() throws ParseException:
808{
809 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700810 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000811}
812{
Till Westmann7d535322013-05-09 00:40:02 -0700813 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700814 {
Till Westmann31c21f92013-05-08 09:21:53 -0700815 return new SetStatement(pn, pv);
816 }
vinayakb38b7ca42012-03-05 05:44:15 +0000817}
818
819Statement WriteStatement() throws ParseException:
820{
Till Westmann14a20a72013-05-09 00:06:24 -0700821 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000822 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000823 Query query;
824 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000825 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000826}
827{
Till Westmann96c1f172013-08-01 02:05:48 -0700828 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700829 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700830 {
831 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000832 }
833}
834
zheilbron28e026f2013-11-20 10:15:15 -0800835LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000836{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000837 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000838 Identifier datasetName = null;
839 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000840 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000841 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000842 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000843}
844{
Till Westmann31c21f92013-05-08 09:21:53 -0700845 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000846 {
Till Westmann31c21f92013-05-08 09:21:53 -0700847 dataverseName = nameComponents.first;
848 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000849 }
Till Westmann31c21f92013-05-08 09:21:53 -0700850 "using" adapterName = AdapterName() properties = Configuration()
851 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000852 {
Till Westmann31c21f92013-05-08 09:21:53 -0700853 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000854 }
855 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700856 {
zheilbron28e026f2013-11-20 10:15:15 -0800857 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Till Westmann31c21f92013-05-08 09:21:53 -0700858 }
vinayakb38b7ca42012-03-05 05:44:15 +0000859}
860
vinayakb38b7ca42012-03-05 05:44:15 +0000861
Till Westmann31c21f92013-05-08 09:21:53 -0700862String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000863{
ramangrover29669d8f62013-02-11 06:03:32 +0000864 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000865}
866{
Till Westmann68d99652013-05-09 11:15:21 -0700867 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000868 {
Till Westmann7d535322013-05-09 00:40:02 -0700869 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000870 }
vinayakb38b7ca42012-03-05 05:44:15 +0000871}
872
salsubaiee0b423fa2013-09-19 19:16:48 -0700873Statement CompactStatement() throws ParseException:
874{
875 Pair<Identifier,Identifier> nameComponents = null;
876 Statement stmt = null;
877}
878{
879 "compact" <DATASET> nameComponents = QualifiedName()
880 {
881 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
882 }
883 {
884 return stmt;
885 }
886}
887
Till Westmann31c21f92013-05-08 09:21:53 -0700888Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000889{
ramangrover29a774ef22013-07-17 09:29:18 -0700890 Pair<Identifier,Identifier> feedNameComponents = null;
891 Pair<Identifier,Identifier> datasetNameComponents = null;
892
Till Westmann31c21f92013-05-08 09:21:53 -0700893 Map<String,String> configuration = null;
894 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700895 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000896}
897{
Till Westmann31c21f92013-05-08 09:21:53 -0700898 (
ramangrover29a774ef22013-07-17 09:29:18 -0700899 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700900 {
ramangrover29a774ef22013-07-17 09:29:18 -0700901 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700902 }
ramangrover29a774ef22013-07-17 09:29:18 -0700903 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700904 {
ramangrover29a774ef22013-07-17 09:29:18 -0700905 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700906 }
907 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000908 {
Till Westmann31c21f92013-05-08 09:21:53 -0700909 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000910 }
911}
912
Till Westmann31c21f92013-05-08 09:21:53 -0700913Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000914{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000915 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700916 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000917}
918{
Till Westmann31c21f92013-05-08 09:21:53 -0700919 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000920 {
Till Westmann31c21f92013-05-08 09:21:53 -0700921 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000922 }
Till Westmann96c1f172013-08-01 02:05:48 -0700923 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000924 {
Till Westmann31c21f92013-05-08 09:21:53 -0700925 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000926 }
Till Westmann31c21f92013-05-08 09:21:53 -0700927 )* )? <RIGHTPAREN>
928 {
929 return configuration;
930 }
931}
932
933Pair<String, String> KeyValuePair() throws ParseException:
934{
935 String key;
936 String value;
937}
938{
Till Westmann96c1f172013-08-01 02:05:48 -0700939 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700940 {
941 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000942 }
Till Westmann31c21f92013-05-08 09:21:53 -0700943}
944
945Map<String,String> Properties() throws ParseException:
946{
947 Map<String,String> properties = new HashMap<String,String>();
948 Pair<String, String> property;
949}
950{
951 ( <LEFTPAREN> property = Property()
952 {
953 properties.put(property.first, property.second);
954 }
Till Westmann96c1f172013-08-01 02:05:48 -0700955 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700956 {
957 properties.put(property.first, property.second);
958 }
959 )* <RIGHTPAREN> )?
960 {
961 return properties;
962 }
963}
964
965Pair<String, String> Property() throws ParseException:
966{
967 String key;
968 String value;
969}
970{
Till Westmann96c1f172013-08-01 02:05:48 -0700971 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700972 {
973 try {
974 value = "" + Long.valueOf(token.image);
975 } catch (NumberFormatException nfe) {
976 throw new ParseException("inapproriate value: " + token.image);
977 }
978 }
979 )
980 {
981 return new Pair<String, String>(key.toUpperCase(), value);
982 }
vinayakb38b7ca42012-03-05 05:44:15 +0000983}
984
985TypeExpression TypeExpr() throws ParseException:
986{
987 TypeExpression typeExpr = null;
988}
989{
990 (
991 typeExpr = RecordTypeDef()
992 | typeExpr = TypeReference()
993 | typeExpr = OrderedListTypeDef()
994 | typeExpr = UnorderedListTypeDef()
995 )
996 {
997 return typeExpr;
998 }
999}
1000
1001RecordTypeDefinition RecordTypeDef() throws ParseException:
1002{
1003 RecordTypeDefinition recType = new RecordTypeDefinition();
1004 RecordTypeDefinition.RecordKind recordKind = null;
1005}
1006{
1007 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1008 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001009 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001010 {
1011 String hint = getHint(token);
1012 if (hint != null) {
1013 String splits[] = hint.split(" +");
1014 if (splits[0].equals(GEN_FIELDS_HINT)) {
1015 if (splits.length != 5) {
1016 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1017 }
1018 if (!splits[1].equals("int")) {
1019 throw new ParseException("The only supported type for gen-fields is int.");
1020 }
1021 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1022 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1023 recType.setUndeclaredFieldsDataGen(ufdg);
1024 }
1025 }
1026
1027 }
1028 (
1029 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -07001030 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +00001031 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001032 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001033 {
1034 if (recordKind == null) {
1035 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1036 }
1037 recType.setRecordKind(recordKind);
1038 return recType;
1039 }
1040}
1041
1042void RecordField(RecordTypeDefinition recType) throws ParseException:
1043{
Till Westmann77cb2f42013-07-15 16:44:19 -07001044 String fieldName;
1045 TypeExpression type = null;
1046 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001047}
1048{
Till Westmann77cb2f42013-07-15 16:44:19 -07001049 fieldName = Identifier()
1050 {
1051 String hint = getHint(token);
1052 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1053 }
Till Westmann96c1f172013-08-01 02:05:48 -07001054 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001055 {
1056 recType.addField(fieldName, type, nullable, rfdg);
1057 }
vinayakb38b7ca42012-03-05 05:44:15 +00001058}
1059
1060TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001061{
Till Westmann14a20a72013-05-09 00:06:24 -07001062 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001063}
1064{
1065 id = Identifier()
1066 {
Till Westmann14a20a72013-05-09 00:06:24 -07001067 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001068 }
vinayakb38b7ca42012-03-05 05:44:15 +00001069}
1070
1071OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1072{
1073 TypeExpression type = null;
1074}
1075{
Till Westmann96c1f172013-08-01 02:05:48 -07001076 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001077 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001078 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001079 {
1080 return new OrderedListTypeDefinition(type);
1081 }
1082}
1083
1084
1085UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1086{
1087 TypeExpression type = null;
1088}
1089{
Till Westmann96c1f172013-08-01 02:05:48 -07001090 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001091 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001092 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001093 {
1094 return new UnorderedListTypeDefinition(type);
1095 }
1096}
1097
ramangrover299f76a5e2013-06-18 10:25:17 -07001098FunctionName FunctionName() throws ParseException:
1099{
1100 String first = null;
1101 String second = null;
1102 String third = null;
1103 boolean secondAfterDot = false;
1104}
1105{
zheilbron555dc9d2013-08-14 19:58:00 -07001106 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001107 {
1108 secondAfterDot = true;
1109 }
1110 ("#" third = Identifier())? | "#" second = Identifier() )?
1111 {
1112 FunctionName result = new FunctionName();
1113 if (second == null) {
1114 result.dataverse = defaultDataverse;
1115 result.library = null;
1116 result.function = first;
1117 } else if (third == null) {
1118 if (secondAfterDot) {
1119 result.dataverse = first;
1120 result.library = null;
1121 result.function = second;
1122 } else {
1123 result.dataverse = defaultDataverse;
1124 result.library = first;
1125 result.function = second;
1126 }
1127 } else {
1128 result.dataverse = first;
1129 result.library = second;
1130 result.function = third;
1131 }
1132 return result;
1133 }
1134}
Till Westmann31c21f92013-05-08 09:21:53 -07001135
ramangrover299f76a5e2013-06-18 10:25:17 -07001136
1137Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001138{
Till Westmann31c21f92013-05-08 09:21:53 -07001139 Pair<Identifier,Identifier> name = null;
1140}
1141{
1142 name = QualifiedName()
1143 {
1144 if (name.first == null) {
1145 name.first = new Identifier(defaultDataverse);
1146 }
1147 return name;
1148 }
1149}
1150
Till Westmann14a20a72013-05-09 00:06:24 -07001151String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001152{
Till Westmann68d99652013-05-09 11:15:21 -07001153 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001154}
1155{
1156 <IDENTIFIER>
1157 {
Till Westmann14a20a72013-05-09 00:06:24 -07001158 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001159 }
Till Westmann68d99652013-05-09 11:15:21 -07001160 | lit = StringLiteral()
1161 {
1162 return lit;
1163 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001164}
1165
Till Westmann7d535322013-05-09 00:40:02 -07001166String StringLiteral() throws ParseException:
1167{
1168}
1169{
1170 <STRING_LITERAL>
1171 {
1172 return removeQuotesAndEscapes(token.image);
1173 }
1174}
1175
Till Westmann31c21f92013-05-08 09:21:53 -07001176Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1177{
Till Westmann14a20a72013-05-09 00:06:24 -07001178 String first = null;
1179 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001180}
1181{
Till Westmann96c1f172013-08-01 02:05:48 -07001182 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001183 {
Till Westmann14a20a72013-05-09 00:06:24 -07001184 Identifier id1 = null;
1185 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001186 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001187 id2 = new Identifier(first);
1188 } else
1189 {
1190 id1 = new Identifier(first);
1191 id2 = new Identifier(second);
1192 }
1193 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001194 }
1195}
1196
Till Westmann31c21f92013-05-08 09:21:53 -07001197Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001198{
Till Westmann14a20a72013-05-09 00:06:24 -07001199 String first = null;
1200 String second = null;
1201 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001202}
1203{
Till Westmann96c1f172013-08-01 02:05:48 -07001204 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001205 {
Till Westmann14a20a72013-05-09 00:06:24 -07001206 Identifier id1 = null;
1207 Identifier id2 = null;
1208 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001209 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001210 id2 = new Identifier(first);
1211 id3 = new Identifier(second);
1212 } else {
1213 id1 = new Identifier(first);
1214 id2 = new Identifier(second);
1215 id3 = new Identifier(third);
1216 }
1217 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001218 }
1219}
1220
vinayakb38b7ca42012-03-05 05:44:15 +00001221FunctionDecl FunctionDeclaration() throws ParseException:
1222{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001223 FunctionDecl funcDecl;
1224 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001225 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001226 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1227 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001228 createNewScope();
1229}
1230{
Till Westmannd7dcb122013-05-16 13:19:09 -07001231 "declare" "function" functionName = Identifier()
1232 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001233 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001234 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001235 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001236 getCurrentScope().addFunctionDescriptor(signature, false);
1237 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001238 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001239 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001240 }
1241}
1242
vinayakb38b7ca42012-03-05 05:44:15 +00001243
Till Westmann31c21f92013-05-08 09:21:53 -07001244Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001245{
1246 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001247 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1248 setDataverses(query.getDataverses());
1249 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001250 Expression expr;
1251}
1252{
Till Westmann31c21f92013-05-08 09:21:53 -07001253 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001254 {
1255 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001256 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001257 // we remove the pointers to the locked entities before we return the query object
1258 setDataverses(null);
1259 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001260 return query;
1261 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001262
vinayakb38b7ca42012-03-05 05:44:15 +00001263}
1264
1265
1266
1267Expression Expression():
1268{
1269 Expression expr = null;
1270 Expression exprP = null;
1271}
1272{
1273(
1274
1275//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1276 expr = OperatorExpr()
1277 | expr = IfThenElse()
1278 | expr = FLWOGR()
1279 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001280
vinayakb38b7ca42012-03-05 05:44:15 +00001281
1282)
1283 {
1284 return (exprP==null) ? expr : exprP;
1285 }
1286}
1287
1288
1289
1290Expression OperatorExpr()throws ParseException:
1291{
1292 OperatorExpr op = null;
1293 Expression operand = null;
1294}
1295{
1296 operand = AndExpr()
1297 (
1298
Till Westmann96c1f172013-08-01 02:05:48 -07001299 <OR>
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 = AndExpr()
1310 {
1311 op.addOperand(operand);
1312 }
1313
1314 )*
1315
1316 {
1317 return op==null? operand: op;
1318 }
1319}
1320
1321Expression AndExpr()throws ParseException:
1322{
1323 OperatorExpr op = null;
1324 Expression operand = null;
1325}
1326{
1327 operand = RelExpr()
1328 (
1329
Till Westmann96c1f172013-08-01 02:05:48 -07001330 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001331 {
1332 if (op == null) {
1333 op = new OperatorExpr();
1334 op.addOperand(operand);
1335 op.setCurrentop(true);
1336 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001337 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001338 }
1339
1340 operand = RelExpr()
1341 {
1342 op.addOperand(operand);
1343 }
1344
1345 )*
1346
1347 {
1348 return op==null? operand: op;
1349 }
1350}
1351
1352
1353
1354Expression RelExpr()throws ParseException:
1355{
1356 OperatorExpr op = null;
1357 Expression operand = null;
1358 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001359 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001360}
1361{
1362 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001363 {
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)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001367 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001368 }
1369 }
1370 }
1371
1372 (
Till Westmann96c1f172013-08-01 02:05:48 -07001373 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001374 {
alexander.behm07617fd2012-07-25 10:13:50 +00001375 String mhint = getHint(token);
salsubaieedf89fbc2013-12-21 19:51:42 -08001376 if (mhint != null) {
1377 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1378 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1379 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1380 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1381 }
alexander.behm07617fd2012-07-25 10:13:50 +00001382 }
vinayakb38b7ca42012-03-05 05:44:15 +00001383 if (op == null) {
1384 op = new OperatorExpr();
1385 op.addOperand(operand, broadcast);
1386 op.setCurrentop(true);
1387 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001388 }
1389 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001390 }
1391
1392 operand = AddExpr()
1393 {
alexander.behm07617fd2012-07-25 10:13:50 +00001394 broadcast = false;
1395 if (operand instanceof VariableExpr) {
1396 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001397 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1398 broadcast = true;
1399 }
alexander.behm07617fd2012-07-25 10:13:50 +00001400 }
vinayakb38b7ca42012-03-05 05:44:15 +00001401 op.addOperand(operand, broadcast);
1402 }
1403 )?
1404
1405 {
alexander.behm07617fd2012-07-25 10:13:50 +00001406 if (annotation != null) {
1407 op.addHint(annotation);
1408 }
vinayakb38b7ca42012-03-05 05:44:15 +00001409 return op==null? operand: op;
1410 }
1411}
1412
1413Expression AddExpr()throws ParseException:
1414{
1415 OperatorExpr op = null;
1416 Expression operand = null;
1417}
1418{
1419 operand = MultExpr()
1420
Till Westmann96c1f172013-08-01 02:05:48 -07001421 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001422 {
1423 if (op == null) {
1424 op = new OperatorExpr();
1425 op.addOperand(operand);
1426 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001427 }
1428 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001429 }
1430
1431 operand = MultExpr()
1432 {
1433 op.addOperand(operand);
1434 }
1435 )*
1436
1437 {
1438 return op==null? operand: op;
1439 }
1440}
1441
1442Expression MultExpr()throws ParseException:
1443{
1444 OperatorExpr op = null;
1445 Expression operand = null;
1446}
1447{
1448 operand = UnionExpr()
1449
Till Westmann96c1f172013-08-01 02:05:48 -07001450 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001451 {
1452 if (op == null) {
1453 op = new OperatorExpr();
1454 op.addOperand(operand);
1455 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001456 }
1457 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001458 }
1459 operand = UnionExpr()
1460 {
1461 op.addOperand(operand);
1462 }
1463 )*
1464
1465 {
1466 return op==null?operand:op;
1467 }
1468}
1469
1470Expression UnionExpr() throws ParseException:
1471{
1472 UnionExpr union = null;
1473 Expression operand1 = null;
1474 Expression operand2 = null;
1475}
1476{
1477 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001478 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001479 (operand2 = UnaryExpr()) {
1480 if (union == null) {
1481 union = new UnionExpr();
1482 union.addExpr(operand1);
1483 }
1484 union.addExpr(operand2);
1485 } )*
1486 {
1487 return (union == null)? operand1: union;
1488 }
1489}
1490
1491Expression UnaryExpr() throws ParseException:
1492{
1493 Expression uexpr = null;
1494 Expression expr = null;
1495}
1496{
Till Westmann96c1f172013-08-01 02:05:48 -07001497 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001498 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001499 uexpr = new UnaryExpr();
1500 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001501 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001502 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001503 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1504 else
1505 throw new ParseException();
1506 }
1507 )?
1508
1509 expr = ValueExpr()
1510 {
1511 if(uexpr!=null){
1512 ((UnaryExpr)uexpr).setExpr(expr);
1513 return uexpr;
1514 }
1515 else{
1516 return expr;
1517 }
1518 }
1519}
1520
Till Westmann04478e72013-05-13 23:01:34 -07001521Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001522{
1523 Expression expr = null;
1524 Identifier ident = null;
1525 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001526 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001527}
1528{
Till Westmann04478e72013-05-13 23:01:34 -07001529 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001530 {
Till Westmann04478e72013-05-13 23:01:34 -07001531 fa = (fa == null ? new FieldAccessor(expr, ident)
1532 : new FieldAccessor(fa, ident));
1533 }
icetindila611ac72014-05-16 10:10:11 -07001534 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001535 {
icetindila611ac72014-05-16 10:10:11 -07001536 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1537 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001538 }
1539 )*
1540 {
1541 return fa == null ? expr : fa;
1542 }
vinayakb38b7ca42012-03-05 05:44:15 +00001543}
1544
1545Identifier Field() throws ParseException:
1546{
Till Westmann14a20a72013-05-09 00:06:24 -07001547 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001548}
1549{
Till Westmann96c1f172013-08-01 02:05:48 -07001550 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001551 {
Till Westmann14a20a72013-05-09 00:06:24 -07001552 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001553 }
vinayakb38b7ca42012-03-05 05:44:15 +00001554}
1555
icetindila611ac72014-05-16 10:10:11 -07001556Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001557{
1558 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001559}
1560{
Till Westmann96c1f172013-08-01 02:05:48 -07001561 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001562 {
1563 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1564 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001565 Literal lit = ((LiteralExpr)expr).getValue();
icetindila611ac72014-05-16 10:10:11 -07001566 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1567 lit.getLiteralType() != Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001568 throw new ParseException("Index should be an INTEGER");
1569 }
1570 }
vinayakb38b7ca42012-03-05 05:44:15 +00001571 }
1572
icetindil5860fb92014-05-16 11:22:15 -07001573 | <QUES> // ANY
vinayakb38b7ca42012-03-05 05:44:15 +00001574
1575 )
1576
Till Westmann96c1f172013-08-01 02:05:48 -07001577 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001578 {
icetindila611ac72014-05-16 10:10:11 -07001579 return expr;
vinayakb38b7ca42012-03-05 05:44:15 +00001580 }
1581}
1582
1583
1584Expression PrimaryExpr()throws ParseException:
1585{
1586 Expression expr = null;
1587}
1588{
Till Westmann68d99652013-05-09 11:15:21 -07001589 ( LOOKAHEAD(2)
1590 expr = FunctionCallExpr()
1591 | expr = Literal()
1592 | expr = DatasetAccessExpression()
1593 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001594 {
1595 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001596 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001597 }
Till Westmann68d99652013-05-09 11:15:21 -07001598 | expr = ListConstructor()
1599 | expr = RecordConstructor()
1600 | expr = ParenthesizedExpression()
1601 )
1602 {
1603 return expr;
1604 }
vinayakb38b7ca42012-03-05 05:44:15 +00001605}
1606
1607Expression Literal() throws ParseException:
1608{
vinayakb38b7ca42012-03-05 05:44:15 +00001609 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001610 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001611}
1612{
Till Westmann7d535322013-05-09 00:40:02 -07001613 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001614 {
Till Westmann7d535322013-05-09 00:40:02 -07001615 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001616 }
1617 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001618 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001619 try {
1620 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1621 } catch(NumberFormatException ex) {
1622 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1623 }
1624 }
1625 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001626 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001627 lit.setValue(new FloatLiteral(new Float(token.image)));
1628 }
1629 | <DOUBLE_LITERAL>
1630 {
1631 lit.setValue(new DoubleLiteral(new Double(token.image)));
1632 }
1633 | <NULL>
1634 {
1635 lit.setValue(NullLiteral.INSTANCE);
1636 }
1637 | <TRUE>
1638 {
1639 lit.setValue(TrueLiteral.INSTANCE);
1640 }
1641 | <FALSE>
1642 {
1643 lit.setValue(FalseLiteral.INSTANCE);
1644 }
1645 )
vinayakb38b7ca42012-03-05 05:44:15 +00001646 {
1647 return lit;
1648 }
1649}
1650
1651
1652VariableExpr VariableRef() throws ParseException:
1653{
1654 VariableExpr varExp = new VariableExpr();
1655 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001656}
1657{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001658 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001659 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001660 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001661 Identifier ident = lookupSymbol(varName);
1662 if (isInForbiddenScopes(varName)) {
1663 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.");
1664 }
1665 if(ident != null) { // exist such ident
1666 varExp.setIsNewVar(false);
1667 varExp.setVar((VarIdentifier)ident);
1668 } else {
1669 varExp.setVar(var);
1670 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001671 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001672 return varExp;
1673 }
1674}
1675
1676
1677VariableExpr Variable() throws ParseException:
1678{
1679 VariableExpr varExp = new VariableExpr();
1680 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001681}
1682{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001683 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001684 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001685 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001686 if(ident != null) { // exist such ident
1687 varExp.setIsNewVar(false);
1688 }
1689 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001690 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001691 return varExp;
1692 }
1693}
1694
1695Expression ListConstructor() throws ParseException:
1696{
1697 Expression expr = null;
1698}
1699{
1700 (
1701 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1702 )
1703
1704 {
1705 return expr;
1706 }
1707}
1708
1709
1710ListConstructor OrderedListConstructor() throws ParseException:
1711{
1712 ListConstructor expr = new ListConstructor();
1713 Expression tmp = null;
1714 List<Expression> exprList = new ArrayList<Expression>();
1715 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1716}
1717{
1718
Till Westmann96c1f172013-08-01 02:05:48 -07001719 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001720 ( tmp = Expression()
1721 {
1722 exprList.add(tmp);
1723 }
1724
Till Westmann96c1f172013-08-01 02:05:48 -07001725 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001726 )?
1727
Till Westmann96c1f172013-08-01 02:05:48 -07001728 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001729
1730 {
1731 expr.setExprList(exprList);
1732 return expr;
1733 }
1734}
1735
1736ListConstructor UnorderedListConstructor() throws ParseException:
1737{
1738 ListConstructor expr = new ListConstructor();
1739 Expression tmp = null;
1740 List<Expression> exprList = new ArrayList<Expression>();
1741 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1742}
1743{
1744
Till Westmann96c1f172013-08-01 02:05:48 -07001745 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001746 {
1747 exprList.add(tmp);
1748 }
Till Westmann96c1f172013-08-01 02:05:48 -07001749 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001750 {
1751 expr.setExprList(exprList);
1752 return expr;
1753 }
1754}
1755
1756RecordConstructor RecordConstructor() throws ParseException:
1757{
1758 RecordConstructor expr = new RecordConstructor();
1759 FieldBinding tmp = null;
1760 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1761}
1762{
Till Westmann96c1f172013-08-01 02:05:48 -07001763 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001764 {
1765 fbList.add(tmp);
1766 }
Till Westmann96c1f172013-08-01 02:05:48 -07001767 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001768 {
1769 expr.setFbList(fbList);
1770 return expr;
1771 }
1772}
1773
1774FieldBinding FieldBinding() throws ParseException:
1775{
1776 FieldBinding fb = new FieldBinding();
1777 Expression left, right;
1778}
1779{
Till Westmann96c1f172013-08-01 02:05:48 -07001780 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001781 {
1782 fb.setLeftExpr(left);
1783 fb.setRightExpr(right);
1784 return fb;
1785 }
1786}
1787
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001788
vinayakb38b7ca42012-03-05 05:44:15 +00001789Expression FunctionCallExpr() throws ParseException:
1790{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001791 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001792 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001793 Expression tmp;
1794 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001795 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001796 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001797}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001798{
ramangrover299f76a5e2013-06-18 10:25:17 -07001799 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001800 {
Till Westmann31c21f92013-05-08 09:21:53 -07001801 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001802 }
Till Westmann31c21f92013-05-08 09:21:53 -07001803 <LEFTPAREN> (tmp = Expression()
1804 {
1805 argList.add(tmp);
1806 arity ++;
1807 }
Till Westmann96c1f172013-08-01 02:05:48 -07001808 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001809 {
1810 argList.add(tmp);
1811 arity++;
1812 }
1813 )*)? <RIGHTPAREN>
1814 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001815 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001816 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001817 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001818 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001819 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001820 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001821 }
1822 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001823 if (hint != null) {
1824 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1825 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1826 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1827 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1828 }
Till Westmann31c21f92013-05-08 09:21:53 -07001829 }
1830 return callExpr;
1831 }
vinayakb38b7ca42012-03-05 05:44:15 +00001832}
1833
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001834
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001835Expression DatasetAccessExpression() throws ParseException:
1836{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001837 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001838 String arg1 = null;
1839 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001840 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001841}
1842{
Till Westmann14a20a72013-05-09 00:06:24 -07001843 <DATASET>
1844 {
Till Westmann14a20a72013-05-09 00:06:24 -07001845 funcName = token.image;
1846 }
Till Westmann96c1f172013-08-01 02:05:48 -07001847 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001848 {
1849 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001850 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001851 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001852 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001853 if(arg2 != null){
1854 addDataverse(arg1.toString());
1855 addDataset(name);
1856 } else {
1857 addDataset(defaultDataverse + "." + name);
1858 }
Till Westmann14a20a72013-05-09 00:06:24 -07001859 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001860 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001861 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001862 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1863 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1864 if (signature == null) {
1865 signature = new FunctionSignature(dataverse, funcName, 1);
1866 }
1867 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001868 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001869 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001870 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001871}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001872
vinayakb38b7ca42012-03-05 05:44:15 +00001873Expression ParenthesizedExpression() throws ParseException:
1874{
1875 Expression expr;
1876}
1877{
1878 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1879 {
1880 return expr;
1881 }
1882}
1883
1884Expression IfThenElse() throws ParseException:
1885{
1886 Expression condExpr;
1887 Expression thenExpr;
1888 Expression elseExpr;
1889 IfExpr ifExpr = new IfExpr();
1890}
1891{
Till Westmann96c1f172013-08-01 02:05:48 -07001892 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001893
1894 {
1895 ifExpr.setCondExpr(condExpr);
1896 ifExpr.setThenExpr(thenExpr);
1897 ifExpr.setElseExpr(elseExpr);
1898 return ifExpr;
1899 }
1900}
1901
1902Expression FLWOGR() throws ParseException:
1903{
1904 FLWOGRExpression flworg = new FLWOGRExpression();
1905 List<Clause> clauseList = new ArrayList<Clause>();
1906 Expression returnExpr;
1907 Clause tmp;
1908 createNewScope();
1909}
1910{
1911 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001912 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001913
1914 {
1915 flworg.setClauseList(clauseList);
1916 flworg.setReturnExpr(returnExpr);
1917 removeCurrentScope();
1918 return flworg;
1919 }
1920}
1921
1922Clause Clause()throws ParseException :
1923{
1924 Clause clause;
1925}
1926{
1927 (
1928 clause = ForClause()
1929 | clause = LetClause()
1930 | clause = WhereClause()
1931 | clause = OrderbyClause()
1932 | clause = GroupClause()
1933 | clause = LimitClause()
1934 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001935 )
1936 {
1937 return clause;
1938 }
1939}
1940
1941Clause ForClause()throws ParseException :
1942{
1943 ForClause fc = new ForClause();
1944 VariableExpr varExp;
1945 VariableExpr varPos = null;
1946 Expression inExp;
1947 extendCurrentScope();
1948}
1949{
Till Westmann96c1f172013-08-01 02:05:48 -07001950 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001951 {
1952 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001953 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001954 fc.setInExpr(inExp);
1955 if (varPos != null) {
1956 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001957 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001958 }
1959 return fc;
1960 }
1961}
1962
1963Clause LetClause() throws ParseException:
1964{
1965 LetClause lc = new LetClause();
1966 VariableExpr varExp;
1967 Expression beExp;
1968 extendCurrentScope();
1969}
1970{
Till Westmann96c1f172013-08-01 02:05:48 -07001971 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001972 {
1973 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001974 lc.setVarExpr(varExp);
1975 lc.setBeExpr(beExp);
1976 return lc;
1977 }
1978}
1979
1980Clause WhereClause()throws ParseException :
1981{
1982 WhereClause wc = new WhereClause();
1983 Expression whereExpr;
1984}
1985{
salsubaieedf89fbc2013-12-21 19:51:42 -08001986 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001987 {
1988 wc.setWhereExpr(whereExpr);
1989 return wc;
1990 }
1991}
1992
1993Clause OrderbyClause()throws ParseException :
1994{
1995 OrderbyClause oc = new OrderbyClause();
1996 Expression orderbyExpr;
1997 List<Expression> orderbyList = new ArrayList<Expression>();
1998 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1999 int numOfOrderby = 0;
2000}
2001{
2002 (
Till Westmann96c1f172013-08-01 02:05:48 -07002003 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002004 {
2005 String hint = getHint(token);
2006 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2007 String splits[] = hint.split(" +");
2008 int numFrames = Integer.parseInt(splits[1]);
2009 int numTuples = Integer.parseInt(splits[2]);
2010 oc.setNumFrames(numFrames);
2011 oc.setNumTuples(numTuples);
2012 }
2013 }
Till Westmann96c1f172013-08-01 02:05:48 -07002014 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002015 {
2016 orderbyList.add(orderbyExpr);
2017 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2018 }
Till Westmann96c1f172013-08-01 02:05:48 -07002019 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2020 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002021 {
2022 modifierList.add(modif);
2023 }
2024
Till Westmann96c1f172013-08-01 02:05:48 -07002025 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002026 {
2027 orderbyList.add(orderbyExpr);
2028 modif = OrderbyClause.OrderModifier.ASC;
2029 }
Till Westmann96c1f172013-08-01 02:05:48 -07002030 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2031 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002032 {
2033 modifierList.add(modif);
2034 }
2035 )*
2036)
2037 {
2038 oc.setModifierList(modifierList);
2039 oc.setOrderbyList(orderbyList);
2040 return oc;
2041 }
2042}
2043Clause GroupClause()throws ParseException :
2044{
2045 GroupbyClause gbc = new GroupbyClause();
2046 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2047 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2048 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2049 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2050 VariableExpr var = null;
2051 VariableExpr withVar = null;
2052 Expression expr = null;
2053 VariableExpr decorVar = null;
2054 Expression decorExpr = null;
2055}
2056{
2057 {
2058 Scope newScope = extendCurrentScopeNoPush(true);
2059 // extendCurrentScope(true);
2060 }
Till Westmann96c1f172013-08-01 02:05:48 -07002061 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002062 {
2063 String hint = getHint(token);
2064 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2065 gbc.setHashGroupByHint(true);
2066 }
2067 }
Till Westmann96c1f172013-08-01 02:05:48 -07002068 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002069 {
2070 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002071 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002072 expr = Expression()
2073 {
2074 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2075 vePairList.add(pair1);
2076 }
Till Westmann96c1f172013-08-01 02:05:48 -07002077 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002078 {
2079 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002080 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002081 expr = Expression()
2082 {
2083 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2084 vePairList.add(pair2);
2085 }
2086 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002087 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002088 {
2089 newScope.addNewVarSymbolToScope(decorVar.getVar());
2090 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2091 decorPairList.add(pair3);
2092 }
Till Westmann96c1f172013-08-01 02:05:48 -07002093 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002094 {
2095 newScope.addNewVarSymbolToScope(decorVar.getVar());
2096 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2097 decorPairList.add(pair4);
2098 }
2099 )*
2100 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002101 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002102 {
2103 if(withVar.getIsNewVar()==true)
2104 throw new ParseException("can't find variable " + withVar.getVar());
2105 withVarList.add(withVar);
2106 newScope.addNewVarSymbolToScope(withVar.getVar());
2107 }
Till Westmann96c1f172013-08-01 02:05:48 -07002108 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002109 {
2110 if(withVar.getIsNewVar()==true)
2111 throw new ParseException("can't find variable " + withVar.getVar());
2112 withVarList.add(withVar);
2113 newScope.addNewVarSymbolToScope(withVar.getVar());
2114 })*
2115 {
2116 gbc.setGbyPairList(vePairList);
2117 gbc.setDecorPairList(decorPairList);
2118 gbc.setWithVarList(withVarList);
2119 replaceCurrentScope(newScope);
2120 return gbc;
2121 }
2122}
2123
2124
2125LimitClause LimitClause() throws ParseException:
2126{
2127 LimitClause lc = new LimitClause();
2128 Expression expr;
2129 pushForbiddenScope(getCurrentScope());
2130}
2131{
Till Westmann96c1f172013-08-01 02:05:48 -07002132 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2133 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002134
2135 {
2136 popForbiddenScope();
2137 return lc;
2138 }
2139}
2140
2141DistinctClause DistinctClause() throws ParseException:
2142{
2143 List<Expression> exprs = new ArrayList<Expression>();
2144 Expression expr;
2145}
2146{
Till Westmann96c1f172013-08-01 02:05:48 -07002147 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002148 {
2149 exprs.add(expr);
2150 }
Till Westmann96c1f172013-08-01 02:05:48 -07002151 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002152 {
2153 exprs.add(expr);
2154 }
2155 )*
2156 {
2157 return new DistinctClause(exprs);
2158 }
2159}
2160
vinayakb38b7ca42012-03-05 05:44:15 +00002161QuantifiedExpression QuantifiedExpression()throws ParseException:
2162{
2163 QuantifiedExpression qc = new QuantifiedExpression();
2164 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2165 Expression satisfiesExpr;
2166 VariableExpr var;
2167 Expression inExpr;
2168 QuantifiedPair pair;
2169}
2170{
2171 {
2172 createNewScope();
2173 }
2174
Till Westmann96c1f172013-08-01 02:05:48 -07002175 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2176 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2177 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002178 {
2179 pair = new QuantifiedPair(var, inExpr);
2180 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2181 quantifiedList.add(pair);
2182 }
2183 (
Till Westmann96c1f172013-08-01 02:05:48 -07002184 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002185 {
2186 pair = new QuantifiedPair(var, inExpr);
2187 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2188 quantifiedList.add(pair);
2189 }
2190 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002191 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002192 {
2193 qc.setSatisfiesExpr(satisfiesExpr);
2194 qc.setQuantifiedList(quantifiedList);
2195 removeCurrentScope();
2196 return qc;
2197 }
2198}
2199
2200TOKEN_MGR_DECLS:
2201{
Till Westmann96c1f172013-08-01 02:05:48 -07002202 public int commentDepth = 0;
2203 public IntStack lexerStateStack = new IntStack();
2204
2205 public void pushState() {
2206 lexerStateStack.push( curLexState );
2207 }
2208
Till Westmannfd733ee2014-07-10 00:57:37 -07002209 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002210 if (lexerStateStack.size() > 0) {
2211 SwitchTo( lexerStateStack.pop() );
2212 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002213 int errorLine = input_stream.getEndLine();
2214 int errorColumn = input_stream.getEndColumn();
2215 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2216 + "\" but state stack is empty.";
2217 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002218 }
2219 }
vinayakb38b7ca42012-03-05 05:44:15 +00002220}
2221
Till Westmann96c1f172013-08-01 02:05:48 -07002222<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002223TOKEN :
2224{
Till Westmann5df7b452013-08-02 13:07:16 -07002225 <ASC : "asc">
2226 | <AT : "at">
2227 | <BY : "by">
2228 | <DATASET : "dataset">
2229 | <DECOR : "decor">
2230 | <DESC : "desc">
2231 | <DISTINCT : "distinct">
2232 | <ELSE : "else">
2233 | <EVERY : "every">
2234 | <FOR : "for">
2235 | <GROUP : "group">
2236 | <IF : "if">
2237 | <IN : "in">
2238 | <LET : "let">
2239 | <LIMIT : "limit">
2240 | <OFFSET : "offset">
2241 | <ORDER : "order">
2242 | <RETURN : "return">
2243 | <SATISFIES : "satisfies">
2244 | <SOME : "some">
2245 | <THEN : "then">
2246 | <UNION : "union">
2247 | <WHERE : "where">
2248 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002249}
2250
Till Westmann96c1f172013-08-01 02:05:48 -07002251<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002252TOKEN :
2253{
Till Westmann5df7b452013-08-02 13:07:16 -07002254 <CARET : "^">
2255 | <DIV : "/">
2256 | <IDIV : "idiv">
2257 | <MINUS : "-">
2258 | <MOD : "%">
2259 | <MUL : "*">
2260 | <PLUS : "+">
2261
2262 | <LEFTPAREN : "(">
2263 | <RIGHTPAREN : ")">
2264 | <LEFTBRACKET : "[">
2265 | <RIGHTBRACKET : "]">
2266
2267 | <COLON : ":">
2268 | <COMMA : ",">
2269 | <DOT : ".">
2270 | <QUES : "?">
2271
2272 | <LT : "<">
2273 | <GT : ">">
2274 | <LE : "<=">
2275 | <GE : ">=">
2276 | <EQ : "=">
2277 | <NE : "!=">
2278 | <SIMILAR : "~=">
2279 | <ASSIGN : ":=">
2280
2281 | <AND : "and">
2282 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002283}
2284
Till Westmann96c1f172013-08-01 02:05:48 -07002285<DEFAULT,IN_DBL_BRACE>
2286TOKEN :
2287{
Till Westmann5df7b452013-08-02 13:07:16 -07002288 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002289}
2290
2291<DEFAULT>
2292TOKEN :
2293{
Till Westmannfd733ee2014-07-10 00:57:37 -07002294 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002295}
2296
Till Westmann96c1f172013-08-01 02:05:48 -07002297<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002298TOKEN :
2299{
Till Westmann5df7b452013-08-02 13:07:16 -07002300 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002301}
2302
Till Westmann96c1f172013-08-01 02:05:48 -07002303<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002304TOKEN :
2305{
Till Westmannfd733ee2014-07-10 00:57:37 -07002306 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
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 Westmann5df7b452013-08-02 13:07:16 -07002312 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002313}
2314
Till Westmann96c1f172013-08-01 02:05:48 -07002315<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002316TOKEN :
2317{
Till Westmann5df7b452013-08-02 13:07:16 -07002318 <NULL : "null">
2319 | <TRUE : "true">
2320 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002321}
2322
Till Westmann96c1f172013-08-01 02:05:48 -07002323<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002324TOKEN :
2325{
Till Westmann5df7b452013-08-02 13:07:16 -07002326 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002327}
2328
Till Westmann96c1f172013-08-01 02:05:48 -07002329<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002330TOKEN:
2331{
Till Westmann5df7b452013-08-02 13:07:16 -07002332 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002333 | <DIGITS> ( "." <DIGITS> )?
2334 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002335 >
2336 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002337 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2338 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002339 >
2340 | <DIGITS : (<DIGIT>)+ >
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 <#LETTER : ["A" - "Z", "a" - "z"]>
2347 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002348}
2349
Till Westmann96c1f172013-08-01 02:05:48 -07002350<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002351TOKEN :
2352{
Till Westmanne0cc01c2014-03-31 10:26:10 -07002353 <STRING_LITERAL : ("\"" (<EscapeQuot> | <EscapeBslash> | ~["\"","\\"])* "\"")
2354 | ("\'"(<EscapeApos> | <EscapeBslash> | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002355 | < #EscapeQuot: "\\\"" >
2356 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002357 | < #EscapeBslash: "\\\\" >
vinayakb38b7ca42012-03-05 05:44:15 +00002358}
2359
Till Westmann96c1f172013-08-01 02:05:48 -07002360<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002361TOKEN :
2362{
Till Westmann5df7b452013-08-02 13:07:16 -07002363 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002364}
2365
Till Westmann96c1f172013-08-01 02:05:48 -07002366<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002367TOKEN :
2368{
Till Westmann5df7b452013-08-02 13:07:16 -07002369 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002370}
2371
Till Westmann96c1f172013-08-01 02:05:48 -07002372<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002373SKIP:
2374{
2375 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002376 | "\t"
2377 | "\r"
2378 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002379}
2380
Till Westmann96c1f172013-08-01 02:05:48 -07002381<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002382SKIP:
2383{
Till Westmann5df7b452013-08-02 13:07:16 -07002384 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002385}
2386
Till Westmann96c1f172013-08-01 02:05:48 -07002387<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002388SKIP:
2389{
Till Westmann5df7b452013-08-02 13:07:16 -07002390 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002391}
2392
Till Westmann96c1f172013-08-01 02:05:48 -07002393<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002394SKIP:
2395{
Till Westmann96c1f172013-08-01 02:05:48 -07002396 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002397}
2398
2399<INSIDE_COMMENT>
2400SPECIAL_TOKEN:
2401{
Till Westmann5df7b452013-08-02 13:07:16 -07002402 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002403}
2404
2405<INSIDE_COMMENT>
2406SKIP:
2407{
Till Westmann96c1f172013-08-01 02:05:48 -07002408 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002409}
2410
2411<INSIDE_COMMENT>
2412SKIP:
2413{
Till Westmannfd733ee2014-07-10 00:57:37 -07002414 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002415 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002416}