blob: 2cd38c61a8b2120cde23451c65149cb0ec5e8129 [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()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800216 | stmt = RunStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700217 )
218 {
219 return stmt;
220 }
221}
222
223DataverseDecl DataverseDeclaration() throws ParseException:
224{
Till Westmann14a20a72013-05-09 00:06:24 -0700225 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700226}
227{
Till Westmanna4242bc2013-05-08 17:49:55 -0700228 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700229 {
Till Westmann14a20a72013-05-09 00:06:24 -0700230 defaultDataverse = dvName;
231 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700232 }
233}
234
235Statement CreateStatement() throws ParseException:
236{
237 String hint = null;
238 boolean dgen = false;
239 Statement stmt = null;
240}
241{
242 "create"
243 (
244 {
245 hint = getHint(token);
246 if (hint != null && hint.startsWith(DGEN_HINT)) {
247 dgen = true;
248 }
249 }
250 stmt = TypeSpecification(hint, dgen)
251 | stmt = NodegroupSpecification()
252 | stmt = DatasetSpecification()
253 | stmt = IndexSpecification()
254 | stmt = DataverseSpecification()
255 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700256 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700257 )
258 {
259 return stmt;
260 }
261}
262
263TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
264{
265 Pair<Identifier,Identifier> nameComponents = null;
266 boolean ifNotExists = false;
267 TypeExpression typeExpr = null;
268}
269{
ramangrover299f76a5e2013-06-18 10:25:17 -0700270 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700271 "as" typeExpr = TypeExpr()
272 {
273 long numValues = -1;
274 String filename = null;
275 if (dgen) {
276 String splits[] = hint.split(" +");
277 if (splits.length != 3) {
278 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
279 }
280 filename = splits[1];
281 numValues = Long.parseLong(splits[2]);
282 }
283 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
284 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
285 }
286}
287
288
289NodegroupDecl NodegroupSpecification() throws ParseException:
290{
Till Westmann14a20a72013-05-09 00:06:24 -0700291 String name = null;
292 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700293 boolean ifNotExists = false;
294 List<Identifier>ncNames = null;
295}
296{
Till Westmanna4242bc2013-05-08 17:49:55 -0700297 "nodegroup" name = Identifier()
298 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700299 {
300 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700301 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700302 }
Till Westmann96c1f172013-08-01 02:05:48 -0700303 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700304 {
Till Westmann14a20a72013-05-09 00:06:24 -0700305 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700306 }
307 )*
308 {
Till Westmann14a20a72013-05-09 00:06:24 -0700309 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700310 }
311}
312
313DatasetDecl DatasetSpecification() throws ParseException:
314{
315 Pair<Identifier,Identifier> nameComponents = null;
316 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700317 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700318 String adapterName = null;
319 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700320 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700321 FunctionSignature appliedFunction = null;
322 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700323 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700324 Map<String,String> hints = new HashMap<String,String>();
325 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700326 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700327 String compactionPolicy = null;
salsubaieea5af4e02014-07-08 15:20:02 -0700328 String filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700329}
330{
331 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700332 "external" <DATASET> nameComponents = QualifiedName()
333 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
334 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700335 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700336 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700337 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700338 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Till Westmann31c21f92013-05-08 09:21:53 -0700339 {
340 ExternalDetailsDecl edd = new ExternalDetailsDecl();
341 edd.setAdapter(adapterName);
342 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700343 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
344 edd.setCompactionPolicy(compactionPolicy);
345 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700346 dsetDecl = new DatasetDecl(nameComponents.first,
347 nameComponents.second,
348 new Identifier(typeName),
349 hints,
350 DatasetType.EXTERNAL,
351 edd,
352 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700353 }
354
Till Westmannd7dcb122013-05-16 13:19:09 -0700355 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700356 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
357 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700358 primaryKeyFields = PrimaryKey()
359 ("autogenerated" { autogenerated = true; } )?
360 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700361 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700362 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
salsubaieea5af4e02014-07-08 15:20:02 -0700363 ( "with filter on" filterField = FilterField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700364 {
Till Westmann14a20a72013-05-09 00:06:24 -0700365 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
366 ? new Identifier(nodeGroupName)
367 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700368 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700369 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700370 compactionPolicy,
salsubaieea5af4e02014-07-08 15:20:02 -0700371 compactionPolicyProperties,
372 filterField);
Till Westmann14a20a72013-05-09 00:06:24 -0700373 dsetDecl = new DatasetDecl(nameComponents.first,
374 nameComponents.second,
375 new Identifier(typeName),
376 hints,
377 DatasetType.INTERNAL,
378 idd,
379 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700380 }
381 )
382 {
383 return dsetDecl;
384 }
385}
386
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700387RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
388{
389 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
390 Pair<Identifier,Identifier> nameComponents = null;
391 String datasetName = null;
392}
393{
394 "refresh external" <DATASET> nameComponents = QualifiedName()
395 {
396 redss.setDataverseName(nameComponents.first);
397 redss.setDatasetName(nameComponents.second);
398 return redss;
399 }
400}
401
Markus Holzemer52c568e2014-12-18 10:51:49 -0800402RunStatement RunStatement() throws ParseException:
403{
404 String system = null;
405 String tmp;
406 ArrayList<String> parameters = new ArrayList<String>();
407 Pair<Identifier,Identifier> nameComponentsFrom = null;
408 Pair<Identifier,Identifier> nameComponentsTo = null;
409}
410{
411 "run" system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
412 {
413 parameters.add(tmp);
414 }
415 )*<RIGHTPAREN>
416 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
417 "to" <DATASET> nameComponentsTo = QualifiedName()
418 {
419 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
420 }
421}
422
Till Westmann31c21f92013-05-08 09:21:53 -0700423CreateIndexStatement IndexSpecification() throws ParseException:
424{
425 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700426 String indexName = null;
427 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700428 boolean ifNotExists = false;
429 Pair<Identifier,Identifier> nameComponents = null;
430 IndexParams indexType = null;
431}
432{
Till Westmanna4242bc2013-05-08 17:49:55 -0700433 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700434 ifNotExists = IfNotExists()
435 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700436 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700437 {
Till Westmann14a20a72013-05-09 00:06:24 -0700438 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700439 }
Till Westmann96c1f172013-08-01 02:05:48 -0700440 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700441 {
Till Westmann14a20a72013-05-09 00:06:24 -0700442 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700443 }
444 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
445 {
Till Westmann14a20a72013-05-09 00:06:24 -0700446 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700447 cis.setIfNotExists(ifNotExists);
448 cis.setDataverseName(nameComponents.first);
449 cis.setDatasetName(nameComponents.second);
450 if (indexType != null) {
451 cis.setIndexType(indexType.type);
452 cis.setGramLength(indexType.gramLength);
453 }
454 return cis;
455 }
456}
457
salsubaiee0b423fa2013-09-19 19:16:48 -0700458String CompactionPolicy() throws ParseException :
459{
460 String compactionPolicy = null;
461}
462{
463 compactionPolicy = Identifier()
464 {
465 return compactionPolicy;
466 }
467}
468
salsubaieea5af4e02014-07-08 15:20:02 -0700469String FilterField() throws ParseException :
470{
471 String filterField = null;
472}
473{
474 filterField = Identifier()
475 {
476 return filterField;
477 }
478}
479
Till Westmann31c21f92013-05-08 09:21:53 -0700480IndexParams IndexType() throws ParseException:
481{
482 IndexType type = null;
483 int gramLength = 0;
484}
485{
486 ("btree"
487 {
488 type = IndexType.BTREE;
489 }
490 | "rtree"
491 {
492 type = IndexType.RTREE;
493 }
494 | "keyword"
495 {
JIMAHNb75446d2013-06-03 08:35:27 -0700496 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700497 }
498 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
499 {
JIMAHNb75446d2013-06-03 08:35:27 -0700500 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700501 gramLength = Integer.valueOf(token.image);
502 }
503 <RIGHTPAREN>)
504 {
505 return new IndexParams(type, gramLength);
506 }
507}
508
509CreateDataverseStatement DataverseSpecification() throws ParseException :
510{
Till Westmann14a20a72013-05-09 00:06:24 -0700511 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700512 boolean ifNotExists = false;
513 String format = null;
514}
515{
Till Westmanna4242bc2013-05-08 17:49:55 -0700516 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700517 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700518 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700519 {
Till Westmann14a20a72013-05-09 00:06:24 -0700520 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700521 }
522}
523
524CreateFunctionStatement FunctionSpecification() throws ParseException:
525{
526 FunctionSignature signature;
527 boolean ifNotExists = false;
528 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
529 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700530 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700531 Expression functionBodyExpr;
532 Token beginPos;
533 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700534 FunctionName fctName = null;
535
Till Westmann31c21f92013-05-08 09:21:53 -0700536 createNewScope();
537}
538{
ramangrover299f76a5e2013-06-18 10:25:17 -0700539 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700540 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700541 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700542 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530543 {
544 beginPos = token;
545 }
Till Westmann96c1f172013-08-01 02:05:48 -0700546 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700547 {
548 endPos = token;
549 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700550 // TODO use fctName.library
551 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700552 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800553 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700554 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
555 }
556}
557
ramangrover29a774ef22013-07-17 09:29:18 -0700558CreateFeedStatement FeedSpecification() throws ParseException:
559{
560 Pair<Identifier,Identifier> nameComponents = null;
561 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700562 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700563 Map<String,String> properties = null;
564 FunctionSignature appliedFunction = null;
565 CreateFeedStatement cfs = null;
566}
567{
568 (
569 "feed" nameComponents = QualifiedName()
570 ifNotExists = IfNotExists()
Chris Hillerye64055d2014-10-11 00:14:39 -0700571 "using" adapterName = AdapterName() properties = Configuration()
ramangrover29a774ef22013-07-17 09:29:18 -0700572 (appliedFunction = ApplyFunction())?
573 {
574 cfs = new CreateFeedStatement(nameComponents.first,
Chris Hillerye64055d2014-10-11 00:14:39 -0700575 nameComponents.second, adapterName, properties, appliedFunction, ifNotExists);
ramangrover29a774ef22013-07-17 09:29:18 -0700576 }
577
578 )
579 {
580 return cfs;
581 }
582}
583
584
585
Till Westmannd7dcb122013-05-16 13:19:09 -0700586List<VarIdentifier> ParameterList() throws ParseException:
587{
588 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
589 VarIdentifier var = null;
590}
591{
Till Westmann31c21f92013-05-08 09:21:53 -0700592 <LEFTPAREN> (<VARIABLE>
593 {
594 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700595 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700596 paramList.add(var);
597 getCurrentScope().addNewVarSymbolToScope(var);
598 }
Till Westmann96c1f172013-08-01 02:05:48 -0700599 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700600 {
601 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700602 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700603 paramList.add(var);
604 getCurrentScope().addNewVarSymbolToScope(var);
605 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700606 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700607 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700608 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700609 }
610}
611
612boolean IfNotExists() throws ParseException:
613{
614}
615{
616 ( "if not exists"
617 {
618 return true;
619 }
620 )?
621 {
622 return false;
623 }
624}
625
626FunctionSignature ApplyFunction() throws ParseException:
627{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530628 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700629 FunctionSignature funcSig = null;
630}
631{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530632 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700633 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530634 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
635 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700636 }
637}
638
ramangrover29566b3a92013-05-28 09:07:10 -0700639String GetPolicy() throws ParseException:
640{
641 String policy = null;
642}
643{
644 "using" "policy" policy = Identifier()
645 {
646 return policy;
647 }
648
649}
650
Till Westmann31c21f92013-05-08 09:21:53 -0700651FunctionSignature FunctionSignature() throws ParseException:
652{
ramangrover299f76a5e2013-06-18 10:25:17 -0700653 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700654 int arity = 0;
655}
656{
ramangrover299f76a5e2013-06-18 10:25:17 -0700657 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700658 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700659 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700660 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
661 throw new ParseException(" invalid arity:" + arity);
662 }
663
ramangrover299f76a5e2013-06-18 10:25:17 -0700664 // TODO use fctName.library
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300665 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700666 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700667 }
668}
669
670List<String> PrimaryKey() throws ParseException:
671{
Till Westmann14a20a72013-05-09 00:06:24 -0700672 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700673 List<String> primaryKeyFields = new ArrayList<String>();
674}
675{
Till Westmann14a20a72013-05-09 00:06:24 -0700676 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700677 {
Till Westmann14a20a72013-05-09 00:06:24 -0700678 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700679 }
Till Westmann96c1f172013-08-01 02:05:48 -0700680 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700681 {
Till Westmann14a20a72013-05-09 00:06:24 -0700682 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700683 }
684 )*
685 {
686 return primaryKeyFields;
687 }
688}
689
690Statement DropStatement() throws ParseException:
691{
Till Westmann14a20a72013-05-09 00:06:24 -0700692 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700693 Pair<Identifier,Identifier> pairId = null;
694 Triple<Identifier,Identifier,Identifier> tripleId = null;
695 FunctionSignature funcSig = null;
696 boolean ifExists = false;
697 Statement stmt = null;
698}
699{
700 "drop"
701 (
702 <DATASET> pairId = QualifiedName() ifExists = IfExists()
703 {
704 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
705 }
706 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
707 {
708 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
709 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700710 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700711 {
Till Westmann14a20a72013-05-09 00:06:24 -0700712 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700713 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700714 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700715 {
716 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
717 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700718 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700719 {
Till Westmann14a20a72013-05-09 00:06:24 -0700720 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700721 }
722 | "function" funcSig = FunctionSignature() ifExists = IfExists()
723 {
724 stmt = new FunctionDropStatement(funcSig, ifExists);
725 }
ramangrover29a774ef22013-07-17 09:29:18 -0700726 | "feed" pairId = QualifiedName() ifExists = IfExists()
727 {
728 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
729 }
Till Westmann31c21f92013-05-08 09:21:53 -0700730 )
731 {
732 return stmt;
733 }
734}
735
736boolean IfExists() throws ParseException :
737{
738}
739{
Till Westmann96c1f172013-08-01 02:05:48 -0700740 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700741 {
742 return true;
743 }
744 )?
745 {
746 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000747 }
748}
749
750InsertStatement InsertStatement() throws ParseException:
751{
Till Westmann31c21f92013-05-08 09:21:53 -0700752 Pair<Identifier,Identifier> nameComponents = null;
753 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000754}
755{
Till Westmann31c21f92013-05-08 09:21:53 -0700756 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
757 {
758 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
759 }
vinayakb38b7ca42012-03-05 05:44:15 +0000760}
761
762DeleteStatement DeleteStatement() throws ParseException:
763{
Till Westmann31c21f92013-05-08 09:21:53 -0700764 VariableExpr var = null;
765 Expression condition = null;
766 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300767 // This is related to the new metadata lock management
768 setDataverses(new ArrayList<String>());
769 setDatasets(new ArrayList<String>());
770
vinayakb38b7ca42012-03-05 05:44:15 +0000771}
772{
Till Westmann31c21f92013-05-08 09:21:53 -0700773 "delete" var = Variable()
774 {
775 getCurrentScope().addNewVarSymbolToScope(var.getVar());
776 }
buyingyi2fd7fa62014-11-24 19:31:55 -0800777 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800778 (<WHERE> condition = Expression())?
779 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300780 // First we get the dataverses and datasets that we want to lock
781 List<String> dataverses = getDataverses();
782 List<String> datasets = getDatasets();
783 // we remove the pointer to the dataverses and datasets
784 setDataverses(null);
785 setDatasets(null);
786 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
787 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700788 }
vinayakb38b7ca42012-03-05 05:44:15 +0000789}
790
791UpdateStatement UpdateStatement() throws ParseException:
792{
Till Westmann31c21f92013-05-08 09:21:53 -0700793 VariableExpr vars;
794 Expression target;
795 Expression condition;
796 UpdateClause uc;
797 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000798}
799{
Till Westmann96c1f172013-08-01 02:05:48 -0700800 "update" vars = Variable() <IN> target = Expression()
801 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700802 <LEFTPAREN> (uc = UpdateClause()
803 {
804 ucs.add(uc);
805 }
Till Westmann96c1f172013-08-01 02:05:48 -0700806 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700807 {
808 ucs.add(uc);
809 }
810 )*) <RIGHTPAREN>
811 {
812 return new UpdateStatement(vars, target, condition, ucs);
813 }
vinayakb38b7ca42012-03-05 05:44:15 +0000814}
815
vinayakb38b7ca42012-03-05 05:44:15 +0000816UpdateClause UpdateClause() throws ParseException:
817{
Till Westmann31c21f92013-05-08 09:21:53 -0700818 Expression target = null;
819 Expression value = null ;
820 InsertStatement is = null;
821 DeleteStatement ds = null;
822 UpdateStatement us = null;
823 Expression condition = null;
824 UpdateClause ifbranch = null;
825 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000826}
827{
Till Westmann96c1f172013-08-01 02:05:48 -0700828 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700829 | is = InsertStatement()
830 | ds = DeleteStatement()
831 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700832 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
833 <THEN> ifbranch = UpdateClause()
834 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700835 {
836 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
837 }
vinayakb38b7ca42012-03-05 05:44:15 +0000838}
839
vinayakb38b7ca42012-03-05 05:44:15 +0000840Statement SetStatement() throws ParseException:
841{
842 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700843 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000844}
845{
Till Westmann7d535322013-05-09 00:40:02 -0700846 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700847 {
Till Westmann31c21f92013-05-08 09:21:53 -0700848 return new SetStatement(pn, pv);
849 }
vinayakb38b7ca42012-03-05 05:44:15 +0000850}
851
852Statement WriteStatement() throws ParseException:
853{
Till Westmann14a20a72013-05-09 00:06:24 -0700854 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000855 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000856 Query query;
857 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000858 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000859}
860{
Till Westmann96c1f172013-08-01 02:05:48 -0700861 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700862 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700863 {
864 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000865 }
866}
867
zheilbron28e026f2013-11-20 10:15:15 -0800868LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000869{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000870 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000871 Identifier datasetName = null;
872 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000873 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000874 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000875 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000876}
877{
Till Westmann31c21f92013-05-08 09:21:53 -0700878 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000879 {
Till Westmann31c21f92013-05-08 09:21:53 -0700880 dataverseName = nameComponents.first;
881 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000882 }
Till Westmann31c21f92013-05-08 09:21:53 -0700883 "using" adapterName = AdapterName() properties = Configuration()
884 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000885 {
Till Westmann31c21f92013-05-08 09:21:53 -0700886 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000887 }
888 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700889 {
zheilbron28e026f2013-11-20 10:15:15 -0800890 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Till Westmann31c21f92013-05-08 09:21:53 -0700891 }
vinayakb38b7ca42012-03-05 05:44:15 +0000892}
893
vinayakb38b7ca42012-03-05 05:44:15 +0000894
Till Westmann31c21f92013-05-08 09:21:53 -0700895String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000896{
ramangrover29669d8f62013-02-11 06:03:32 +0000897 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000898}
899{
Till Westmann68d99652013-05-09 11:15:21 -0700900 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000901 {
Till Westmann7d535322013-05-09 00:40:02 -0700902 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000903 }
vinayakb38b7ca42012-03-05 05:44:15 +0000904}
905
salsubaiee0b423fa2013-09-19 19:16:48 -0700906Statement CompactStatement() throws ParseException:
907{
908 Pair<Identifier,Identifier> nameComponents = null;
909 Statement stmt = null;
910}
911{
912 "compact" <DATASET> nameComponents = QualifiedName()
913 {
914 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
915 }
916 {
917 return stmt;
918 }
919}
920
Till Westmann31c21f92013-05-08 09:21:53 -0700921Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000922{
ramangrover29a774ef22013-07-17 09:29:18 -0700923 Pair<Identifier,Identifier> feedNameComponents = null;
924 Pair<Identifier,Identifier> datasetNameComponents = null;
925
Till Westmann31c21f92013-05-08 09:21:53 -0700926 Map<String,String> configuration = null;
927 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700928 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000929}
930{
Till Westmann31c21f92013-05-08 09:21:53 -0700931 (
ramangrover29a774ef22013-07-17 09:29:18 -0700932 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700933 {
ramangrover29a774ef22013-07-17 09:29:18 -0700934 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700935 }
buyingyi2fd7fa62014-11-24 19:31:55 -0800936 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700937 {
ramangrover29a774ef22013-07-17 09:29:18 -0700938 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700939 }
940 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000941 {
Till Westmann31c21f92013-05-08 09:21:53 -0700942 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000943 }
944}
945
Till Westmann31c21f92013-05-08 09:21:53 -0700946Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000947{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000948 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700949 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000950}
951{
Till Westmann31c21f92013-05-08 09:21:53 -0700952 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000953 {
Till Westmann31c21f92013-05-08 09:21:53 -0700954 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000955 }
Till Westmann96c1f172013-08-01 02:05:48 -0700956 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000957 {
Till Westmann31c21f92013-05-08 09:21:53 -0700958 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000959 }
Till Westmann31c21f92013-05-08 09:21:53 -0700960 )* )? <RIGHTPAREN>
961 {
962 return configuration;
963 }
964}
965
966Pair<String, String> KeyValuePair() throws ParseException:
967{
968 String key;
969 String value;
970}
971{
Till Westmann96c1f172013-08-01 02:05:48 -0700972 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700973 {
974 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000975 }
Till Westmann31c21f92013-05-08 09:21:53 -0700976}
977
978Map<String,String> Properties() throws ParseException:
979{
980 Map<String,String> properties = new HashMap<String,String>();
981 Pair<String, String> property;
982}
983{
984 ( <LEFTPAREN> property = Property()
985 {
986 properties.put(property.first, property.second);
987 }
Till Westmann96c1f172013-08-01 02:05:48 -0700988 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700989 {
990 properties.put(property.first, property.second);
991 }
992 )* <RIGHTPAREN> )?
993 {
994 return properties;
995 }
996}
997
998Pair<String, String> Property() throws ParseException:
999{
1000 String key;
1001 String value;
1002}
1003{
Till Westmann96c1f172013-08-01 02:05:48 -07001004 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001005 {
1006 try {
1007 value = "" + Long.valueOf(token.image);
1008 } catch (NumberFormatException nfe) {
1009 throw new ParseException("inapproriate value: " + token.image);
1010 }
1011 }
1012 )
1013 {
1014 return new Pair<String, String>(key.toUpperCase(), value);
1015 }
vinayakb38b7ca42012-03-05 05:44:15 +00001016}
1017
1018TypeExpression TypeExpr() throws ParseException:
1019{
1020 TypeExpression typeExpr = null;
1021}
1022{
1023 (
1024 typeExpr = RecordTypeDef()
1025 | typeExpr = TypeReference()
1026 | typeExpr = OrderedListTypeDef()
1027 | typeExpr = UnorderedListTypeDef()
1028 )
1029 {
1030 return typeExpr;
1031 }
1032}
1033
1034RecordTypeDefinition RecordTypeDef() throws ParseException:
1035{
1036 RecordTypeDefinition recType = new RecordTypeDefinition();
1037 RecordTypeDefinition.RecordKind recordKind = null;
1038}
1039{
1040 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1041 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001042 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001043 {
1044 String hint = getHint(token);
1045 if (hint != null) {
1046 String splits[] = hint.split(" +");
1047 if (splits[0].equals(GEN_FIELDS_HINT)) {
1048 if (splits.length != 5) {
1049 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1050 }
1051 if (!splits[1].equals("int")) {
1052 throw new ParseException("The only supported type for gen-fields is int.");
1053 }
1054 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1055 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1056 recType.setUndeclaredFieldsDataGen(ufdg);
1057 }
1058 }
1059
1060 }
1061 (
1062 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -07001063 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +00001064 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001065 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001066 {
1067 if (recordKind == null) {
1068 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1069 }
1070 recType.setRecordKind(recordKind);
1071 return recType;
1072 }
1073}
1074
1075void RecordField(RecordTypeDefinition recType) throws ParseException:
1076{
Till Westmann77cb2f42013-07-15 16:44:19 -07001077 String fieldName;
1078 TypeExpression type = null;
1079 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001080}
1081{
Till Westmann77cb2f42013-07-15 16:44:19 -07001082 fieldName = Identifier()
1083 {
1084 String hint = getHint(token);
1085 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1086 }
Till Westmann96c1f172013-08-01 02:05:48 -07001087 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001088 {
1089 recType.addField(fieldName, type, nullable, rfdg);
1090 }
vinayakb38b7ca42012-03-05 05:44:15 +00001091}
1092
1093TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001094{
Till Westmann14a20a72013-05-09 00:06:24 -07001095 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001096}
1097{
1098 id = Identifier()
1099 {
Till Westmann14a20a72013-05-09 00:06:24 -07001100 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001101 }
vinayakb38b7ca42012-03-05 05:44:15 +00001102}
1103
1104OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1105{
1106 TypeExpression type = null;
1107}
1108{
Till Westmann96c1f172013-08-01 02:05:48 -07001109 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001110 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001111 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001112 {
1113 return new OrderedListTypeDefinition(type);
1114 }
1115}
1116
1117
1118UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1119{
1120 TypeExpression type = null;
1121}
1122{
Till Westmann96c1f172013-08-01 02:05:48 -07001123 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001124 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001125 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001126 {
1127 return new UnorderedListTypeDefinition(type);
1128 }
1129}
1130
ramangrover299f76a5e2013-06-18 10:25:17 -07001131FunctionName FunctionName() throws ParseException:
1132{
1133 String first = null;
1134 String second = null;
1135 String third = null;
1136 boolean secondAfterDot = false;
1137}
1138{
zheilbron555dc9d2013-08-14 19:58:00 -07001139 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001140 {
1141 secondAfterDot = true;
1142 }
1143 ("#" third = Identifier())? | "#" second = Identifier() )?
1144 {
1145 FunctionName result = new FunctionName();
1146 if (second == null) {
1147 result.dataverse = defaultDataverse;
1148 result.library = null;
1149 result.function = first;
1150 } else if (third == null) {
1151 if (secondAfterDot) {
1152 result.dataverse = first;
1153 result.library = null;
1154 result.function = second;
1155 } else {
1156 result.dataverse = defaultDataverse;
1157 result.library = first;
1158 result.function = second;
1159 }
1160 } else {
1161 result.dataverse = first;
1162 result.library = second;
1163 result.function = third;
1164 }
1165 return result;
1166 }
1167}
Till Westmann31c21f92013-05-08 09:21:53 -07001168
ramangrover299f76a5e2013-06-18 10:25:17 -07001169
1170Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001171{
Till Westmann31c21f92013-05-08 09:21:53 -07001172 Pair<Identifier,Identifier> name = null;
1173}
1174{
1175 name = QualifiedName()
1176 {
1177 if (name.first == null) {
1178 name.first = new Identifier(defaultDataverse);
1179 }
1180 return name;
1181 }
1182}
1183
Till Westmann14a20a72013-05-09 00:06:24 -07001184String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001185{
Till Westmann68d99652013-05-09 11:15:21 -07001186 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001187}
1188{
1189 <IDENTIFIER>
1190 {
Till Westmann14a20a72013-05-09 00:06:24 -07001191 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001192 }
Till Westmann68d99652013-05-09 11:15:21 -07001193 | lit = StringLiteral()
1194 {
1195 return lit;
1196 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001197}
1198
Till Westmann7d535322013-05-09 00:40:02 -07001199String StringLiteral() throws ParseException:
1200{
1201}
1202{
1203 <STRING_LITERAL>
1204 {
1205 return removeQuotesAndEscapes(token.image);
1206 }
1207}
1208
Till Westmann31c21f92013-05-08 09:21:53 -07001209Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1210{
Till Westmann14a20a72013-05-09 00:06:24 -07001211 String first = null;
1212 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001213}
1214{
Till Westmann96c1f172013-08-01 02:05:48 -07001215 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001216 {
Till Westmann14a20a72013-05-09 00:06:24 -07001217 Identifier id1 = null;
1218 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001219 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001220 id2 = new Identifier(first);
1221 } else
1222 {
1223 id1 = new Identifier(first);
1224 id2 = new Identifier(second);
1225 }
1226 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001227 }
1228}
1229
Till Westmann31c21f92013-05-08 09:21:53 -07001230Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001231{
Till Westmann14a20a72013-05-09 00:06:24 -07001232 String first = null;
1233 String second = null;
1234 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001235}
1236{
Till Westmann96c1f172013-08-01 02:05:48 -07001237 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001238 {
Till Westmann14a20a72013-05-09 00:06:24 -07001239 Identifier id1 = null;
1240 Identifier id2 = null;
1241 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001242 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001243 id2 = new Identifier(first);
1244 id3 = new Identifier(second);
1245 } else {
1246 id1 = new Identifier(first);
1247 id2 = new Identifier(second);
1248 id3 = new Identifier(third);
1249 }
1250 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001251 }
1252}
1253
vinayakb38b7ca42012-03-05 05:44:15 +00001254FunctionDecl FunctionDeclaration() throws ParseException:
1255{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001256 FunctionDecl funcDecl;
1257 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001258 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001259 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1260 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001261 createNewScope();
1262}
1263{
Till Westmannd7dcb122013-05-16 13:19:09 -07001264 "declare" "function" functionName = Identifier()
1265 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001266 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001267 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001268 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001269 getCurrentScope().addFunctionDescriptor(signature, false);
1270 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001271 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001272 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001273 }
1274}
1275
vinayakb38b7ca42012-03-05 05:44:15 +00001276
Till Westmann31c21f92013-05-08 09:21:53 -07001277Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001278{
1279 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001280 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1281 setDataverses(query.getDataverses());
1282 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001283 Expression expr;
1284}
1285{
Till Westmann31c21f92013-05-08 09:21:53 -07001286 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001287 {
1288 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001289 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001290 // we remove the pointers to the locked entities before we return the query object
1291 setDataverses(null);
1292 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001293 return query;
1294 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001295
vinayakb38b7ca42012-03-05 05:44:15 +00001296}
1297
1298
1299
1300Expression Expression():
1301{
1302 Expression expr = null;
1303 Expression exprP = null;
1304}
1305{
1306(
1307
1308//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1309 expr = OperatorExpr()
1310 | expr = IfThenElse()
1311 | expr = FLWOGR()
1312 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001313
vinayakb38b7ca42012-03-05 05:44:15 +00001314
1315)
1316 {
1317 return (exprP==null) ? expr : exprP;
1318 }
1319}
1320
1321
1322
1323Expression OperatorExpr()throws ParseException:
1324{
1325 OperatorExpr op = null;
1326 Expression operand = null;
1327}
1328{
1329 operand = AndExpr()
1330 (
1331
Till Westmann96c1f172013-08-01 02:05:48 -07001332 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001333 {
1334 if (op == null) {
1335 op = new OperatorExpr();
1336 op.addOperand(operand);
1337 op.setCurrentop(true);
1338 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001339 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001340 }
1341
1342 operand = AndExpr()
1343 {
1344 op.addOperand(operand);
1345 }
1346
1347 )*
1348
1349 {
1350 return op==null? operand: op;
1351 }
1352}
1353
1354Expression AndExpr()throws ParseException:
1355{
1356 OperatorExpr op = null;
1357 Expression operand = null;
1358}
1359{
1360 operand = RelExpr()
1361 (
1362
Till Westmann96c1f172013-08-01 02:05:48 -07001363 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001364 {
1365 if (op == null) {
1366 op = new OperatorExpr();
1367 op.addOperand(operand);
1368 op.setCurrentop(true);
1369 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001370 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001371 }
1372
1373 operand = RelExpr()
1374 {
1375 op.addOperand(operand);
1376 }
1377
1378 )*
1379
1380 {
1381 return op==null? operand: op;
1382 }
1383}
1384
1385
1386
1387Expression RelExpr()throws ParseException:
1388{
1389 OperatorExpr op = null;
1390 Expression operand = null;
1391 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001392 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001393}
1394{
1395 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001396 {
1397 if (operand instanceof VariableExpr) {
1398 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001399 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001400 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001401 }
1402 }
1403 }
1404
1405 (
Till Westmann96c1f172013-08-01 02:05:48 -07001406 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001407 {
alexander.behm07617fd2012-07-25 10:13:50 +00001408 String mhint = getHint(token);
salsubaieedf89fbc2013-12-21 19:51:42 -08001409 if (mhint != null) {
1410 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1411 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1412 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1413 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1414 }
alexander.behm07617fd2012-07-25 10:13:50 +00001415 }
vinayakb38b7ca42012-03-05 05:44:15 +00001416 if (op == null) {
1417 op = new OperatorExpr();
1418 op.addOperand(operand, broadcast);
1419 op.setCurrentop(true);
1420 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001421 }
1422 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001423 }
1424
1425 operand = AddExpr()
1426 {
alexander.behm07617fd2012-07-25 10:13:50 +00001427 broadcast = false;
1428 if (operand instanceof VariableExpr) {
1429 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001430 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1431 broadcast = true;
1432 }
alexander.behm07617fd2012-07-25 10:13:50 +00001433 }
vinayakb38b7ca42012-03-05 05:44:15 +00001434 op.addOperand(operand, broadcast);
1435 }
1436 )?
1437
1438 {
alexander.behm07617fd2012-07-25 10:13:50 +00001439 if (annotation != null) {
1440 op.addHint(annotation);
1441 }
vinayakb38b7ca42012-03-05 05:44:15 +00001442 return op==null? operand: op;
1443 }
1444}
1445
1446Expression AddExpr()throws ParseException:
1447{
1448 OperatorExpr op = null;
1449 Expression operand = null;
1450}
1451{
1452 operand = MultExpr()
1453
Till Westmann96c1f172013-08-01 02:05:48 -07001454 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001455 {
1456 if (op == null) {
1457 op = new OperatorExpr();
1458 op.addOperand(operand);
1459 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001460 }
1461 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001462 }
1463
1464 operand = MultExpr()
1465 {
1466 op.addOperand(operand);
1467 }
1468 )*
1469
1470 {
1471 return op==null? operand: op;
1472 }
1473}
1474
1475Expression MultExpr()throws ParseException:
1476{
1477 OperatorExpr op = null;
1478 Expression operand = null;
1479}
1480{
1481 operand = UnionExpr()
1482
Till Westmann96c1f172013-08-01 02:05:48 -07001483 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001484 {
1485 if (op == null) {
1486 op = new OperatorExpr();
1487 op.addOperand(operand);
1488 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001489 }
1490 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001491 }
1492 operand = UnionExpr()
1493 {
1494 op.addOperand(operand);
1495 }
1496 )*
1497
1498 {
1499 return op==null?operand:op;
1500 }
1501}
1502
1503Expression UnionExpr() throws ParseException:
1504{
1505 UnionExpr union = null;
1506 Expression operand1 = null;
1507 Expression operand2 = null;
1508}
1509{
1510 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001511 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001512 (operand2 = UnaryExpr()) {
1513 if (union == null) {
1514 union = new UnionExpr();
1515 union.addExpr(operand1);
1516 }
1517 union.addExpr(operand2);
1518 } )*
1519 {
1520 return (union == null)? operand1: union;
1521 }
1522}
1523
1524Expression UnaryExpr() throws ParseException:
1525{
1526 Expression uexpr = null;
1527 Expression expr = null;
1528}
1529{
Till Westmann96c1f172013-08-01 02:05:48 -07001530 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001531 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001532 uexpr = new UnaryExpr();
1533 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001534 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001535 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001536 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1537 else
1538 throw new ParseException();
1539 }
1540 )?
1541
1542 expr = ValueExpr()
1543 {
1544 if(uexpr!=null){
1545 ((UnaryExpr)uexpr).setExpr(expr);
1546 return uexpr;
1547 }
1548 else{
1549 return expr;
1550 }
1551 }
1552}
1553
Till Westmann04478e72013-05-13 23:01:34 -07001554Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001555{
1556 Expression expr = null;
1557 Identifier ident = null;
1558 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001559 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001560}
1561{
Till Westmann04478e72013-05-13 23:01:34 -07001562 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001563 {
Till Westmann04478e72013-05-13 23:01:34 -07001564 fa = (fa == null ? new FieldAccessor(expr, ident)
1565 : new FieldAccessor(fa, ident));
1566 }
icetindila611ac72014-05-16 10:10:11 -07001567 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001568 {
icetindila611ac72014-05-16 10:10:11 -07001569 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1570 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001571 }
1572 )*
1573 {
1574 return fa == null ? expr : fa;
1575 }
vinayakb38b7ca42012-03-05 05:44:15 +00001576}
1577
1578Identifier Field() throws ParseException:
1579{
Till Westmann14a20a72013-05-09 00:06:24 -07001580 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001581}
1582{
Till Westmann96c1f172013-08-01 02:05:48 -07001583 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001584 {
Till Westmann14a20a72013-05-09 00:06:24 -07001585 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001586 }
vinayakb38b7ca42012-03-05 05:44:15 +00001587}
1588
icetindila611ac72014-05-16 10:10:11 -07001589Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001590{
1591 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001592}
1593{
Till Westmann96c1f172013-08-01 02:05:48 -07001594 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001595 {
1596 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1597 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001598 Literal lit = ((LiteralExpr)expr).getValue();
icetindila611ac72014-05-16 10:10:11 -07001599 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1600 lit.getLiteralType() != Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001601 throw new ParseException("Index should be an INTEGER");
1602 }
1603 }
vinayakb38b7ca42012-03-05 05:44:15 +00001604 }
1605
icetindil5860fb92014-05-16 11:22:15 -07001606 | <QUES> // ANY
vinayakb38b7ca42012-03-05 05:44:15 +00001607
1608 )
1609
Till Westmann96c1f172013-08-01 02:05:48 -07001610 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001611 {
icetindila611ac72014-05-16 10:10:11 -07001612 return expr;
vinayakb38b7ca42012-03-05 05:44:15 +00001613 }
1614}
1615
1616
1617Expression PrimaryExpr()throws ParseException:
1618{
1619 Expression expr = null;
1620}
1621{
Till Westmann68d99652013-05-09 11:15:21 -07001622 ( LOOKAHEAD(2)
1623 expr = FunctionCallExpr()
1624 | expr = Literal()
1625 | expr = DatasetAccessExpression()
1626 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001627 {
1628 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001629 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001630 }
Till Westmann68d99652013-05-09 11:15:21 -07001631 | expr = ListConstructor()
1632 | expr = RecordConstructor()
1633 | expr = ParenthesizedExpression()
1634 )
1635 {
1636 return expr;
1637 }
vinayakb38b7ca42012-03-05 05:44:15 +00001638}
1639
1640Expression Literal() throws ParseException:
1641{
vinayakb38b7ca42012-03-05 05:44:15 +00001642 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001643 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001644}
1645{
Till Westmann7d535322013-05-09 00:40:02 -07001646 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001647 {
Till Westmann7d535322013-05-09 00:40:02 -07001648 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001649 }
1650 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001651 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001652 try {
1653 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1654 } catch(NumberFormatException ex) {
1655 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1656 }
1657 }
1658 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001659 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001660 lit.setValue(new FloatLiteral(new Float(token.image)));
1661 }
1662 | <DOUBLE_LITERAL>
1663 {
1664 lit.setValue(new DoubleLiteral(new Double(token.image)));
1665 }
1666 | <NULL>
1667 {
1668 lit.setValue(NullLiteral.INSTANCE);
1669 }
1670 | <TRUE>
1671 {
1672 lit.setValue(TrueLiteral.INSTANCE);
1673 }
1674 | <FALSE>
1675 {
1676 lit.setValue(FalseLiteral.INSTANCE);
1677 }
1678 )
vinayakb38b7ca42012-03-05 05:44:15 +00001679 {
1680 return lit;
1681 }
1682}
1683
1684
1685VariableExpr VariableRef() throws ParseException:
1686{
1687 VariableExpr varExp = new VariableExpr();
1688 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001689}
1690{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001691 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001692 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001693 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001694 Identifier ident = lookupSymbol(varName);
1695 if (isInForbiddenScopes(varName)) {
1696 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.");
1697 }
1698 if(ident != null) { // exist such ident
1699 varExp.setIsNewVar(false);
1700 varExp.setVar((VarIdentifier)ident);
1701 } else {
1702 varExp.setVar(var);
1703 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001704 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001705 return varExp;
1706 }
1707}
1708
1709
1710VariableExpr Variable() throws ParseException:
1711{
1712 VariableExpr varExp = new VariableExpr();
1713 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001714}
1715{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001716 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001717 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001718 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001719 if(ident != null) { // exist such ident
1720 varExp.setIsNewVar(false);
1721 }
1722 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001723 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001724 return varExp;
1725 }
1726}
1727
1728Expression ListConstructor() throws ParseException:
1729{
1730 Expression expr = null;
1731}
1732{
1733 (
1734 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1735 )
1736
1737 {
1738 return expr;
1739 }
1740}
1741
1742
1743ListConstructor OrderedListConstructor() throws ParseException:
1744{
1745 ListConstructor expr = new ListConstructor();
1746 Expression tmp = null;
1747 List<Expression> exprList = new ArrayList<Expression>();
1748 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1749}
1750{
1751
Till Westmann96c1f172013-08-01 02:05:48 -07001752 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001753 ( tmp = Expression()
1754 {
1755 exprList.add(tmp);
1756 }
1757
Till Westmann96c1f172013-08-01 02:05:48 -07001758 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001759 )?
1760
Till Westmann96c1f172013-08-01 02:05:48 -07001761 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001762
1763 {
1764 expr.setExprList(exprList);
1765 return expr;
1766 }
1767}
1768
1769ListConstructor UnorderedListConstructor() throws ParseException:
1770{
1771 ListConstructor expr = new ListConstructor();
1772 Expression tmp = null;
1773 List<Expression> exprList = new ArrayList<Expression>();
1774 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1775}
1776{
1777
Till Westmann96c1f172013-08-01 02:05:48 -07001778 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001779 {
1780 exprList.add(tmp);
1781 }
Till Westmann96c1f172013-08-01 02:05:48 -07001782 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001783 {
1784 expr.setExprList(exprList);
1785 return expr;
1786 }
1787}
1788
1789RecordConstructor RecordConstructor() throws ParseException:
1790{
1791 RecordConstructor expr = new RecordConstructor();
1792 FieldBinding tmp = null;
1793 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1794}
1795{
Till Westmann96c1f172013-08-01 02:05:48 -07001796 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001797 {
1798 fbList.add(tmp);
1799 }
Till Westmann96c1f172013-08-01 02:05:48 -07001800 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001801 {
1802 expr.setFbList(fbList);
1803 return expr;
1804 }
1805}
1806
1807FieldBinding FieldBinding() throws ParseException:
1808{
1809 FieldBinding fb = new FieldBinding();
1810 Expression left, right;
1811}
1812{
Till Westmann96c1f172013-08-01 02:05:48 -07001813 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001814 {
1815 fb.setLeftExpr(left);
1816 fb.setRightExpr(right);
1817 return fb;
1818 }
1819}
1820
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001821
vinayakb38b7ca42012-03-05 05:44:15 +00001822Expression FunctionCallExpr() throws ParseException:
1823{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001824 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001825 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001826 Expression tmp;
1827 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001828 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001829 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001830}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001831{
ramangrover299f76a5e2013-06-18 10:25:17 -07001832 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001833 {
Till Westmann31c21f92013-05-08 09:21:53 -07001834 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001835 }
Till Westmann31c21f92013-05-08 09:21:53 -07001836 <LEFTPAREN> (tmp = Expression()
1837 {
1838 argList.add(tmp);
1839 arity ++;
1840 }
Till Westmann96c1f172013-08-01 02:05:48 -07001841 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001842 {
1843 argList.add(tmp);
1844 arity++;
1845 }
1846 )*)? <RIGHTPAREN>
1847 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001848 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001849 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001850 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001851 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001852 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001853 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001854 }
1855 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001856 if (hint != null) {
1857 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1858 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1859 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1860 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1861 }
Till Westmann31c21f92013-05-08 09:21:53 -07001862 }
1863 return callExpr;
1864 }
vinayakb38b7ca42012-03-05 05:44:15 +00001865}
1866
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001867
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001868Expression DatasetAccessExpression() throws ParseException:
1869{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001870 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001871 String arg1 = null;
1872 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001873 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001874}
1875{
Till Westmann14a20a72013-05-09 00:06:24 -07001876 <DATASET>
1877 {
Till Westmann14a20a72013-05-09 00:06:24 -07001878 funcName = token.image;
1879 }
Till Westmann96c1f172013-08-01 02:05:48 -07001880 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001881 {
1882 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001883 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001884 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001885 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001886 if(arg2 != null){
1887 addDataverse(arg1.toString());
1888 addDataset(name);
1889 } else {
1890 addDataset(defaultDataverse + "." + name);
1891 }
Till Westmann14a20a72013-05-09 00:06:24 -07001892 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001893 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001894 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001895 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1896 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1897 if (signature == null) {
1898 signature = new FunctionSignature(dataverse, funcName, 1);
1899 }
1900 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001901 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001902 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001903 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001904}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001905
vinayakb38b7ca42012-03-05 05:44:15 +00001906Expression ParenthesizedExpression() throws ParseException:
1907{
1908 Expression expr;
1909}
1910{
1911 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1912 {
1913 return expr;
1914 }
1915}
1916
1917Expression IfThenElse() throws ParseException:
1918{
1919 Expression condExpr;
1920 Expression thenExpr;
1921 Expression elseExpr;
1922 IfExpr ifExpr = new IfExpr();
1923}
1924{
Till Westmann96c1f172013-08-01 02:05:48 -07001925 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001926
1927 {
1928 ifExpr.setCondExpr(condExpr);
1929 ifExpr.setThenExpr(thenExpr);
1930 ifExpr.setElseExpr(elseExpr);
1931 return ifExpr;
1932 }
1933}
1934
1935Expression FLWOGR() throws ParseException:
1936{
1937 FLWOGRExpression flworg = new FLWOGRExpression();
1938 List<Clause> clauseList = new ArrayList<Clause>();
1939 Expression returnExpr;
1940 Clause tmp;
1941 createNewScope();
1942}
1943{
1944 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08001945 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001946
1947 {
1948 flworg.setClauseList(clauseList);
1949 flworg.setReturnExpr(returnExpr);
1950 removeCurrentScope();
1951 return flworg;
1952 }
1953}
1954
1955Clause Clause()throws ParseException :
1956{
1957 Clause clause;
1958}
1959{
1960 (
1961 clause = ForClause()
1962 | clause = LetClause()
1963 | clause = WhereClause()
1964 | clause = OrderbyClause()
1965 | clause = GroupClause()
1966 | clause = LimitClause()
1967 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001968 )
1969 {
1970 return clause;
1971 }
1972}
1973
1974Clause ForClause()throws ParseException :
1975{
1976 ForClause fc = new ForClause();
1977 VariableExpr varExp;
1978 VariableExpr varPos = null;
1979 Expression inExp;
1980 extendCurrentScope();
1981}
1982{
buyingyi2fd7fa62014-11-24 19:31:55 -08001983 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001984 {
1985 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001986 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001987 fc.setInExpr(inExp);
1988 if (varPos != null) {
1989 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001990 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001991 }
1992 return fc;
1993 }
1994}
1995
1996Clause LetClause() throws ParseException:
1997{
1998 LetClause lc = new LetClause();
1999 VariableExpr varExp;
2000 Expression beExp;
2001 extendCurrentScope();
2002}
2003{
buyingyi2fd7fa62014-11-24 19:31:55 -08002004 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002005 {
2006 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002007 lc.setVarExpr(varExp);
2008 lc.setBeExpr(beExp);
2009 return lc;
2010 }
2011}
2012
2013Clause WhereClause()throws ParseException :
2014{
2015 WhereClause wc = new WhereClause();
2016 Expression whereExpr;
2017}
2018{
salsubaieedf89fbc2013-12-21 19:51:42 -08002019 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002020 {
2021 wc.setWhereExpr(whereExpr);
2022 return wc;
2023 }
2024}
2025
2026Clause OrderbyClause()throws ParseException :
2027{
2028 OrderbyClause oc = new OrderbyClause();
2029 Expression orderbyExpr;
2030 List<Expression> orderbyList = new ArrayList<Expression>();
2031 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2032 int numOfOrderby = 0;
2033}
2034{
2035 (
Till Westmann96c1f172013-08-01 02:05:48 -07002036 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002037 {
2038 String hint = getHint(token);
2039 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
2040 String splits[] = hint.split(" +");
2041 int numFrames = Integer.parseInt(splits[1]);
2042 int numTuples = Integer.parseInt(splits[2]);
2043 oc.setNumFrames(numFrames);
2044 oc.setNumTuples(numTuples);
2045 }
2046 }
Till Westmann96c1f172013-08-01 02:05:48 -07002047 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002048 {
2049 orderbyList.add(orderbyExpr);
2050 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2051 }
Till Westmann96c1f172013-08-01 02:05:48 -07002052 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2053 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002054 {
2055 modifierList.add(modif);
2056 }
2057
Till Westmann96c1f172013-08-01 02:05:48 -07002058 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002059 {
2060 orderbyList.add(orderbyExpr);
2061 modif = OrderbyClause.OrderModifier.ASC;
2062 }
Till Westmann96c1f172013-08-01 02:05:48 -07002063 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2064 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002065 {
2066 modifierList.add(modif);
2067 }
2068 )*
2069)
2070 {
2071 oc.setModifierList(modifierList);
2072 oc.setOrderbyList(orderbyList);
2073 return oc;
2074 }
2075}
2076Clause GroupClause()throws ParseException :
2077{
2078 GroupbyClause gbc = new GroupbyClause();
2079 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2080 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2081 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2082 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2083 VariableExpr var = null;
2084 VariableExpr withVar = null;
2085 Expression expr = null;
2086 VariableExpr decorVar = null;
2087 Expression decorExpr = null;
2088}
2089{
2090 {
2091 Scope newScope = extendCurrentScopeNoPush(true);
2092 // extendCurrentScope(true);
2093 }
Till Westmann96c1f172013-08-01 02:05:48 -07002094 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002095 {
2096 String hint = getHint(token);
2097 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2098 gbc.setHashGroupByHint(true);
2099 }
2100 }
Till Westmann96c1f172013-08-01 02:05:48 -07002101 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002102 {
2103 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002104 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002105 expr = Expression()
2106 {
2107 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2108 vePairList.add(pair1);
2109 }
Till Westmann96c1f172013-08-01 02:05:48 -07002110 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002111 {
2112 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002113 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002114 expr = Expression()
2115 {
2116 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2117 vePairList.add(pair2);
2118 }
2119 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002120 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002121 {
2122 newScope.addNewVarSymbolToScope(decorVar.getVar());
2123 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2124 decorPairList.add(pair3);
2125 }
Till Westmann96c1f172013-08-01 02:05:48 -07002126 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002127 {
2128 newScope.addNewVarSymbolToScope(decorVar.getVar());
2129 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2130 decorPairList.add(pair4);
2131 }
2132 )*
2133 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002134 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002135 {
2136 if(withVar.getIsNewVar()==true)
2137 throw new ParseException("can't find variable " + withVar.getVar());
2138 withVarList.add(withVar);
2139 newScope.addNewVarSymbolToScope(withVar.getVar());
2140 }
Till Westmann96c1f172013-08-01 02:05:48 -07002141 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002142 {
2143 if(withVar.getIsNewVar()==true)
2144 throw new ParseException("can't find variable " + withVar.getVar());
2145 withVarList.add(withVar);
2146 newScope.addNewVarSymbolToScope(withVar.getVar());
2147 })*
2148 {
2149 gbc.setGbyPairList(vePairList);
2150 gbc.setDecorPairList(decorPairList);
2151 gbc.setWithVarList(withVarList);
2152 replaceCurrentScope(newScope);
2153 return gbc;
2154 }
2155}
2156
2157
2158LimitClause LimitClause() throws ParseException:
2159{
2160 LimitClause lc = new LimitClause();
2161 Expression expr;
2162 pushForbiddenScope(getCurrentScope());
2163}
2164{
Till Westmann96c1f172013-08-01 02:05:48 -07002165 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2166 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002167
2168 {
2169 popForbiddenScope();
2170 return lc;
2171 }
2172}
2173
2174DistinctClause DistinctClause() throws ParseException:
2175{
2176 List<Expression> exprs = new ArrayList<Expression>();
2177 Expression expr;
2178}
2179{
Till Westmann96c1f172013-08-01 02:05:48 -07002180 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002181 {
2182 exprs.add(expr);
2183 }
Till Westmann96c1f172013-08-01 02:05:48 -07002184 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002185 {
2186 exprs.add(expr);
2187 }
2188 )*
2189 {
2190 return new DistinctClause(exprs);
2191 }
2192}
2193
vinayakb38b7ca42012-03-05 05:44:15 +00002194QuantifiedExpression QuantifiedExpression()throws ParseException:
2195{
2196 QuantifiedExpression qc = new QuantifiedExpression();
2197 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2198 Expression satisfiesExpr;
2199 VariableExpr var;
2200 Expression inExpr;
2201 QuantifiedPair pair;
2202}
2203{
2204 {
2205 createNewScope();
2206 }
2207
Till Westmann96c1f172013-08-01 02:05:48 -07002208 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2209 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2210 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002211 {
2212 pair = new QuantifiedPair(var, inExpr);
2213 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2214 quantifiedList.add(pair);
2215 }
2216 (
Till Westmann96c1f172013-08-01 02:05:48 -07002217 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002218 {
2219 pair = new QuantifiedPair(var, inExpr);
2220 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2221 quantifiedList.add(pair);
2222 }
2223 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002224 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002225 {
2226 qc.setSatisfiesExpr(satisfiesExpr);
2227 qc.setQuantifiedList(quantifiedList);
2228 removeCurrentScope();
2229 return qc;
2230 }
2231}
2232
2233TOKEN_MGR_DECLS:
2234{
Till Westmann96c1f172013-08-01 02:05:48 -07002235 public int commentDepth = 0;
2236 public IntStack lexerStateStack = new IntStack();
2237
2238 public void pushState() {
2239 lexerStateStack.push( curLexState );
2240 }
2241
Till Westmannfd733ee2014-07-10 00:57:37 -07002242 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002243 if (lexerStateStack.size() > 0) {
2244 SwitchTo( lexerStateStack.pop() );
2245 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002246 int errorLine = input_stream.getEndLine();
2247 int errorColumn = input_stream.getEndColumn();
2248 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2249 + "\" but state stack is empty.";
2250 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002251 }
2252 }
vinayakb38b7ca42012-03-05 05:44:15 +00002253}
2254
Till Westmann96c1f172013-08-01 02:05:48 -07002255<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002256TOKEN :
2257{
Till Westmann5df7b452013-08-02 13:07:16 -07002258 <ASC : "asc">
2259 | <AT : "at">
2260 | <BY : "by">
2261 | <DATASET : "dataset">
2262 | <DECOR : "decor">
2263 | <DESC : "desc">
2264 | <DISTINCT : "distinct">
2265 | <ELSE : "else">
2266 | <EVERY : "every">
2267 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002268 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002269 | <GROUP : "group">
2270 | <IF : "if">
2271 | <IN : "in">
2272 | <LET : "let">
2273 | <LIMIT : "limit">
2274 | <OFFSET : "offset">
2275 | <ORDER : "order">
2276 | <RETURN : "return">
2277 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002278 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002279 | <SOME : "some">
2280 | <THEN : "then">
2281 | <UNION : "union">
2282 | <WHERE : "where">
2283 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002284}
2285
Till Westmann96c1f172013-08-01 02:05:48 -07002286<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002287TOKEN :
2288{
Till Westmann5df7b452013-08-02 13:07:16 -07002289 <CARET : "^">
2290 | <DIV : "/">
2291 | <IDIV : "idiv">
2292 | <MINUS : "-">
2293 | <MOD : "%">
2294 | <MUL : "*">
2295 | <PLUS : "+">
2296
2297 | <LEFTPAREN : "(">
2298 | <RIGHTPAREN : ")">
2299 | <LEFTBRACKET : "[">
2300 | <RIGHTBRACKET : "]">
2301
2302 | <COLON : ":">
2303 | <COMMA : ",">
2304 | <DOT : ".">
2305 | <QUES : "?">
2306
2307 | <LT : "<">
2308 | <GT : ">">
2309 | <LE : "<=">
2310 | <GE : ">=">
2311 | <EQ : "=">
2312 | <NE : "!=">
2313 | <SIMILAR : "~=">
2314 | <ASSIGN : ":=">
2315
2316 | <AND : "and">
2317 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002318}
2319
Till Westmann96c1f172013-08-01 02:05:48 -07002320<DEFAULT,IN_DBL_BRACE>
2321TOKEN :
2322{
Till Westmann5df7b452013-08-02 13:07:16 -07002323 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002324}
2325
2326<DEFAULT>
2327TOKEN :
2328{
Till Westmannfd733ee2014-07-10 00:57:37 -07002329 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002330}
2331
Till Westmann96c1f172013-08-01 02:05:48 -07002332<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002333TOKEN :
2334{
Till Westmann5df7b452013-08-02 13:07:16 -07002335 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002336}
2337
Till Westmann96c1f172013-08-01 02:05:48 -07002338<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002339TOKEN :
2340{
Till Westmannfd733ee2014-07-10 00:57:37 -07002341 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002342}
2343
Till Westmann96c1f172013-08-01 02:05:48 -07002344<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002345TOKEN :
2346{
Till Westmann5df7b452013-08-02 13:07:16 -07002347 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002348}
2349
Till Westmann96c1f172013-08-01 02:05:48 -07002350<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002351TOKEN :
2352{
Till Westmann5df7b452013-08-02 13:07:16 -07002353 <NULL : "null">
2354 | <TRUE : "true">
2355 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002356}
2357
Till Westmann96c1f172013-08-01 02:05:48 -07002358<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002359TOKEN :
2360{
Till Westmann5df7b452013-08-02 13:07:16 -07002361 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002362}
2363
Till Westmann96c1f172013-08-01 02:05:48 -07002364<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002365TOKEN:
2366{
Till Westmann5df7b452013-08-02 13:07:16 -07002367 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002368 | <DIGITS> ( "." <DIGITS> )?
2369 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002370 >
2371 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002372 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2373 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002374 >
2375 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002376}
2377
Till Westmann96c1f172013-08-01 02:05:48 -07002378<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002379TOKEN :
2380{
Till Westmann5df7b452013-08-02 13:07:16 -07002381 <#LETTER : ["A" - "Z", "a" - "z"]>
2382 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002383}
2384
Till Westmann96c1f172013-08-01 02:05:48 -07002385<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002386TOKEN :
2387{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002388 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2389 <STRING_LITERAL : ("\"" (
2390 <EscapeQuot>
2391 | <EscapeBslash>
2392 | <EscapeSlash>
2393 | <EscapeBspace>
2394 | <EscapeFormf>
2395 | <EscapeNl>
2396 | <EscapeCr>
2397 | <EscapeTab>
2398 | ~["\"","\\"])* "\"")
2399 | ("\'"(
2400 <EscapeApos>
2401 | <EscapeBslash>
2402 | <EscapeSlash>
2403 | <EscapeBspace>
2404 | <EscapeFormf>
2405 | <EscapeNl>
2406 | <EscapeCr>
2407 | <EscapeTab>
2408 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002409 | < #EscapeQuot: "\\\"" >
2410 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002411 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002412 | < #EscapeSlash: "\\/" >
2413 | < #EscapeBspace: "\\b" >
2414 | < #EscapeFormf: "\\f" >
2415 | < #EscapeNl: "\\n" >
2416 | < #EscapeCr: "\\r" >
2417 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002418}
2419
Till Westmann96c1f172013-08-01 02:05:48 -07002420<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002421TOKEN :
2422{
Till Westmann5df7b452013-08-02 13:07:16 -07002423 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002424}
2425
Till Westmann96c1f172013-08-01 02:05:48 -07002426<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002427TOKEN :
2428{
Till Westmann5df7b452013-08-02 13:07:16 -07002429 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002430}
2431
Till Westmann96c1f172013-08-01 02:05:48 -07002432<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002433SKIP:
2434{
2435 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002436 | "\t"
2437 | "\r"
2438 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002439}
2440
Till Westmann96c1f172013-08-01 02:05:48 -07002441<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002442SKIP:
2443{
Till Westmann5df7b452013-08-02 13:07:16 -07002444 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002445}
2446
Till Westmann96c1f172013-08-01 02:05:48 -07002447<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002448SKIP:
2449{
Till Westmann5df7b452013-08-02 13:07:16 -07002450 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002451}
2452
Till Westmann96c1f172013-08-01 02:05:48 -07002453<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002454SKIP:
2455{
Till Westmann96c1f172013-08-01 02:05:48 -07002456 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002457}
2458
2459<INSIDE_COMMENT>
2460SPECIAL_TOKEN:
2461{
Till Westmann5df7b452013-08-02 13:07:16 -07002462 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002463}
2464
2465<INSIDE_COMMENT>
2466SKIP:
2467{
Till Westmann96c1f172013-08-01 02:05:48 -07002468 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002469}
2470
2471<INSIDE_COMMENT>
2472SKIP:
2473{
Till Westmannfd733ee2014-07-10 00:57:37 -07002474 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002475 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002476}