blob: e85b56b21131c5f404fc85eb7ef18c37e245df56 [file] [log] [blame]
vinayakb38b7ca42012-03-05 05:44:15 +00001options {
2
Taewoo Kima12d8cd2015-03-04 13:47:08 -08003
vinayakb38b7ca42012-03-05 05:44:15 +00004 STATIC = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08005
vinayakb38b7ca42012-03-05 05:44:15 +00006}
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;
Taewoo Kima12d8cd2015-03-04 13:47:08 -080039import edu.uci.ics.asterix.aql.expression.TypeExpression.TypeExprKind;
vinayakb38b7ca42012-03-05 05:44:15 +000040import edu.uci.ics.asterix.aql.base.Statement.Kind;
41import edu.uci.ics.asterix.aql.context.Scope;
42import edu.uci.ics.asterix.aql.context.RootScopeFactory;
43import edu.uci.ics.asterix.common.annotations.*;
44import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000045import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000046import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000047import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
48import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000049import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
50import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
51import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
52
53
vinayakb38b7ca42012-03-05 05:44:15 +000054
55
56public class AQLParser extends ScopeChecker {
57
vinayakb38b7ca42012-03-05 05:44:15 +000058 // optimizer hints
59 private static final String HASH_GROUP_BY_HINT = "hash";
salsubaieebb167912013-12-21 12:55:52 -080060 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
vinayakb38b7ca42012-03-05 05:44:15 +000061 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000062 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000063 private static final String INMEMORY_HINT = "inmem";
64 private static final String VAL_FILE_HINT = "val-files";
65 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
66 private static final String INTERVAL_HINT = "interval";
67 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
68 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
69 private static final String LIST_VAL_FILE_HINT = "list-val-file";
70 private static final String LIST_HINT = "list";
71 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
72 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
73 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
Taewoo Kima12d8cd2015-03-04 13:47:08 -080074 private static final String AUTO_HINT = "auto";
75
76 private static final String GEN_FIELDS_HINT = "gen-fields";
77
vinayakb38b7ca42012-03-05 05:44:15 +000078 // data generator hints
79 private static final String DGEN_HINT = "dgen";
Taewoo Kima12d8cd2015-03-04 13:47:08 -080080
Till Westmann31c21f92013-05-08 09:21:53 -070081 private static class IndexParams {
82 public IndexType type;
83 public int gramLength;
Taewoo Kima12d8cd2015-03-04 13:47:08 -080084
Till Westmann31c21f92013-05-08 09:21:53 -070085 public IndexParams(IndexType type, int gramLength) {
86 this.type = type;
87 this.gramLength = gramLength;
88 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -080089 };
90
ramangrover299f76a5e2013-06-18 10:25:17 -070091 private static class FunctionName {
Taewoo Kima12d8cd2015-03-04 13:47:08 -080092 public String dataverse = null;
93 public String library = null;
94 public String function = null;
95 }
ramangrover299f76a5e2013-06-18 10:25:17 -070096
vinayakb38b7ca42012-03-05 05:44:15 +000097 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070098 if (t.specialToken == null) {
99 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800100 }
Till Westmann31c21f92013-05-08 09:21:53 -0700101 String s = t.specialToken.image;
102 int n = s.length();
103 if (n < 2) {
104 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800105 }
Till Westmann31c21f92013-05-08 09:21:53 -0700106 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000107 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800108
Till Westmann77cb2f42013-07-15 16:44:19 -0700109 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
110 IRecordFieldDataGen rfdg = null;
111 String splits[] = hint.split(" +");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800112 if (splits[0].equals(VAL_FILE_HINT)) {
Till Westmann77cb2f42013-07-15 16:44:19 -0700113 File[] valFiles = new File[splits.length - 1];
114 for (int k=1; k<splits.length; k++) {
115 valFiles[k-1] = new File(splits[k]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800116 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700117 rfdg = new FieldValFileDataGen(valFiles);
118 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
119 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
120 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
121 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
122 } else if (splits[0].equals(LIST_HINT)) {
123 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
124 } else if (splits[0].equals(INTERVAL_HINT)) {
125 FieldIntervalDataGen.ValueType vt;
126 if (splits[1].equals("int")) {
127 vt = FieldIntervalDataGen.ValueType.INT;
128 } else if (splits[1].equals("long")) {
129 vt = FieldIntervalDataGen.ValueType.LONG;
130 } else if (splits[1].equals("float")) {
131 vt = FieldIntervalDataGen.ValueType.FLOAT;
132 } else if (splits[1].equals("double")) {
133 vt = FieldIntervalDataGen.ValueType.DOUBLE;
134 } else {
135 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
136 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800137 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
Till Westmann77cb2f42013-07-15 16:44:19 -0700138 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
139 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
140 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
141 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
142 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
143 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
144 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
145 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
146 } else if (splits[0].equals(AUTO_HINT)) {
147 rfdg = new AutoDataGen(splits[1]);
148 }
149 return rfdg;
150 }
vinayakb38b7ca42012-03-05 05:44:15 +0000151
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000152 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700153 this(new StringReader(s));
154 super.setInput(s);
155 }
vinayakb38b7ca42012-03-05 05:44:15 +0000156
Till Westmann31c21f92013-05-08 09:21:53 -0700157 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
158 File file = new File(args[0]);
159 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
160 AQLParser parser = new AQLParser(fis);
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700161 List<Statement> st = parser.parse();
Till Westmann31c21f92013-05-08 09:21:53 -0700162 //st.accept(new AQLPrintVisitor(), 0);
163 }
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700164
165 public List<Statement> parse() throws ParseException {
166 try {
167 return Statement();
168 } catch (Error e) {
169 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
170 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
171 throw new ParseException(e.getMessage());
172 }
173 }
vinayakb38b7ca42012-03-05 05:44:15 +0000174}
175
176PARSER_END(AQLParser)
177
178
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000179List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000180{
vinayakb38b7ca42012-03-05 05:44:15 +0000181 scopeStack.push(RootScopeFactory.createRootScope(this));
182 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700183 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000184}
185{
Till Westmann31c21f92013-05-08 09:21:53 -0700186 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000187 {
Till Westmann31c21f92013-05-08 09:21:53 -0700188 decls.add(stmt);
189 }
190 )*
191 <EOF>
192 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800193 return decls;
Till Westmann31c21f92013-05-08 09:21:53 -0700194 }
195}
196
197Statement SingleStatement() throws ParseException:
198{
199 Statement stmt = null;
200}
201{
202 (
203 stmt = DataverseDeclaration()
204 | stmt = FunctionDeclaration()
205 | stmt = CreateStatement()
206 | stmt = LoadStatement()
207 | stmt = DropStatement()
208 | stmt = WriteStatement()
209 | stmt = SetStatement()
210 | stmt = InsertStatement()
211 | stmt = DeleteStatement()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800212 | stmt = UpdateStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700213 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700214 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700215 | stmt = Query()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700216 | stmt = RefreshExternalDatasetStatement()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800217 | stmt = RunStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700218 )
219 {
220 return stmt;
221 }
222}
223
224DataverseDecl DataverseDeclaration() throws ParseException:
225{
Till Westmann14a20a72013-05-09 00:06:24 -0700226 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700227}
228{
Till Westmanna4242bc2013-05-08 17:49:55 -0700229 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700230 {
Till Westmann14a20a72013-05-09 00:06:24 -0700231 defaultDataverse = dvName;
232 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700233 }
234}
235
236Statement CreateStatement() throws ParseException:
237{
238 String hint = null;
239 boolean dgen = false;
240 Statement stmt = null;
241}
242{
243 "create"
244 (
245 {
246 hint = getHint(token);
247 if (hint != null && hint.startsWith(DGEN_HINT)) {
248 dgen = true;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800249 }
Till Westmann31c21f92013-05-08 09:21:53 -0700250 }
251 stmt = TypeSpecification(hint, dgen)
252 | stmt = NodegroupSpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800253 | stmt = DatasetSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700254 | stmt = IndexSpecification()
255 | stmt = DataverseSpecification()
256 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700257 | stmt = FeedSpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800258 )
Till Westmann31c21f92013-05-08 09:21:53 -0700259 {
260 return stmt;
261 }
262}
263
264TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
265{
266 Pair<Identifier,Identifier> nameComponents = null;
267 boolean ifNotExists = false;
268 TypeExpression typeExpr = null;
269}
270{
ramangrover299f76a5e2013-06-18 10:25:17 -0700271 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700272 "as" typeExpr = TypeExpr()
273 {
274 long numValues = -1;
275 String filename = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800276 if (dgen) {
Till Westmann31c21f92013-05-08 09:21:53 -0700277 String splits[] = hint.split(" +");
278 if (splits.length != 3) {
279 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800280 }
Till Westmann31c21f92013-05-08 09:21:53 -0700281 filename = splits[1];
282 numValues = Long.parseLong(splits[2]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800283 }
Till Westmann31c21f92013-05-08 09:21:53 -0700284 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
285 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
286 }
287}
288
289
290NodegroupDecl NodegroupSpecification() throws ParseException:
291{
Till Westmann14a20a72013-05-09 00:06:24 -0700292 String name = null;
293 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700294 boolean ifNotExists = false;
295 List<Identifier>ncNames = null;
296}
297{
Till Westmanna4242bc2013-05-08 17:49:55 -0700298 "nodegroup" name = Identifier()
299 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700300 {
301 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700302 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700303 }
Till Westmann96c1f172013-08-01 02:05:48 -0700304 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700305 {
Till Westmann14a20a72013-05-09 00:06:24 -0700306 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700307 }
308 )*
309 {
Till Westmann14a20a72013-05-09 00:06:24 -0700310 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700311 }
312}
313
314DatasetDecl DatasetSpecification() throws ParseException:
315{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800316 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700317 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700318 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700319 String adapterName = null;
320 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700321 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700322 FunctionSignature appliedFunction = null;
323 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700324 String nodeGroupName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800325 Map<String,String> hints = new HashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700326 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700327 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700328 String compactionPolicy = null;
salsubaieea5af4e02014-07-08 15:20:02 -0700329 String filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700330}
331{
332 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700333 "external" <DATASET> nameComponents = QualifiedName()
334 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
335 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700336 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700337 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700338 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700339 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Till Westmann31c21f92013-05-08 09:21:53 -0700340 {
341 ExternalDetailsDecl edd = new ExternalDetailsDecl();
342 edd.setAdapter(adapterName);
343 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700344 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
345 edd.setCompactionPolicy(compactionPolicy);
346 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700347 dsetDecl = new DatasetDecl(nameComponents.first,
348 nameComponents.second,
349 new Identifier(typeName),
350 hints,
351 DatasetType.EXTERNAL,
352 edd,
353 ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800354 }
Till Westmann31c21f92013-05-08 09:21:53 -0700355
Till Westmannd7dcb122013-05-16 13:19:09 -0700356 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700357 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
358 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800359 primaryKeyFields = PrimaryKey()
360 ("autogenerated" { autogenerated = true; } )?
zheilbron2467f2e2013-08-23 19:07:31 -0700361 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700362 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700363 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
salsubaieea5af4e02014-07-08 15:20:02 -0700364 ( "with filter on" filterField = FilterField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700365 {
Till Westmann14a20a72013-05-09 00:06:24 -0700366 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
367 ? new Identifier(nodeGroupName)
368 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700369 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700370 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700371 compactionPolicy,
salsubaieea5af4e02014-07-08 15:20:02 -0700372 compactionPolicyProperties,
373 filterField);
Till Westmann14a20a72013-05-09 00:06:24 -0700374 dsetDecl = new DatasetDecl(nameComponents.first,
375 nameComponents.second,
376 new Identifier(typeName),
377 hints,
378 DatasetType.INTERNAL,
379 idd,
380 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700381 }
382 )
383 {
384 return dsetDecl;
385 }
386}
387
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700388RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
389{
390 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
391 Pair<Identifier,Identifier> nameComponents = null;
392 String datasetName = null;
393}
394{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800395 "refresh external" <DATASET> nameComponents = QualifiedName()
396 {
397 redss.setDataverseName(nameComponents.first);
398 redss.setDatasetName(nameComponents.second);
399 return redss;
400 }
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700401}
402
Markus Holzemer52c568e2014-12-18 10:51:49 -0800403RunStatement RunStatement() throws ParseException:
404{
405 String system = null;
406 String tmp;
407 ArrayList<String> parameters = new ArrayList<String>();
408 Pair<Identifier,Identifier> nameComponentsFrom = null;
409 Pair<Identifier,Identifier> nameComponentsTo = null;
410}
411{
412 "run" system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
413 {
414 parameters.add(tmp);
415 }
416 )*<RIGHTPAREN>
417 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800418 "to" <DATASET> nameComponentsTo = QualifiedName()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800419 {
420 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
421 }
422}
423
Till Westmann31c21f92013-05-08 09:21:53 -0700424CreateIndexStatement IndexSpecification() throws ParseException:
425{
426 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700427 String indexName = null;
428 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700429 boolean ifNotExists = false;
430 Pair<Identifier,Identifier> nameComponents = null;
431 IndexParams indexType = null;
432}
433{
Till Westmanna4242bc2013-05-08 17:49:55 -0700434 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700435 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800436 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700437 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700438 {
Till Westmann14a20a72013-05-09 00:06:24 -0700439 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700440 }
Till Westmann96c1f172013-08-01 02:05:48 -0700441 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700442 {
Till Westmann14a20a72013-05-09 00:06:24 -0700443 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700444 }
445 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
446 {
Till Westmann14a20a72013-05-09 00:06:24 -0700447 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700448 cis.setIfNotExists(ifNotExists);
449 cis.setDataverseName(nameComponents.first);
450 cis.setDatasetName(nameComponents.second);
451 if (indexType != null) {
452 cis.setIndexType(indexType.type);
453 cis.setGramLength(indexType.gramLength);
454 }
455 return cis;
456 }
457}
458
salsubaiee0b423fa2013-09-19 19:16:48 -0700459String CompactionPolicy() throws ParseException :
460{
461 String compactionPolicy = null;
462}
463{
464 compactionPolicy = Identifier()
465 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800466 return compactionPolicy;
salsubaiee0b423fa2013-09-19 19:16:48 -0700467 }
468}
469
salsubaieea5af4e02014-07-08 15:20:02 -0700470String FilterField() throws ParseException :
471{
472 String filterField = null;
473}
474{
475 filterField = Identifier()
476 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800477 return filterField;
salsubaieea5af4e02014-07-08 15:20:02 -0700478 }
479}
480
Till Westmann31c21f92013-05-08 09:21:53 -0700481IndexParams IndexType() throws ParseException:
482{
483 IndexType type = null;
484 int gramLength = 0;
485}
486{
487 ("btree"
488 {
489 type = IndexType.BTREE;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800490 }
Till Westmann31c21f92013-05-08 09:21:53 -0700491 | "rtree"
492 {
493 type = IndexType.RTREE;
494 }
495 | "keyword"
496 {
JIMAHNb75446d2013-06-03 08:35:27 -0700497 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700498 }
499 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
500 {
JIMAHNb75446d2013-06-03 08:35:27 -0700501 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700502 gramLength = Integer.valueOf(token.image);
503 }
504 <RIGHTPAREN>)
505 {
506 return new IndexParams(type, gramLength);
507 }
508}
509
510CreateDataverseStatement DataverseSpecification() throws ParseException :
511{
Till Westmann14a20a72013-05-09 00:06:24 -0700512 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700513 boolean ifNotExists = false;
514 String format = null;
515}
516{
Till Westmanna4242bc2013-05-08 17:49:55 -0700517 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700518 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700519 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700520 {
Till Westmann14a20a72013-05-09 00:06:24 -0700521 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700522 }
523}
524
525CreateFunctionStatement FunctionSpecification() throws ParseException:
526{
527 FunctionSignature signature;
528 boolean ifNotExists = false;
529 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
530 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700531 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700532 Expression functionBodyExpr;
533 Token beginPos;
534 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700535 FunctionName fctName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800536
Till Westmann31c21f92013-05-08 09:21:53 -0700537 createNewScope();
538}
539{
ramangrover299f76a5e2013-06-18 10:25:17 -0700540 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700541 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700542 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700543 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530544 {
545 beginPos = token;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800546 }
Till Westmann96c1f172013-08-01 02:05:48 -0700547 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700548 {
549 endPos = token;
550 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700551 // TODO use fctName.library
552 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700553 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800554 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700555 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
556 }
557}
558
ramangrover29a774ef22013-07-17 09:29:18 -0700559CreateFeedStatement FeedSpecification() throws ParseException:
560{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800561 Pair<Identifier,Identifier> nameComponents = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700562 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700563 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700564 Map<String,String> properties = null;
565 FunctionSignature appliedFunction = null;
566 CreateFeedStatement cfs = null;
567}
568{
569 (
570 "feed" nameComponents = QualifiedName()
571 ifNotExists = IfNotExists()
Chris Hillerye64055d2014-10-11 00:14:39 -0700572 "using" adapterName = AdapterName() properties = Configuration()
ramangrover29a774ef22013-07-17 09:29:18 -0700573 (appliedFunction = ApplyFunction())?
574 {
575 cfs = new CreateFeedStatement(nameComponents.first,
Chris Hillerye64055d2014-10-11 00:14:39 -0700576 nameComponents.second, adapterName, properties, appliedFunction, ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800577 }
578
ramangrover29a774ef22013-07-17 09:29:18 -0700579 )
580 {
581 return cfs;
582 }
583}
584
585
586
Till Westmannd7dcb122013-05-16 13:19:09 -0700587List<VarIdentifier> ParameterList() throws ParseException:
588{
589 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
590 VarIdentifier var = null;
591}
592{
Till Westmann31c21f92013-05-08 09:21:53 -0700593 <LEFTPAREN> (<VARIABLE>
594 {
595 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700596 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700597 paramList.add(var);
598 getCurrentScope().addNewVarSymbolToScope(var);
599 }
Till Westmann96c1f172013-08-01 02:05:48 -0700600 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700601 {
602 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700603 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700604 paramList.add(var);
605 getCurrentScope().addNewVarSymbolToScope(var);
606 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700607 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700608 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700609 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700610 }
611}
612
613boolean IfNotExists() throws ParseException:
614{
615}
616{
617 ( "if not exists"
618 {
619 return true;
620 }
621 )?
622 {
623 return false;
624 }
625}
626
627FunctionSignature ApplyFunction() throws ParseException:
628{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530629 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700630 FunctionSignature funcSig = null;
631}
632{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530633 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700634 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530635 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
636 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700637 }
638}
639
ramangrover29566b3a92013-05-28 09:07:10 -0700640String GetPolicy() throws ParseException:
641{
642 String policy = null;
643}
644{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800645 "using" "policy" policy = Identifier()
ramangrover29566b3a92013-05-28 09:07:10 -0700646 {
647 return policy;
648 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800649
650}
ramangrover29566b3a92013-05-28 09:07:10 -0700651
Till Westmann31c21f92013-05-08 09:21:53 -0700652FunctionSignature FunctionSignature() throws ParseException:
653{
ramangrover299f76a5e2013-06-18 10:25:17 -0700654 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700655 int arity = 0;
656}
657{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800658 fctName = FunctionName() "@" <INTEGER_LITERAL>
659 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700660 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700661 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
662 throw new ParseException(" invalid arity:" + arity);
663 }
664
ramangrover299f76a5e2013-06-18 10:25:17 -0700665 // TODO use fctName.library
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800666 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700667 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700668 }
669}
670
671List<String> PrimaryKey() throws ParseException:
672{
Till Westmann14a20a72013-05-09 00:06:24 -0700673 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700674 List<String> primaryKeyFields = new ArrayList<String>();
675}
676{
Till Westmann14a20a72013-05-09 00:06:24 -0700677 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700678 {
Till Westmann14a20a72013-05-09 00:06:24 -0700679 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700680 }
Till Westmann96c1f172013-08-01 02:05:48 -0700681 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700682 {
Till Westmann14a20a72013-05-09 00:06:24 -0700683 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700684 }
685 )*
686 {
687 return primaryKeyFields;
688 }
689}
690
691Statement DropStatement() throws ParseException:
692{
Till Westmann14a20a72013-05-09 00:06:24 -0700693 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700694 Pair<Identifier,Identifier> pairId = null;
695 Triple<Identifier,Identifier,Identifier> tripleId = null;
696 FunctionSignature funcSig = null;
697 boolean ifExists = false;
698 Statement stmt = null;
699}
700{
701 "drop"
702 (
703 <DATASET> pairId = QualifiedName() ifExists = IfExists()
704 {
705 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
706 }
707 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
708 {
709 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
710 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700711 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700712 {
Till Westmann14a20a72013-05-09 00:06:24 -0700713 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700714 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700715 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700716 {
717 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
718 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700719 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700720 {
Till Westmann14a20a72013-05-09 00:06:24 -0700721 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700722 }
723 | "function" funcSig = FunctionSignature() ifExists = IfExists()
724 {
725 stmt = new FunctionDropStatement(funcSig, ifExists);
726 }
ramangrover29a774ef22013-07-17 09:29:18 -0700727 | "feed" pairId = QualifiedName() ifExists = IfExists()
728 {
729 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800730 }
Till Westmann31c21f92013-05-08 09:21:53 -0700731 )
732 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800733 return stmt;
Till Westmann31c21f92013-05-08 09:21:53 -0700734 }
735}
736
737boolean IfExists() throws ParseException :
738{
739}
740{
Till Westmann96c1f172013-08-01 02:05:48 -0700741 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700742 {
743 return true;
744 }
745 )?
746 {
747 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000748 }
749}
750
751InsertStatement InsertStatement() throws ParseException:
752{
Till Westmann31c21f92013-05-08 09:21:53 -0700753 Pair<Identifier,Identifier> nameComponents = null;
754 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000755}
756{
Till Westmann31c21f92013-05-08 09:21:53 -0700757 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
758 {
759 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
760 }
vinayakb38b7ca42012-03-05 05:44:15 +0000761}
762
763DeleteStatement DeleteStatement() throws ParseException:
764{
Till Westmann31c21f92013-05-08 09:21:53 -0700765 VariableExpr var = null;
766 Expression condition = null;
767 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300768 // This is related to the new metadata lock management
769 setDataverses(new ArrayList<String>());
770 setDatasets(new ArrayList<String>());
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800771
vinayakb38b7ca42012-03-05 05:44:15 +0000772}
773{
Till Westmann31c21f92013-05-08 09:21:53 -0700774 "delete" var = Variable()
775 {
776 getCurrentScope().addNewVarSymbolToScope(var.getVar());
777 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800778 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800779 (<WHERE> condition = Expression())?
780 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300781 // First we get the dataverses and datasets that we want to lock
782 List<String> dataverses = getDataverses();
783 List<String> datasets = getDatasets();
784 // we remove the pointer to the dataverses and datasets
785 setDataverses(null);
786 setDatasets(null);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800787 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
788 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700789 }
vinayakb38b7ca42012-03-05 05:44:15 +0000790}
791
792UpdateStatement UpdateStatement() throws ParseException:
793{
Till Westmann31c21f92013-05-08 09:21:53 -0700794 VariableExpr vars;
795 Expression target;
796 Expression condition;
797 UpdateClause uc;
798 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000799}
800{
Till Westmann96c1f172013-08-01 02:05:48 -0700801 "update" vars = Variable() <IN> target = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800802 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700803 <LEFTPAREN> (uc = UpdateClause()
804 {
805 ucs.add(uc);
806 }
Till Westmann96c1f172013-08-01 02:05:48 -0700807 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700808 {
809 ucs.add(uc);
810 }
811 )*) <RIGHTPAREN>
812 {
813 return new UpdateStatement(vars, target, condition, ucs);
814 }
vinayakb38b7ca42012-03-05 05:44:15 +0000815}
816
vinayakb38b7ca42012-03-05 05:44:15 +0000817UpdateClause UpdateClause() throws ParseException:
818{
Till Westmann31c21f92013-05-08 09:21:53 -0700819 Expression target = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800820 Expression value = null ;
Till Westmann31c21f92013-05-08 09:21:53 -0700821 InsertStatement is = null;
822 DeleteStatement ds = null;
823 UpdateStatement us = null;
824 Expression condition = null;
825 UpdateClause ifbranch = null;
826 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000827}
828{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800829 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700830 | is = InsertStatement()
831 | ds = DeleteStatement()
832 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700833 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
834 <THEN> ifbranch = UpdateClause()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800835 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700836 {
837 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
838 }
vinayakb38b7ca42012-03-05 05:44:15 +0000839}
840
vinayakb38b7ca42012-03-05 05:44:15 +0000841Statement SetStatement() throws ParseException:
842{
843 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700844 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000845}
846{
Till Westmann7d535322013-05-09 00:40:02 -0700847 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700848 {
Till Westmann31c21f92013-05-08 09:21:53 -0700849 return new SetStatement(pn, pv);
850 }
vinayakb38b7ca42012-03-05 05:44:15 +0000851}
852
853Statement WriteStatement() throws ParseException:
854{
Till Westmann14a20a72013-05-09 00:06:24 -0700855 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000856 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000857 Query query;
858 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000859 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000860}
861{
Till Westmann96c1f172013-08-01 02:05:48 -0700862 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700863 ( "using" writerClass = StringLiteral() )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800864 {
865 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000866 }
867}
868
zheilbron28e026f2013-11-20 10:15:15 -0800869LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000870{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000871 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000872 Identifier datasetName = null;
873 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000874 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000875 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000876 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000877}
878{
Till Westmann31c21f92013-05-08 09:21:53 -0700879 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000880 {
Till Westmann31c21f92013-05-08 09:21:53 -0700881 dataverseName = nameComponents.first;
882 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000883 }
Till Westmann31c21f92013-05-08 09:21:53 -0700884 "using" adapterName = AdapterName() properties = Configuration()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800885 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000886 {
Till Westmann31c21f92013-05-08 09:21:53 -0700887 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000888 }
889 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700890 {
zheilbron28e026f2013-11-20 10:15:15 -0800891 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800892 }
vinayakb38b7ca42012-03-05 05:44:15 +0000893}
894
vinayakb38b7ca42012-03-05 05:44:15 +0000895
Till Westmann31c21f92013-05-08 09:21:53 -0700896String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000897{
ramangrover29669d8f62013-02-11 06:03:32 +0000898 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000899}
900{
Till Westmann68d99652013-05-09 11:15:21 -0700901 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000902 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800903 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000904 }
vinayakb38b7ca42012-03-05 05:44:15 +0000905}
906
salsubaiee0b423fa2013-09-19 19:16:48 -0700907Statement CompactStatement() throws ParseException:
908{
909 Pair<Identifier,Identifier> nameComponents = null;
910 Statement stmt = null;
911}
912{
913 "compact" <DATASET> nameComponents = QualifiedName()
914 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800915 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
salsubaiee0b423fa2013-09-19 19:16:48 -0700916 }
917 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800918 return stmt;
salsubaiee0b423fa2013-09-19 19:16:48 -0700919 }
920}
921
Till Westmann31c21f92013-05-08 09:21:53 -0700922Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000923{
ramangrover29a774ef22013-07-17 09:29:18 -0700924 Pair<Identifier,Identifier> feedNameComponents = null;
925 Pair<Identifier,Identifier> datasetNameComponents = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800926
Till Westmann31c21f92013-05-08 09:21:53 -0700927 Map<String,String> configuration = null;
928 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700929 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000930}
931{
Till Westmann31c21f92013-05-08 09:21:53 -0700932 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800933 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700934 {
ramangrover29a774ef22013-07-17 09:29:18 -0700935 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700936 }
buyingyi2fd7fa62014-11-24 19:31:55 -0800937 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700938 {
ramangrover29a774ef22013-07-17 09:29:18 -0700939 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700940 }
941 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000942 {
Till Westmann31c21f92013-05-08 09:21:53 -0700943 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000944 }
945}
946
Till Westmann31c21f92013-05-08 09:21:53 -0700947Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000948{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800949 Map<String,String> configuration = new LinkedHashMap<String,String>();
950 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000951}
952{
Till Westmann31c21f92013-05-08 09:21:53 -0700953 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000954 {
Till Westmann31c21f92013-05-08 09:21:53 -0700955 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000956 }
Till Westmann96c1f172013-08-01 02:05:48 -0700957 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000958 {
Till Westmann31c21f92013-05-08 09:21:53 -0700959 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000960 }
Till Westmann31c21f92013-05-08 09:21:53 -0700961 )* )? <RIGHTPAREN>
962 {
963 return configuration;
964 }
965}
966
967Pair<String, String> KeyValuePair() throws ParseException:
968{
969 String key;
970 String value;
971}
972{
Till Westmann96c1f172013-08-01 02:05:48 -0700973 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700974 {
975 return new Pair<String, String>(key, value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800976 }
Till Westmann31c21f92013-05-08 09:21:53 -0700977}
978
979Map<String,String> Properties() throws ParseException:
980{
981 Map<String,String> properties = new HashMap<String,String>();
982 Pair<String, String> property;
983}
984{
985 ( <LEFTPAREN> property = Property()
986 {
987 properties.put(property.first, property.second);
988 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800989 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700990 {
991 properties.put(property.first, property.second);
992 }
993 )* <RIGHTPAREN> )?
994 {
995 return properties;
996 }
997}
998
999Pair<String, String> Property() throws ParseException:
1000{
1001 String key;
1002 String value;
1003}
1004{
Till Westmann96c1f172013-08-01 02:05:48 -07001005 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001006 {
1007 try {
1008 value = "" + Long.valueOf(token.image);
1009 } catch (NumberFormatException nfe) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001010 throw new ParseException("inapproriate value: " + token.image);
Till Westmann31c21f92013-05-08 09:21:53 -07001011 }
1012 }
1013 )
1014 {
1015 return new Pair<String, String>(key.toUpperCase(), value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001016 }
vinayakb38b7ca42012-03-05 05:44:15 +00001017}
1018
1019TypeExpression TypeExpr() throws ParseException:
1020{
1021 TypeExpression typeExpr = null;
1022}
1023{
1024 (
1025 typeExpr = RecordTypeDef()
1026 | typeExpr = TypeReference()
1027 | typeExpr = OrderedListTypeDef()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001028 | typeExpr = UnorderedListTypeDef()
1029 )
vinayakb38b7ca42012-03-05 05:44:15 +00001030 {
1031 return typeExpr;
1032 }
1033}
1034
1035RecordTypeDefinition RecordTypeDef() throws ParseException:
1036{
1037 RecordTypeDefinition recType = new RecordTypeDefinition();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001038 RecordTypeDefinition.RecordKind recordKind = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001039}
1040{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001041 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
vinayakb38b7ca42012-03-05 05:44:15 +00001042 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001043 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001044 {
1045 String hint = getHint(token);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001046 if (hint != null) {
vinayakb38b7ca42012-03-05 05:44:15 +00001047 String splits[] = hint.split(" +");
1048 if (splits[0].equals(GEN_FIELDS_HINT)) {
1049 if (splits.length != 5) {
1050 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1051 }
1052 if (!splits[1].equals("int")) {
1053 throw new ParseException("The only supported type for gen-fields is int.");
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001054 }
1055 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
vinayakb38b7ca42012-03-05 05:44:15 +00001056 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001057 recType.setUndeclaredFieldsDataGen(ufdg);
vinayakb38b7ca42012-03-05 05:44:15 +00001058 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001059 }
1060
vinayakb38b7ca42012-03-05 05:44:15 +00001061 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001062 (
1063 RecordField(recType)
1064 ( <COMMA> RecordField(recType) )*
1065 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001066 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001067 {
1068 if (recordKind == null) {
1069 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1070 }
1071 recType.setRecordKind(recordKind);
1072 return recType;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001073 }
vinayakb38b7ca42012-03-05 05:44:15 +00001074}
1075
1076void RecordField(RecordTypeDefinition recType) throws ParseException:
1077{
Till Westmann77cb2f42013-07-15 16:44:19 -07001078 String fieldName;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001079 TypeExpression type = null;
Till Westmann77cb2f42013-07-15 16:44:19 -07001080 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001081}
1082{
Till Westmann77cb2f42013-07-15 16:44:19 -07001083 fieldName = Identifier()
1084 {
1085 String hint = getHint(token);
1086 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1087 }
Till Westmann96c1f172013-08-01 02:05:48 -07001088 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001089 {
1090 recType.addField(fieldName, type, nullable, rfdg);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001091 }
vinayakb38b7ca42012-03-05 05:44:15 +00001092}
1093
1094TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001095{
Till Westmann14a20a72013-05-09 00:06:24 -07001096 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001097}
1098{
1099 id = Identifier()
1100 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001101 if (id.equalsIgnoreCase("int")) {
1102 id = "int64";
1103 }
1104
Till Westmann14a20a72013-05-09 00:06:24 -07001105 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001106 }
vinayakb38b7ca42012-03-05 05:44:15 +00001107}
1108
1109OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001110{
vinayakb38b7ca42012-03-05 05:44:15 +00001111 TypeExpression type = null;
1112}
1113{
Till Westmann96c1f172013-08-01 02:05:48 -07001114 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001115 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001116 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001117 {
1118 return new OrderedListTypeDefinition(type);
1119 }
1120}
1121
1122
1123UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001124{
vinayakb38b7ca42012-03-05 05:44:15 +00001125 TypeExpression type = null;
1126}
1127{
Till Westmann96c1f172013-08-01 02:05:48 -07001128 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001129 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001130 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001131 {
1132 return new UnorderedListTypeDefinition(type);
1133 }
1134}
1135
ramangrover299f76a5e2013-06-18 10:25:17 -07001136FunctionName FunctionName() throws ParseException:
1137{
1138 String first = null;
1139 String second = null;
1140 String third = null;
1141 boolean secondAfterDot = false;
1142}
1143{
zheilbron555dc9d2013-08-14 19:58:00 -07001144 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001145 {
1146 secondAfterDot = true;
1147 }
1148 ("#" third = Identifier())? | "#" second = Identifier() )?
1149 {
1150 FunctionName result = new FunctionName();
1151 if (second == null) {
1152 result.dataverse = defaultDataverse;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001153 result.library = null;
1154 result.function = first;
ramangrover299f76a5e2013-06-18 10:25:17 -07001155 } else if (third == null) {
1156 if (secondAfterDot) {
1157 result.dataverse = first;
1158 result.library = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001159 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001160 } else {
1161 result.dataverse = defaultDataverse;
1162 result.library = first;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001163 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001164 }
1165 } else {
1166 result.dataverse = first;
1167 result.library = second;
1168 result.function = third;
1169 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001170
1171 if (result.function.equalsIgnoreCase("int")) {
1172 result.function = "int64";
1173 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001174 return result;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001175 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001176}
Till Westmann31c21f92013-05-08 09:21:53 -07001177
ramangrover299f76a5e2013-06-18 10:25:17 -07001178
1179Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001180{
Till Westmann31c21f92013-05-08 09:21:53 -07001181 Pair<Identifier,Identifier> name = null;
1182}
1183{
1184 name = QualifiedName()
1185 {
1186 if (name.first == null) {
1187 name.first = new Identifier(defaultDataverse);
1188 }
1189 return name;
1190 }
1191}
1192
Till Westmann14a20a72013-05-09 00:06:24 -07001193String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001194{
Till Westmann68d99652013-05-09 11:15:21 -07001195 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001196}
1197{
1198 <IDENTIFIER>
1199 {
Till Westmann14a20a72013-05-09 00:06:24 -07001200 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001201 }
Till Westmann68d99652013-05-09 11:15:21 -07001202 | lit = StringLiteral()
1203 {
1204 return lit;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001205 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001206}
1207
Till Westmann7d535322013-05-09 00:40:02 -07001208String StringLiteral() throws ParseException:
1209{
1210}
1211{
1212 <STRING_LITERAL>
1213 {
1214 return removeQuotesAndEscapes(token.image);
1215 }
1216}
1217
Till Westmann31c21f92013-05-08 09:21:53 -07001218Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1219{
Till Westmann14a20a72013-05-09 00:06:24 -07001220 String first = null;
1221 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001222}
1223{
Till Westmann96c1f172013-08-01 02:05:48 -07001224 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001225 {
Till Westmann14a20a72013-05-09 00:06:24 -07001226 Identifier id1 = null;
1227 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001228 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001229 id2 = new Identifier(first);
1230 } else
1231 {
1232 id1 = new Identifier(first);
1233 id2 = new Identifier(second);
1234 }
1235 return new Pair<Identifier,Identifier>(id1, id2);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001236 }
1237}
1238
Till Westmann31c21f92013-05-08 09:21:53 -07001239Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001240{
Till Westmann14a20a72013-05-09 00:06:24 -07001241 String first = null;
1242 String second = null;
1243 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001244}
1245{
Till Westmann96c1f172013-08-01 02:05:48 -07001246 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001247 {
Till Westmann14a20a72013-05-09 00:06:24 -07001248 Identifier id1 = null;
1249 Identifier id2 = null;
1250 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001251 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001252 id2 = new Identifier(first);
1253 id3 = new Identifier(second);
1254 } else {
1255 id1 = new Identifier(first);
1256 id2 = new Identifier(second);
1257 id3 = new Identifier(third);
1258 }
1259 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001260 }
1261}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001262
vinayakb38b7ca42012-03-05 05:44:15 +00001263FunctionDecl FunctionDeclaration() throws ParseException:
1264{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001265 FunctionDecl funcDecl;
1266 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001267 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001268 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1269 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001270 createNewScope();
1271}
1272{
Till Westmannd7dcb122013-05-16 13:19:09 -07001273 "declare" "function" functionName = Identifier()
1274 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001275 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001276 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001277 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001278 getCurrentScope().addFunctionDescriptor(signature, false);
1279 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001280 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001281 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001282 }
1283}
1284
vinayakb38b7ca42012-03-05 05:44:15 +00001285
Till Westmann31c21f92013-05-08 09:21:53 -07001286Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001287{
1288 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001289 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1290 setDataverses(query.getDataverses());
1291 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001292 Expression expr;
1293}
1294{
Till Westmann31c21f92013-05-08 09:21:53 -07001295 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001296 {
1297 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001298 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001299 // we remove the pointers to the locked entities before we return the query object
1300 setDataverses(null);
1301 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001302 return query;
1303 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001304
vinayakb38b7ca42012-03-05 05:44:15 +00001305}
1306
1307
1308
1309Expression Expression():
1310{
1311 Expression expr = null;
1312 Expression exprP = null;
1313}
1314{
1315(
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001316
vinayakb38b7ca42012-03-05 05:44:15 +00001317//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1318 expr = OperatorExpr()
1319 | expr = IfThenElse()
1320 | expr = FLWOGR()
1321 | expr = QuantifiedExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001322
vinayakb38b7ca42012-03-05 05:44:15 +00001323
1324)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001325 {
1326 return (exprP==null) ? expr : exprP;
1327 }
vinayakb38b7ca42012-03-05 05:44:15 +00001328}
1329
1330
1331
1332Expression OperatorExpr()throws ParseException:
1333{
1334 OperatorExpr op = null;
1335 Expression operand = null;
1336}
1337{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001338 operand = AndExpr()
1339 (
1340
1341 <OR>
1342 {
1343 if (op == null) {
1344 op = new OperatorExpr();
1345 op.addOperand(operand);
1346 op.setCurrentop(true);
1347 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001348 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001349 }
vinayakb38b7ca42012-03-05 05:44:15 +00001350
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001351 operand = AndExpr()
1352 {
1353 op.addOperand(operand);
1354 }
vinayakb38b7ca42012-03-05 05:44:15 +00001355
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001356 )*
1357
1358 {
1359 return op==null? operand: op;
1360 }
vinayakb38b7ca42012-03-05 05:44:15 +00001361}
1362
1363Expression AndExpr()throws ParseException:
1364{
1365 OperatorExpr op = null;
1366 Expression operand = null;
1367}
1368{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001369 operand = RelExpr()
1370 (
1371
1372 <AND>
1373 {
1374 if (op == null) {
1375 op = new OperatorExpr();
1376 op.addOperand(operand);
1377 op.setCurrentop(true);
1378 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001379 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001380 }
vinayakb38b7ca42012-03-05 05:44:15 +00001381
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001382 operand = RelExpr()
1383 {
1384 op.addOperand(operand);
1385 }
vinayakb38b7ca42012-03-05 05:44:15 +00001386
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001387 )*
1388
1389 {
1390 return op==null? operand: op;
1391 }
vinayakb38b7ca42012-03-05 05:44:15 +00001392}
1393
1394
1395
1396Expression RelExpr()throws ParseException:
1397{
1398 OperatorExpr op = null;
1399 Expression operand = null;
1400 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001401 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001402}
1403{
1404 operand = AddExpr()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001405 {
1406 if (operand instanceof VariableExpr) {
1407 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001408 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001409 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001410 }
1411 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001412 }
vinayakb38b7ca42012-03-05 05:44:15 +00001413
1414 (
Till Westmann96c1f172013-08-01 02:05:48 -07001415 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001416 {
1417 String mhint = getHint(token);
1418 if (mhint != null) {
1419 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
salsubaieedf89fbc2013-12-21 19:51:42 -08001420 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1421 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1422 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1423 }
alexander.behm07617fd2012-07-25 10:13:50 +00001424 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001425 if (op == null) {
1426 op = new OperatorExpr();
1427 op.addOperand(operand, broadcast);
vinayakb38b7ca42012-03-05 05:44:15 +00001428 op.setCurrentop(true);
1429 broadcast = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001430 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001431 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001432 }
1433
1434 operand = AddExpr()
1435 {
1436 broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001437 if (operand instanceof VariableExpr) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001438 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001439 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1440 broadcast = true;
1441 }
alexander.behm07617fd2012-07-25 10:13:50 +00001442 }
vinayakb38b7ca42012-03-05 05:44:15 +00001443 op.addOperand(operand, broadcast);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001444 }
vinayakb38b7ca42012-03-05 05:44:15 +00001445 )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001446
1447 {
1448 if (annotation != null) {
1449 op.addHint(annotation);
1450 }
1451 return op==null? operand: op;
1452 }
vinayakb38b7ca42012-03-05 05:44:15 +00001453}
1454
1455Expression AddExpr()throws ParseException:
1456{
1457 OperatorExpr op = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001458 Expression operand = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001459}
1460{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001461 operand = MultExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001462
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001463 ( (<PLUS> | <MINUS>)
1464 {
1465 if (op == null) {
1466 op = new OperatorExpr();
1467 op.addOperand(operand);
1468 op.setCurrentop(true);
1469 }
1470 ((OperatorExpr)op).addOperator(token.image);
1471 }
vinayakb38b7ca42012-03-05 05:44:15 +00001472
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001473 operand = MultExpr()
1474 {
1475 op.addOperand(operand);
1476 }
1477 )*
1478
1479 {
1480 return op==null? operand: op;
1481 }
vinayakb38b7ca42012-03-05 05:44:15 +00001482}
1483
1484Expression MultExpr()throws ParseException:
1485{
1486 OperatorExpr op = null;
1487 Expression operand = null;
1488}
1489{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001490 operand = UnionExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001491
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001492 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1493 {
1494 if (op == null) {
1495 op = new OperatorExpr();
vinayakb38b7ca42012-03-05 05:44:15 +00001496 op.addOperand(operand);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001497 op.setCurrentop(true);
1498 }
1499 op.addOperator(token.image);
1500 }
1501 operand = UnionExpr()
1502 {
1503 op.addOperand(operand);
1504 }
1505 )*
1506
1507 {
1508 return op==null?operand:op;
1509 }
vinayakb38b7ca42012-03-05 05:44:15 +00001510}
1511
1512Expression UnionExpr() throws ParseException:
1513{
1514 UnionExpr union = null;
1515 Expression operand1 = null;
1516 Expression operand2 = null;
1517}
1518{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001519 operand1 = UnaryExpr()
1520 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001521 (operand2 = UnaryExpr()) {
1522 if (union == null) {
1523 union = new UnionExpr();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001524 union.addExpr(operand1);
vinayakb38b7ca42012-03-05 05:44:15 +00001525 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001526 union.addExpr(operand2);
vinayakb38b7ca42012-03-05 05:44:15 +00001527 } )*
1528 {
1529 return (union == null)? operand1: union;
1530 }
1531}
1532
1533Expression UnaryExpr() throws ParseException:
1534{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001535 Expression uexpr = null;
1536 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001537}
1538{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001539 ( (<PLUS> | <MINUS>)
1540 {
1541 uexpr = new UnaryExpr();
1542 if("+".equals(token.image))
1543 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1544 else if("-".equals(token.image))
1545 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1546 else
1547 throw new ParseException();
1548 }
1549 )?
1550
1551 expr = ValueExpr()
1552 {
1553 if(uexpr!=null){
1554 ((UnaryExpr)uexpr).setExpr(expr);
1555 return uexpr;
1556 }
1557 else{
1558 return expr;
1559 }
1560 }
vinayakb38b7ca42012-03-05 05:44:15 +00001561}
1562
Till Westmann04478e72013-05-13 23:01:34 -07001563Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001564{
1565 Expression expr = null;
1566 Identifier ident = null;
1567 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001568 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001569}
1570{
Till Westmann04478e72013-05-13 23:01:34 -07001571 expr = PrimaryExpr() ( ident = Field()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001572 {
1573 fa = (fa == null ? new FieldAccessor(expr, ident)
Till Westmann04478e72013-05-13 23:01:34 -07001574 : new FieldAccessor(fa, ident));
1575 }
icetindila611ac72014-05-16 10:10:11 -07001576 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001577 {
icetindila611ac72014-05-16 10:10:11 -07001578 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1579 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001580 }
1581 )*
1582 {
1583 return fa == null ? expr : fa;
1584 }
vinayakb38b7ca42012-03-05 05:44:15 +00001585}
1586
1587Identifier Field() throws ParseException:
1588{
Till Westmann14a20a72013-05-09 00:06:24 -07001589 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001590}
1591{
Till Westmann96c1f172013-08-01 02:05:48 -07001592 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001593 {
Till Westmann14a20a72013-05-09 00:06:24 -07001594 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001595 }
vinayakb38b7ca42012-03-05 05:44:15 +00001596}
1597
icetindila611ac72014-05-16 10:10:11 -07001598Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001599{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001600 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001601}
1602{
Till Westmann96c1f172013-08-01 02:05:48 -07001603 <LEFTBRACKET> ( expr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001604 {
1605 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1606 {
1607 Literal lit = ((LiteralExpr)expr).getValue();
1608 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1609 lit.getLiteralType() != Literal.Type.LONG) {
1610 throw new ParseException("Index should be an INTEGER");
vinayakb38b7ca42012-03-05 05:44:15 +00001611 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001612 }
1613 }
vinayakb38b7ca42012-03-05 05:44:15 +00001614
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001615 | <QUES> // ANY
1616
1617 )
vinayakb38b7ca42012-03-05 05:44:15 +00001618
Till Westmann96c1f172013-08-01 02:05:48 -07001619 <RIGHTBRACKET>
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001620 {
1621 return expr;
1622 }
vinayakb38b7ca42012-03-05 05:44:15 +00001623}
1624
1625
1626Expression PrimaryExpr()throws ParseException:
1627{
1628 Expression expr = null;
1629}
1630{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001631 ( LOOKAHEAD(2)
Till Westmann68d99652013-05-09 11:15:21 -07001632 expr = FunctionCallExpr()
1633 | expr = Literal()
1634 | expr = DatasetAccessExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001635 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001636 {
1637 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001638 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001639 }
Till Westmann68d99652013-05-09 11:15:21 -07001640 | expr = ListConstructor()
1641 | expr = RecordConstructor()
1642 | expr = ParenthesizedExpression()
1643 )
1644 {
1645 return expr;
1646 }
vinayakb38b7ca42012-03-05 05:44:15 +00001647}
1648
1649Expression Literal() throws ParseException:
1650{
vinayakb38b7ca42012-03-05 05:44:15 +00001651 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001652 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001653}
1654{
Till Westmann7d535322013-05-09 00:40:02 -07001655 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001656 {
Till Westmann7d535322013-05-09 00:40:02 -07001657 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001658 }
1659 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001660 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001661 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
Till Westmanna4242bc2013-05-08 17:49:55 -07001662 }
1663 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001664 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001665 lit.setValue(new FloatLiteral(new Float(token.image)));
1666 }
1667 | <DOUBLE_LITERAL>
1668 {
1669 lit.setValue(new DoubleLiteral(new Double(token.image)));
1670 }
1671 | <NULL>
1672 {
1673 lit.setValue(NullLiteral.INSTANCE);
1674 }
1675 | <TRUE>
1676 {
1677 lit.setValue(TrueLiteral.INSTANCE);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001678 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001679 | <FALSE>
1680 {
1681 lit.setValue(FalseLiteral.INSTANCE);
1682 }
1683 )
vinayakb38b7ca42012-03-05 05:44:15 +00001684 {
1685 return lit;
1686 }
1687}
1688
1689
1690VariableExpr VariableRef() throws ParseException:
1691{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001692 VariableExpr varExp = new VariableExpr();
1693 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001694}
1695{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001696 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001697 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001698 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001699 Identifier ident = lookupSymbol(varName);
1700 if (isInForbiddenScopes(varName)) {
1701 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.");
1702 }
1703 if(ident != null) { // exist such ident
1704 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001705 varExp.setVar((VarIdentifier)ident);
vinayakb38b7ca42012-03-05 05:44:15 +00001706 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001707 varExp.setVar(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001708 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001709 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001710 return varExp;
1711 }
1712}
1713
1714
1715VariableExpr Variable() throws ParseException:
1716{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001717 VariableExpr varExp = new VariableExpr();
1718 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001719}
1720{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001721 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001722 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001723 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001724 if(ident != null) { // exist such ident
1725 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001726 }
1727 varExp.setVar(var);
1728 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001729 return varExp;
1730 }
1731}
1732
1733Expression ListConstructor() throws ParseException:
1734{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001735 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001736}
1737{
1738 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001739 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
vinayakb38b7ca42012-03-05 05:44:15 +00001740 )
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001741
vinayakb38b7ca42012-03-05 05:44:15 +00001742 {
1743 return expr;
1744 }
1745}
1746
1747
1748ListConstructor OrderedListConstructor() throws ParseException:
1749{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001750 ListConstructor expr = new ListConstructor();
1751 Expression tmp = null;
1752 List<Expression> exprList = new ArrayList<Expression>();
1753 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001754}
1755{
1756
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001757 <LEFTBRACKET>
1758 ( tmp = Expression()
1759 {
1760 exprList.add(tmp);
1761 }
1762
1763 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
1764 )?
1765
Till Westmann96c1f172013-08-01 02:05:48 -07001766 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001767
1768 {
1769 expr.setExprList(exprList);
1770 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001771 }
vinayakb38b7ca42012-03-05 05:44:15 +00001772}
1773
1774ListConstructor UnorderedListConstructor() throws ParseException:
1775{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001776 ListConstructor expr = new ListConstructor();
1777 Expression tmp = null;
1778 List<Expression> exprList = new ArrayList<Expression>();
1779 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001780}
1781{
1782
Till Westmann96c1f172013-08-01 02:05:48 -07001783 <LEFTDBLBRACE> ( tmp = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001784 {
1785 exprList.add(tmp);
1786 }
Till Westmann96c1f172013-08-01 02:05:48 -07001787 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001788 {
1789 expr.setExprList(exprList);
1790 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001791 }
vinayakb38b7ca42012-03-05 05:44:15 +00001792}
1793
1794RecordConstructor RecordConstructor() throws ParseException:
1795{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001796 RecordConstructor expr = new RecordConstructor();
1797 FieldBinding tmp = null;
1798 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
vinayakb38b7ca42012-03-05 05:44:15 +00001799}
1800{
Till Westmann96c1f172013-08-01 02:05:48 -07001801 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001802 {
1803 fbList.add(tmp);
1804 }
Till Westmann96c1f172013-08-01 02:05:48 -07001805 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001806 {
1807 expr.setFbList(fbList);
1808 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001809 }
vinayakb38b7ca42012-03-05 05:44:15 +00001810}
1811
1812FieldBinding FieldBinding() throws ParseException:
1813{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001814 FieldBinding fb = new FieldBinding();
1815 Expression left, right;
vinayakb38b7ca42012-03-05 05:44:15 +00001816}
1817{
Till Westmann96c1f172013-08-01 02:05:48 -07001818 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001819 {
1820 fb.setLeftExpr(left);
1821 fb.setRightExpr(right);
1822 return fb;
1823 }
1824}
1825
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001826
vinayakb38b7ca42012-03-05 05:44:15 +00001827Expression FunctionCallExpr() throws ParseException:
1828{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001829 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001830 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001831 Expression tmp;
1832 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001833 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001834 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001835}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001836{
ramangrover299f76a5e2013-06-18 10:25:17 -07001837 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001838 {
Till Westmann31c21f92013-05-08 09:21:53 -07001839 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001840 }
Till Westmann31c21f92013-05-08 09:21:53 -07001841 <LEFTPAREN> (tmp = Expression()
1842 {
1843 argList.add(tmp);
1844 arity ++;
1845 }
Till Westmann96c1f172013-08-01 02:05:48 -07001846 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001847 {
1848 argList.add(tmp);
1849 arity++;
1850 }
1851 )*)? <RIGHTPAREN>
1852 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001853 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001854 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001855 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001856 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001857 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001858 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001859 }
1860 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001861 if (hint != null) {
1862 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1863 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1864 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1865 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1866 }
Till Westmann31c21f92013-05-08 09:21:53 -07001867 }
1868 return callExpr;
1869 }
vinayakb38b7ca42012-03-05 05:44:15 +00001870}
1871
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001872
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001873Expression DatasetAccessExpression() throws ParseException:
1874{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001875 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001876 String arg1 = null;
1877 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001878 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001879}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001880{
Till Westmann14a20a72013-05-09 00:06:24 -07001881 <DATASET>
1882 {
Till Westmann14a20a72013-05-09 00:06:24 -07001883 funcName = token.image;
1884 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001885 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001886 {
1887 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001888 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001889 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001890 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001891 if(arg2 != null){
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001892 addDataverse(arg1.toString());
1893 addDataset(name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001894 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001895 addDataset(defaultDataverse + "." + name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001896 }
Till Westmann14a20a72013-05-09 00:06:24 -07001897 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001898 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001899 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001900 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1901 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1902 if (signature == null) {
1903 signature = new FunctionSignature(dataverse, funcName, 1);
1904 }
1905 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001906 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001907 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001908 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001909}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001910
vinayakb38b7ca42012-03-05 05:44:15 +00001911Expression ParenthesizedExpression() throws ParseException:
1912{
1913 Expression expr;
1914}
1915{
1916 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1917 {
1918 return expr;
1919 }
1920}
1921
1922Expression IfThenElse() throws ParseException:
1923{
1924 Expression condExpr;
1925 Expression thenExpr;
1926 Expression elseExpr;
1927 IfExpr ifExpr = new IfExpr();
1928}
1929{
Till Westmann96c1f172013-08-01 02:05:48 -07001930 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001931
1932 {
1933 ifExpr.setCondExpr(condExpr);
1934 ifExpr.setThenExpr(thenExpr);
1935 ifExpr.setElseExpr(elseExpr);
1936 return ifExpr;
1937 }
1938}
1939
1940Expression FLWOGR() throws ParseException:
1941{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001942 FLWOGRExpression flworg = new FLWOGRExpression();
1943 List<Clause> clauseList = new ArrayList<Clause>();
1944 Expression returnExpr;
1945 Clause tmp;
1946 createNewScope();
vinayakb38b7ca42012-03-05 05:44:15 +00001947}
1948{
1949 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08001950 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001951
1952 {
1953 flworg.setClauseList(clauseList);
1954 flworg.setReturnExpr(returnExpr);
1955 removeCurrentScope();
1956 return flworg;
1957 }
1958}
1959
1960Clause Clause()throws ParseException :
1961{
1962 Clause clause;
1963}
1964{
1965 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001966 clause = ForClause()
1967 | clause = LetClause()
1968 | clause = WhereClause()
1969 | clause = OrderbyClause()
1970 | clause = GroupClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001971 | clause = LimitClause()
1972 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001973 )
1974 {
1975 return clause;
1976 }
1977}
1978
1979Clause ForClause()throws ParseException :
1980{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001981 ForClause fc = new ForClause();
1982 VariableExpr varExp;
1983 VariableExpr varPos = null;
1984 Expression inExp;
1985 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00001986}
1987{
buyingyi2fd7fa62014-11-24 19:31:55 -08001988 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001989 {
1990 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001991 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001992 fc.setInExpr(inExp);
1993 if (varPos != null) {
1994 fc.setPosExpr(varPos);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001995 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001996 }
1997 return fc;
1998 }
1999}
2000
2001Clause LetClause() throws ParseException:
2002{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002003 LetClause lc = new LetClause();
2004 VariableExpr varExp;
2005 Expression beExp;
2006 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002007}
2008{
buyingyi2fd7fa62014-11-24 19:31:55 -08002009 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002010 {
2011 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002012 lc.setVarExpr(varExp);
2013 lc.setBeExpr(beExp);
2014 return lc;
2015 }
2016}
2017
2018Clause WhereClause()throws ParseException :
2019{
2020 WhereClause wc = new WhereClause();
2021 Expression whereExpr;
2022}
2023{
salsubaieedf89fbc2013-12-21 19:51:42 -08002024 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002025 {
2026 wc.setWhereExpr(whereExpr);
2027 return wc;
2028 }
2029}
2030
2031Clause OrderbyClause()throws ParseException :
2032{
2033 OrderbyClause oc = new OrderbyClause();
2034 Expression orderbyExpr;
2035 List<Expression> orderbyList = new ArrayList<Expression>();
2036 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2037 int numOfOrderby = 0;
2038}
2039{
2040 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002041 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002042 {
2043 String hint = getHint(token);
2044 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002045 String splits[] = hint.split(" +");
vinayakb38b7ca42012-03-05 05:44:15 +00002046 int numFrames = Integer.parseInt(splits[1]);
2047 int numTuples = Integer.parseInt(splits[2]);
2048 oc.setNumFrames(numFrames);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002049 oc.setNumTuples(numTuples);
2050 }
2051 }
Till Westmann96c1f172013-08-01 02:05:48 -07002052 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002053 {
2054 orderbyList.add(orderbyExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002055 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
vinayakb38b7ca42012-03-05 05:44:15 +00002056 }
Till Westmann96c1f172013-08-01 02:05:48 -07002057 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2058 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002059 {
2060 modifierList.add(modif);
2061 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002062
Till Westmann96c1f172013-08-01 02:05:48 -07002063 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002064 {
2065 orderbyList.add(orderbyExpr);
2066 modif = OrderbyClause.OrderModifier.ASC;
2067 }
Till Westmann96c1f172013-08-01 02:05:48 -07002068 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2069 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002070 {
2071 modifierList.add(modif);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002072 }
vinayakb38b7ca42012-03-05 05:44:15 +00002073 )*
2074)
2075 {
2076 oc.setModifierList(modifierList);
2077 oc.setOrderbyList(orderbyList);
2078 return oc;
2079 }
2080}
2081Clause GroupClause()throws ParseException :
2082{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002083 GroupbyClause gbc = new GroupbyClause();
2084 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2085 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
vinayakb38b7ca42012-03-05 05:44:15 +00002086 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002087 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2088 VariableExpr var = null;
2089 VariableExpr withVar = null;
2090 Expression expr = null;
2091 VariableExpr decorVar = null;
2092 Expression decorExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002093}
2094{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002095 {
2096 Scope newScope = extendCurrentScopeNoPush(true);
2097 // extendCurrentScope(true);
2098 }
Till Westmann96c1f172013-08-01 02:05:48 -07002099 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002100 {
2101 String hint = getHint(token);
2102 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002103 gbc.setHashGroupByHint(true);
2104 }
2105 }
Till Westmann96c1f172013-08-01 02:05:48 -07002106 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002107 {
2108 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002109 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002110 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002111 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002112 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002113 vePairList.add(pair1);
2114 }
Till Westmann96c1f172013-08-01 02:05:48 -07002115 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002116 {
2117 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002118 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002119 expr = Expression()
2120 {
2121 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002122 vePairList.add(pair2);
2123 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002124 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002125 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002126 {
2127 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002128 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2129 decorPairList.add(pair3);
2130 }
Till Westmann96c1f172013-08-01 02:05:48 -07002131 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002132 {
2133 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002134 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002135 decorPairList.add(pair4);
vinayakb38b7ca42012-03-05 05:44:15 +00002136 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002137 )*
2138 )?
buyingyi3ca46d02015-01-27 23:22:09 -08002139 (<WITH>|<KEEPING>) withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002140 {
2141 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002142 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002143 withVarList.add(withVar);
2144 newScope.addNewVarSymbolToScope(withVar.getVar());
2145 }
Till Westmann96c1f172013-08-01 02:05:48 -07002146 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002147 {
2148 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002149 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002150 withVarList.add(withVar);
2151 newScope.addNewVarSymbolToScope(withVar.getVar());
2152 })*
2153 {
2154 gbc.setGbyPairList(vePairList);
2155 gbc.setDecorPairList(decorPairList);
2156 gbc.setWithVarList(withVarList);
2157 replaceCurrentScope(newScope);
2158 return gbc;
2159 }
2160}
2161
2162
2163LimitClause LimitClause() throws ParseException:
2164{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002165 LimitClause lc = new LimitClause();
2166 Expression expr;
2167 pushForbiddenScope(getCurrentScope());
vinayakb38b7ca42012-03-05 05:44:15 +00002168}
2169{
Till Westmann96c1f172013-08-01 02:05:48 -07002170 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2171 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002172
2173 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002174 popForbiddenScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002175 return lc;
2176 }
2177}
2178
2179DistinctClause DistinctClause() throws ParseException:
2180{
2181 List<Expression> exprs = new ArrayList<Expression>();
2182 Expression expr;
2183}
2184{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002185 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002186 {
2187 exprs.add(expr);
2188 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002189 (<COMMA> expr = Expression()
2190 {
2191 exprs.add(expr);
2192 }
vinayakb38b7ca42012-03-05 05:44:15 +00002193 )*
2194 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002195 return new DistinctClause(exprs);
vinayakb38b7ca42012-03-05 05:44:15 +00002196 }
2197}
2198
vinayakb38b7ca42012-03-05 05:44:15 +00002199QuantifiedExpression QuantifiedExpression()throws ParseException:
2200{
2201 QuantifiedExpression qc = new QuantifiedExpression();
2202 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2203 Expression satisfiesExpr;
2204 VariableExpr var;
2205 Expression inExpr;
2206 QuantifiedPair pair;
2207}
2208{
2209 {
2210 createNewScope();
2211 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002212
Till Westmann96c1f172013-08-01 02:05:48 -07002213 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002214 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2215 var = Variable() <IN> inExpr = Expression()
2216 {
vinayakb38b7ca42012-03-05 05:44:15 +00002217 pair = new QuantifiedPair(var, inExpr);
2218 getCurrentScope().addNewVarSymbolToScope(var.getVar());
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002219 quantifiedList.add(pair);
2220 }
2221 (
2222 <COMMA> var = Variable() <IN> inExpr = Expression()
2223 {
2224 pair = new QuantifiedPair(var, inExpr);
2225 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2226 quantifiedList.add(pair);
2227 }
2228 )*
2229 <SATISFIES> satisfiesExpr = Expression()
2230 {
2231 qc.setSatisfiesExpr(satisfiesExpr);
2232 qc.setQuantifiedList(quantifiedList);
2233 removeCurrentScope();
2234 return qc;
2235 }
vinayakb38b7ca42012-03-05 05:44:15 +00002236}
2237
2238TOKEN_MGR_DECLS:
2239{
Till Westmann96c1f172013-08-01 02:05:48 -07002240 public int commentDepth = 0;
2241 public IntStack lexerStateStack = new IntStack();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002242
Till Westmann96c1f172013-08-01 02:05:48 -07002243 public void pushState() {
2244 lexerStateStack.push( curLexState );
2245 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002246
Till Westmannfd733ee2014-07-10 00:57:37 -07002247 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002248 if (lexerStateStack.size() > 0) {
2249 SwitchTo( lexerStateStack.pop() );
2250 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002251 int errorLine = input_stream.getEndLine();
2252 int errorColumn = input_stream.getEndColumn();
2253 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2254 + "\" but state stack is empty.";
2255 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002256 }
2257 }
vinayakb38b7ca42012-03-05 05:44:15 +00002258}
2259
Till Westmann96c1f172013-08-01 02:05:48 -07002260<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002261TOKEN :
2262{
Till Westmann5df7b452013-08-02 13:07:16 -07002263 <ASC : "asc">
2264 | <AT : "at">
2265 | <BY : "by">
2266 | <DATASET : "dataset">
2267 | <DECOR : "decor">
2268 | <DESC : "desc">
2269 | <DISTINCT : "distinct">
2270 | <ELSE : "else">
2271 | <EVERY : "every">
2272 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002273 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002274 | <GROUP : "group">
2275 | <IF : "if">
2276 | <IN : "in">
2277 | <LET : "let">
2278 | <LIMIT : "limit">
2279 | <OFFSET : "offset">
2280 | <ORDER : "order">
2281 | <RETURN : "return">
2282 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002283 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002284 | <SOME : "some">
2285 | <THEN : "then">
2286 | <UNION : "union">
2287 | <WHERE : "where">
2288 | <WITH : "with">
buyingyi3ca46d02015-01-27 23:22:09 -08002289 | <KEEPING : "keeping">
vinayakb38b7ca42012-03-05 05:44:15 +00002290}
2291
Till Westmann96c1f172013-08-01 02:05:48 -07002292<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002293TOKEN :
2294{
Till Westmann5df7b452013-08-02 13:07:16 -07002295 <CARET : "^">
2296 | <DIV : "/">
2297 | <IDIV : "idiv">
2298 | <MINUS : "-">
2299 | <MOD : "%">
2300 | <MUL : "*">
2301 | <PLUS : "+">
2302
2303 | <LEFTPAREN : "(">
2304 | <RIGHTPAREN : ")">
2305 | <LEFTBRACKET : "[">
2306 | <RIGHTBRACKET : "]">
2307
2308 | <COLON : ":">
2309 | <COMMA : ",">
2310 | <DOT : ".">
2311 | <QUES : "?">
2312
2313 | <LT : "<">
2314 | <GT : ">">
2315 | <LE : "<=">
2316 | <GE : ">=">
2317 | <EQ : "=">
2318 | <NE : "!=">
2319 | <SIMILAR : "~=">
2320 | <ASSIGN : ":=">
2321
2322 | <AND : "and">
2323 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002324}
2325
Till Westmann96c1f172013-08-01 02:05:48 -07002326<DEFAULT,IN_DBL_BRACE>
2327TOKEN :
2328{
Till Westmann5df7b452013-08-02 13:07:16 -07002329 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002330}
2331
2332<DEFAULT>
2333TOKEN :
2334{
Till Westmannfd733ee2014-07-10 00:57:37 -07002335 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002336}
2337
Till Westmann96c1f172013-08-01 02:05:48 -07002338<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002339TOKEN :
2340{
Till Westmann5df7b452013-08-02 13:07:16 -07002341 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002342}
2343
Till Westmann96c1f172013-08-01 02:05:48 -07002344<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002345TOKEN :
2346{
Till Westmannfd733ee2014-07-10 00:57:37 -07002347 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
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 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002354}
2355
Till Westmann96c1f172013-08-01 02:05:48 -07002356<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002357TOKEN :
2358{
Till Westmann5df7b452013-08-02 13:07:16 -07002359 <NULL : "null">
2360 | <TRUE : "true">
2361 | <FALSE : "false">
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 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002368}
2369
Till Westmann96c1f172013-08-01 02:05:48 -07002370<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002371TOKEN:
2372{
Till Westmann5df7b452013-08-02 13:07:16 -07002373 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002374 | <DIGITS> ( "." <DIGITS> )?
2375 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002376 >
2377 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002378 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2379 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002380 >
2381 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002382}
2383
Till Westmann96c1f172013-08-01 02:05:48 -07002384<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002385TOKEN :
2386{
Till Westmann5df7b452013-08-02 13:07:16 -07002387 <#LETTER : ["A" - "Z", "a" - "z"]>
2388 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002389}
2390
Till Westmann96c1f172013-08-01 02:05:48 -07002391<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002392TOKEN :
2393{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002394 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2395 <STRING_LITERAL : ("\"" (
2396 <EscapeQuot>
2397 | <EscapeBslash>
2398 | <EscapeSlash>
2399 | <EscapeBspace>
2400 | <EscapeFormf>
2401 | <EscapeNl>
2402 | <EscapeCr>
2403 | <EscapeTab>
2404 | ~["\"","\\"])* "\"")
2405 | ("\'"(
2406 <EscapeApos>
2407 | <EscapeBslash>
2408 | <EscapeSlash>
2409 | <EscapeBspace>
2410 | <EscapeFormf>
2411 | <EscapeNl>
2412 | <EscapeCr>
2413 | <EscapeTab>
2414 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002415 | < #EscapeQuot: "\\\"" >
2416 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002417 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002418 | < #EscapeSlash: "\\/" >
2419 | < #EscapeBspace: "\\b" >
2420 | < #EscapeFormf: "\\f" >
2421 | < #EscapeNl: "\\n" >
2422 | < #EscapeCr: "\\r" >
2423 | < #EscapeTab: "\\t" >
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 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
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 +00002433TOKEN :
2434{
Till Westmann5df7b452013-08-02 13:07:16 -07002435 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002436}
2437
Till Westmann96c1f172013-08-01 02:05:48 -07002438<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002439SKIP:
2440{
2441 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002442 | "\t"
2443 | "\r"
2444 | "\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"])* "\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{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002456 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002457}
2458
Till Westmann96c1f172013-08-01 02:05:48 -07002459<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002460SKIP:
2461{
Till Westmann96c1f172013-08-01 02:05:48 -07002462 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002463}
2464
2465<INSIDE_COMMENT>
2466SPECIAL_TOKEN:
2467{
Till Westmann5df7b452013-08-02 13:07:16 -07002468 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002469}
2470
2471<INSIDE_COMMENT>
2472SKIP:
2473{
Till Westmann96c1f172013-08-01 02:05:48 -07002474 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002475}
2476
2477<INSIDE_COMMENT>
2478SKIP:
2479{
Till Westmannfd733ee2014-07-10 00:57:37 -07002480 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002481 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002482}