blob: 236beabd52a14fcad11cb84611c9bc7579706be8 [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);
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700160 List<Statement> st = parser.parse();
Till Westmann31c21f92013-05-08 09:21:53 -0700161 //st.accept(new AQLPrintVisitor(), 0);
162 }
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700163
164 public List<Statement> parse() throws ParseException {
165 try {
166 return Statement();
167 } catch (Error e) {
168 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
169 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
170 throw new ParseException(e.getMessage());
171 }
172 }
vinayakb38b7ca42012-03-05 05:44:15 +0000173}
174
175PARSER_END(AQLParser)
176
177
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000178List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000179{
vinayakb38b7ca42012-03-05 05:44:15 +0000180 scopeStack.push(RootScopeFactory.createRootScope(this));
181 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700182 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000183}
184{
Till Westmann31c21f92013-05-08 09:21:53 -0700185 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000186 {
Till Westmann31c21f92013-05-08 09:21:53 -0700187 decls.add(stmt);
188 }
189 )*
190 <EOF>
191 {
192 return decls;
193 }
194}
195
196Statement SingleStatement() throws ParseException:
197{
198 Statement stmt = null;
199}
200{
201 (
202 stmt = DataverseDeclaration()
203 | stmt = FunctionDeclaration()
204 | stmt = CreateStatement()
205 | stmt = LoadStatement()
206 | stmt = DropStatement()
207 | stmt = WriteStatement()
208 | stmt = SetStatement()
209 | stmt = InsertStatement()
210 | stmt = DeleteStatement()
211 | stmt = UpdateStatement()
212 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700213 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700214 | stmt = Query()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700215 | stmt = RefreshExternalDatasetStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700216 )
217 {
218 return stmt;
219 }
220}
221
222DataverseDecl DataverseDeclaration() throws ParseException:
223{
Till Westmann14a20a72013-05-09 00:06:24 -0700224 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700225}
226{
Till Westmanna4242bc2013-05-08 17:49:55 -0700227 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700228 {
Till Westmann14a20a72013-05-09 00:06:24 -0700229 defaultDataverse = dvName;
230 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700231 }
232}
233
234Statement CreateStatement() throws ParseException:
235{
236 String hint = null;
237 boolean dgen = false;
238 Statement stmt = null;
239}
240{
241 "create"
242 (
243 {
244 hint = getHint(token);
245 if (hint != null && hint.startsWith(DGEN_HINT)) {
246 dgen = true;
247 }
248 }
249 stmt = TypeSpecification(hint, dgen)
250 | stmt = NodegroupSpecification()
251 | stmt = DatasetSpecification()
252 | stmt = IndexSpecification()
253 | stmt = DataverseSpecification()
254 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700255 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700256 )
257 {
258 return stmt;
259 }
260}
261
262TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
263{
264 Pair<Identifier,Identifier> nameComponents = null;
265 boolean ifNotExists = false;
266 TypeExpression typeExpr = null;
267}
268{
ramangrover299f76a5e2013-06-18 10:25:17 -0700269 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700270 "as" typeExpr = TypeExpr()
271 {
272 long numValues = -1;
273 String filename = null;
274 if (dgen) {
275 String splits[] = hint.split(" +");
276 if (splits.length != 3) {
277 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
278 }
279 filename = splits[1];
280 numValues = Long.parseLong(splits[2]);
281 }
282 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
283 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
284 }
285}
286
287
288NodegroupDecl NodegroupSpecification() throws ParseException:
289{
Till Westmann14a20a72013-05-09 00:06:24 -0700290 String name = null;
291 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700292 boolean ifNotExists = false;
293 List<Identifier>ncNames = null;
294}
295{
Till Westmanna4242bc2013-05-08 17:49:55 -0700296 "nodegroup" name = Identifier()
297 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700298 {
299 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700300 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700301 }
Till Westmann96c1f172013-08-01 02:05:48 -0700302 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700303 {
Till Westmann14a20a72013-05-09 00:06:24 -0700304 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700305 }
306 )*
307 {
Till Westmann14a20a72013-05-09 00:06:24 -0700308 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700309 }
310}
311
312DatasetDecl DatasetSpecification() throws ParseException:
313{
314 Pair<Identifier,Identifier> nameComponents = null;
315 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700316 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700317 String adapterName = null;
318 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700319 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700320 FunctionSignature appliedFunction = null;
321 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700322 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700323 Map<String,String> hints = new HashMap<String,String>();
324 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700325 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700326 String compactionPolicy = null;
salsubaieea5af4e02014-07-08 15:20:02 -0700327 String filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700328}
329{
330 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700331 "external" <DATASET> nameComponents = QualifiedName()
332 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
333 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700334 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700335 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700336 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700337 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Till Westmann31c21f92013-05-08 09:21:53 -0700338 {
339 ExternalDetailsDecl edd = new ExternalDetailsDecl();
340 edd.setAdapter(adapterName);
341 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700342 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
343 edd.setCompactionPolicy(compactionPolicy);
344 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700345 dsetDecl = new DatasetDecl(nameComponents.first,
346 nameComponents.second,
347 new Identifier(typeName),
348 hints,
349 DatasetType.EXTERNAL,
350 edd,
351 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700352 }
353
Till Westmannd7dcb122013-05-16 13:19:09 -0700354 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700355 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
356 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700357 primaryKeyFields = PrimaryKey()
358 ("autogenerated" { autogenerated = true; } )?
359 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700360 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700361 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
salsubaieea5af4e02014-07-08 15:20:02 -0700362 ( "with filter on" filterField = FilterField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700363 {
Till Westmann14a20a72013-05-09 00:06:24 -0700364 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
365 ? new Identifier(nodeGroupName)
366 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700367 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700368 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700369 compactionPolicy,
salsubaieea5af4e02014-07-08 15:20:02 -0700370 compactionPolicyProperties,
371 filterField);
Till Westmann14a20a72013-05-09 00:06:24 -0700372 dsetDecl = new DatasetDecl(nameComponents.first,
373 nameComponents.second,
374 new Identifier(typeName),
375 hints,
376 DatasetType.INTERNAL,
377 idd,
378 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700379 }
380 )
381 {
382 return dsetDecl;
383 }
384}
385
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700386RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
387{
388 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
389 Pair<Identifier,Identifier> nameComponents = null;
390 String datasetName = null;
391}
392{
393 "refresh external" <DATASET> nameComponents = QualifiedName()
394 {
395 redss.setDataverseName(nameComponents.first);
396 redss.setDatasetName(nameComponents.second);
397 return redss;
398 }
399}
400
Till Westmann31c21f92013-05-08 09:21:53 -0700401CreateIndexStatement IndexSpecification() throws ParseException:
402{
403 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700404 String indexName = null;
405 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700406 boolean ifNotExists = false;
407 Pair<Identifier,Identifier> nameComponents = null;
408 IndexParams indexType = null;
409}
410{
Till Westmanna4242bc2013-05-08 17:49:55 -0700411 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700412 ifNotExists = IfNotExists()
413 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700414 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700415 {
Till Westmann14a20a72013-05-09 00:06:24 -0700416 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700417 }
Till Westmann96c1f172013-08-01 02:05:48 -0700418 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700419 {
Till Westmann14a20a72013-05-09 00:06:24 -0700420 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700421 }
422 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
423 {
Till Westmann14a20a72013-05-09 00:06:24 -0700424 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700425 cis.setIfNotExists(ifNotExists);
426 cis.setDataverseName(nameComponents.first);
427 cis.setDatasetName(nameComponents.second);
428 if (indexType != null) {
429 cis.setIndexType(indexType.type);
430 cis.setGramLength(indexType.gramLength);
431 }
432 return cis;
433 }
434}
435
salsubaiee0b423fa2013-09-19 19:16:48 -0700436String CompactionPolicy() throws ParseException :
437{
438 String compactionPolicy = null;
439}
440{
441 compactionPolicy = Identifier()
442 {
443 return compactionPolicy;
444 }
445}
446
salsubaieea5af4e02014-07-08 15:20:02 -0700447String FilterField() throws ParseException :
448{
449 String filterField = null;
450}
451{
452 filterField = Identifier()
453 {
454 return filterField;
455 }
456}
457
Till Westmann31c21f92013-05-08 09:21:53 -0700458IndexParams IndexType() throws ParseException:
459{
460 IndexType type = null;
461 int gramLength = 0;
462}
463{
464 ("btree"
465 {
466 type = IndexType.BTREE;
467 }
468 | "rtree"
469 {
470 type = IndexType.RTREE;
471 }
472 | "keyword"
473 {
JIMAHNb75446d2013-06-03 08:35:27 -0700474 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700475 }
476 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
477 {
JIMAHNb75446d2013-06-03 08:35:27 -0700478 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700479 gramLength = Integer.valueOf(token.image);
480 }
481 <RIGHTPAREN>)
482 {
483 return new IndexParams(type, gramLength);
484 }
485}
486
487CreateDataverseStatement DataverseSpecification() throws ParseException :
488{
Till Westmann14a20a72013-05-09 00:06:24 -0700489 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700490 boolean ifNotExists = false;
491 String format = null;
492}
493{
Till Westmanna4242bc2013-05-08 17:49:55 -0700494 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700495 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700496 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700497 {
Till Westmann14a20a72013-05-09 00:06:24 -0700498 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700499 }
500}
501
502CreateFunctionStatement FunctionSpecification() throws ParseException:
503{
504 FunctionSignature signature;
505 boolean ifNotExists = false;
506 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
507 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700508 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700509 Expression functionBodyExpr;
510 Token beginPos;
511 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700512 FunctionName fctName = null;
513
Till Westmann31c21f92013-05-08 09:21:53 -0700514 createNewScope();
515}
516{
ramangrover299f76a5e2013-06-18 10:25:17 -0700517 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700518 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700519 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700520 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530521 {
522 beginPos = token;
523 }
Till Westmann96c1f172013-08-01 02:05:48 -0700524 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700525 {
526 endPos = token;
527 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700528 // TODO use fctName.library
529 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700530 getCurrentScope().addFunctionDescriptor(signature, false);
531 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
532 }
533}
534
ramangrover29a774ef22013-07-17 09:29:18 -0700535CreateFeedStatement FeedSpecification() throws ParseException:
536{
537 Pair<Identifier,Identifier> nameComponents = null;
538 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700539 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700540 Map<String,String> properties = null;
541 FunctionSignature appliedFunction = null;
542 CreateFeedStatement cfs = null;
543}
544{
545 (
546 "feed" nameComponents = QualifiedName()
547 ifNotExists = IfNotExists()
Chris Hillerye64055d2014-10-11 00:14:39 -0700548 "using" adapterName = AdapterName() properties = Configuration()
ramangrover29a774ef22013-07-17 09:29:18 -0700549 (appliedFunction = ApplyFunction())?
550 {
551 cfs = new CreateFeedStatement(nameComponents.first,
Chris Hillerye64055d2014-10-11 00:14:39 -0700552 nameComponents.second, adapterName, properties, appliedFunction, ifNotExists);
ramangrover29a774ef22013-07-17 09:29:18 -0700553 }
554
555 )
556 {
557 return cfs;
558 }
559}
560
561
562
Till Westmannd7dcb122013-05-16 13:19:09 -0700563List<VarIdentifier> ParameterList() throws ParseException:
564{
565 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
566 VarIdentifier var = null;
567}
568{
Till Westmann31c21f92013-05-08 09:21:53 -0700569 <LEFTPAREN> (<VARIABLE>
570 {
571 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700572 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700573 paramList.add(var);
574 getCurrentScope().addNewVarSymbolToScope(var);
575 }
Till Westmann96c1f172013-08-01 02:05:48 -0700576 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700577 {
578 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700579 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700580 paramList.add(var);
581 getCurrentScope().addNewVarSymbolToScope(var);
582 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700583 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700584 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700585 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700586 }
587}
588
589boolean IfNotExists() throws ParseException:
590{
591}
592{
593 ( "if not exists"
594 {
595 return true;
596 }
597 )?
598 {
599 return false;
600 }
601}
602
603FunctionSignature ApplyFunction() throws ParseException:
604{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530605 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700606 FunctionSignature funcSig = null;
607}
608{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530609 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700610 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530611 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
612 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700613 }
614}
615
ramangrover29566b3a92013-05-28 09:07:10 -0700616String GetPolicy() throws ParseException:
617{
618 String policy = null;
619}
620{
621 "using" "policy" policy = Identifier()
622 {
623 return policy;
624 }
625
626}
627
Till Westmann31c21f92013-05-08 09:21:53 -0700628FunctionSignature FunctionSignature() throws ParseException:
629{
ramangrover299f76a5e2013-06-18 10:25:17 -0700630 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700631 int arity = 0;
632}
633{
ramangrover299f76a5e2013-06-18 10:25:17 -0700634 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700635 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700636 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700637 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
638 throw new ParseException(" invalid arity:" + arity);
639 }
640
ramangrover299f76a5e2013-06-18 10:25:17 -0700641 // TODO use fctName.library
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300642 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700643 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700644 }
645}
646
647List<String> PrimaryKey() throws ParseException:
648{
Till Westmann14a20a72013-05-09 00:06:24 -0700649 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700650 List<String> primaryKeyFields = new ArrayList<String>();
651}
652{
Till Westmann14a20a72013-05-09 00:06:24 -0700653 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700654 {
Till Westmann14a20a72013-05-09 00:06:24 -0700655 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700656 }
Till Westmann96c1f172013-08-01 02:05:48 -0700657 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700658 {
Till Westmann14a20a72013-05-09 00:06:24 -0700659 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700660 }
661 )*
662 {
663 return primaryKeyFields;
664 }
665}
666
667Statement DropStatement() throws ParseException:
668{
Till Westmann14a20a72013-05-09 00:06:24 -0700669 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700670 Pair<Identifier,Identifier> pairId = null;
671 Triple<Identifier,Identifier,Identifier> tripleId = null;
672 FunctionSignature funcSig = null;
673 boolean ifExists = false;
674 Statement stmt = null;
675}
676{
677 "drop"
678 (
679 <DATASET> pairId = QualifiedName() ifExists = IfExists()
680 {
681 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
682 }
683 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
684 {
685 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
686 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700687 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700688 {
Till Westmann14a20a72013-05-09 00:06:24 -0700689 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700690 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700691 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700692 {
693 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
694 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700695 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700696 {
Till Westmann14a20a72013-05-09 00:06:24 -0700697 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700698 }
699 | "function" funcSig = FunctionSignature() ifExists = IfExists()
700 {
701 stmt = new FunctionDropStatement(funcSig, ifExists);
702 }
ramangrover29a774ef22013-07-17 09:29:18 -0700703 | "feed" pairId = QualifiedName() ifExists = IfExists()
704 {
705 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
706 }
Till Westmann31c21f92013-05-08 09:21:53 -0700707 )
708 {
709 return stmt;
710 }
711}
712
713boolean IfExists() throws ParseException :
714{
715}
716{
Till Westmann96c1f172013-08-01 02:05:48 -0700717 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700718 {
719 return true;
720 }
721 )?
722 {
723 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000724 }
725}
726
727InsertStatement InsertStatement() throws ParseException:
728{
Till Westmann31c21f92013-05-08 09:21:53 -0700729 Pair<Identifier,Identifier> nameComponents = null;
730 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000731}
732{
Till Westmann31c21f92013-05-08 09:21:53 -0700733 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
734 {
735 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
736 }
vinayakb38b7ca42012-03-05 05:44:15 +0000737}
738
739DeleteStatement DeleteStatement() throws ParseException:
740{
Till Westmann31c21f92013-05-08 09:21:53 -0700741 VariableExpr var = null;
742 Expression condition = null;
743 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300744 // This is related to the new metadata lock management
745 setDataverses(new ArrayList<String>());
746 setDatasets(new ArrayList<String>());
747
vinayakb38b7ca42012-03-05 05:44:15 +0000748}
749{
Till Westmann31c21f92013-05-08 09:21:53 -0700750 "delete" var = Variable()
751 {
752 getCurrentScope().addNewVarSymbolToScope(var.getVar());
753 }
buyingyi2fd7fa62014-11-24 19:31:55 -0800754 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800755 (<WHERE> condition = Expression())?
756 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300757 // First we get the dataverses and datasets that we want to lock
758 List<String> dataverses = getDataverses();
759 List<String> datasets = getDatasets();
760 // we remove the pointer to the dataverses and datasets
761 setDataverses(null);
762 setDatasets(null);
763 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
764 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700765 }
vinayakb38b7ca42012-03-05 05:44:15 +0000766}
767
768UpdateStatement UpdateStatement() throws ParseException:
769{
Till Westmann31c21f92013-05-08 09:21:53 -0700770 VariableExpr vars;
771 Expression target;
772 Expression condition;
773 UpdateClause uc;
774 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000775}
776{
Till Westmann96c1f172013-08-01 02:05:48 -0700777 "update" vars = Variable() <IN> target = Expression()
778 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700779 <LEFTPAREN> (uc = UpdateClause()
780 {
781 ucs.add(uc);
782 }
Till Westmann96c1f172013-08-01 02:05:48 -0700783 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700784 {
785 ucs.add(uc);
786 }
787 )*) <RIGHTPAREN>
788 {
789 return new UpdateStatement(vars, target, condition, ucs);
790 }
vinayakb38b7ca42012-03-05 05:44:15 +0000791}
792
vinayakb38b7ca42012-03-05 05:44:15 +0000793UpdateClause UpdateClause() throws ParseException:
794{
Till Westmann31c21f92013-05-08 09:21:53 -0700795 Expression target = null;
796 Expression value = null ;
797 InsertStatement is = null;
798 DeleteStatement ds = null;
799 UpdateStatement us = null;
800 Expression condition = null;
801 UpdateClause ifbranch = null;
802 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000803}
804{
Till Westmann96c1f172013-08-01 02:05:48 -0700805 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700806 | is = InsertStatement()
807 | ds = DeleteStatement()
808 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700809 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
810 <THEN> ifbranch = UpdateClause()
811 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700812 {
813 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
814 }
vinayakb38b7ca42012-03-05 05:44:15 +0000815}
816
vinayakb38b7ca42012-03-05 05:44:15 +0000817Statement SetStatement() throws ParseException:
818{
819 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700820 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000821}
822{
Till Westmann7d535322013-05-09 00:40:02 -0700823 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700824 {
Till Westmann31c21f92013-05-08 09:21:53 -0700825 return new SetStatement(pn, pv);
826 }
vinayakb38b7ca42012-03-05 05:44:15 +0000827}
828
829Statement WriteStatement() throws ParseException:
830{
Till Westmann14a20a72013-05-09 00:06:24 -0700831 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000832 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000833 Query query;
834 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000835 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000836}
837{
Till Westmann96c1f172013-08-01 02:05:48 -0700838 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700839 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700840 {
841 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000842 }
843}
844
zheilbron28e026f2013-11-20 10:15:15 -0800845LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000846{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000847 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000848 Identifier datasetName = null;
849 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000850 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000851 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000852 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000853}
854{
Till Westmann31c21f92013-05-08 09:21:53 -0700855 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000856 {
Till Westmann31c21f92013-05-08 09:21:53 -0700857 dataverseName = nameComponents.first;
858 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000859 }
Till Westmann31c21f92013-05-08 09:21:53 -0700860 "using" adapterName = AdapterName() properties = Configuration()
861 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000862 {
Till Westmann31c21f92013-05-08 09:21:53 -0700863 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000864 }
865 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700866 {
zheilbron28e026f2013-11-20 10:15:15 -0800867 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Till Westmann31c21f92013-05-08 09:21:53 -0700868 }
vinayakb38b7ca42012-03-05 05:44:15 +0000869}
870
vinayakb38b7ca42012-03-05 05:44:15 +0000871
Till Westmann31c21f92013-05-08 09:21:53 -0700872String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000873{
ramangrover29669d8f62013-02-11 06:03:32 +0000874 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000875}
876{
Till Westmann68d99652013-05-09 11:15:21 -0700877 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000878 {
Till Westmann7d535322013-05-09 00:40:02 -0700879 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000880 }
vinayakb38b7ca42012-03-05 05:44:15 +0000881}
882
salsubaiee0b423fa2013-09-19 19:16:48 -0700883Statement CompactStatement() throws ParseException:
884{
885 Pair<Identifier,Identifier> nameComponents = null;
886 Statement stmt = null;
887}
888{
889 "compact" <DATASET> nameComponents = QualifiedName()
890 {
891 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
892 }
893 {
894 return stmt;
895 }
896}
897
Till Westmann31c21f92013-05-08 09:21:53 -0700898Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000899{
ramangrover29a774ef22013-07-17 09:29:18 -0700900 Pair<Identifier,Identifier> feedNameComponents = null;
901 Pair<Identifier,Identifier> datasetNameComponents = null;
902
Till Westmann31c21f92013-05-08 09:21:53 -0700903 Map<String,String> configuration = null;
904 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700905 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000906}
907{
Till Westmann31c21f92013-05-08 09:21:53 -0700908 (
ramangrover29a774ef22013-07-17 09:29:18 -0700909 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700910 {
ramangrover29a774ef22013-07-17 09:29:18 -0700911 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700912 }
buyingyi2fd7fa62014-11-24 19:31:55 -0800913 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700914 {
ramangrover29a774ef22013-07-17 09:29:18 -0700915 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700916 }
917 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000918 {
Till Westmann31c21f92013-05-08 09:21:53 -0700919 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000920 }
921}
922
Till Westmann31c21f92013-05-08 09:21:53 -0700923Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000924{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000925 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700926 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000927}
928{
Till Westmann31c21f92013-05-08 09:21:53 -0700929 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000930 {
Till Westmann31c21f92013-05-08 09:21:53 -0700931 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000932 }
Till Westmann96c1f172013-08-01 02:05:48 -0700933 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000934 {
Till Westmann31c21f92013-05-08 09:21:53 -0700935 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000936 }
Till Westmann31c21f92013-05-08 09:21:53 -0700937 )* )? <RIGHTPAREN>
938 {
939 return configuration;
940 }
941}
942
943Pair<String, String> KeyValuePair() throws ParseException:
944{
945 String key;
946 String value;
947}
948{
Till Westmann96c1f172013-08-01 02:05:48 -0700949 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700950 {
951 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000952 }
Till Westmann31c21f92013-05-08 09:21:53 -0700953}
954
955Map<String,String> Properties() throws ParseException:
956{
957 Map<String,String> properties = new HashMap<String,String>();
958 Pair<String, String> property;
959}
960{
961 ( <LEFTPAREN> property = Property()
962 {
963 properties.put(property.first, property.second);
964 }
Till Westmann96c1f172013-08-01 02:05:48 -0700965 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700966 {
967 properties.put(property.first, property.second);
968 }
969 )* <RIGHTPAREN> )?
970 {
971 return properties;
972 }
973}
974
975Pair<String, String> Property() throws ParseException:
976{
977 String key;
978 String value;
979}
980{
Till Westmann96c1f172013-08-01 02:05:48 -0700981 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700982 {
983 try {
984 value = "" + Long.valueOf(token.image);
985 } catch (NumberFormatException nfe) {
986 throw new ParseException("inapproriate value: " + token.image);
987 }
988 }
989 )
990 {
991 return new Pair<String, String>(key.toUpperCase(), value);
992 }
vinayakb38b7ca42012-03-05 05:44:15 +0000993}
994
995TypeExpression TypeExpr() throws ParseException:
996{
997 TypeExpression typeExpr = null;
998}
999{
1000 (
1001 typeExpr = RecordTypeDef()
1002 | typeExpr = TypeReference()
1003 | typeExpr = OrderedListTypeDef()
1004 | typeExpr = UnorderedListTypeDef()
1005 )
1006 {
1007 return typeExpr;
1008 }
1009}
1010
1011RecordTypeDefinition RecordTypeDef() throws ParseException:
1012{
1013 RecordTypeDefinition recType = new RecordTypeDefinition();
1014 RecordTypeDefinition.RecordKind recordKind = null;
1015}
1016{
1017 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1018 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001019 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001020 {
1021 String hint = getHint(token);
1022 if (hint != null) {
1023 String splits[] = hint.split(" +");
1024 if (splits[0].equals(GEN_FIELDS_HINT)) {
1025 if (splits.length != 5) {
1026 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1027 }
1028 if (!splits[1].equals("int")) {
1029 throw new ParseException("The only supported type for gen-fields is int.");
1030 }
1031 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1032 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1033 recType.setUndeclaredFieldsDataGen(ufdg);
1034 }
1035 }
1036
1037 }
1038 (
1039 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -07001040 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +00001041 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001042 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001043 {
1044 if (recordKind == null) {
1045 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1046 }
1047 recType.setRecordKind(recordKind);
1048 return recType;
1049 }
1050}
1051
1052void RecordField(RecordTypeDefinition recType) throws ParseException:
1053{
Till Westmann77cb2f42013-07-15 16:44:19 -07001054 String fieldName;
1055 TypeExpression type = null;
1056 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001057}
1058{
Till Westmann77cb2f42013-07-15 16:44:19 -07001059 fieldName = Identifier()
1060 {
1061 String hint = getHint(token);
1062 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1063 }
Till Westmann96c1f172013-08-01 02:05:48 -07001064 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001065 {
1066 recType.addField(fieldName, type, nullable, rfdg);
1067 }
vinayakb38b7ca42012-03-05 05:44:15 +00001068}
1069
1070TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001071{
Till Westmann14a20a72013-05-09 00:06:24 -07001072 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001073}
1074{
1075 id = Identifier()
1076 {
Till Westmann14a20a72013-05-09 00:06:24 -07001077 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001078 }
vinayakb38b7ca42012-03-05 05:44:15 +00001079}
1080
1081OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1082{
1083 TypeExpression type = null;
1084}
1085{
Till Westmann96c1f172013-08-01 02:05:48 -07001086 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001087 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001088 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001089 {
1090 return new OrderedListTypeDefinition(type);
1091 }
1092}
1093
1094
1095UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1096{
1097 TypeExpression type = null;
1098}
1099{
Till Westmann96c1f172013-08-01 02:05:48 -07001100 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001101 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001102 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001103 {
1104 return new UnorderedListTypeDefinition(type);
1105 }
1106}
1107
ramangrover299f76a5e2013-06-18 10:25:17 -07001108FunctionName FunctionName() throws ParseException:
1109{
1110 String first = null;
1111 String second = null;
1112 String third = null;
1113 boolean secondAfterDot = false;
1114}
1115{
zheilbron555dc9d2013-08-14 19:58:00 -07001116 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001117 {
1118 secondAfterDot = true;
1119 }
1120 ("#" third = Identifier())? | "#" second = Identifier() )?
1121 {
1122 FunctionName result = new FunctionName();
1123 if (second == null) {
1124 result.dataverse = defaultDataverse;
1125 result.library = null;
1126 result.function = first;
1127 } else if (third == null) {
1128 if (secondAfterDot) {
1129 result.dataverse = first;
1130 result.library = null;
1131 result.function = second;
1132 } else {
1133 result.dataverse = defaultDataverse;
1134 result.library = first;
1135 result.function = second;
1136 }
1137 } else {
1138 result.dataverse = first;
1139 result.library = second;
1140 result.function = third;
1141 }
1142 return result;
1143 }
1144}
Till Westmann31c21f92013-05-08 09:21:53 -07001145
ramangrover299f76a5e2013-06-18 10:25:17 -07001146
1147Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001148{
Till Westmann31c21f92013-05-08 09:21:53 -07001149 Pair<Identifier,Identifier> name = null;
1150}
1151{
1152 name = QualifiedName()
1153 {
1154 if (name.first == null) {
1155 name.first = new Identifier(defaultDataverse);
1156 }
1157 return name;
1158 }
1159}
1160
Till Westmann14a20a72013-05-09 00:06:24 -07001161String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001162{
Till Westmann68d99652013-05-09 11:15:21 -07001163 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001164}
1165{
1166 <IDENTIFIER>
1167 {
Till Westmann14a20a72013-05-09 00:06:24 -07001168 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001169 }
Till Westmann68d99652013-05-09 11:15:21 -07001170 | lit = StringLiteral()
1171 {
1172 return lit;
1173 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001174}
1175
Till Westmann7d535322013-05-09 00:40:02 -07001176String StringLiteral() throws ParseException:
1177{
1178}
1179{
1180 <STRING_LITERAL>
1181 {
1182 return removeQuotesAndEscapes(token.image);
1183 }
1184}
1185
Till Westmann31c21f92013-05-08 09:21:53 -07001186Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1187{
Till Westmann14a20a72013-05-09 00:06:24 -07001188 String first = null;
1189 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001190}
1191{
Till Westmann96c1f172013-08-01 02:05:48 -07001192 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001193 {
Till Westmann14a20a72013-05-09 00:06:24 -07001194 Identifier id1 = null;
1195 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001196 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001197 id2 = new Identifier(first);
1198 } else
1199 {
1200 id1 = new Identifier(first);
1201 id2 = new Identifier(second);
1202 }
1203 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001204 }
1205}
1206
Till Westmann31c21f92013-05-08 09:21:53 -07001207Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001208{
Till Westmann14a20a72013-05-09 00:06:24 -07001209 String first = null;
1210 String second = null;
1211 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001212}
1213{
Till Westmann96c1f172013-08-01 02:05:48 -07001214 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001215 {
Till Westmann14a20a72013-05-09 00:06:24 -07001216 Identifier id1 = null;
1217 Identifier id2 = null;
1218 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001219 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001220 id2 = new Identifier(first);
1221 id3 = new Identifier(second);
1222 } else {
1223 id1 = new Identifier(first);
1224 id2 = new Identifier(second);
1225 id3 = new Identifier(third);
1226 }
1227 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001228 }
1229}
1230
vinayakb38b7ca42012-03-05 05:44:15 +00001231FunctionDecl FunctionDeclaration() throws ParseException:
1232{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001233 FunctionDecl funcDecl;
1234 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001235 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001236 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1237 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001238 createNewScope();
1239}
1240{
Till Westmannd7dcb122013-05-16 13:19:09 -07001241 "declare" "function" functionName = Identifier()
1242 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001243 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001244 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001245 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001246 getCurrentScope().addFunctionDescriptor(signature, false);
1247 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001248 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001249 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001250 }
1251}
1252
vinayakb38b7ca42012-03-05 05:44:15 +00001253
Till Westmann31c21f92013-05-08 09:21:53 -07001254Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001255{
1256 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001257 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1258 setDataverses(query.getDataverses());
1259 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001260 Expression expr;
1261}
1262{
Till Westmann31c21f92013-05-08 09:21:53 -07001263 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001264 {
1265 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001266 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001267 // we remove the pointers to the locked entities before we return the query object
1268 setDataverses(null);
1269 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001270 return query;
1271 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001272
vinayakb38b7ca42012-03-05 05:44:15 +00001273}
1274
1275
1276
1277Expression Expression():
1278{
1279 Expression expr = null;
1280 Expression exprP = null;
1281}
1282{
1283(
1284
1285//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1286 expr = OperatorExpr()
1287 | expr = IfThenElse()
1288 | expr = FLWOGR()
1289 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001290
vinayakb38b7ca42012-03-05 05:44:15 +00001291
1292)
1293 {
1294 return (exprP==null) ? expr : exprP;
1295 }
1296}
1297
1298
1299
1300Expression OperatorExpr()throws ParseException:
1301{
1302 OperatorExpr op = null;
1303 Expression operand = null;
1304}
1305{
1306 operand = AndExpr()
1307 (
1308
Till Westmann96c1f172013-08-01 02:05:48 -07001309 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001310 {
1311 if (op == null) {
1312 op = new OperatorExpr();
1313 op.addOperand(operand);
1314 op.setCurrentop(true);
1315 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001316 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001317 }
1318
1319 operand = AndExpr()
1320 {
1321 op.addOperand(operand);
1322 }
1323
1324 )*
1325
1326 {
1327 return op==null? operand: op;
1328 }
1329}
1330
1331Expression AndExpr()throws ParseException:
1332{
1333 OperatorExpr op = null;
1334 Expression operand = null;
1335}
1336{
1337 operand = RelExpr()
1338 (
1339
Till Westmann96c1f172013-08-01 02:05:48 -07001340 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001341 {
1342 if (op == null) {
1343 op = new OperatorExpr();
1344 op.addOperand(operand);
1345 op.setCurrentop(true);
1346 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001347 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001348 }
1349
1350 operand = RelExpr()
1351 {
1352 op.addOperand(operand);
1353 }
1354
1355 )*
1356
1357 {
1358 return op==null? operand: op;
1359 }
1360}
1361
1362
1363
1364Expression RelExpr()throws ParseException:
1365{
1366 OperatorExpr op = null;
1367 Expression operand = null;
1368 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001369 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001370}
1371{
1372 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001373 {
1374 if (operand instanceof VariableExpr) {
1375 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001376 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001377 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001378 }
1379 }
1380 }
1381
1382 (
Till Westmann96c1f172013-08-01 02:05:48 -07001383 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001384 {
alexander.behm07617fd2012-07-25 10:13:50 +00001385 String mhint = getHint(token);
salsubaieedf89fbc2013-12-21 19:51:42 -08001386 if (mhint != null) {
1387 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1388 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1389 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1390 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1391 }
alexander.behm07617fd2012-07-25 10:13:50 +00001392 }
vinayakb38b7ca42012-03-05 05:44:15 +00001393 if (op == null) {
1394 op = new OperatorExpr();
1395 op.addOperand(operand, broadcast);
1396 op.setCurrentop(true);
1397 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001398 }
1399 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001400 }
1401
1402 operand = AddExpr()
1403 {
alexander.behm07617fd2012-07-25 10:13:50 +00001404 broadcast = false;
1405 if (operand instanceof VariableExpr) {
1406 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001407 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1408 broadcast = true;
1409 }
alexander.behm07617fd2012-07-25 10:13:50 +00001410 }
vinayakb38b7ca42012-03-05 05:44:15 +00001411 op.addOperand(operand, broadcast);
1412 }
1413 )?
1414
1415 {
alexander.behm07617fd2012-07-25 10:13:50 +00001416 if (annotation != null) {
1417 op.addHint(annotation);
1418 }
vinayakb38b7ca42012-03-05 05:44:15 +00001419 return op==null? operand: op;
1420 }
1421}
1422
1423Expression AddExpr()throws ParseException:
1424{
1425 OperatorExpr op = null;
1426 Expression operand = null;
1427}
1428{
1429 operand = MultExpr()
1430
Till Westmann96c1f172013-08-01 02:05:48 -07001431 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001432 {
1433 if (op == null) {
1434 op = new OperatorExpr();
1435 op.addOperand(operand);
1436 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001437 }
1438 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001439 }
1440
1441 operand = MultExpr()
1442 {
1443 op.addOperand(operand);
1444 }
1445 )*
1446
1447 {
1448 return op==null? operand: op;
1449 }
1450}
1451
1452Expression MultExpr()throws ParseException:
1453{
1454 OperatorExpr op = null;
1455 Expression operand = null;
1456}
1457{
1458 operand = UnionExpr()
1459
Till Westmann96c1f172013-08-01 02:05:48 -07001460 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001461 {
1462 if (op == null) {
1463 op = new OperatorExpr();
1464 op.addOperand(operand);
1465 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001466 }
1467 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001468 }
1469 operand = UnionExpr()
1470 {
1471 op.addOperand(operand);
1472 }
1473 )*
1474
1475 {
1476 return op==null?operand:op;
1477 }
1478}
1479
1480Expression UnionExpr() throws ParseException:
1481{
1482 UnionExpr union = null;
1483 Expression operand1 = null;
1484 Expression operand2 = null;
1485}
1486{
1487 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001488 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001489 (operand2 = UnaryExpr()) {
1490 if (union == null) {
1491 union = new UnionExpr();
1492 union.addExpr(operand1);
1493 }
1494 union.addExpr(operand2);
1495 } )*
1496 {
1497 return (union == null)? operand1: union;
1498 }
1499}
1500
1501Expression UnaryExpr() throws ParseException:
1502{
1503 Expression uexpr = null;
1504 Expression expr = null;
1505}
1506{
Till Westmann96c1f172013-08-01 02:05:48 -07001507 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001508 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001509 uexpr = new UnaryExpr();
1510 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001511 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001512 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001513 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1514 else
1515 throw new ParseException();
1516 }
1517 )?
1518
1519 expr = ValueExpr()
1520 {
1521 if(uexpr!=null){
1522 ((UnaryExpr)uexpr).setExpr(expr);
1523 return uexpr;
1524 }
1525 else{
1526 return expr;
1527 }
1528 }
1529}
1530
Till Westmann04478e72013-05-13 23:01:34 -07001531Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001532{
1533 Expression expr = null;
1534 Identifier ident = null;
1535 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001536 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001537}
1538{
Till Westmann04478e72013-05-13 23:01:34 -07001539 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001540 {
Till Westmann04478e72013-05-13 23:01:34 -07001541 fa = (fa == null ? new FieldAccessor(expr, ident)
1542 : new FieldAccessor(fa, ident));
1543 }
icetindila611ac72014-05-16 10:10:11 -07001544 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001545 {
icetindila611ac72014-05-16 10:10:11 -07001546 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1547 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001548 }
1549 )*
1550 {
1551 return fa == null ? expr : fa;
1552 }
vinayakb38b7ca42012-03-05 05:44:15 +00001553}
1554
1555Identifier Field() throws ParseException:
1556{
Till Westmann14a20a72013-05-09 00:06:24 -07001557 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001558}
1559{
Till Westmann96c1f172013-08-01 02:05:48 -07001560 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001561 {
Till Westmann14a20a72013-05-09 00:06:24 -07001562 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001563 }
vinayakb38b7ca42012-03-05 05:44:15 +00001564}
1565
icetindila611ac72014-05-16 10:10:11 -07001566Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001567{
1568 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001569}
1570{
Till Westmann96c1f172013-08-01 02:05:48 -07001571 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001572 {
1573 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1574 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001575 Literal lit = ((LiteralExpr)expr).getValue();
icetindila611ac72014-05-16 10:10:11 -07001576 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1577 lit.getLiteralType() != Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001578 throw new ParseException("Index should be an INTEGER");
1579 }
1580 }
vinayakb38b7ca42012-03-05 05:44:15 +00001581 }
1582
icetindil5860fb92014-05-16 11:22:15 -07001583 | <QUES> // ANY
vinayakb38b7ca42012-03-05 05:44:15 +00001584
1585 )
1586
Till Westmann96c1f172013-08-01 02:05:48 -07001587 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001588 {
icetindila611ac72014-05-16 10:10:11 -07001589 return expr;
vinayakb38b7ca42012-03-05 05:44:15 +00001590 }
1591}
1592
1593
1594Expression PrimaryExpr()throws ParseException:
1595{
1596 Expression expr = null;
1597}
1598{
Till Westmann68d99652013-05-09 11:15:21 -07001599 ( LOOKAHEAD(2)
1600 expr = FunctionCallExpr()
1601 | expr = Literal()
1602 | expr = DatasetAccessExpression()
1603 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001604 {
1605 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001606 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001607 }
Till Westmann68d99652013-05-09 11:15:21 -07001608 | expr = ListConstructor()
1609 | expr = RecordConstructor()
1610 | expr = ParenthesizedExpression()
1611 )
1612 {
1613 return expr;
1614 }
vinayakb38b7ca42012-03-05 05:44:15 +00001615}
1616
1617Expression Literal() throws ParseException:
1618{
vinayakb38b7ca42012-03-05 05:44:15 +00001619 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001620 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001621}
1622{
Till Westmann7d535322013-05-09 00:40:02 -07001623 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001624 {
Till Westmann7d535322013-05-09 00:40:02 -07001625 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001626 }
1627 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001628 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001629 try {
1630 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1631 } catch(NumberFormatException ex) {
1632 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1633 }
1634 }
1635 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001636 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001637 lit.setValue(new FloatLiteral(new Float(token.image)));
1638 }
1639 | <DOUBLE_LITERAL>
1640 {
1641 lit.setValue(new DoubleLiteral(new Double(token.image)));
1642 }
1643 | <NULL>
1644 {
1645 lit.setValue(NullLiteral.INSTANCE);
1646 }
1647 | <TRUE>
1648 {
1649 lit.setValue(TrueLiteral.INSTANCE);
1650 }
1651 | <FALSE>
1652 {
1653 lit.setValue(FalseLiteral.INSTANCE);
1654 }
1655 )
vinayakb38b7ca42012-03-05 05:44:15 +00001656 {
1657 return lit;
1658 }
1659}
1660
1661
1662VariableExpr VariableRef() throws ParseException:
1663{
1664 VariableExpr varExp = new VariableExpr();
1665 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001666}
1667{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001668 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001669 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001670 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001671 Identifier ident = lookupSymbol(varName);
1672 if (isInForbiddenScopes(varName)) {
1673 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.");
1674 }
1675 if(ident != null) { // exist such ident
1676 varExp.setIsNewVar(false);
1677 varExp.setVar((VarIdentifier)ident);
1678 } else {
1679 varExp.setVar(var);
1680 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001681 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001682 return varExp;
1683 }
1684}
1685
1686
1687VariableExpr Variable() throws ParseException:
1688{
1689 VariableExpr varExp = new VariableExpr();
1690 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001691}
1692{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001693 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001694 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001695 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001696 if(ident != null) { // exist such ident
1697 varExp.setIsNewVar(false);
1698 }
1699 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001700 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001701 return varExp;
1702 }
1703}
1704
1705Expression ListConstructor() throws ParseException:
1706{
1707 Expression expr = null;
1708}
1709{
1710 (
1711 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1712 )
1713
1714 {
1715 return expr;
1716 }
1717}
1718
1719
1720ListConstructor OrderedListConstructor() throws ParseException:
1721{
1722 ListConstructor expr = new ListConstructor();
1723 Expression tmp = null;
1724 List<Expression> exprList = new ArrayList<Expression>();
1725 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1726}
1727{
1728
Till Westmann96c1f172013-08-01 02:05:48 -07001729 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001730 ( tmp = Expression()
1731 {
1732 exprList.add(tmp);
1733 }
1734
Till Westmann96c1f172013-08-01 02:05:48 -07001735 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001736 )?
1737
Till Westmann96c1f172013-08-01 02:05:48 -07001738 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001739
1740 {
1741 expr.setExprList(exprList);
1742 return expr;
1743 }
1744}
1745
1746ListConstructor UnorderedListConstructor() throws ParseException:
1747{
1748 ListConstructor expr = new ListConstructor();
1749 Expression tmp = null;
1750 List<Expression> exprList = new ArrayList<Expression>();
1751 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1752}
1753{
1754
Till Westmann96c1f172013-08-01 02:05:48 -07001755 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001756 {
1757 exprList.add(tmp);
1758 }
Till Westmann96c1f172013-08-01 02:05:48 -07001759 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001760 {
1761 expr.setExprList(exprList);
1762 return expr;
1763 }
1764}
1765
1766RecordConstructor RecordConstructor() throws ParseException:
1767{
1768 RecordConstructor expr = new RecordConstructor();
1769 FieldBinding tmp = null;
1770 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1771}
1772{
Till Westmann96c1f172013-08-01 02:05:48 -07001773 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001774 {
1775 fbList.add(tmp);
1776 }
Till Westmann96c1f172013-08-01 02:05:48 -07001777 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001778 {
1779 expr.setFbList(fbList);
1780 return expr;
1781 }
1782}
1783
1784FieldBinding FieldBinding() throws ParseException:
1785{
1786 FieldBinding fb = new FieldBinding();
1787 Expression left, right;
1788}
1789{
Till Westmann96c1f172013-08-01 02:05:48 -07001790 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001791 {
1792 fb.setLeftExpr(left);
1793 fb.setRightExpr(right);
1794 return fb;
1795 }
1796}
1797
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001798
vinayakb38b7ca42012-03-05 05:44:15 +00001799Expression FunctionCallExpr() throws ParseException:
1800{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001801 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001802 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001803 Expression tmp;
1804 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001805 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001806 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001807}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001808{
ramangrover299f76a5e2013-06-18 10:25:17 -07001809 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001810 {
Till Westmann31c21f92013-05-08 09:21:53 -07001811 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001812 }
Till Westmann31c21f92013-05-08 09:21:53 -07001813 <LEFTPAREN> (tmp = Expression()
1814 {
1815 argList.add(tmp);
1816 arity ++;
1817 }
Till Westmann96c1f172013-08-01 02:05:48 -07001818 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001819 {
1820 argList.add(tmp);
1821 arity++;
1822 }
1823 )*)? <RIGHTPAREN>
1824 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001825 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001826 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001827 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001828 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001829 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001830 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001831 }
1832 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001833 if (hint != null) {
1834 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1835 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1836 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1837 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1838 }
Till Westmann31c21f92013-05-08 09:21:53 -07001839 }
1840 return callExpr;
1841 }
vinayakb38b7ca42012-03-05 05:44:15 +00001842}
1843
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001844
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001845Expression DatasetAccessExpression() throws ParseException:
1846{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001847 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001848 String arg1 = null;
1849 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001850 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001851}
1852{
Till Westmann14a20a72013-05-09 00:06:24 -07001853 <DATASET>
1854 {
Till Westmann14a20a72013-05-09 00:06:24 -07001855 funcName = token.image;
1856 }
Till Westmann96c1f172013-08-01 02:05:48 -07001857 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001858 {
1859 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001860 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001861 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001862 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001863 if(arg2 != null){
1864 addDataverse(arg1.toString());
1865 addDataset(name);
1866 } else {
1867 addDataset(defaultDataverse + "." + name);
1868 }
Till Westmann14a20a72013-05-09 00:06:24 -07001869 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001870 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001871 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001872 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1873 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1874 if (signature == null) {
1875 signature = new FunctionSignature(dataverse, funcName, 1);
1876 }
1877 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001878 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001879 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001880 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001881}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001882
vinayakb38b7ca42012-03-05 05:44:15 +00001883Expression ParenthesizedExpression() throws ParseException:
1884{
1885 Expression expr;
1886}
1887{
1888 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1889 {
1890 return expr;
1891 }
1892}
1893
1894Expression IfThenElse() throws ParseException:
1895{
1896 Expression condExpr;
1897 Expression thenExpr;
1898 Expression elseExpr;
1899 IfExpr ifExpr = new IfExpr();
1900}
1901{
Till Westmann96c1f172013-08-01 02:05:48 -07001902 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001903
1904 {
1905 ifExpr.setCondExpr(condExpr);
1906 ifExpr.setThenExpr(thenExpr);
1907 ifExpr.setElseExpr(elseExpr);
1908 return ifExpr;
1909 }
1910}
1911
1912Expression FLWOGR() throws ParseException:
1913{
1914 FLWOGRExpression flworg = new FLWOGRExpression();
1915 List<Clause> clauseList = new ArrayList<Clause>();
1916 Expression returnExpr;
1917 Clause tmp;
1918 createNewScope();
1919}
1920{
1921 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08001922 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001923
1924 {
1925 flworg.setClauseList(clauseList);
1926 flworg.setReturnExpr(returnExpr);
1927 removeCurrentScope();
1928 return flworg;
1929 }
1930}
1931
1932Clause Clause()throws ParseException :
1933{
1934 Clause clause;
1935}
1936{
1937 (
1938 clause = ForClause()
1939 | clause = LetClause()
1940 | clause = WhereClause()
1941 | clause = OrderbyClause()
1942 | clause = GroupClause()
1943 | clause = LimitClause()
1944 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001945 )
1946 {
1947 return clause;
1948 }
1949}
1950
1951Clause ForClause()throws ParseException :
1952{
1953 ForClause fc = new ForClause();
1954 VariableExpr varExp;
1955 VariableExpr varPos = null;
1956 Expression inExp;
1957 extendCurrentScope();
1958}
1959{
buyingyi2fd7fa62014-11-24 19:31:55 -08001960 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001961 {
1962 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001963 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001964 fc.setInExpr(inExp);
1965 if (varPos != null) {
1966 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001967 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001968 }
1969 return fc;
1970 }
1971}
1972
1973Clause LetClause() throws ParseException:
1974{
1975 LetClause lc = new LetClause();
1976 VariableExpr varExp;
1977 Expression beExp;
1978 extendCurrentScope();
1979}
1980{
buyingyi2fd7fa62014-11-24 19:31:55 -08001981 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001982 {
1983 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001984 lc.setVarExpr(varExp);
1985 lc.setBeExpr(beExp);
1986 return lc;
1987 }
1988}
1989
1990Clause WhereClause()throws ParseException :
1991{
1992 WhereClause wc = new WhereClause();
1993 Expression whereExpr;
1994}
1995{
salsubaieedf89fbc2013-12-21 19:51:42 -08001996 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001997 {
1998 wc.setWhereExpr(whereExpr);
1999 return wc;
2000 }
2001}
2002
2003Clause OrderbyClause()throws ParseException :
2004{
2005 OrderbyClause oc = new OrderbyClause();
2006 Expression orderbyExpr;
2007 List<Expression> orderbyList = new ArrayList<Expression>();
2008 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2009 int numOfOrderby = 0;
2010}
2011{
2012 (
Till Westmann96c1f172013-08-01 02:05:48 -07002013 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002014 {
2015 String hint = getHint(token);
2016 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2017 String splits[] = hint.split(" +");
2018 int numFrames = Integer.parseInt(splits[1]);
2019 int numTuples = Integer.parseInt(splits[2]);
2020 oc.setNumFrames(numFrames);
2021 oc.setNumTuples(numTuples);
2022 }
2023 }
Till Westmann96c1f172013-08-01 02:05:48 -07002024 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002025 {
2026 orderbyList.add(orderbyExpr);
2027 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2028 }
Till Westmann96c1f172013-08-01 02:05:48 -07002029 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2030 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002031 {
2032 modifierList.add(modif);
2033 }
2034
Till Westmann96c1f172013-08-01 02:05:48 -07002035 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002036 {
2037 orderbyList.add(orderbyExpr);
2038 modif = OrderbyClause.OrderModifier.ASC;
2039 }
Till Westmann96c1f172013-08-01 02:05:48 -07002040 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2041 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002042 {
2043 modifierList.add(modif);
2044 }
2045 )*
2046)
2047 {
2048 oc.setModifierList(modifierList);
2049 oc.setOrderbyList(orderbyList);
2050 return oc;
2051 }
2052}
2053Clause GroupClause()throws ParseException :
2054{
2055 GroupbyClause gbc = new GroupbyClause();
2056 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2057 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2058 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2059 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2060 VariableExpr var = null;
2061 VariableExpr withVar = null;
2062 Expression expr = null;
2063 VariableExpr decorVar = null;
2064 Expression decorExpr = null;
2065}
2066{
2067 {
2068 Scope newScope = extendCurrentScopeNoPush(true);
2069 // extendCurrentScope(true);
2070 }
Till Westmann96c1f172013-08-01 02:05:48 -07002071 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002072 {
2073 String hint = getHint(token);
2074 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2075 gbc.setHashGroupByHint(true);
2076 }
2077 }
Till Westmann96c1f172013-08-01 02:05:48 -07002078 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002079 {
2080 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002081 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002082 expr = Expression()
2083 {
2084 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2085 vePairList.add(pair1);
2086 }
Till Westmann96c1f172013-08-01 02:05:48 -07002087 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002088 {
2089 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002090 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002091 expr = Expression()
2092 {
2093 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2094 vePairList.add(pair2);
2095 }
2096 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002097 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002098 {
2099 newScope.addNewVarSymbolToScope(decorVar.getVar());
2100 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2101 decorPairList.add(pair3);
2102 }
Till Westmann96c1f172013-08-01 02:05:48 -07002103 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002104 {
2105 newScope.addNewVarSymbolToScope(decorVar.getVar());
2106 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2107 decorPairList.add(pair4);
2108 }
2109 )*
2110 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002111 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002112 {
2113 if(withVar.getIsNewVar()==true)
2114 throw new ParseException("can't find variable " + withVar.getVar());
2115 withVarList.add(withVar);
2116 newScope.addNewVarSymbolToScope(withVar.getVar());
2117 }
Till Westmann96c1f172013-08-01 02:05:48 -07002118 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002119 {
2120 if(withVar.getIsNewVar()==true)
2121 throw new ParseException("can't find variable " + withVar.getVar());
2122 withVarList.add(withVar);
2123 newScope.addNewVarSymbolToScope(withVar.getVar());
2124 })*
2125 {
2126 gbc.setGbyPairList(vePairList);
2127 gbc.setDecorPairList(decorPairList);
2128 gbc.setWithVarList(withVarList);
2129 replaceCurrentScope(newScope);
2130 return gbc;
2131 }
2132}
2133
2134
2135LimitClause LimitClause() throws ParseException:
2136{
2137 LimitClause lc = new LimitClause();
2138 Expression expr;
2139 pushForbiddenScope(getCurrentScope());
2140}
2141{
Till Westmann96c1f172013-08-01 02:05:48 -07002142 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2143 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002144
2145 {
2146 popForbiddenScope();
2147 return lc;
2148 }
2149}
2150
2151DistinctClause DistinctClause() throws ParseException:
2152{
2153 List<Expression> exprs = new ArrayList<Expression>();
2154 Expression expr;
2155}
2156{
Till Westmann96c1f172013-08-01 02:05:48 -07002157 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002158 {
2159 exprs.add(expr);
2160 }
Till Westmann96c1f172013-08-01 02:05:48 -07002161 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002162 {
2163 exprs.add(expr);
2164 }
2165 )*
2166 {
2167 return new DistinctClause(exprs);
2168 }
2169}
2170
vinayakb38b7ca42012-03-05 05:44:15 +00002171QuantifiedExpression QuantifiedExpression()throws ParseException:
2172{
2173 QuantifiedExpression qc = new QuantifiedExpression();
2174 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2175 Expression satisfiesExpr;
2176 VariableExpr var;
2177 Expression inExpr;
2178 QuantifiedPair pair;
2179}
2180{
2181 {
2182 createNewScope();
2183 }
2184
Till Westmann96c1f172013-08-01 02:05:48 -07002185 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2186 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2187 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002188 {
2189 pair = new QuantifiedPair(var, inExpr);
2190 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2191 quantifiedList.add(pair);
2192 }
2193 (
Till Westmann96c1f172013-08-01 02:05:48 -07002194 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002195 {
2196 pair = new QuantifiedPair(var, inExpr);
2197 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2198 quantifiedList.add(pair);
2199 }
2200 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002201 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002202 {
2203 qc.setSatisfiesExpr(satisfiesExpr);
2204 qc.setQuantifiedList(quantifiedList);
2205 removeCurrentScope();
2206 return qc;
2207 }
2208}
2209
2210TOKEN_MGR_DECLS:
2211{
Till Westmann96c1f172013-08-01 02:05:48 -07002212 public int commentDepth = 0;
2213 public IntStack lexerStateStack = new IntStack();
2214
2215 public void pushState() {
2216 lexerStateStack.push( curLexState );
2217 }
2218
Till Westmannfd733ee2014-07-10 00:57:37 -07002219 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002220 if (lexerStateStack.size() > 0) {
2221 SwitchTo( lexerStateStack.pop() );
2222 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002223 int errorLine = input_stream.getEndLine();
2224 int errorColumn = input_stream.getEndColumn();
2225 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2226 + "\" but state stack is empty.";
2227 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002228 }
2229 }
vinayakb38b7ca42012-03-05 05:44:15 +00002230}
2231
Till Westmann96c1f172013-08-01 02:05:48 -07002232<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002233TOKEN :
2234{
Till Westmann5df7b452013-08-02 13:07:16 -07002235 <ASC : "asc">
2236 | <AT : "at">
2237 | <BY : "by">
2238 | <DATASET : "dataset">
2239 | <DECOR : "decor">
2240 | <DESC : "desc">
2241 | <DISTINCT : "distinct">
2242 | <ELSE : "else">
2243 | <EVERY : "every">
2244 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002245 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002246 | <GROUP : "group">
2247 | <IF : "if">
2248 | <IN : "in">
2249 | <LET : "let">
2250 | <LIMIT : "limit">
2251 | <OFFSET : "offset">
2252 | <ORDER : "order">
2253 | <RETURN : "return">
2254 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002255 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002256 | <SOME : "some">
2257 | <THEN : "then">
2258 | <UNION : "union">
2259 | <WHERE : "where">
2260 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002261}
2262
Till Westmann96c1f172013-08-01 02:05:48 -07002263<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002264TOKEN :
2265{
Till Westmann5df7b452013-08-02 13:07:16 -07002266 <CARET : "^">
2267 | <DIV : "/">
2268 | <IDIV : "idiv">
2269 | <MINUS : "-">
2270 | <MOD : "%">
2271 | <MUL : "*">
2272 | <PLUS : "+">
2273
2274 | <LEFTPAREN : "(">
2275 | <RIGHTPAREN : ")">
2276 | <LEFTBRACKET : "[">
2277 | <RIGHTBRACKET : "]">
2278
2279 | <COLON : ":">
2280 | <COMMA : ",">
2281 | <DOT : ".">
2282 | <QUES : "?">
2283
2284 | <LT : "<">
2285 | <GT : ">">
2286 | <LE : "<=">
2287 | <GE : ">=">
2288 | <EQ : "=">
2289 | <NE : "!=">
2290 | <SIMILAR : "~=">
2291 | <ASSIGN : ":=">
2292
2293 | <AND : "and">
2294 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002295}
2296
Till Westmann96c1f172013-08-01 02:05:48 -07002297<DEFAULT,IN_DBL_BRACE>
2298TOKEN :
2299{
Till Westmann5df7b452013-08-02 13:07:16 -07002300 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002301}
2302
2303<DEFAULT>
2304TOKEN :
2305{
Till Westmannfd733ee2014-07-10 00:57:37 -07002306 <RIGHTBRACE : "}"> { 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 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002313}
2314
Till Westmann96c1f172013-08-01 02:05:48 -07002315<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002316TOKEN :
2317{
Till Westmannfd733ee2014-07-10 00:57:37 -07002318 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002319}
2320
Till Westmann96c1f172013-08-01 02:05:48 -07002321<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002322TOKEN :
2323{
Till Westmann5df7b452013-08-02 13:07:16 -07002324 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002325}
2326
Till Westmann96c1f172013-08-01 02:05:48 -07002327<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002328TOKEN :
2329{
Till Westmann5df7b452013-08-02 13:07:16 -07002330 <NULL : "null">
2331 | <TRUE : "true">
2332 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002333}
2334
Till Westmann96c1f172013-08-01 02:05:48 -07002335<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002336TOKEN :
2337{
Till Westmann5df7b452013-08-02 13:07:16 -07002338 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002339}
2340
Till Westmann96c1f172013-08-01 02:05:48 -07002341<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002342TOKEN:
2343{
Till Westmann5df7b452013-08-02 13:07:16 -07002344 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002345 | <DIGITS> ( "." <DIGITS> )?
2346 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002347 >
2348 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002349 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2350 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002351 >
2352 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002353}
2354
Till Westmann96c1f172013-08-01 02:05:48 -07002355<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002356TOKEN :
2357{
Till Westmann5df7b452013-08-02 13:07:16 -07002358 <#LETTER : ["A" - "Z", "a" - "z"]>
2359 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002360}
2361
Till Westmann96c1f172013-08-01 02:05:48 -07002362<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002363TOKEN :
2364{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002365 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2366 <STRING_LITERAL : ("\"" (
2367 <EscapeQuot>
2368 | <EscapeBslash>
2369 | <EscapeSlash>
2370 | <EscapeBspace>
2371 | <EscapeFormf>
2372 | <EscapeNl>
2373 | <EscapeCr>
2374 | <EscapeTab>
2375 | ~["\"","\\"])* "\"")
2376 | ("\'"(
2377 <EscapeApos>
2378 | <EscapeBslash>
2379 | <EscapeSlash>
2380 | <EscapeBspace>
2381 | <EscapeFormf>
2382 | <EscapeNl>
2383 | <EscapeCr>
2384 | <EscapeTab>
2385 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002386 | < #EscapeQuot: "\\\"" >
2387 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002388 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002389 | < #EscapeSlash: "\\/" >
2390 | < #EscapeBspace: "\\b" >
2391 | < #EscapeFormf: "\\f" >
2392 | < #EscapeNl: "\\n" >
2393 | < #EscapeCr: "\\r" >
2394 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002395}
2396
Till Westmann96c1f172013-08-01 02:05:48 -07002397<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002398TOKEN :
2399{
Till Westmann5df7b452013-08-02 13:07:16 -07002400 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002401}
2402
Till Westmann96c1f172013-08-01 02:05:48 -07002403<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002404TOKEN :
2405{
Till Westmann5df7b452013-08-02 13:07:16 -07002406 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002407}
2408
Till Westmann96c1f172013-08-01 02:05:48 -07002409<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002410SKIP:
2411{
2412 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002413 | "\t"
2414 | "\r"
2415 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002416}
2417
Till Westmann96c1f172013-08-01 02:05:48 -07002418<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002419SKIP:
2420{
Till Westmann5df7b452013-08-02 13:07:16 -07002421 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002422}
2423
Till Westmann96c1f172013-08-01 02:05:48 -07002424<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002425SKIP:
2426{
Till Westmann5df7b452013-08-02 13:07:16 -07002427 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002428}
2429
Till Westmann96c1f172013-08-01 02:05:48 -07002430<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002431SKIP:
2432{
Till Westmann96c1f172013-08-01 02:05:48 -07002433 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002434}
2435
2436<INSIDE_COMMENT>
2437SPECIAL_TOKEN:
2438{
Till Westmann5df7b452013-08-02 13:07:16 -07002439 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002440}
2441
2442<INSIDE_COMMENT>
2443SKIP:
2444{
Till Westmann96c1f172013-08-01 02:05:48 -07002445 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002446}
2447
2448<INSIDE_COMMENT>
2449SKIP:
2450{
Till Westmannfd733ee2014-07-10 00:57:37 -07002451 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002452 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002453}