blob: 7ed63b172c2dfd4255a409c30b6668480a5ba5de [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;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700323 List<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;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700329 List<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())? )?
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700364 ( "with filter on" filterField = NestedField() )?
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;
Till Westmann31c21f92013-05-08 09:21:53 -0700428 boolean ifNotExists = false;
429 Pair<Identifier,Identifier> nameComponents = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700430 Pair<List<String>, TypeExpression> fieldPair = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700431 IndexParams indexType = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700432 boolean enforced = false;
Till Westmann31c21f92013-05-08 09:21:53 -0700433}
434{
Till Westmanna4242bc2013-05-08 17:49:55 -0700435 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700436 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800437 "on" nameComponents = QualifiedName()
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700438 <LEFTPAREN> ( fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700439 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700440 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700441 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700442 ) (<COMMA> fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700443 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700444 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700445 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700446 )* <RIGHTPAREN> ( "type" indexType = IndexType() )? ( "enforced" { enforced = true; } )?
Till Westmann31c21f92013-05-08 09:21:53 -0700447 {
Till Westmann14a20a72013-05-09 00:06:24 -0700448 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700449 cis.setIfNotExists(ifNotExists);
450 cis.setDataverseName(nameComponents.first);
451 cis.setDatasetName(nameComponents.second);
452 if (indexType != null) {
453 cis.setIndexType(indexType.type);
454 cis.setGramLength(indexType.gramLength);
455 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700456 cis.setEnforced(enforced);
Till Westmann31c21f92013-05-08 09:21:53 -0700457 return cis;
458 }
459}
460
salsubaiee0b423fa2013-09-19 19:16:48 -0700461String CompactionPolicy() throws ParseException :
462{
463 String compactionPolicy = null;
464}
465{
466 compactionPolicy = Identifier()
467 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800468 return compactionPolicy;
salsubaiee0b423fa2013-09-19 19:16:48 -0700469 }
470}
471
salsubaieea5af4e02014-07-08 15:20:02 -0700472String FilterField() throws ParseException :
473{
474 String filterField = null;
475}
476{
477 filterField = Identifier()
478 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800479 return filterField;
salsubaieea5af4e02014-07-08 15:20:02 -0700480 }
481}
482
Till Westmann31c21f92013-05-08 09:21:53 -0700483IndexParams IndexType() throws ParseException:
484{
485 IndexType type = null;
486 int gramLength = 0;
487}
488{
489 ("btree"
490 {
491 type = IndexType.BTREE;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800492 }
Till Westmann31c21f92013-05-08 09:21:53 -0700493 | "rtree"
494 {
495 type = IndexType.RTREE;
496 }
497 | "keyword"
498 {
JIMAHNb75446d2013-06-03 08:35:27 -0700499 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700500 }
501 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
502 {
JIMAHNb75446d2013-06-03 08:35:27 -0700503 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700504 gramLength = Integer.valueOf(token.image);
505 }
506 <RIGHTPAREN>)
507 {
508 return new IndexParams(type, gramLength);
509 }
510}
511
512CreateDataverseStatement DataverseSpecification() throws ParseException :
513{
Till Westmann14a20a72013-05-09 00:06:24 -0700514 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700515 boolean ifNotExists = false;
516 String format = null;
517}
518{
Till Westmanna4242bc2013-05-08 17:49:55 -0700519 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700520 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700521 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700522 {
Till Westmann14a20a72013-05-09 00:06:24 -0700523 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700524 }
525}
526
527CreateFunctionStatement FunctionSpecification() throws ParseException:
528{
529 FunctionSignature signature;
530 boolean ifNotExists = false;
531 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
532 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700533 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700534 Expression functionBodyExpr;
535 Token beginPos;
536 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700537 FunctionName fctName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800538
Till Westmann31c21f92013-05-08 09:21:53 -0700539 createNewScope();
540}
541{
ramangrover299f76a5e2013-06-18 10:25:17 -0700542 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700543 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700544 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700545 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530546 {
547 beginPos = token;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800548 }
Till Westmann96c1f172013-08-01 02:05:48 -0700549 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700550 {
551 endPos = token;
552 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700553 // TODO use fctName.library
554 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700555 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800556 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700557 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
558 }
559}
560
ramangrover29a774ef22013-07-17 09:29:18 -0700561CreateFeedStatement FeedSpecification() throws ParseException:
562{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800563 Pair<Identifier,Identifier> nameComponents = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700564 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700565 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700566 Map<String,String> properties = null;
567 FunctionSignature appliedFunction = null;
568 CreateFeedStatement cfs = null;
569}
570{
571 (
572 "feed" nameComponents = QualifiedName()
573 ifNotExists = IfNotExists()
Chris Hillerye64055d2014-10-11 00:14:39 -0700574 "using" adapterName = AdapterName() properties = Configuration()
ramangrover29a774ef22013-07-17 09:29:18 -0700575 (appliedFunction = ApplyFunction())?
576 {
577 cfs = new CreateFeedStatement(nameComponents.first,
Chris Hillerye64055d2014-10-11 00:14:39 -0700578 nameComponents.second, adapterName, properties, appliedFunction, ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800579 }
580
ramangrover29a774ef22013-07-17 09:29:18 -0700581 )
582 {
583 return cfs;
584 }
585}
586
587
588
Till Westmannd7dcb122013-05-16 13:19:09 -0700589List<VarIdentifier> ParameterList() throws ParseException:
590{
591 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
592 VarIdentifier var = null;
593}
594{
Till Westmann31c21f92013-05-08 09:21:53 -0700595 <LEFTPAREN> (<VARIABLE>
596 {
597 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700598 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700599 paramList.add(var);
600 getCurrentScope().addNewVarSymbolToScope(var);
601 }
Till Westmann96c1f172013-08-01 02:05:48 -0700602 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700603 {
604 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700605 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700606 paramList.add(var);
607 getCurrentScope().addNewVarSymbolToScope(var);
608 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700609 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700610 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700611 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700612 }
613}
614
615boolean IfNotExists() throws ParseException:
616{
617}
618{
619 ( "if not exists"
620 {
621 return true;
622 }
623 )?
624 {
625 return false;
626 }
627}
628
629FunctionSignature ApplyFunction() throws ParseException:
630{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530631 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700632 FunctionSignature funcSig = null;
633}
634{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530635 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700636 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530637 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
638 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700639 }
640}
641
ramangrover29566b3a92013-05-28 09:07:10 -0700642String GetPolicy() throws ParseException:
643{
644 String policy = null;
645}
646{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800647 "using" "policy" policy = Identifier()
ramangrover29566b3a92013-05-28 09:07:10 -0700648 {
649 return policy;
650 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800651
652}
ramangrover29566b3a92013-05-28 09:07:10 -0700653
Till Westmann31c21f92013-05-08 09:21:53 -0700654FunctionSignature FunctionSignature() throws ParseException:
655{
ramangrover299f76a5e2013-06-18 10:25:17 -0700656 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700657 int arity = 0;
658}
659{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800660 fctName = FunctionName() "@" <INTEGER_LITERAL>
661 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700662 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700663 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
664 throw new ParseException(" invalid arity:" + arity);
665 }
666
ramangrover299f76a5e2013-06-18 10:25:17 -0700667 // TODO use fctName.library
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800668 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700669 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700670 }
671}
672
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700673List<List<String>> PrimaryKey() throws ParseException:
Till Westmann31c21f92013-05-08 09:21:53 -0700674{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700675 List<String> tmp = null;
676 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Till Westmann31c21f92013-05-08 09:21:53 -0700677}
678{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700679 "primary" "key" tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700680 {
Till Westmann14a20a72013-05-09 00:06:24 -0700681 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700682 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700683 ( <COMMA> tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700684 {
Till Westmann14a20a72013-05-09 00:06:24 -0700685 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700686 }
687 )*
688 {
689 return primaryKeyFields;
690 }
691}
692
693Statement DropStatement() throws ParseException:
694{
Till Westmann14a20a72013-05-09 00:06:24 -0700695 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700696 Pair<Identifier,Identifier> pairId = null;
697 Triple<Identifier,Identifier,Identifier> tripleId = null;
698 FunctionSignature funcSig = null;
699 boolean ifExists = false;
700 Statement stmt = null;
701}
702{
703 "drop"
704 (
705 <DATASET> pairId = QualifiedName() ifExists = IfExists()
706 {
707 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
708 }
709 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
710 {
711 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
712 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700713 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700714 {
Till Westmann14a20a72013-05-09 00:06:24 -0700715 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700716 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700717 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700718 {
719 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
720 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700721 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700722 {
Till Westmann14a20a72013-05-09 00:06:24 -0700723 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700724 }
725 | "function" funcSig = FunctionSignature() ifExists = IfExists()
726 {
727 stmt = new FunctionDropStatement(funcSig, ifExists);
728 }
ramangrover29a774ef22013-07-17 09:29:18 -0700729 | "feed" pairId = QualifiedName() ifExists = IfExists()
730 {
731 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800732 }
Till Westmann31c21f92013-05-08 09:21:53 -0700733 )
734 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800735 return stmt;
Till Westmann31c21f92013-05-08 09:21:53 -0700736 }
737}
738
739boolean IfExists() throws ParseException :
740{
741}
742{
Till Westmann96c1f172013-08-01 02:05:48 -0700743 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700744 {
745 return true;
746 }
747 )?
748 {
749 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000750 }
751}
752
753InsertStatement InsertStatement() throws ParseException:
754{
Till Westmann31c21f92013-05-08 09:21:53 -0700755 Pair<Identifier,Identifier> nameComponents = null;
756 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000757}
758{
Till Westmann31c21f92013-05-08 09:21:53 -0700759 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
760 {
761 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
762 }
vinayakb38b7ca42012-03-05 05:44:15 +0000763}
764
765DeleteStatement DeleteStatement() throws ParseException:
766{
Till Westmann31c21f92013-05-08 09:21:53 -0700767 VariableExpr var = null;
768 Expression condition = null;
769 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300770 // This is related to the new metadata lock management
771 setDataverses(new ArrayList<String>());
772 setDatasets(new ArrayList<String>());
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800773
vinayakb38b7ca42012-03-05 05:44:15 +0000774}
775{
Till Westmann31c21f92013-05-08 09:21:53 -0700776 "delete" var = Variable()
777 {
778 getCurrentScope().addNewVarSymbolToScope(var.getVar());
779 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800780 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800781 (<WHERE> condition = Expression())?
782 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300783 // First we get the dataverses and datasets that we want to lock
784 List<String> dataverses = getDataverses();
785 List<String> datasets = getDatasets();
786 // we remove the pointer to the dataverses and datasets
787 setDataverses(null);
788 setDatasets(null);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800789 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
790 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700791 }
vinayakb38b7ca42012-03-05 05:44:15 +0000792}
793
794UpdateStatement UpdateStatement() throws ParseException:
795{
Till Westmann31c21f92013-05-08 09:21:53 -0700796 VariableExpr vars;
797 Expression target;
798 Expression condition;
799 UpdateClause uc;
800 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000801}
802{
Till Westmann96c1f172013-08-01 02:05:48 -0700803 "update" vars = Variable() <IN> target = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800804 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700805 <LEFTPAREN> (uc = UpdateClause()
806 {
807 ucs.add(uc);
808 }
Till Westmann96c1f172013-08-01 02:05:48 -0700809 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700810 {
811 ucs.add(uc);
812 }
813 )*) <RIGHTPAREN>
814 {
815 return new UpdateStatement(vars, target, condition, ucs);
816 }
vinayakb38b7ca42012-03-05 05:44:15 +0000817}
818
vinayakb38b7ca42012-03-05 05:44:15 +0000819UpdateClause UpdateClause() throws ParseException:
820{
Till Westmann31c21f92013-05-08 09:21:53 -0700821 Expression target = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800822 Expression value = null ;
Till Westmann31c21f92013-05-08 09:21:53 -0700823 InsertStatement is = null;
824 DeleteStatement ds = null;
825 UpdateStatement us = null;
826 Expression condition = null;
827 UpdateClause ifbranch = null;
828 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000829}
830{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800831 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700832 | is = InsertStatement()
833 | ds = DeleteStatement()
834 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700835 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
836 <THEN> ifbranch = UpdateClause()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800837 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700838 {
839 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
840 }
vinayakb38b7ca42012-03-05 05:44:15 +0000841}
842
vinayakb38b7ca42012-03-05 05:44:15 +0000843Statement SetStatement() throws ParseException:
844{
845 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700846 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000847}
848{
Till Westmann7d535322013-05-09 00:40:02 -0700849 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700850 {
Till Westmann31c21f92013-05-08 09:21:53 -0700851 return new SetStatement(pn, pv);
852 }
vinayakb38b7ca42012-03-05 05:44:15 +0000853}
854
855Statement WriteStatement() throws ParseException:
856{
Till Westmann14a20a72013-05-09 00:06:24 -0700857 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000858 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000859 Query query;
860 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000861 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000862}
863{
Till Westmann96c1f172013-08-01 02:05:48 -0700864 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700865 ( "using" writerClass = StringLiteral() )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800866 {
867 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000868 }
869}
870
zheilbron28e026f2013-11-20 10:15:15 -0800871LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000872{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000873 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000874 Identifier datasetName = null;
875 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000876 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000877 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000878 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000879}
880{
Till Westmann31c21f92013-05-08 09:21:53 -0700881 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000882 {
Till Westmann31c21f92013-05-08 09:21:53 -0700883 dataverseName = nameComponents.first;
884 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000885 }
Till Westmann31c21f92013-05-08 09:21:53 -0700886 "using" adapterName = AdapterName() properties = Configuration()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800887 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000888 {
Till Westmann31c21f92013-05-08 09:21:53 -0700889 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000890 }
891 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700892 {
zheilbron28e026f2013-11-20 10:15:15 -0800893 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800894 }
vinayakb38b7ca42012-03-05 05:44:15 +0000895}
896
vinayakb38b7ca42012-03-05 05:44:15 +0000897
Till Westmann31c21f92013-05-08 09:21:53 -0700898String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000899{
ramangrover29669d8f62013-02-11 06:03:32 +0000900 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000901}
902{
Till Westmann68d99652013-05-09 11:15:21 -0700903 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000904 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800905 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000906 }
vinayakb38b7ca42012-03-05 05:44:15 +0000907}
908
salsubaiee0b423fa2013-09-19 19:16:48 -0700909Statement CompactStatement() throws ParseException:
910{
911 Pair<Identifier,Identifier> nameComponents = null;
912 Statement stmt = null;
913}
914{
915 "compact" <DATASET> nameComponents = QualifiedName()
916 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800917 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
salsubaiee0b423fa2013-09-19 19:16:48 -0700918 }
919 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800920 return stmt;
salsubaiee0b423fa2013-09-19 19:16:48 -0700921 }
922}
923
Till Westmann31c21f92013-05-08 09:21:53 -0700924Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000925{
ramangrover29a774ef22013-07-17 09:29:18 -0700926 Pair<Identifier,Identifier> feedNameComponents = null;
927 Pair<Identifier,Identifier> datasetNameComponents = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800928
Till Westmann31c21f92013-05-08 09:21:53 -0700929 Map<String,String> configuration = null;
930 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700931 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000932}
933{
Till Westmann31c21f92013-05-08 09:21:53 -0700934 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800935 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700936 {
ramangrover29a774ef22013-07-17 09:29:18 -0700937 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700938 }
buyingyi2fd7fa62014-11-24 19:31:55 -0800939 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700940 {
ramangrover29a774ef22013-07-17 09:29:18 -0700941 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700942 }
943 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000944 {
Till Westmann31c21f92013-05-08 09:21:53 -0700945 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000946 }
947}
948
Till Westmann31c21f92013-05-08 09:21:53 -0700949Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000950{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800951 Map<String,String> configuration = new LinkedHashMap<String,String>();
952 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000953}
954{
Till Westmann31c21f92013-05-08 09:21:53 -0700955 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000956 {
Till Westmann31c21f92013-05-08 09:21:53 -0700957 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000958 }
Till Westmann96c1f172013-08-01 02:05:48 -0700959 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000960 {
Till Westmann31c21f92013-05-08 09:21:53 -0700961 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000962 }
Till Westmann31c21f92013-05-08 09:21:53 -0700963 )* )? <RIGHTPAREN>
964 {
965 return configuration;
966 }
967}
968
969Pair<String, String> KeyValuePair() throws ParseException:
970{
971 String key;
972 String value;
973}
974{
Till Westmann96c1f172013-08-01 02:05:48 -0700975 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700976 {
977 return new Pair<String, String>(key, value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800978 }
Till Westmann31c21f92013-05-08 09:21:53 -0700979}
980
981Map<String,String> Properties() throws ParseException:
982{
983 Map<String,String> properties = new HashMap<String,String>();
984 Pair<String, String> property;
985}
986{
987 ( <LEFTPAREN> property = Property()
988 {
989 properties.put(property.first, property.second);
990 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800991 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700992 {
993 properties.put(property.first, property.second);
994 }
995 )* <RIGHTPAREN> )?
996 {
997 return properties;
998 }
999}
1000
1001Pair<String, String> Property() throws ParseException:
1002{
1003 String key;
1004 String value;
1005}
1006{
Till Westmann96c1f172013-08-01 02:05:48 -07001007 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001008 {
1009 try {
1010 value = "" + Long.valueOf(token.image);
1011 } catch (NumberFormatException nfe) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001012 throw new ParseException("inapproriate value: " + token.image);
Till Westmann31c21f92013-05-08 09:21:53 -07001013 }
1014 }
1015 )
1016 {
1017 return new Pair<String, String>(key.toUpperCase(), value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001018 }
vinayakb38b7ca42012-03-05 05:44:15 +00001019}
1020
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001021TypeExpression IndexedTypeExpr() throws ParseException:
1022{
1023 TypeExpression typeExpr = null;
1024}
1025{
1026 (
1027 typeExpr = TypeReference()
1028 | typeExpr = OrderedListTypeDef()
1029 | typeExpr = UnorderedListTypeDef()
1030 )
1031 {
1032 return typeExpr;
1033 }
1034}
1035
vinayakb38b7ca42012-03-05 05:44:15 +00001036TypeExpression TypeExpr() throws ParseException:
1037{
1038 TypeExpression typeExpr = null;
1039}
1040{
1041 (
1042 typeExpr = RecordTypeDef()
1043 | typeExpr = TypeReference()
1044 | typeExpr = OrderedListTypeDef()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001045 | typeExpr = UnorderedListTypeDef()
1046 )
vinayakb38b7ca42012-03-05 05:44:15 +00001047 {
1048 return typeExpr;
1049 }
1050}
1051
1052RecordTypeDefinition RecordTypeDef() throws ParseException:
1053{
1054 RecordTypeDefinition recType = new RecordTypeDefinition();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001055 RecordTypeDefinition.RecordKind recordKind = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001056}
1057{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001058 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
vinayakb38b7ca42012-03-05 05:44:15 +00001059 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001060 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001061 {
1062 String hint = getHint(token);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001063 if (hint != null) {
vinayakb38b7ca42012-03-05 05:44:15 +00001064 String splits[] = hint.split(" +");
1065 if (splits[0].equals(GEN_FIELDS_HINT)) {
1066 if (splits.length != 5) {
1067 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1068 }
1069 if (!splits[1].equals("int")) {
1070 throw new ParseException("The only supported type for gen-fields is int.");
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001071 }
1072 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
vinayakb38b7ca42012-03-05 05:44:15 +00001073 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001074 recType.setUndeclaredFieldsDataGen(ufdg);
vinayakb38b7ca42012-03-05 05:44:15 +00001075 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001076 }
1077
vinayakb38b7ca42012-03-05 05:44:15 +00001078 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001079 (
1080 RecordField(recType)
1081 ( <COMMA> RecordField(recType) )*
1082 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001083 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001084 {
1085 if (recordKind == null) {
1086 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1087 }
1088 recType.setRecordKind(recordKind);
1089 return recType;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001090 }
vinayakb38b7ca42012-03-05 05:44:15 +00001091}
1092
1093void RecordField(RecordTypeDefinition recType) throws ParseException:
1094{
Till Westmann77cb2f42013-07-15 16:44:19 -07001095 String fieldName;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001096 TypeExpression type = null;
Till Westmann77cb2f42013-07-15 16:44:19 -07001097 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001098}
1099{
Till Westmann77cb2f42013-07-15 16:44:19 -07001100 fieldName = Identifier()
1101 {
1102 String hint = getHint(token);
1103 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1104 }
Till Westmann96c1f172013-08-01 02:05:48 -07001105 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001106 {
1107 recType.addField(fieldName, type, nullable, rfdg);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001108 }
vinayakb38b7ca42012-03-05 05:44:15 +00001109}
1110
1111TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001112{
Till Westmann14a20a72013-05-09 00:06:24 -07001113 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001114}
1115{
1116 id = Identifier()
1117 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001118 if (id.equalsIgnoreCase("int")) {
1119 id = "int64";
1120 }
1121
Till Westmann14a20a72013-05-09 00:06:24 -07001122 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001123 }
vinayakb38b7ca42012-03-05 05:44:15 +00001124}
1125
1126OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001127{
vinayakb38b7ca42012-03-05 05:44:15 +00001128 TypeExpression type = null;
1129}
1130{
Till Westmann96c1f172013-08-01 02:05:48 -07001131 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001132 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001133 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001134 {
1135 return new OrderedListTypeDefinition(type);
1136 }
1137}
1138
1139
1140UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001141{
vinayakb38b7ca42012-03-05 05:44:15 +00001142 TypeExpression type = null;
1143}
1144{
Till Westmann96c1f172013-08-01 02:05:48 -07001145 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001146 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001147 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001148 {
1149 return new UnorderedListTypeDefinition(type);
1150 }
1151}
1152
ramangrover299f76a5e2013-06-18 10:25:17 -07001153FunctionName FunctionName() throws ParseException:
1154{
1155 String first = null;
1156 String second = null;
1157 String third = null;
1158 boolean secondAfterDot = false;
1159}
1160{
zheilbron555dc9d2013-08-14 19:58:00 -07001161 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001162 {
1163 secondAfterDot = true;
1164 }
1165 ("#" third = Identifier())? | "#" second = Identifier() )?
1166 {
1167 FunctionName result = new FunctionName();
1168 if (second == null) {
1169 result.dataverse = defaultDataverse;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001170 result.library = null;
1171 result.function = first;
ramangrover299f76a5e2013-06-18 10:25:17 -07001172 } else if (third == null) {
1173 if (secondAfterDot) {
1174 result.dataverse = first;
1175 result.library = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001176 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001177 } else {
1178 result.dataverse = defaultDataverse;
1179 result.library = first;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001180 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001181 }
1182 } else {
1183 result.dataverse = first;
1184 result.library = second;
1185 result.function = third;
1186 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001187
1188 if (result.function.equalsIgnoreCase("int")) {
1189 result.function = "int64";
1190 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001191 return result;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001192 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001193}
Till Westmann31c21f92013-05-08 09:21:53 -07001194
ramangrover299f76a5e2013-06-18 10:25:17 -07001195
1196Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001197{
Till Westmann31c21f92013-05-08 09:21:53 -07001198 Pair<Identifier,Identifier> name = null;
1199}
1200{
1201 name = QualifiedName()
1202 {
1203 if (name.first == null) {
1204 name.first = new Identifier(defaultDataverse);
1205 }
1206 return name;
1207 }
1208}
1209
Till Westmann14a20a72013-05-09 00:06:24 -07001210String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001211{
Till Westmann68d99652013-05-09 11:15:21 -07001212 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001213}
1214{
1215 <IDENTIFIER>
1216 {
Till Westmann14a20a72013-05-09 00:06:24 -07001217 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001218 }
Till Westmann68d99652013-05-09 11:15:21 -07001219 | lit = StringLiteral()
1220 {
1221 return lit;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001222 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001223}
1224
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001225Pair<List<String>, TypeExpression> OpenField() throws ParseException:
1226{
1227 TypeExpression fieldType = null;
1228 List<String> fieldList = null;
1229}
1230{
1231 fieldList = NestedField()
1232 ( <COLON> fieldType = IndexedTypeExpr() )?
1233 {
1234 return new Pair<List<String>, TypeExpression>(fieldList, fieldType);
1235 }
1236}
1237
1238List<String> NestedField() throws ParseException:
1239{
1240 List<String> exprList = new ArrayList<String>();
1241 String lit = null;
1242}
1243{
1244 lit = Identifier()
1245 {
1246 exprList.add(lit);
1247 }
1248 (<DOT>
1249 lit = Identifier()
1250 {
1251 exprList.add(lit);
1252 }
1253 )*
1254 {
1255 return exprList;
1256 }
1257}
1258
1259
1260
Till Westmann7d535322013-05-09 00:40:02 -07001261String StringLiteral() throws ParseException:
1262{
1263}
1264{
1265 <STRING_LITERAL>
1266 {
1267 return removeQuotesAndEscapes(token.image);
1268 }
1269}
1270
Till Westmann31c21f92013-05-08 09:21:53 -07001271Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1272{
Till Westmann14a20a72013-05-09 00:06:24 -07001273 String first = null;
1274 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001275}
1276{
Till Westmann96c1f172013-08-01 02:05:48 -07001277 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001278 {
Till Westmann14a20a72013-05-09 00:06:24 -07001279 Identifier id1 = null;
1280 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001281 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001282 id2 = new Identifier(first);
1283 } else
1284 {
1285 id1 = new Identifier(first);
1286 id2 = new Identifier(second);
1287 }
1288 return new Pair<Identifier,Identifier>(id1, id2);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001289 }
1290}
1291
Till Westmann31c21f92013-05-08 09:21:53 -07001292Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001293{
Till Westmann14a20a72013-05-09 00:06:24 -07001294 String first = null;
1295 String second = null;
1296 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001297}
1298{
Till Westmann96c1f172013-08-01 02:05:48 -07001299 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001300 {
Till Westmann14a20a72013-05-09 00:06:24 -07001301 Identifier id1 = null;
1302 Identifier id2 = null;
1303 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001304 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001305 id2 = new Identifier(first);
1306 id3 = new Identifier(second);
1307 } else {
1308 id1 = new Identifier(first);
1309 id2 = new Identifier(second);
1310 id3 = new Identifier(third);
1311 }
1312 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001313 }
1314}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001315
vinayakb38b7ca42012-03-05 05:44:15 +00001316FunctionDecl FunctionDeclaration() throws ParseException:
1317{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001318 FunctionDecl funcDecl;
1319 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001320 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001321 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1322 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001323 createNewScope();
1324}
1325{
Till Westmannd7dcb122013-05-16 13:19:09 -07001326 "declare" "function" functionName = Identifier()
1327 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001328 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001329 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001330 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001331 getCurrentScope().addFunctionDescriptor(signature, false);
1332 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001333 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001334 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001335 }
1336}
1337
vinayakb38b7ca42012-03-05 05:44:15 +00001338
Till Westmann31c21f92013-05-08 09:21:53 -07001339Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001340{
1341 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001342 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1343 setDataverses(query.getDataverses());
1344 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001345 Expression expr;
1346}
1347{
Till Westmann31c21f92013-05-08 09:21:53 -07001348 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001349 {
1350 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001351 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001352 // we remove the pointers to the locked entities before we return the query object
1353 setDataverses(null);
1354 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001355 return query;
1356 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001357
vinayakb38b7ca42012-03-05 05:44:15 +00001358}
1359
1360
1361
1362Expression Expression():
1363{
1364 Expression expr = null;
1365 Expression exprP = null;
1366}
1367{
1368(
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001369
vinayakb38b7ca42012-03-05 05:44:15 +00001370//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1371 expr = OperatorExpr()
1372 | expr = IfThenElse()
1373 | expr = FLWOGR()
1374 | expr = QuantifiedExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001375
vinayakb38b7ca42012-03-05 05:44:15 +00001376
1377)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001378 {
1379 return (exprP==null) ? expr : exprP;
1380 }
vinayakb38b7ca42012-03-05 05:44:15 +00001381}
1382
1383
1384
1385Expression OperatorExpr()throws ParseException:
1386{
1387 OperatorExpr op = null;
1388 Expression operand = null;
1389}
1390{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001391 operand = AndExpr()
1392 (
1393
1394 <OR>
1395 {
1396 if (op == null) {
1397 op = new OperatorExpr();
1398 op.addOperand(operand);
1399 op.setCurrentop(true);
1400 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001401 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001402 }
vinayakb38b7ca42012-03-05 05:44:15 +00001403
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001404 operand = AndExpr()
1405 {
1406 op.addOperand(operand);
1407 }
vinayakb38b7ca42012-03-05 05:44:15 +00001408
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001409 )*
1410
1411 {
1412 return op==null? operand: op;
1413 }
vinayakb38b7ca42012-03-05 05:44:15 +00001414}
1415
1416Expression AndExpr()throws ParseException:
1417{
1418 OperatorExpr op = null;
1419 Expression operand = null;
1420}
1421{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001422 operand = RelExpr()
1423 (
1424
1425 <AND>
1426 {
1427 if (op == null) {
1428 op = new OperatorExpr();
1429 op.addOperand(operand);
1430 op.setCurrentop(true);
1431 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001432 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001433 }
vinayakb38b7ca42012-03-05 05:44:15 +00001434
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001435 operand = RelExpr()
1436 {
1437 op.addOperand(operand);
1438 }
vinayakb38b7ca42012-03-05 05:44:15 +00001439
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001440 )*
1441
1442 {
1443 return op==null? operand: op;
1444 }
vinayakb38b7ca42012-03-05 05:44:15 +00001445}
1446
1447
1448
1449Expression RelExpr()throws ParseException:
1450{
1451 OperatorExpr op = null;
1452 Expression operand = null;
1453 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001454 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001455}
1456{
1457 operand = AddExpr()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001458 {
1459 if (operand instanceof VariableExpr) {
1460 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001461 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001462 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001463 }
1464 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001465 }
vinayakb38b7ca42012-03-05 05:44:15 +00001466
1467 (
Till Westmann96c1f172013-08-01 02:05:48 -07001468 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001469 {
1470 String mhint = getHint(token);
1471 if (mhint != null) {
1472 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
salsubaieedf89fbc2013-12-21 19:51:42 -08001473 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1474 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1475 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1476 }
alexander.behm07617fd2012-07-25 10:13:50 +00001477 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001478 if (op == null) {
1479 op = new OperatorExpr();
1480 op.addOperand(operand, broadcast);
vinayakb38b7ca42012-03-05 05:44:15 +00001481 op.setCurrentop(true);
1482 broadcast = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001483 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001484 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001485 }
1486
1487 operand = AddExpr()
1488 {
1489 broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001490 if (operand instanceof VariableExpr) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001491 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001492 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1493 broadcast = true;
1494 }
alexander.behm07617fd2012-07-25 10:13:50 +00001495 }
vinayakb38b7ca42012-03-05 05:44:15 +00001496 op.addOperand(operand, broadcast);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001497 }
vinayakb38b7ca42012-03-05 05:44:15 +00001498 )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001499
1500 {
1501 if (annotation != null) {
1502 op.addHint(annotation);
1503 }
1504 return op==null? operand: op;
1505 }
vinayakb38b7ca42012-03-05 05:44:15 +00001506}
1507
1508Expression AddExpr()throws ParseException:
1509{
1510 OperatorExpr op = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001511 Expression operand = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001512}
1513{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001514 operand = MultExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001515
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001516 ( (<PLUS> | <MINUS>)
1517 {
1518 if (op == null) {
1519 op = new OperatorExpr();
1520 op.addOperand(operand);
1521 op.setCurrentop(true);
1522 }
1523 ((OperatorExpr)op).addOperator(token.image);
1524 }
vinayakb38b7ca42012-03-05 05:44:15 +00001525
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001526 operand = MultExpr()
1527 {
1528 op.addOperand(operand);
1529 }
1530 )*
1531
1532 {
1533 return op==null? operand: op;
1534 }
vinayakb38b7ca42012-03-05 05:44:15 +00001535}
1536
1537Expression MultExpr()throws ParseException:
1538{
1539 OperatorExpr op = null;
1540 Expression operand = null;
1541}
1542{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001543 operand = UnionExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001544
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001545 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1546 {
1547 if (op == null) {
1548 op = new OperatorExpr();
vinayakb38b7ca42012-03-05 05:44:15 +00001549 op.addOperand(operand);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001550 op.setCurrentop(true);
1551 }
1552 op.addOperator(token.image);
1553 }
1554 operand = UnionExpr()
1555 {
1556 op.addOperand(operand);
1557 }
1558 )*
1559
1560 {
1561 return op==null?operand:op;
1562 }
vinayakb38b7ca42012-03-05 05:44:15 +00001563}
1564
1565Expression UnionExpr() throws ParseException:
1566{
1567 UnionExpr union = null;
1568 Expression operand1 = null;
1569 Expression operand2 = null;
1570}
1571{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001572 operand1 = UnaryExpr()
1573 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001574 (operand2 = UnaryExpr()) {
1575 if (union == null) {
1576 union = new UnionExpr();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001577 union.addExpr(operand1);
vinayakb38b7ca42012-03-05 05:44:15 +00001578 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001579 union.addExpr(operand2);
vinayakb38b7ca42012-03-05 05:44:15 +00001580 } )*
1581 {
1582 return (union == null)? operand1: union;
1583 }
1584}
1585
1586Expression UnaryExpr() throws ParseException:
1587{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001588 Expression uexpr = null;
1589 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001590}
1591{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001592 ( (<PLUS> | <MINUS>)
1593 {
1594 uexpr = new UnaryExpr();
1595 if("+".equals(token.image))
1596 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1597 else if("-".equals(token.image))
1598 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1599 else
1600 throw new ParseException();
1601 }
1602 )?
1603
1604 expr = ValueExpr()
1605 {
1606 if(uexpr!=null){
1607 ((UnaryExpr)uexpr).setExpr(expr);
1608 return uexpr;
1609 }
1610 else{
1611 return expr;
1612 }
1613 }
vinayakb38b7ca42012-03-05 05:44:15 +00001614}
1615
Till Westmann04478e72013-05-13 23:01:34 -07001616Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001617{
1618 Expression expr = null;
1619 Identifier ident = null;
1620 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001621 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001622}
1623{
Till Westmann04478e72013-05-13 23:01:34 -07001624 expr = PrimaryExpr() ( ident = Field()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001625 {
1626 fa = (fa == null ? new FieldAccessor(expr, ident)
Till Westmann04478e72013-05-13 23:01:34 -07001627 : new FieldAccessor(fa, ident));
1628 }
icetindila611ac72014-05-16 10:10:11 -07001629 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001630 {
icetindila611ac72014-05-16 10:10:11 -07001631 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1632 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001633 }
1634 )*
1635 {
1636 return fa == null ? expr : fa;
1637 }
vinayakb38b7ca42012-03-05 05:44:15 +00001638}
1639
1640Identifier Field() throws ParseException:
1641{
Till Westmann14a20a72013-05-09 00:06:24 -07001642 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001643}
1644{
Till Westmann96c1f172013-08-01 02:05:48 -07001645 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001646 {
Till Westmann14a20a72013-05-09 00:06:24 -07001647 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001648 }
vinayakb38b7ca42012-03-05 05:44:15 +00001649}
1650
icetindila611ac72014-05-16 10:10:11 -07001651Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001652{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001653 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001654}
1655{
Till Westmann96c1f172013-08-01 02:05:48 -07001656 <LEFTBRACKET> ( expr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001657 {
1658 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1659 {
1660 Literal lit = ((LiteralExpr)expr).getValue();
1661 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1662 lit.getLiteralType() != Literal.Type.LONG) {
1663 throw new ParseException("Index should be an INTEGER");
vinayakb38b7ca42012-03-05 05:44:15 +00001664 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001665 }
1666 }
vinayakb38b7ca42012-03-05 05:44:15 +00001667
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001668 | <QUES> // ANY
1669
1670 )
vinayakb38b7ca42012-03-05 05:44:15 +00001671
Till Westmann96c1f172013-08-01 02:05:48 -07001672 <RIGHTBRACKET>
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001673 {
1674 return expr;
1675 }
vinayakb38b7ca42012-03-05 05:44:15 +00001676}
1677
1678
1679Expression PrimaryExpr()throws ParseException:
1680{
1681 Expression expr = null;
1682}
1683{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001684 ( LOOKAHEAD(2)
Till Westmann68d99652013-05-09 11:15:21 -07001685 expr = FunctionCallExpr()
1686 | expr = Literal()
1687 | expr = DatasetAccessExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001688 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001689 {
1690 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001691 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001692 }
Till Westmann68d99652013-05-09 11:15:21 -07001693 | expr = ListConstructor()
1694 | expr = RecordConstructor()
1695 | expr = ParenthesizedExpression()
1696 )
1697 {
1698 return expr;
1699 }
vinayakb38b7ca42012-03-05 05:44:15 +00001700}
1701
1702Expression Literal() throws ParseException:
1703{
vinayakb38b7ca42012-03-05 05:44:15 +00001704 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001705 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001706}
1707{
Till Westmann7d535322013-05-09 00:40:02 -07001708 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001709 {
Till Westmann7d535322013-05-09 00:40:02 -07001710 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001711 }
1712 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001713 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001714 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
Till Westmanna4242bc2013-05-08 17:49:55 -07001715 }
1716 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001717 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001718 lit.setValue(new FloatLiteral(new Float(token.image)));
1719 }
1720 | <DOUBLE_LITERAL>
1721 {
1722 lit.setValue(new DoubleLiteral(new Double(token.image)));
1723 }
1724 | <NULL>
1725 {
1726 lit.setValue(NullLiteral.INSTANCE);
1727 }
1728 | <TRUE>
1729 {
1730 lit.setValue(TrueLiteral.INSTANCE);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001731 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001732 | <FALSE>
1733 {
1734 lit.setValue(FalseLiteral.INSTANCE);
1735 }
1736 )
vinayakb38b7ca42012-03-05 05:44:15 +00001737 {
1738 return lit;
1739 }
1740}
1741
1742
1743VariableExpr VariableRef() throws ParseException:
1744{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001745 VariableExpr varExp = new VariableExpr();
1746 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001747}
1748{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001749 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001750 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001751 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001752 Identifier ident = lookupSymbol(varName);
1753 if (isInForbiddenScopes(varName)) {
1754 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.");
1755 }
1756 if(ident != null) { // exist such ident
1757 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001758 varExp.setVar((VarIdentifier)ident);
vinayakb38b7ca42012-03-05 05:44:15 +00001759 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001760 varExp.setVar(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001761 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001762 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001763 return varExp;
1764 }
1765}
1766
1767
1768VariableExpr Variable() throws ParseException:
1769{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001770 VariableExpr varExp = new VariableExpr();
1771 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001772}
1773{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001774 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001775 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001776 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001777 if(ident != null) { // exist such ident
1778 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001779 }
1780 varExp.setVar(var);
1781 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001782 return varExp;
1783 }
1784}
1785
1786Expression ListConstructor() throws ParseException:
1787{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001788 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001789}
1790{
1791 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001792 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
vinayakb38b7ca42012-03-05 05:44:15 +00001793 )
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001794
vinayakb38b7ca42012-03-05 05:44:15 +00001795 {
1796 return expr;
1797 }
1798}
1799
1800
1801ListConstructor OrderedListConstructor() throws ParseException:
1802{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001803 ListConstructor expr = new ListConstructor();
1804 Expression tmp = null;
1805 List<Expression> exprList = new ArrayList<Expression>();
1806 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001807}
1808{
1809
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001810 <LEFTBRACKET>
1811 ( tmp = Expression()
1812 {
1813 exprList.add(tmp);
1814 }
1815
1816 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
1817 )?
1818
Till Westmann96c1f172013-08-01 02:05:48 -07001819 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001820
1821 {
1822 expr.setExprList(exprList);
1823 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001824 }
vinayakb38b7ca42012-03-05 05:44:15 +00001825}
1826
1827ListConstructor UnorderedListConstructor() throws ParseException:
1828{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001829 ListConstructor expr = new ListConstructor();
1830 Expression tmp = null;
1831 List<Expression> exprList = new ArrayList<Expression>();
1832 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001833}
1834{
1835
Till Westmann96c1f172013-08-01 02:05:48 -07001836 <LEFTDBLBRACE> ( tmp = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001837 {
1838 exprList.add(tmp);
1839 }
Till Westmann96c1f172013-08-01 02:05:48 -07001840 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001841 {
1842 expr.setExprList(exprList);
1843 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001844 }
vinayakb38b7ca42012-03-05 05:44:15 +00001845}
1846
1847RecordConstructor RecordConstructor() throws ParseException:
1848{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001849 RecordConstructor expr = new RecordConstructor();
1850 FieldBinding tmp = null;
1851 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
vinayakb38b7ca42012-03-05 05:44:15 +00001852}
1853{
Till Westmann96c1f172013-08-01 02:05:48 -07001854 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001855 {
1856 fbList.add(tmp);
1857 }
Till Westmann96c1f172013-08-01 02:05:48 -07001858 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001859 {
1860 expr.setFbList(fbList);
1861 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001862 }
vinayakb38b7ca42012-03-05 05:44:15 +00001863}
1864
1865FieldBinding FieldBinding() throws ParseException:
1866{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001867 FieldBinding fb = new FieldBinding();
1868 Expression left, right;
vinayakb38b7ca42012-03-05 05:44:15 +00001869}
1870{
Till Westmann96c1f172013-08-01 02:05:48 -07001871 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001872 {
1873 fb.setLeftExpr(left);
1874 fb.setRightExpr(right);
1875 return fb;
1876 }
1877}
1878
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001879
vinayakb38b7ca42012-03-05 05:44:15 +00001880Expression FunctionCallExpr() throws ParseException:
1881{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001882 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001883 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001884 Expression tmp;
1885 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001886 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001887 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001888}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001889{
ramangrover299f76a5e2013-06-18 10:25:17 -07001890 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001891 {
Till Westmann31c21f92013-05-08 09:21:53 -07001892 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001893 }
Till Westmann31c21f92013-05-08 09:21:53 -07001894 <LEFTPAREN> (tmp = Expression()
1895 {
1896 argList.add(tmp);
1897 arity ++;
1898 }
Till Westmann96c1f172013-08-01 02:05:48 -07001899 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001900 {
1901 argList.add(tmp);
1902 arity++;
1903 }
1904 )*)? <RIGHTPAREN>
1905 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001906 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001907 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001908 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001909 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001910 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001911 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001912 }
1913 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001914 if (hint != null) {
1915 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1916 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1917 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1918 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1919 }
Till Westmann31c21f92013-05-08 09:21:53 -07001920 }
1921 return callExpr;
1922 }
vinayakb38b7ca42012-03-05 05:44:15 +00001923}
1924
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001925
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001926Expression DatasetAccessExpression() throws ParseException:
1927{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001928 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001929 String arg1 = null;
1930 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001931 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001932}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001933{
Till Westmann14a20a72013-05-09 00:06:24 -07001934 <DATASET>
1935 {
Till Westmann14a20a72013-05-09 00:06:24 -07001936 funcName = token.image;
1937 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001938 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001939 {
1940 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001941 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001942 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001943 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001944 if(arg2 != null){
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001945 addDataverse(arg1.toString());
1946 addDataset(name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001947 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001948 addDataset(defaultDataverse + "." + name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001949 }
Till Westmann14a20a72013-05-09 00:06:24 -07001950 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001951 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001952 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001953 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1954 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1955 if (signature == null) {
1956 signature = new FunctionSignature(dataverse, funcName, 1);
1957 }
1958 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001959 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001960 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001961 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001962}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001963
vinayakb38b7ca42012-03-05 05:44:15 +00001964Expression ParenthesizedExpression() throws ParseException:
1965{
1966 Expression expr;
1967}
1968{
1969 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1970 {
1971 return expr;
1972 }
1973}
1974
1975Expression IfThenElse() throws ParseException:
1976{
1977 Expression condExpr;
1978 Expression thenExpr;
1979 Expression elseExpr;
1980 IfExpr ifExpr = new IfExpr();
1981}
1982{
Till Westmann96c1f172013-08-01 02:05:48 -07001983 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001984
1985 {
1986 ifExpr.setCondExpr(condExpr);
1987 ifExpr.setThenExpr(thenExpr);
1988 ifExpr.setElseExpr(elseExpr);
1989 return ifExpr;
1990 }
1991}
1992
1993Expression FLWOGR() throws ParseException:
1994{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001995 FLWOGRExpression flworg = new FLWOGRExpression();
1996 List<Clause> clauseList = new ArrayList<Clause>();
1997 Expression returnExpr;
1998 Clause tmp;
1999 createNewScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002000}
2001{
2002 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08002003 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002004
2005 {
2006 flworg.setClauseList(clauseList);
2007 flworg.setReturnExpr(returnExpr);
2008 removeCurrentScope();
2009 return flworg;
2010 }
2011}
2012
2013Clause Clause()throws ParseException :
2014{
2015 Clause clause;
2016}
2017{
2018 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002019 clause = ForClause()
2020 | clause = LetClause()
2021 | clause = WhereClause()
2022 | clause = OrderbyClause()
2023 | clause = GroupClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002024 | clause = LimitClause()
2025 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002026 )
2027 {
2028 return clause;
2029 }
2030}
2031
2032Clause ForClause()throws ParseException :
2033{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002034 ForClause fc = new ForClause();
2035 VariableExpr varExp;
2036 VariableExpr varPos = null;
2037 Expression inExp;
2038 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002039}
2040{
buyingyi2fd7fa62014-11-24 19:31:55 -08002041 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00002042 {
2043 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07002044 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002045 fc.setInExpr(inExp);
2046 if (varPos != null) {
2047 fc.setPosExpr(varPos);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002048 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002049 }
2050 return fc;
2051 }
2052}
2053
2054Clause LetClause() throws ParseException:
2055{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002056 LetClause lc = new LetClause();
2057 VariableExpr varExp;
2058 Expression beExp;
2059 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002060}
2061{
buyingyi2fd7fa62014-11-24 19:31:55 -08002062 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002063 {
2064 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002065 lc.setVarExpr(varExp);
2066 lc.setBeExpr(beExp);
2067 return lc;
2068 }
2069}
2070
2071Clause WhereClause()throws ParseException :
2072{
2073 WhereClause wc = new WhereClause();
2074 Expression whereExpr;
2075}
2076{
salsubaieedf89fbc2013-12-21 19:51:42 -08002077 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002078 {
2079 wc.setWhereExpr(whereExpr);
2080 return wc;
2081 }
2082}
2083
2084Clause OrderbyClause()throws ParseException :
2085{
2086 OrderbyClause oc = new OrderbyClause();
2087 Expression orderbyExpr;
2088 List<Expression> orderbyList = new ArrayList<Expression>();
2089 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2090 int numOfOrderby = 0;
2091}
2092{
2093 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002094 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002095 {
2096 String hint = getHint(token);
2097 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002098 String splits[] = hint.split(" +");
vinayakb38b7ca42012-03-05 05:44:15 +00002099 int numFrames = Integer.parseInt(splits[1]);
2100 int numTuples = Integer.parseInt(splits[2]);
2101 oc.setNumFrames(numFrames);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002102 oc.setNumTuples(numTuples);
2103 }
2104 }
Till Westmann96c1f172013-08-01 02:05:48 -07002105 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002106 {
2107 orderbyList.add(orderbyExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002108 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
vinayakb38b7ca42012-03-05 05:44:15 +00002109 }
Till Westmann96c1f172013-08-01 02:05:48 -07002110 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2111 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002112 {
2113 modifierList.add(modif);
2114 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002115
Till Westmann96c1f172013-08-01 02:05:48 -07002116 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002117 {
2118 orderbyList.add(orderbyExpr);
2119 modif = OrderbyClause.OrderModifier.ASC;
2120 }
Till Westmann96c1f172013-08-01 02:05:48 -07002121 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2122 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002123 {
2124 modifierList.add(modif);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002125 }
vinayakb38b7ca42012-03-05 05:44:15 +00002126 )*
2127)
2128 {
2129 oc.setModifierList(modifierList);
2130 oc.setOrderbyList(orderbyList);
2131 return oc;
2132 }
2133}
2134Clause GroupClause()throws ParseException :
2135{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002136 GroupbyClause gbc = new GroupbyClause();
2137 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2138 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
vinayakb38b7ca42012-03-05 05:44:15 +00002139 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002140 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2141 VariableExpr var = null;
2142 VariableExpr withVar = null;
2143 Expression expr = null;
2144 VariableExpr decorVar = null;
2145 Expression decorExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002146}
2147{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002148 {
2149 Scope newScope = extendCurrentScopeNoPush(true);
2150 // extendCurrentScope(true);
2151 }
Till Westmann96c1f172013-08-01 02:05:48 -07002152 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002153 {
2154 String hint = getHint(token);
2155 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002156 gbc.setHashGroupByHint(true);
2157 }
2158 }
Till Westmann96c1f172013-08-01 02:05:48 -07002159 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002160 {
2161 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002162 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002163 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002164 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002165 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002166 vePairList.add(pair1);
2167 }
Till Westmann96c1f172013-08-01 02:05:48 -07002168 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002169 {
2170 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002171 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002172 expr = Expression()
2173 {
2174 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002175 vePairList.add(pair2);
2176 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002177 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002178 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002179 {
2180 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002181 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2182 decorPairList.add(pair3);
2183 }
Till Westmann96c1f172013-08-01 02:05:48 -07002184 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002185 {
2186 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002187 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002188 decorPairList.add(pair4);
vinayakb38b7ca42012-03-05 05:44:15 +00002189 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002190 )*
2191 )?
buyingyi3ca46d02015-01-27 23:22:09 -08002192 (<WITH>|<KEEPING>) withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002193 {
2194 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002195 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002196 withVarList.add(withVar);
2197 newScope.addNewVarSymbolToScope(withVar.getVar());
2198 }
Till Westmann96c1f172013-08-01 02:05:48 -07002199 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002200 {
2201 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002202 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002203 withVarList.add(withVar);
2204 newScope.addNewVarSymbolToScope(withVar.getVar());
2205 })*
2206 {
2207 gbc.setGbyPairList(vePairList);
2208 gbc.setDecorPairList(decorPairList);
2209 gbc.setWithVarList(withVarList);
2210 replaceCurrentScope(newScope);
2211 return gbc;
2212 }
2213}
2214
2215
2216LimitClause LimitClause() throws ParseException:
2217{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002218 LimitClause lc = new LimitClause();
2219 Expression expr;
2220 pushForbiddenScope(getCurrentScope());
vinayakb38b7ca42012-03-05 05:44:15 +00002221}
2222{
Till Westmann96c1f172013-08-01 02:05:48 -07002223 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2224 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002225
2226 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002227 popForbiddenScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002228 return lc;
2229 }
2230}
2231
2232DistinctClause DistinctClause() throws ParseException:
2233{
2234 List<Expression> exprs = new ArrayList<Expression>();
2235 Expression expr;
2236}
2237{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002238 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002239 {
2240 exprs.add(expr);
2241 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002242 (<COMMA> expr = Expression()
2243 {
2244 exprs.add(expr);
2245 }
vinayakb38b7ca42012-03-05 05:44:15 +00002246 )*
2247 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002248 return new DistinctClause(exprs);
vinayakb38b7ca42012-03-05 05:44:15 +00002249 }
2250}
2251
vinayakb38b7ca42012-03-05 05:44:15 +00002252QuantifiedExpression QuantifiedExpression()throws ParseException:
2253{
2254 QuantifiedExpression qc = new QuantifiedExpression();
2255 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2256 Expression satisfiesExpr;
2257 VariableExpr var;
2258 Expression inExpr;
2259 QuantifiedPair pair;
2260}
2261{
2262 {
2263 createNewScope();
2264 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002265
Till Westmann96c1f172013-08-01 02:05:48 -07002266 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002267 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2268 var = Variable() <IN> inExpr = Expression()
2269 {
vinayakb38b7ca42012-03-05 05:44:15 +00002270 pair = new QuantifiedPair(var, inExpr);
2271 getCurrentScope().addNewVarSymbolToScope(var.getVar());
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002272 quantifiedList.add(pair);
2273 }
2274 (
2275 <COMMA> var = Variable() <IN> inExpr = Expression()
2276 {
2277 pair = new QuantifiedPair(var, inExpr);
2278 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2279 quantifiedList.add(pair);
2280 }
2281 )*
2282 <SATISFIES> satisfiesExpr = Expression()
2283 {
2284 qc.setSatisfiesExpr(satisfiesExpr);
2285 qc.setQuantifiedList(quantifiedList);
2286 removeCurrentScope();
2287 return qc;
2288 }
vinayakb38b7ca42012-03-05 05:44:15 +00002289}
2290
2291TOKEN_MGR_DECLS:
2292{
Till Westmann96c1f172013-08-01 02:05:48 -07002293 public int commentDepth = 0;
2294 public IntStack lexerStateStack = new IntStack();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002295
Till Westmann96c1f172013-08-01 02:05:48 -07002296 public void pushState() {
2297 lexerStateStack.push( curLexState );
2298 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002299
Till Westmannfd733ee2014-07-10 00:57:37 -07002300 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002301 if (lexerStateStack.size() > 0) {
2302 SwitchTo( lexerStateStack.pop() );
2303 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002304 int errorLine = input_stream.getEndLine();
2305 int errorColumn = input_stream.getEndColumn();
2306 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2307 + "\" but state stack is empty.";
2308 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002309 }
2310 }
vinayakb38b7ca42012-03-05 05:44:15 +00002311}
2312
Till Westmann96c1f172013-08-01 02:05:48 -07002313<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002314TOKEN :
2315{
Till Westmann5df7b452013-08-02 13:07:16 -07002316 <ASC : "asc">
2317 | <AT : "at">
2318 | <BY : "by">
2319 | <DATASET : "dataset">
2320 | <DECOR : "decor">
2321 | <DESC : "desc">
2322 | <DISTINCT : "distinct">
2323 | <ELSE : "else">
2324 | <EVERY : "every">
2325 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002326 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002327 | <GROUP : "group">
2328 | <IF : "if">
2329 | <IN : "in">
2330 | <LET : "let">
2331 | <LIMIT : "limit">
2332 | <OFFSET : "offset">
2333 | <ORDER : "order">
2334 | <RETURN : "return">
2335 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002336 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002337 | <SOME : "some">
2338 | <THEN : "then">
2339 | <UNION : "union">
2340 | <WHERE : "where">
2341 | <WITH : "with">
buyingyi3ca46d02015-01-27 23:22:09 -08002342 | <KEEPING : "keeping">
vinayakb38b7ca42012-03-05 05:44:15 +00002343}
2344
Till Westmann96c1f172013-08-01 02:05:48 -07002345<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002346TOKEN :
2347{
Till Westmann5df7b452013-08-02 13:07:16 -07002348 <CARET : "^">
2349 | <DIV : "/">
2350 | <IDIV : "idiv">
2351 | <MINUS : "-">
2352 | <MOD : "%">
2353 | <MUL : "*">
2354 | <PLUS : "+">
2355
2356 | <LEFTPAREN : "(">
2357 | <RIGHTPAREN : ")">
2358 | <LEFTBRACKET : "[">
2359 | <RIGHTBRACKET : "]">
2360
2361 | <COLON : ":">
2362 | <COMMA : ",">
2363 | <DOT : ".">
2364 | <QUES : "?">
2365
2366 | <LT : "<">
2367 | <GT : ">">
2368 | <LE : "<=">
2369 | <GE : ">=">
2370 | <EQ : "=">
2371 | <NE : "!=">
2372 | <SIMILAR : "~=">
2373 | <ASSIGN : ":=">
2374
2375 | <AND : "and">
2376 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002377}
2378
Till Westmann96c1f172013-08-01 02:05:48 -07002379<DEFAULT,IN_DBL_BRACE>
2380TOKEN :
2381{
Till Westmann5df7b452013-08-02 13:07:16 -07002382 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002383}
2384
2385<DEFAULT>
2386TOKEN :
2387{
Till Westmannfd733ee2014-07-10 00:57:37 -07002388 <RIGHTBRACE : "}"> { popState("}"); }
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 Westmann5df7b452013-08-02 13:07:16 -07002394 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002395}
2396
Till Westmann96c1f172013-08-01 02:05:48 -07002397<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002398TOKEN :
2399{
Till Westmannfd733ee2014-07-10 00:57:37 -07002400 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002401}
2402
Till Westmann96c1f172013-08-01 02:05:48 -07002403<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002404TOKEN :
2405{
Till Westmann5df7b452013-08-02 13:07:16 -07002406 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002407}
2408
Till Westmann96c1f172013-08-01 02:05:48 -07002409<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002410TOKEN :
2411{
Till Westmann5df7b452013-08-02 13:07:16 -07002412 <NULL : "null">
2413 | <TRUE : "true">
2414 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002415}
2416
Till Westmann96c1f172013-08-01 02:05:48 -07002417<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002418TOKEN :
2419{
Till Westmann5df7b452013-08-02 13:07:16 -07002420 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002421}
2422
Till Westmann96c1f172013-08-01 02:05:48 -07002423<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002424TOKEN:
2425{
Till Westmann5df7b452013-08-02 13:07:16 -07002426 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002427 | <DIGITS> ( "." <DIGITS> )?
2428 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002429 >
2430 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002431 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2432 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002433 >
2434 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002435}
2436
Till Westmann96c1f172013-08-01 02:05:48 -07002437<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002438TOKEN :
2439{
Till Westmann5df7b452013-08-02 13:07:16 -07002440 <#LETTER : ["A" - "Z", "a" - "z"]>
2441 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002442}
2443
Till Westmann96c1f172013-08-01 02:05:48 -07002444<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002445TOKEN :
2446{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002447 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2448 <STRING_LITERAL : ("\"" (
2449 <EscapeQuot>
2450 | <EscapeBslash>
2451 | <EscapeSlash>
2452 | <EscapeBspace>
2453 | <EscapeFormf>
2454 | <EscapeNl>
2455 | <EscapeCr>
2456 | <EscapeTab>
2457 | ~["\"","\\"])* "\"")
2458 | ("\'"(
2459 <EscapeApos>
2460 | <EscapeBslash>
2461 | <EscapeSlash>
2462 | <EscapeBspace>
2463 | <EscapeFormf>
2464 | <EscapeNl>
2465 | <EscapeCr>
2466 | <EscapeTab>
2467 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002468 | < #EscapeQuot: "\\\"" >
2469 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002470 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002471 | < #EscapeSlash: "\\/" >
2472 | < #EscapeBspace: "\\b" >
2473 | < #EscapeFormf: "\\f" >
2474 | < #EscapeNl: "\\n" >
2475 | < #EscapeCr: "\\r" >
2476 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002477}
2478
Till Westmann96c1f172013-08-01 02:05:48 -07002479<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002480TOKEN :
2481{
Till Westmann5df7b452013-08-02 13:07:16 -07002482 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002483}
2484
Till Westmann96c1f172013-08-01 02:05:48 -07002485<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002486TOKEN :
2487{
Till Westmann5df7b452013-08-02 13:07:16 -07002488 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002489}
2490
Till Westmann96c1f172013-08-01 02:05:48 -07002491<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002492SKIP:
2493{
2494 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002495 | "\t"
2496 | "\r"
2497 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002498}
2499
Till Westmann96c1f172013-08-01 02:05:48 -07002500<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002501SKIP:
2502{
Till Westmann5df7b452013-08-02 13:07:16 -07002503 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002504}
2505
Till Westmann96c1f172013-08-01 02:05:48 -07002506<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002507SKIP:
2508{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002509 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002510}
2511
Till Westmann96c1f172013-08-01 02:05:48 -07002512<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002513SKIP:
2514{
Till Westmann96c1f172013-08-01 02:05:48 -07002515 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002516}
2517
2518<INSIDE_COMMENT>
2519SPECIAL_TOKEN:
2520{
Till Westmann5df7b452013-08-02 13:07:16 -07002521 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002522}
2523
2524<INSIDE_COMMENT>
2525SKIP:
2526{
Till Westmann96c1f172013-08-01 02:05:48 -07002527 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002528}
2529
2530<INSIDE_COMMENT>
2531SKIP:
2532{
Till Westmannfd733ee2014-07-10 00:57:37 -07002533 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002534 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002535}