blob: 81508718a76ac776b826d43d69b27fb16c70c8dc [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
Eldon Carmand2d78ad2015-05-07 16:23:41 -070013// For AQLParserTokenManager
Till Westmann96c1f172013-08-01 02:05:48 -070014import org.apache.xerces.util.IntStack;
15
Eldon Carmand2d78ad2015-05-07 16:23:41 -070016import java.io.BufferedReader;
17import java.io.File;
18import java.io.FileInputStream;
19import java.io.FileNotFoundException;
20import java.io.IOException;
21import java.io.InputStreamReader;
22import java.io.Reader;
23import java.io.StringReader;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.LinkedHashMap;
27import java.util.List;
28import java.util.Map;
29
30import edu.uci.ics.asterix.aql.base.Clause;
31import edu.uci.ics.asterix.aql.base.Expression;
32import edu.uci.ics.asterix.aql.base.Literal;
33import edu.uci.ics.asterix.aql.base.Statement;
34import edu.uci.ics.asterix.aql.context.RootScopeFactory;
35import edu.uci.ics.asterix.aql.context.Scope;
36import edu.uci.ics.asterix.aql.expression.AbstractAccessor;
37import edu.uci.ics.asterix.aql.expression.CallExpr;
38import edu.uci.ics.asterix.aql.expression.CompactStatement;
39import edu.uci.ics.asterix.aql.expression.ConnectFeedStatement;
40import edu.uci.ics.asterix.aql.expression.CreateDataverseStatement;
41import edu.uci.ics.asterix.aql.expression.CreateFeedStatement;
42import edu.uci.ics.asterix.aql.expression.CreateFunctionStatement;
43import edu.uci.ics.asterix.aql.expression.CreateIndexStatement;
44import edu.uci.ics.asterix.aql.expression.DatasetDecl;
45import edu.uci.ics.asterix.aql.expression.DataverseDecl;
46import edu.uci.ics.asterix.aql.expression.DataverseDropStatement;
47import edu.uci.ics.asterix.aql.expression.DeleteStatement;
48import edu.uci.ics.asterix.aql.expression.DisconnectFeedStatement;
49import edu.uci.ics.asterix.aql.expression.DistinctClause;
50import edu.uci.ics.asterix.aql.expression.DropStatement;
51import edu.uci.ics.asterix.aql.expression.ExternalDetailsDecl;
52import edu.uci.ics.asterix.aql.expression.FLWOGRExpression;
53import edu.uci.ics.asterix.aql.expression.FeedDropStatement;
54import edu.uci.ics.asterix.aql.expression.FieldAccessor;
55import edu.uci.ics.asterix.aql.expression.FieldBinding;
56import edu.uci.ics.asterix.aql.expression.ForClause;
57import edu.uci.ics.asterix.aql.expression.FunctionDecl;
58import edu.uci.ics.asterix.aql.expression.FunctionDropStatement;
59import edu.uci.ics.asterix.aql.expression.GbyVariableExpressionPair;
60import edu.uci.ics.asterix.aql.expression.GroupbyClause;
61import edu.uci.ics.asterix.aql.expression.Identifier;
62import edu.uci.ics.asterix.aql.expression.IfExpr;
63import edu.uci.ics.asterix.aql.expression.IndexAccessor;
64import edu.uci.ics.asterix.aql.expression.IndexDropStatement;
65import edu.uci.ics.asterix.aql.expression.InsertStatement;
66import edu.uci.ics.asterix.aql.expression.InternalDetailsDecl;
67import edu.uci.ics.asterix.aql.expression.LetClause;
68import edu.uci.ics.asterix.aql.expression.LimitClause;
69import edu.uci.ics.asterix.aql.expression.ListConstructor;
70import edu.uci.ics.asterix.aql.expression.LiteralExpr;
71import edu.uci.ics.asterix.aql.expression.LoadStatement;
72import edu.uci.ics.asterix.aql.expression.NodeGroupDropStatement;
73import edu.uci.ics.asterix.aql.expression.NodegroupDecl;
74import edu.uci.ics.asterix.aql.expression.OperatorExpr;
75import edu.uci.ics.asterix.aql.expression.OrderbyClause;
76import edu.uci.ics.asterix.aql.expression.OrderedListTypeDefinition;
77import edu.uci.ics.asterix.aql.expression.QuantifiedExpression;
78import edu.uci.ics.asterix.aql.expression.QuantifiedPair;
79import edu.uci.ics.asterix.aql.expression.Query;
80import edu.uci.ics.asterix.aql.expression.RecordConstructor;
81import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition;
82import edu.uci.ics.asterix.aql.expression.RefreshExternalDatasetStatement;
83import edu.uci.ics.asterix.aql.expression.RunStatement;
84import edu.uci.ics.asterix.aql.expression.SetStatement;
85import edu.uci.ics.asterix.aql.expression.TypeDecl;
86import edu.uci.ics.asterix.aql.expression.TypeDropStatement;
87import edu.uci.ics.asterix.aql.expression.TypeExpression;
88import edu.uci.ics.asterix.aql.expression.TypeReferenceExpression;
89import edu.uci.ics.asterix.aql.expression.UnaryExpr;
90import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
91import edu.uci.ics.asterix.aql.expression.UnionExpr;
92import edu.uci.ics.asterix.aql.expression.UnorderedListTypeDefinition;
93import edu.uci.ics.asterix.aql.expression.UpdateClause;
94import edu.uci.ics.asterix.aql.expression.UpdateStatement;
95import edu.uci.ics.asterix.aql.expression.VarIdentifier;
96import edu.uci.ics.asterix.aql.expression.VariableExpr;
97import edu.uci.ics.asterix.aql.expression.WhereClause;
98import edu.uci.ics.asterix.aql.expression.WriteStatement;
vinayakb38b7ca42012-03-05 05:44:15 +000099import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
100import edu.uci.ics.asterix.aql.literal.FalseLiteral;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700101import edu.uci.ics.asterix.aql.literal.FloatLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +0000102import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +0000103import edu.uci.ics.asterix.aql.literal.NullLiteral;
104import edu.uci.ics.asterix.aql.literal.StringLiteral;
105import edu.uci.ics.asterix.aql.literal.TrueLiteral;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700106import edu.uci.ics.asterix.aql.util.RangeMapBuilder;
107import edu.uci.ics.asterix.common.annotations.AutoDataGen;
108import edu.uci.ics.asterix.common.annotations.DateBetweenYearsDataGen;
109import edu.uci.ics.asterix.common.annotations.DatetimeAddRandHoursDataGen;
110import edu.uci.ics.asterix.common.annotations.DatetimeBetweenYearsDataGen;
111import edu.uci.ics.asterix.common.annotations.FieldIntervalDataGen;
112import edu.uci.ics.asterix.common.annotations.FieldValFileDataGen;
113import edu.uci.ics.asterix.common.annotations.FieldValFileSameIndexDataGen;
114import edu.uci.ics.asterix.common.annotations.IRecordFieldDataGen;
115import edu.uci.ics.asterix.common.annotations.InsertRandIntDataGen;
116import edu.uci.ics.asterix.common.annotations.ListDataGen;
117import edu.uci.ics.asterix.common.annotations.ListValFileDataGen;
118import edu.uci.ics.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
119import edu.uci.ics.asterix.common.annotations.TypeDataGen;
120import edu.uci.ics.asterix.common.annotations.UndeclaredFieldsDataGen;
vinayakb38b7ca42012-03-05 05:44:15 +0000121import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
122import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
vinayakb38b7ca42012-03-05 05:44:15 +0000123import edu.uci.ics.asterix.common.exceptions.AsterixException;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000124import edu.uci.ics.asterix.common.functions.FunctionSignature;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700125import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
126import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
127import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
alexander.behm07617fd2012-07-25 10:13:50 +0000128import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
129import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000130import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700131import edu.uci.ics.hyracks.dataflow.common.data.partition.range.IRangeMap;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000132
133
vinayakb38b7ca42012-03-05 05:44:15 +0000134
135
136public class AQLParser extends ScopeChecker {
137
vinayakb38b7ca42012-03-05 05:44:15 +0000138 // optimizer hints
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700139 private static final String AUTO_HINT = "auto";
vinayakb38b7ca42012-03-05 05:44:15 +0000140 private static final String BROADCAST_JOIN_HINT = "bcast";
vinayakb38b7ca42012-03-05 05:44:15 +0000141 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
vinayakb38b7ca42012-03-05 05:44:15 +0000142 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
143 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700144 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
145 private static final String HASH_GROUP_BY_HINT = "hash";
146 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
147 private static final String INMEMORY_HINT = "inmem";
148 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
149 private static final String INTERVAL_HINT = "interval";
150 private static final String LIST_HINT = "list";
151 private static final String LIST_VAL_FILE_HINT = "list-val-file";
152 private static final String RANGE_HINT = "range";
153 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
154 private static final String VAL_FILE_HINT = "val-files";
155 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800156
157 private static final String GEN_FIELDS_HINT = "gen-fields";
158
vinayakb38b7ca42012-03-05 05:44:15 +0000159 // data generator hints
160 private static final String DGEN_HINT = "dgen";
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800161
Till Westmann31c21f92013-05-08 09:21:53 -0700162 private static class IndexParams {
163 public IndexType type;
164 public int gramLength;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800165
Till Westmann31c21f92013-05-08 09:21:53 -0700166 public IndexParams(IndexType type, int gramLength) {
167 this.type = type;
168 this.gramLength = gramLength;
169 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800170 };
171
ramangrover299f76a5e2013-06-18 10:25:17 -0700172 private static class FunctionName {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800173 public String dataverse = null;
174 public String library = null;
175 public String function = null;
176 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700177
vinayakb38b7ca42012-03-05 05:44:15 +0000178 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -0700179 if (t.specialToken == null) {
180 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800181 }
Till Westmann31c21f92013-05-08 09:21:53 -0700182 String s = t.specialToken.image;
183 int n = s.length();
184 if (n < 2) {
185 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800186 }
Till Westmann31c21f92013-05-08 09:21:53 -0700187 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000188 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800189
Till Westmann77cb2f42013-07-15 16:44:19 -0700190 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
191 IRecordFieldDataGen rfdg = null;
192 String splits[] = hint.split(" +");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800193 if (splits[0].equals(VAL_FILE_HINT)) {
Till Westmann77cb2f42013-07-15 16:44:19 -0700194 File[] valFiles = new File[splits.length - 1];
195 for (int k=1; k<splits.length; k++) {
196 valFiles[k-1] = new File(splits[k]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800197 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700198 rfdg = new FieldValFileDataGen(valFiles);
199 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
200 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
201 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
202 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
203 } else if (splits[0].equals(LIST_HINT)) {
204 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
205 } else if (splits[0].equals(INTERVAL_HINT)) {
206 FieldIntervalDataGen.ValueType vt;
207 if (splits[1].equals("int")) {
208 vt = FieldIntervalDataGen.ValueType.INT;
209 } else if (splits[1].equals("long")) {
210 vt = FieldIntervalDataGen.ValueType.LONG;
211 } else if (splits[1].equals("float")) {
212 vt = FieldIntervalDataGen.ValueType.FLOAT;
213 } else if (splits[1].equals("double")) {
214 vt = FieldIntervalDataGen.ValueType.DOUBLE;
215 } else {
216 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
217 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800218 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
Till Westmann77cb2f42013-07-15 16:44:19 -0700219 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
220 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
221 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
222 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
223 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
224 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
225 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
226 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
227 } else if (splits[0].equals(AUTO_HINT)) {
228 rfdg = new AutoDataGen(splits[1]);
229 }
230 return rfdg;
231 }
vinayakb38b7ca42012-03-05 05:44:15 +0000232
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000233 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700234 this(new StringReader(s));
235 super.setInput(s);
236 }
vinayakb38b7ca42012-03-05 05:44:15 +0000237
Till Westmann31c21f92013-05-08 09:21:53 -0700238 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
239 File file = new File(args[0]);
240 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
241 AQLParser parser = new AQLParser(fis);
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700242 List<Statement> st = parser.parse();
Till Westmann31c21f92013-05-08 09:21:53 -0700243 //st.accept(new AQLPrintVisitor(), 0);
244 }
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700245
246 public List<Statement> parse() throws ParseException {
247 try {
248 return Statement();
249 } catch (Error e) {
250 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
251 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
252 throw new ParseException(e.getMessage());
253 }
254 }
vinayakb38b7ca42012-03-05 05:44:15 +0000255}
256
257PARSER_END(AQLParser)
258
259
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000260List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000261{
vinayakb38b7ca42012-03-05 05:44:15 +0000262 scopeStack.push(RootScopeFactory.createRootScope(this));
263 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700264 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000265}
266{
Till Westmann31c21f92013-05-08 09:21:53 -0700267 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000268 {
Till Westmann31c21f92013-05-08 09:21:53 -0700269 decls.add(stmt);
270 }
271 )*
272 <EOF>
273 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800274 return decls;
Till Westmann31c21f92013-05-08 09:21:53 -0700275 }
276}
277
278Statement SingleStatement() throws ParseException:
279{
280 Statement stmt = null;
281}
282{
283 (
284 stmt = DataverseDeclaration()
285 | stmt = FunctionDeclaration()
286 | stmt = CreateStatement()
287 | stmt = LoadStatement()
288 | stmt = DropStatement()
289 | stmt = WriteStatement()
290 | stmt = SetStatement()
291 | stmt = InsertStatement()
292 | stmt = DeleteStatement()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800293 | stmt = UpdateStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700294 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700295 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700296 | stmt = Query()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700297 | stmt = RefreshExternalDatasetStatement()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800298 | stmt = RunStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700299 )
300 {
301 return stmt;
302 }
303}
304
305DataverseDecl DataverseDeclaration() throws ParseException:
306{
Till Westmann14a20a72013-05-09 00:06:24 -0700307 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700308}
309{
Till Westmanna4242bc2013-05-08 17:49:55 -0700310 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700311 {
Till Westmann14a20a72013-05-09 00:06:24 -0700312 defaultDataverse = dvName;
313 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700314 }
315}
316
317Statement CreateStatement() throws ParseException:
318{
319 String hint = null;
320 boolean dgen = false;
321 Statement stmt = null;
322}
323{
324 "create"
325 (
326 {
327 hint = getHint(token);
328 if (hint != null && hint.startsWith(DGEN_HINT)) {
329 dgen = true;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800330 }
Till Westmann31c21f92013-05-08 09:21:53 -0700331 }
332 stmt = TypeSpecification(hint, dgen)
333 | stmt = NodegroupSpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800334 | stmt = DatasetSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700335 | stmt = IndexSpecification()
336 | stmt = DataverseSpecification()
337 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700338 | stmt = FeedSpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800339 )
Till Westmann31c21f92013-05-08 09:21:53 -0700340 {
341 return stmt;
342 }
343}
344
345TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
346{
347 Pair<Identifier,Identifier> nameComponents = null;
348 boolean ifNotExists = false;
349 TypeExpression typeExpr = null;
350}
351{
ramangrover299f76a5e2013-06-18 10:25:17 -0700352 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700353 "as" typeExpr = TypeExpr()
354 {
355 long numValues = -1;
356 String filename = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800357 if (dgen) {
Till Westmann31c21f92013-05-08 09:21:53 -0700358 String splits[] = hint.split(" +");
359 if (splits.length != 3) {
360 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800361 }
Till Westmann31c21f92013-05-08 09:21:53 -0700362 filename = splits[1];
363 numValues = Long.parseLong(splits[2]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800364 }
Till Westmann31c21f92013-05-08 09:21:53 -0700365 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
366 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
367 }
368}
369
370
371NodegroupDecl NodegroupSpecification() throws ParseException:
372{
Till Westmann14a20a72013-05-09 00:06:24 -0700373 String name = null;
374 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700375 boolean ifNotExists = false;
376 List<Identifier>ncNames = null;
377}
378{
Till Westmanna4242bc2013-05-08 17:49:55 -0700379 "nodegroup" name = Identifier()
380 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700381 {
382 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700383 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700384 }
Till Westmann96c1f172013-08-01 02:05:48 -0700385 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700386 {
Till Westmann14a20a72013-05-09 00:06:24 -0700387 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700388 }
389 )*
390 {
Till Westmann14a20a72013-05-09 00:06:24 -0700391 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700392 }
393}
394
395DatasetDecl DatasetSpecification() throws ParseException:
396{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800397 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700398 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700399 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700400 String adapterName = null;
401 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700402 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700403 FunctionSignature appliedFunction = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700404 List<List<String>> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700405 String nodeGroupName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800406 Map<String,String> hints = new HashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700407 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700408 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700409 String compactionPolicy = null;
buyingyiccd67fe2015-05-19 11:53:39 -0700410 boolean temp = false;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700411 List<String> filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700412}
413{
414 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700415 "external" <DATASET> nameComponents = QualifiedName()
416 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
417 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700418 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700419 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700420 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700421 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Till Westmann31c21f92013-05-08 09:21:53 -0700422 {
423 ExternalDetailsDecl edd = new ExternalDetailsDecl();
424 edd.setAdapter(adapterName);
425 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700426 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
427 edd.setCompactionPolicy(compactionPolicy);
428 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700429 dsetDecl = new DatasetDecl(nameComponents.first,
430 nameComponents.second,
431 new Identifier(typeName),
432 hints,
433 DatasetType.EXTERNAL,
434 edd,
435 ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800436 }
Till Westmann31c21f92013-05-08 09:21:53 -0700437
buyingyiccd67fe2015-05-19 11:53:39 -0700438 | ("internal" | "temporary" {
439 temp = token.image.toLowerCase().equals("temporary");
440 }
441 )?
442 <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700443 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
444 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800445 primaryKeyFields = PrimaryKey()
446 ("autogenerated" { autogenerated = true; } )?
zheilbron2467f2e2013-08-23 19:07:31 -0700447 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700448 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700449 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700450 ( "with filter on" filterField = NestedField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700451 {
Till Westmann14a20a72013-05-09 00:06:24 -0700452 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
453 ? new Identifier(nodeGroupName)
454 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700455 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700456 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700457 compactionPolicy,
salsubaieea5af4e02014-07-08 15:20:02 -0700458 compactionPolicyProperties,
buyingyiccd67fe2015-05-19 11:53:39 -0700459 filterField,
460 temp);
Till Westmann14a20a72013-05-09 00:06:24 -0700461 dsetDecl = new DatasetDecl(nameComponents.first,
462 nameComponents.second,
463 new Identifier(typeName),
464 hints,
465 DatasetType.INTERNAL,
466 idd,
467 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700468 }
469 )
470 {
471 return dsetDecl;
472 }
473}
474
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700475RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
476{
477 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
478 Pair<Identifier,Identifier> nameComponents = null;
479 String datasetName = null;
480}
481{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800482 "refresh external" <DATASET> nameComponents = QualifiedName()
483 {
484 redss.setDataverseName(nameComponents.first);
485 redss.setDatasetName(nameComponents.second);
486 return redss;
487 }
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700488}
489
Markus Holzemer52c568e2014-12-18 10:51:49 -0800490RunStatement RunStatement() throws ParseException:
491{
492 String system = null;
493 String tmp;
494 ArrayList<String> parameters = new ArrayList<String>();
495 Pair<Identifier,Identifier> nameComponentsFrom = null;
496 Pair<Identifier,Identifier> nameComponentsTo = null;
497}
498{
499 "run" system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
500 {
501 parameters.add(tmp);
502 }
503 )*<RIGHTPAREN>
504 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800505 "to" <DATASET> nameComponentsTo = QualifiedName()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800506 {
507 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
508 }
509}
510
Till Westmann31c21f92013-05-08 09:21:53 -0700511CreateIndexStatement IndexSpecification() throws ParseException:
512{
513 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700514 String indexName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700515 boolean ifNotExists = false;
516 Pair<Identifier,Identifier> nameComponents = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700517 Pair<List<String>, TypeExpression> fieldPair = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700518 IndexParams indexType = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700519 boolean enforced = false;
Till Westmann31c21f92013-05-08 09:21:53 -0700520}
521{
Till Westmanna4242bc2013-05-08 17:49:55 -0700522 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700523 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800524 "on" nameComponents = QualifiedName()
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700525 <LEFTPAREN> ( fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700526 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700527 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700528 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700529 ) (<COMMA> fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700530 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700531 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700532 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700533 )* <RIGHTPAREN> ( "type" indexType = IndexType() )? ( "enforced" { enforced = true; } )?
Till Westmann31c21f92013-05-08 09:21:53 -0700534 {
Till Westmann14a20a72013-05-09 00:06:24 -0700535 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700536 cis.setIfNotExists(ifNotExists);
537 cis.setDataverseName(nameComponents.first);
538 cis.setDatasetName(nameComponents.second);
539 if (indexType != null) {
540 cis.setIndexType(indexType.type);
541 cis.setGramLength(indexType.gramLength);
542 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700543 cis.setEnforced(enforced);
Till Westmann31c21f92013-05-08 09:21:53 -0700544 return cis;
545 }
546}
547
salsubaiee0b423fa2013-09-19 19:16:48 -0700548String CompactionPolicy() throws ParseException :
549{
550 String compactionPolicy = null;
551}
552{
553 compactionPolicy = Identifier()
554 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800555 return compactionPolicy;
salsubaiee0b423fa2013-09-19 19:16:48 -0700556 }
557}
558
salsubaieea5af4e02014-07-08 15:20:02 -0700559String FilterField() throws ParseException :
560{
561 String filterField = null;
562}
563{
564 filterField = Identifier()
565 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800566 return filterField;
salsubaieea5af4e02014-07-08 15:20:02 -0700567 }
568}
569
Till Westmann31c21f92013-05-08 09:21:53 -0700570IndexParams IndexType() throws ParseException:
571{
572 IndexType type = null;
573 int gramLength = 0;
574}
575{
576 ("btree"
577 {
578 type = IndexType.BTREE;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800579 }
Till Westmann31c21f92013-05-08 09:21:53 -0700580 | "rtree"
581 {
582 type = IndexType.RTREE;
583 }
584 | "keyword"
585 {
JIMAHNb75446d2013-06-03 08:35:27 -0700586 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700587 }
588 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
589 {
JIMAHNb75446d2013-06-03 08:35:27 -0700590 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700591 gramLength = Integer.valueOf(token.image);
592 }
593 <RIGHTPAREN>)
594 {
595 return new IndexParams(type, gramLength);
596 }
597}
598
599CreateDataverseStatement DataverseSpecification() throws ParseException :
600{
Till Westmann14a20a72013-05-09 00:06:24 -0700601 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700602 boolean ifNotExists = false;
603 String format = null;
604}
605{
Till Westmanna4242bc2013-05-08 17:49:55 -0700606 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700607 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700608 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700609 {
Till Westmann14a20a72013-05-09 00:06:24 -0700610 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700611 }
612}
613
614CreateFunctionStatement FunctionSpecification() throws ParseException:
615{
616 FunctionSignature signature;
617 boolean ifNotExists = false;
618 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
619 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700620 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700621 Expression functionBodyExpr;
622 Token beginPos;
623 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700624 FunctionName fctName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800625
Till Westmann31c21f92013-05-08 09:21:53 -0700626 createNewScope();
627}
628{
ramangrover299f76a5e2013-06-18 10:25:17 -0700629 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700630 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700631 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700632 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530633 {
634 beginPos = token;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800635 }
Till Westmann96c1f172013-08-01 02:05:48 -0700636 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700637 {
638 endPos = token;
639 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700640 // TODO use fctName.library
641 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700642 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800643 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700644 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
645 }
646}
647
ramangrover29a774ef22013-07-17 09:29:18 -0700648CreateFeedStatement FeedSpecification() throws ParseException:
649{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800650 Pair<Identifier,Identifier> nameComponents = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700651 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700652 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700653 Map<String,String> properties = null;
654 FunctionSignature appliedFunction = null;
655 CreateFeedStatement cfs = null;
656}
657{
658 (
659 "feed" nameComponents = QualifiedName()
660 ifNotExists = IfNotExists()
Chris Hillerye64055d2014-10-11 00:14:39 -0700661 "using" adapterName = AdapterName() properties = Configuration()
ramangrover29a774ef22013-07-17 09:29:18 -0700662 (appliedFunction = ApplyFunction())?
663 {
664 cfs = new CreateFeedStatement(nameComponents.first,
Chris Hillerye64055d2014-10-11 00:14:39 -0700665 nameComponents.second, adapterName, properties, appliedFunction, ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800666 }
667
ramangrover29a774ef22013-07-17 09:29:18 -0700668 )
669 {
670 return cfs;
671 }
672}
673
674
675
Till Westmannd7dcb122013-05-16 13:19:09 -0700676List<VarIdentifier> ParameterList() throws ParseException:
677{
678 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
679 VarIdentifier var = null;
680}
681{
Till Westmann31c21f92013-05-08 09:21:53 -0700682 <LEFTPAREN> (<VARIABLE>
683 {
684 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700685 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700686 paramList.add(var);
687 getCurrentScope().addNewVarSymbolToScope(var);
688 }
Till Westmann96c1f172013-08-01 02:05:48 -0700689 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700690 {
691 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700692 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700693 paramList.add(var);
694 getCurrentScope().addNewVarSymbolToScope(var);
695 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700696 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700697 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700698 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700699 }
700}
701
702boolean IfNotExists() throws ParseException:
703{
704}
705{
706 ( "if not exists"
707 {
708 return true;
709 }
710 )?
711 {
712 return false;
713 }
714}
715
716FunctionSignature ApplyFunction() throws ParseException:
717{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530718 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700719 FunctionSignature funcSig = null;
720}
721{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530722 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700723 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530724 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
725 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700726 }
727}
728
ramangrover29566b3a92013-05-28 09:07:10 -0700729String GetPolicy() throws ParseException:
730{
731 String policy = null;
732}
733{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800734 "using" "policy" policy = Identifier()
ramangrover29566b3a92013-05-28 09:07:10 -0700735 {
736 return policy;
737 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800738
739}
ramangrover29566b3a92013-05-28 09:07:10 -0700740
Till Westmann31c21f92013-05-08 09:21:53 -0700741FunctionSignature FunctionSignature() throws ParseException:
742{
ramangrover299f76a5e2013-06-18 10:25:17 -0700743 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700744 int arity = 0;
745}
746{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800747 fctName = FunctionName() "@" <INTEGER_LITERAL>
748 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700749 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700750 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
751 throw new ParseException(" invalid arity:" + arity);
752 }
753
ramangrover299f76a5e2013-06-18 10:25:17 -0700754 // TODO use fctName.library
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800755 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700756 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700757 }
758}
759
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700760List<List<String>> PrimaryKey() throws ParseException:
Till Westmann31c21f92013-05-08 09:21:53 -0700761{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700762 List<String> tmp = null;
763 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Till Westmann31c21f92013-05-08 09:21:53 -0700764}
765{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700766 "primary" "key" tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700767 {
Till Westmann14a20a72013-05-09 00:06:24 -0700768 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700769 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700770 ( <COMMA> tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700771 {
Till Westmann14a20a72013-05-09 00:06:24 -0700772 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700773 }
774 )*
775 {
776 return primaryKeyFields;
777 }
778}
779
780Statement DropStatement() throws ParseException:
781{
Till Westmann14a20a72013-05-09 00:06:24 -0700782 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700783 Pair<Identifier,Identifier> pairId = null;
784 Triple<Identifier,Identifier,Identifier> tripleId = null;
785 FunctionSignature funcSig = null;
786 boolean ifExists = false;
787 Statement stmt = null;
788}
789{
790 "drop"
791 (
792 <DATASET> pairId = QualifiedName() ifExists = IfExists()
793 {
794 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
795 }
796 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
797 {
798 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
799 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700800 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700801 {
Till Westmann14a20a72013-05-09 00:06:24 -0700802 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700803 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700804 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700805 {
806 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
807 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700808 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700809 {
Till Westmann14a20a72013-05-09 00:06:24 -0700810 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700811 }
812 | "function" funcSig = FunctionSignature() ifExists = IfExists()
813 {
814 stmt = new FunctionDropStatement(funcSig, ifExists);
815 }
ramangrover29a774ef22013-07-17 09:29:18 -0700816 | "feed" pairId = QualifiedName() ifExists = IfExists()
817 {
818 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800819 }
Till Westmann31c21f92013-05-08 09:21:53 -0700820 )
821 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800822 return stmt;
Till Westmann31c21f92013-05-08 09:21:53 -0700823 }
824}
825
826boolean IfExists() throws ParseException :
827{
828}
829{
Till Westmann96c1f172013-08-01 02:05:48 -0700830 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700831 {
832 return true;
833 }
834 )?
835 {
836 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000837 }
838}
839
840InsertStatement InsertStatement() throws ParseException:
841{
Till Westmann31c21f92013-05-08 09:21:53 -0700842 Pair<Identifier,Identifier> nameComponents = null;
843 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000844}
845{
Till Westmann31c21f92013-05-08 09:21:53 -0700846 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
847 {
848 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
849 }
vinayakb38b7ca42012-03-05 05:44:15 +0000850}
851
852DeleteStatement DeleteStatement() throws ParseException:
853{
Till Westmann31c21f92013-05-08 09:21:53 -0700854 VariableExpr var = null;
855 Expression condition = null;
856 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300857 // This is related to the new metadata lock management
858 setDataverses(new ArrayList<String>());
859 setDatasets(new ArrayList<String>());
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800860
vinayakb38b7ca42012-03-05 05:44:15 +0000861}
862{
Till Westmann31c21f92013-05-08 09:21:53 -0700863 "delete" var = Variable()
864 {
865 getCurrentScope().addNewVarSymbolToScope(var.getVar());
866 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800867 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800868 (<WHERE> condition = Expression())?
869 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300870 // First we get the dataverses and datasets that we want to lock
871 List<String> dataverses = getDataverses();
872 List<String> datasets = getDatasets();
873 // we remove the pointer to the dataverses and datasets
874 setDataverses(null);
875 setDatasets(null);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800876 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
877 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700878 }
vinayakb38b7ca42012-03-05 05:44:15 +0000879}
880
881UpdateStatement UpdateStatement() throws ParseException:
882{
Till Westmann31c21f92013-05-08 09:21:53 -0700883 VariableExpr vars;
884 Expression target;
885 Expression condition;
886 UpdateClause uc;
887 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000888}
889{
Till Westmann96c1f172013-08-01 02:05:48 -0700890 "update" vars = Variable() <IN> target = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800891 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700892 <LEFTPAREN> (uc = UpdateClause()
893 {
894 ucs.add(uc);
895 }
Till Westmann96c1f172013-08-01 02:05:48 -0700896 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700897 {
898 ucs.add(uc);
899 }
900 )*) <RIGHTPAREN>
901 {
902 return new UpdateStatement(vars, target, condition, ucs);
903 }
vinayakb38b7ca42012-03-05 05:44:15 +0000904}
905
vinayakb38b7ca42012-03-05 05:44:15 +0000906UpdateClause UpdateClause() throws ParseException:
907{
Till Westmann31c21f92013-05-08 09:21:53 -0700908 Expression target = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800909 Expression value = null ;
Till Westmann31c21f92013-05-08 09:21:53 -0700910 InsertStatement is = null;
911 DeleteStatement ds = null;
912 UpdateStatement us = null;
913 Expression condition = null;
914 UpdateClause ifbranch = null;
915 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000916}
917{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800918 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700919 | is = InsertStatement()
920 | ds = DeleteStatement()
921 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700922 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
923 <THEN> ifbranch = UpdateClause()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800924 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700925 {
926 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
927 }
vinayakb38b7ca42012-03-05 05:44:15 +0000928}
929
vinayakb38b7ca42012-03-05 05:44:15 +0000930Statement SetStatement() throws ParseException:
931{
932 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700933 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000934}
935{
Till Westmann7d535322013-05-09 00:40:02 -0700936 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700937 {
Till Westmann31c21f92013-05-08 09:21:53 -0700938 return new SetStatement(pn, pv);
939 }
vinayakb38b7ca42012-03-05 05:44:15 +0000940}
941
942Statement WriteStatement() throws ParseException:
943{
Till Westmann14a20a72013-05-09 00:06:24 -0700944 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000945 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000946 Query query;
947 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000948 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000949}
950{
Till Westmann96c1f172013-08-01 02:05:48 -0700951 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700952 ( "using" writerClass = StringLiteral() )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800953 {
954 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000955 }
956}
957
zheilbron28e026f2013-11-20 10:15:15 -0800958LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000959{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000960 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000961 Identifier datasetName = null;
962 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000963 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000964 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000965 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000966}
967{
Till Westmann31c21f92013-05-08 09:21:53 -0700968 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000969 {
Till Westmann31c21f92013-05-08 09:21:53 -0700970 dataverseName = nameComponents.first;
971 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000972 }
Till Westmann31c21f92013-05-08 09:21:53 -0700973 "using" adapterName = AdapterName() properties = Configuration()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800974 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000975 {
Till Westmann31c21f92013-05-08 09:21:53 -0700976 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000977 }
978 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700979 {
zheilbron28e026f2013-11-20 10:15:15 -0800980 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800981 }
vinayakb38b7ca42012-03-05 05:44:15 +0000982}
983
vinayakb38b7ca42012-03-05 05:44:15 +0000984
Till Westmann31c21f92013-05-08 09:21:53 -0700985String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000986{
ramangrover29669d8f62013-02-11 06:03:32 +0000987 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000988}
989{
Till Westmann68d99652013-05-09 11:15:21 -0700990 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000991 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800992 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000993 }
vinayakb38b7ca42012-03-05 05:44:15 +0000994}
995
salsubaiee0b423fa2013-09-19 19:16:48 -0700996Statement CompactStatement() throws ParseException:
997{
998 Pair<Identifier,Identifier> nameComponents = null;
999 Statement stmt = null;
1000}
1001{
1002 "compact" <DATASET> nameComponents = QualifiedName()
1003 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001004 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
salsubaiee0b423fa2013-09-19 19:16:48 -07001005 }
1006 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001007 return stmt;
salsubaiee0b423fa2013-09-19 19:16:48 -07001008 }
1009}
1010
Till Westmann31c21f92013-05-08 09:21:53 -07001011Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001012{
ramangrover29a774ef22013-07-17 09:29:18 -07001013 Pair<Identifier,Identifier> feedNameComponents = null;
1014 Pair<Identifier,Identifier> datasetNameComponents = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001015
Till Westmann31c21f92013-05-08 09:21:53 -07001016 Map<String,String> configuration = null;
1017 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -07001018 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001019}
1020{
Till Westmann31c21f92013-05-08 09:21:53 -07001021 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001022 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -07001023 {
ramangrover29a774ef22013-07-17 09:29:18 -07001024 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -07001025 }
buyingyi2fd7fa62014-11-24 19:31:55 -08001026 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -07001027 {
ramangrover29a774ef22013-07-17 09:29:18 -07001028 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -07001029 }
1030 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001031 {
Till Westmann31c21f92013-05-08 09:21:53 -07001032 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001033 }
1034}
1035
Till Westmann31c21f92013-05-08 09:21:53 -07001036Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001037{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001038 Map<String,String> configuration = new LinkedHashMap<String,String>();
1039 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001040}
1041{
Till Westmann31c21f92013-05-08 09:21:53 -07001042 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001043 {
Till Westmann31c21f92013-05-08 09:21:53 -07001044 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001045 }
Till Westmann96c1f172013-08-01 02:05:48 -07001046 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001047 {
Till Westmann31c21f92013-05-08 09:21:53 -07001048 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001049 }
Till Westmann31c21f92013-05-08 09:21:53 -07001050 )* )? <RIGHTPAREN>
1051 {
1052 return configuration;
1053 }
1054}
1055
1056Pair<String, String> KeyValuePair() throws ParseException:
1057{
1058 String key;
1059 String value;
1060}
1061{
Till Westmann96c1f172013-08-01 02:05:48 -07001062 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -07001063 {
1064 return new Pair<String, String>(key, value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001065 }
Till Westmann31c21f92013-05-08 09:21:53 -07001066}
1067
1068Map<String,String> Properties() throws ParseException:
1069{
1070 Map<String,String> properties = new HashMap<String,String>();
1071 Pair<String, String> property;
1072}
1073{
1074 ( <LEFTPAREN> property = Property()
1075 {
1076 properties.put(property.first, property.second);
1077 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001078 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -07001079 {
1080 properties.put(property.first, property.second);
1081 }
1082 )* <RIGHTPAREN> )?
1083 {
1084 return properties;
1085 }
1086}
1087
1088Pair<String, String> Property() throws ParseException:
1089{
1090 String key;
1091 String value;
1092}
1093{
Till Westmann96c1f172013-08-01 02:05:48 -07001094 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001095 {
1096 try {
1097 value = "" + Long.valueOf(token.image);
1098 } catch (NumberFormatException nfe) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001099 throw new ParseException("inapproriate value: " + token.image);
Till Westmann31c21f92013-05-08 09:21:53 -07001100 }
1101 }
1102 )
1103 {
1104 return new Pair<String, String>(key.toUpperCase(), value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001105 }
vinayakb38b7ca42012-03-05 05:44:15 +00001106}
1107
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001108TypeExpression IndexedTypeExpr() throws ParseException:
1109{
1110 TypeExpression typeExpr = null;
1111}
1112{
1113 (
1114 typeExpr = TypeReference()
1115 | typeExpr = OrderedListTypeDef()
1116 | typeExpr = UnorderedListTypeDef()
1117 )
1118 {
1119 return typeExpr;
1120 }
1121}
1122
vinayakb38b7ca42012-03-05 05:44:15 +00001123TypeExpression TypeExpr() throws ParseException:
1124{
1125 TypeExpression typeExpr = null;
1126}
1127{
1128 (
1129 typeExpr = RecordTypeDef()
1130 | typeExpr = TypeReference()
1131 | typeExpr = OrderedListTypeDef()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001132 | typeExpr = UnorderedListTypeDef()
1133 )
vinayakb38b7ca42012-03-05 05:44:15 +00001134 {
1135 return typeExpr;
1136 }
1137}
1138
1139RecordTypeDefinition RecordTypeDef() throws ParseException:
1140{
1141 RecordTypeDefinition recType = new RecordTypeDefinition();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001142 RecordTypeDefinition.RecordKind recordKind = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001143}
1144{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001145 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
vinayakb38b7ca42012-03-05 05:44:15 +00001146 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001147 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001148 {
1149 String hint = getHint(token);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001150 if (hint != null) {
vinayakb38b7ca42012-03-05 05:44:15 +00001151 String splits[] = hint.split(" +");
1152 if (splits[0].equals(GEN_FIELDS_HINT)) {
1153 if (splits.length != 5) {
1154 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1155 }
1156 if (!splits[1].equals("int")) {
1157 throw new ParseException("The only supported type for gen-fields is int.");
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001158 }
1159 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
vinayakb38b7ca42012-03-05 05:44:15 +00001160 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001161 recType.setUndeclaredFieldsDataGen(ufdg);
vinayakb38b7ca42012-03-05 05:44:15 +00001162 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001163 }
1164
vinayakb38b7ca42012-03-05 05:44:15 +00001165 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001166 (
1167 RecordField(recType)
1168 ( <COMMA> RecordField(recType) )*
1169 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001170 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001171 {
1172 if (recordKind == null) {
1173 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1174 }
1175 recType.setRecordKind(recordKind);
1176 return recType;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001177 }
vinayakb38b7ca42012-03-05 05:44:15 +00001178}
1179
1180void RecordField(RecordTypeDefinition recType) throws ParseException:
1181{
Till Westmann77cb2f42013-07-15 16:44:19 -07001182 String fieldName;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001183 TypeExpression type = null;
Till Westmann77cb2f42013-07-15 16:44:19 -07001184 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001185}
1186{
Till Westmann77cb2f42013-07-15 16:44:19 -07001187 fieldName = Identifier()
1188 {
1189 String hint = getHint(token);
1190 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1191 }
Till Westmann96c1f172013-08-01 02:05:48 -07001192 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001193 {
1194 recType.addField(fieldName, type, nullable, rfdg);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001195 }
vinayakb38b7ca42012-03-05 05:44:15 +00001196}
1197
1198TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001199{
Till Westmann14a20a72013-05-09 00:06:24 -07001200 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001201}
1202{
1203 id = Identifier()
1204 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001205 if (id.equalsIgnoreCase("int")) {
1206 id = "int64";
1207 }
1208
Till Westmann14a20a72013-05-09 00:06:24 -07001209 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001210 }
vinayakb38b7ca42012-03-05 05:44:15 +00001211}
1212
1213OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001214{
vinayakb38b7ca42012-03-05 05:44:15 +00001215 TypeExpression type = null;
1216}
1217{
Till Westmann96c1f172013-08-01 02:05:48 -07001218 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001219 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001220 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001221 {
1222 return new OrderedListTypeDefinition(type);
1223 }
1224}
1225
1226
1227UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001228{
vinayakb38b7ca42012-03-05 05:44:15 +00001229 TypeExpression type = null;
1230}
1231{
Till Westmann96c1f172013-08-01 02:05:48 -07001232 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001233 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001234 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001235 {
1236 return new UnorderedListTypeDefinition(type);
1237 }
1238}
1239
ramangrover299f76a5e2013-06-18 10:25:17 -07001240FunctionName FunctionName() throws ParseException:
1241{
1242 String first = null;
1243 String second = null;
1244 String third = null;
1245 boolean secondAfterDot = false;
1246}
1247{
zheilbron555dc9d2013-08-14 19:58:00 -07001248 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001249 {
1250 secondAfterDot = true;
1251 }
1252 ("#" third = Identifier())? | "#" second = Identifier() )?
1253 {
1254 FunctionName result = new FunctionName();
1255 if (second == null) {
1256 result.dataverse = defaultDataverse;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001257 result.library = null;
1258 result.function = first;
ramangrover299f76a5e2013-06-18 10:25:17 -07001259 } else if (third == null) {
1260 if (secondAfterDot) {
1261 result.dataverse = first;
1262 result.library = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001263 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001264 } else {
1265 result.dataverse = defaultDataverse;
1266 result.library = first;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001267 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001268 }
1269 } else {
1270 result.dataverse = first;
1271 result.library = second;
1272 result.function = third;
1273 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001274
1275 if (result.function.equalsIgnoreCase("int")) {
1276 result.function = "int64";
1277 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001278 return result;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001279 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001280}
Till Westmann31c21f92013-05-08 09:21:53 -07001281
ramangrover299f76a5e2013-06-18 10:25:17 -07001282
1283Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001284{
Till Westmann31c21f92013-05-08 09:21:53 -07001285 Pair<Identifier,Identifier> name = null;
1286}
1287{
1288 name = QualifiedName()
1289 {
1290 if (name.first == null) {
1291 name.first = new Identifier(defaultDataverse);
1292 }
1293 return name;
1294 }
1295}
1296
Till Westmann14a20a72013-05-09 00:06:24 -07001297String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001298{
Till Westmann68d99652013-05-09 11:15:21 -07001299 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001300}
1301{
1302 <IDENTIFIER>
1303 {
Till Westmann14a20a72013-05-09 00:06:24 -07001304 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001305 }
Till Westmann68d99652013-05-09 11:15:21 -07001306 | lit = StringLiteral()
1307 {
1308 return lit;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001309 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001310}
1311
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001312Pair<List<String>, TypeExpression> OpenField() throws ParseException:
1313{
1314 TypeExpression fieldType = null;
1315 List<String> fieldList = null;
1316}
1317{
1318 fieldList = NestedField()
1319 ( <COLON> fieldType = IndexedTypeExpr() )?
1320 {
1321 return new Pair<List<String>, TypeExpression>(fieldList, fieldType);
1322 }
1323}
1324
1325List<String> NestedField() throws ParseException:
1326{
1327 List<String> exprList = new ArrayList<String>();
1328 String lit = null;
1329}
1330{
1331 lit = Identifier()
1332 {
1333 exprList.add(lit);
1334 }
1335 (<DOT>
1336 lit = Identifier()
1337 {
1338 exprList.add(lit);
1339 }
1340 )*
1341 {
1342 return exprList;
1343 }
1344}
1345
1346
1347
Till Westmann7d535322013-05-09 00:40:02 -07001348String StringLiteral() throws ParseException:
1349{
1350}
1351{
1352 <STRING_LITERAL>
1353 {
1354 return removeQuotesAndEscapes(token.image);
1355 }
1356}
1357
Till Westmann31c21f92013-05-08 09:21:53 -07001358Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1359{
Till Westmann14a20a72013-05-09 00:06:24 -07001360 String first = null;
1361 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001362}
1363{
Till Westmann96c1f172013-08-01 02:05:48 -07001364 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001365 {
Till Westmann14a20a72013-05-09 00:06:24 -07001366 Identifier id1 = null;
1367 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001368 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001369 id2 = new Identifier(first);
1370 } else
1371 {
1372 id1 = new Identifier(first);
1373 id2 = new Identifier(second);
1374 }
1375 return new Pair<Identifier,Identifier>(id1, id2);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001376 }
1377}
1378
Till Westmann31c21f92013-05-08 09:21:53 -07001379Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001380{
Till Westmann14a20a72013-05-09 00:06:24 -07001381 String first = null;
1382 String second = null;
1383 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001384}
1385{
Till Westmann96c1f172013-08-01 02:05:48 -07001386 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001387 {
Till Westmann14a20a72013-05-09 00:06:24 -07001388 Identifier id1 = null;
1389 Identifier id2 = null;
1390 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001391 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001392 id2 = new Identifier(first);
1393 id3 = new Identifier(second);
1394 } else {
1395 id1 = new Identifier(first);
1396 id2 = new Identifier(second);
1397 id3 = new Identifier(third);
1398 }
1399 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001400 }
1401}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001402
vinayakb38b7ca42012-03-05 05:44:15 +00001403FunctionDecl FunctionDeclaration() throws ParseException:
1404{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001405 FunctionDecl funcDecl;
1406 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001407 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001408 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1409 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001410 createNewScope();
1411}
1412{
Till Westmannd7dcb122013-05-16 13:19:09 -07001413 "declare" "function" functionName = Identifier()
1414 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001415 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001416 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001417 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001418 getCurrentScope().addFunctionDescriptor(signature, false);
1419 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001420 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001421 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001422 }
1423}
1424
vinayakb38b7ca42012-03-05 05:44:15 +00001425
Till Westmann31c21f92013-05-08 09:21:53 -07001426Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001427{
1428 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001429 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1430 setDataverses(query.getDataverses());
1431 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001432 Expression expr;
1433}
1434{
Till Westmann31c21f92013-05-08 09:21:53 -07001435 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001436 {
1437 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001438 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001439 // we remove the pointers to the locked entities before we return the query object
1440 setDataverses(null);
1441 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001442 return query;
1443 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001444
vinayakb38b7ca42012-03-05 05:44:15 +00001445}
1446
1447
1448
1449Expression Expression():
1450{
1451 Expression expr = null;
1452 Expression exprP = null;
1453}
1454{
1455(
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001456
vinayakb38b7ca42012-03-05 05:44:15 +00001457//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1458 expr = OperatorExpr()
1459 | expr = IfThenElse()
1460 | expr = FLWOGR()
1461 | expr = QuantifiedExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001462
vinayakb38b7ca42012-03-05 05:44:15 +00001463
1464)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001465 {
1466 return (exprP==null) ? expr : exprP;
1467 }
vinayakb38b7ca42012-03-05 05:44:15 +00001468}
1469
1470
1471
1472Expression OperatorExpr()throws ParseException:
1473{
1474 OperatorExpr op = null;
1475 Expression operand = null;
1476}
1477{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001478 operand = AndExpr()
1479 (
1480
1481 <OR>
1482 {
1483 if (op == null) {
1484 op = new OperatorExpr();
1485 op.addOperand(operand);
1486 op.setCurrentop(true);
1487 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001488 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001489 }
vinayakb38b7ca42012-03-05 05:44:15 +00001490
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001491 operand = AndExpr()
1492 {
1493 op.addOperand(operand);
1494 }
vinayakb38b7ca42012-03-05 05:44:15 +00001495
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001496 )*
1497
1498 {
1499 return op==null? operand: op;
1500 }
vinayakb38b7ca42012-03-05 05:44:15 +00001501}
1502
1503Expression AndExpr()throws ParseException:
1504{
1505 OperatorExpr op = null;
1506 Expression operand = null;
1507}
1508{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001509 operand = RelExpr()
1510 (
1511
1512 <AND>
1513 {
1514 if (op == null) {
1515 op = new OperatorExpr();
1516 op.addOperand(operand);
1517 op.setCurrentop(true);
1518 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001519 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001520 }
vinayakb38b7ca42012-03-05 05:44:15 +00001521
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001522 operand = RelExpr()
1523 {
1524 op.addOperand(operand);
1525 }
vinayakb38b7ca42012-03-05 05:44:15 +00001526
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001527 )*
1528
1529 {
1530 return op==null? operand: op;
1531 }
vinayakb38b7ca42012-03-05 05:44:15 +00001532}
1533
1534
1535
1536Expression RelExpr()throws ParseException:
1537{
1538 OperatorExpr op = null;
1539 Expression operand = null;
1540 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001541 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001542}
1543{
1544 operand = AddExpr()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001545 {
1546 if (operand instanceof VariableExpr) {
1547 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001548 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001549 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001550 }
1551 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001552 }
vinayakb38b7ca42012-03-05 05:44:15 +00001553
1554 (
Till Westmann96c1f172013-08-01 02:05:48 -07001555 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001556 {
1557 String mhint = getHint(token);
1558 if (mhint != null) {
1559 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
salsubaieedf89fbc2013-12-21 19:51:42 -08001560 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1561 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1562 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1563 }
alexander.behm07617fd2012-07-25 10:13:50 +00001564 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001565 if (op == null) {
1566 op = new OperatorExpr();
1567 op.addOperand(operand, broadcast);
vinayakb38b7ca42012-03-05 05:44:15 +00001568 op.setCurrentop(true);
1569 broadcast = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001570 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001571 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001572 }
1573
1574 operand = AddExpr()
1575 {
1576 broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001577 if (operand instanceof VariableExpr) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001578 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001579 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1580 broadcast = true;
1581 }
alexander.behm07617fd2012-07-25 10:13:50 +00001582 }
vinayakb38b7ca42012-03-05 05:44:15 +00001583 op.addOperand(operand, broadcast);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001584 }
vinayakb38b7ca42012-03-05 05:44:15 +00001585 )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001586
1587 {
1588 if (annotation != null) {
1589 op.addHint(annotation);
1590 }
1591 return op==null? operand: op;
1592 }
vinayakb38b7ca42012-03-05 05:44:15 +00001593}
1594
1595Expression AddExpr()throws ParseException:
1596{
1597 OperatorExpr op = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001598 Expression operand = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001599}
1600{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001601 operand = MultExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001602
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001603 ( (<PLUS> | <MINUS>)
1604 {
1605 if (op == null) {
1606 op = new OperatorExpr();
1607 op.addOperand(operand);
1608 op.setCurrentop(true);
1609 }
1610 ((OperatorExpr)op).addOperator(token.image);
1611 }
vinayakb38b7ca42012-03-05 05:44:15 +00001612
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001613 operand = MultExpr()
1614 {
1615 op.addOperand(operand);
1616 }
1617 )*
1618
1619 {
1620 return op==null? operand: op;
1621 }
vinayakb38b7ca42012-03-05 05:44:15 +00001622}
1623
1624Expression MultExpr()throws ParseException:
1625{
1626 OperatorExpr op = null;
1627 Expression operand = null;
1628}
1629{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001630 operand = UnionExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001631
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001632 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1633 {
1634 if (op == null) {
1635 op = new OperatorExpr();
vinayakb38b7ca42012-03-05 05:44:15 +00001636 op.addOperand(operand);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001637 op.setCurrentop(true);
1638 }
1639 op.addOperator(token.image);
1640 }
1641 operand = UnionExpr()
1642 {
1643 op.addOperand(operand);
1644 }
1645 )*
1646
1647 {
1648 return op==null?operand:op;
1649 }
vinayakb38b7ca42012-03-05 05:44:15 +00001650}
1651
1652Expression UnionExpr() throws ParseException:
1653{
1654 UnionExpr union = null;
1655 Expression operand1 = null;
1656 Expression operand2 = null;
1657}
1658{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001659 operand1 = UnaryExpr()
1660 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001661 (operand2 = UnaryExpr()) {
1662 if (union == null) {
1663 union = new UnionExpr();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001664 union.addExpr(operand1);
vinayakb38b7ca42012-03-05 05:44:15 +00001665 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001666 union.addExpr(operand2);
vinayakb38b7ca42012-03-05 05:44:15 +00001667 } )*
1668 {
1669 return (union == null)? operand1: union;
1670 }
1671}
1672
1673Expression UnaryExpr() throws ParseException:
1674{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001675 Expression uexpr = null;
1676 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001677}
1678{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001679 ( (<PLUS> | <MINUS>)
1680 {
1681 uexpr = new UnaryExpr();
1682 if("+".equals(token.image))
1683 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1684 else if("-".equals(token.image))
1685 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1686 else
1687 throw new ParseException();
1688 }
1689 )?
1690
1691 expr = ValueExpr()
1692 {
1693 if(uexpr!=null){
1694 ((UnaryExpr)uexpr).setExpr(expr);
1695 return uexpr;
1696 }
1697 else{
1698 return expr;
1699 }
1700 }
vinayakb38b7ca42012-03-05 05:44:15 +00001701}
1702
Till Westmann04478e72013-05-13 23:01:34 -07001703Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001704{
1705 Expression expr = null;
1706 Identifier ident = null;
1707 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001708 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001709}
1710{
Till Westmann04478e72013-05-13 23:01:34 -07001711 expr = PrimaryExpr() ( ident = Field()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001712 {
1713 fa = (fa == null ? new FieldAccessor(expr, ident)
Till Westmann04478e72013-05-13 23:01:34 -07001714 : new FieldAccessor(fa, ident));
1715 }
icetindila611ac72014-05-16 10:10:11 -07001716 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001717 {
icetindila611ac72014-05-16 10:10:11 -07001718 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1719 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001720 }
1721 )*
1722 {
1723 return fa == null ? expr : fa;
1724 }
vinayakb38b7ca42012-03-05 05:44:15 +00001725}
1726
1727Identifier Field() throws ParseException:
1728{
Till Westmann14a20a72013-05-09 00:06:24 -07001729 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001730}
1731{
Till Westmann96c1f172013-08-01 02:05:48 -07001732 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001733 {
Till Westmann14a20a72013-05-09 00:06:24 -07001734 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001735 }
vinayakb38b7ca42012-03-05 05:44:15 +00001736}
1737
icetindila611ac72014-05-16 10:10:11 -07001738Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001739{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001740 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001741}
1742{
Till Westmann96c1f172013-08-01 02:05:48 -07001743 <LEFTBRACKET> ( expr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001744 {
1745 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1746 {
1747 Literal lit = ((LiteralExpr)expr).getValue();
1748 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1749 lit.getLiteralType() != Literal.Type.LONG) {
1750 throw new ParseException("Index should be an INTEGER");
vinayakb38b7ca42012-03-05 05:44:15 +00001751 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001752 }
1753 }
vinayakb38b7ca42012-03-05 05:44:15 +00001754
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001755 | <QUES> // ANY
1756
1757 )
vinayakb38b7ca42012-03-05 05:44:15 +00001758
Till Westmann96c1f172013-08-01 02:05:48 -07001759 <RIGHTBRACKET>
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001760 {
1761 return expr;
1762 }
vinayakb38b7ca42012-03-05 05:44:15 +00001763}
1764
1765
1766Expression PrimaryExpr()throws ParseException:
1767{
1768 Expression expr = null;
1769}
1770{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001771 ( LOOKAHEAD(2)
Till Westmann68d99652013-05-09 11:15:21 -07001772 expr = FunctionCallExpr()
1773 | expr = Literal()
1774 | expr = DatasetAccessExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001775 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001776 {
1777 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001778 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001779 }
Till Westmann68d99652013-05-09 11:15:21 -07001780 | expr = ListConstructor()
1781 | expr = RecordConstructor()
1782 | expr = ParenthesizedExpression()
1783 )
1784 {
1785 return expr;
1786 }
vinayakb38b7ca42012-03-05 05:44:15 +00001787}
1788
1789Expression Literal() throws ParseException:
1790{
vinayakb38b7ca42012-03-05 05:44:15 +00001791 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001792 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001793}
1794{
Till Westmann7d535322013-05-09 00:40:02 -07001795 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001796 {
Till Westmann7d535322013-05-09 00:40:02 -07001797 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001798 }
1799 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001800 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001801 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
Till Westmanna4242bc2013-05-08 17:49:55 -07001802 }
1803 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001804 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001805 lit.setValue(new FloatLiteral(new Float(token.image)));
1806 }
1807 | <DOUBLE_LITERAL>
1808 {
1809 lit.setValue(new DoubleLiteral(new Double(token.image)));
1810 }
1811 | <NULL>
1812 {
1813 lit.setValue(NullLiteral.INSTANCE);
1814 }
1815 | <TRUE>
1816 {
1817 lit.setValue(TrueLiteral.INSTANCE);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001818 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001819 | <FALSE>
1820 {
1821 lit.setValue(FalseLiteral.INSTANCE);
1822 }
1823 )
vinayakb38b7ca42012-03-05 05:44:15 +00001824 {
1825 return lit;
1826 }
1827}
1828
1829
1830VariableExpr VariableRef() throws ParseException:
1831{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001832 VariableExpr varExp = new VariableExpr();
1833 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001834}
1835{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001836 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001837 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001838 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001839 Identifier ident = lookupSymbol(varName);
1840 if (isInForbiddenScopes(varName)) {
1841 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.");
1842 }
1843 if(ident != null) { // exist such ident
1844 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001845 varExp.setVar((VarIdentifier)ident);
vinayakb38b7ca42012-03-05 05:44:15 +00001846 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001847 varExp.setVar(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001848 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001849 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001850 return varExp;
1851 }
1852}
1853
1854
1855VariableExpr Variable() throws ParseException:
1856{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001857 VariableExpr varExp = new VariableExpr();
1858 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001859}
1860{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001861 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001862 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001863 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001864 if(ident != null) { // exist such ident
1865 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001866 }
1867 varExp.setVar(var);
1868 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001869 return varExp;
1870 }
1871}
1872
1873Expression ListConstructor() throws ParseException:
1874{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001875 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001876}
1877{
1878 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001879 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
vinayakb38b7ca42012-03-05 05:44:15 +00001880 )
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001881
vinayakb38b7ca42012-03-05 05:44:15 +00001882 {
1883 return expr;
1884 }
1885}
1886
1887
1888ListConstructor OrderedListConstructor() throws ParseException:
1889{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001890 ListConstructor expr = new ListConstructor();
1891 Expression tmp = null;
1892 List<Expression> exprList = new ArrayList<Expression>();
1893 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001894}
1895{
1896
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001897 <LEFTBRACKET>
1898 ( tmp = Expression()
1899 {
1900 exprList.add(tmp);
1901 }
1902
1903 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
1904 )?
1905
Till Westmann96c1f172013-08-01 02:05:48 -07001906 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001907
1908 {
1909 expr.setExprList(exprList);
1910 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001911 }
vinayakb38b7ca42012-03-05 05:44:15 +00001912}
1913
1914ListConstructor UnorderedListConstructor() throws ParseException:
1915{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001916 ListConstructor expr = new ListConstructor();
1917 Expression tmp = null;
1918 List<Expression> exprList = new ArrayList<Expression>();
1919 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001920}
1921{
1922
Till Westmann96c1f172013-08-01 02:05:48 -07001923 <LEFTDBLBRACE> ( tmp = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001924 {
1925 exprList.add(tmp);
1926 }
Till Westmann96c1f172013-08-01 02:05:48 -07001927 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001928 {
1929 expr.setExprList(exprList);
1930 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001931 }
vinayakb38b7ca42012-03-05 05:44:15 +00001932}
1933
1934RecordConstructor RecordConstructor() throws ParseException:
1935{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001936 RecordConstructor expr = new RecordConstructor();
1937 FieldBinding tmp = null;
1938 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
vinayakb38b7ca42012-03-05 05:44:15 +00001939}
1940{
Till Westmann96c1f172013-08-01 02:05:48 -07001941 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001942 {
1943 fbList.add(tmp);
1944 }
Till Westmann96c1f172013-08-01 02:05:48 -07001945 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001946 {
1947 expr.setFbList(fbList);
1948 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001949 }
vinayakb38b7ca42012-03-05 05:44:15 +00001950}
1951
1952FieldBinding FieldBinding() throws ParseException:
1953{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001954 FieldBinding fb = new FieldBinding();
1955 Expression left, right;
vinayakb38b7ca42012-03-05 05:44:15 +00001956}
1957{
Till Westmann96c1f172013-08-01 02:05:48 -07001958 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001959 {
1960 fb.setLeftExpr(left);
1961 fb.setRightExpr(right);
1962 return fb;
1963 }
1964}
1965
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001966
vinayakb38b7ca42012-03-05 05:44:15 +00001967Expression FunctionCallExpr() throws ParseException:
1968{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001969 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001970 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001971 Expression tmp;
1972 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001973 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001974 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001975}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001976{
ramangrover299f76a5e2013-06-18 10:25:17 -07001977 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001978 {
Till Westmann31c21f92013-05-08 09:21:53 -07001979 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001980 }
Till Westmann31c21f92013-05-08 09:21:53 -07001981 <LEFTPAREN> (tmp = Expression()
1982 {
1983 argList.add(tmp);
1984 arity ++;
1985 }
Till Westmann96c1f172013-08-01 02:05:48 -07001986 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001987 {
1988 argList.add(tmp);
1989 arity++;
1990 }
1991 )*)? <RIGHTPAREN>
1992 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001993 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001994 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001995 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001996 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001997 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001998 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001999 }
2000 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08002001 if (hint != null) {
2002 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2003 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2004 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2005 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2006 }
Till Westmann31c21f92013-05-08 09:21:53 -07002007 }
2008 return callExpr;
2009 }
vinayakb38b7ca42012-03-05 05:44:15 +00002010}
2011
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002012
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002013Expression DatasetAccessExpression() throws ParseException:
2014{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002015 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07002016 String arg1 = null;
2017 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002018 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002019}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002020{
Till Westmann14a20a72013-05-09 00:06:24 -07002021 <DATASET>
2022 {
Till Westmann14a20a72013-05-09 00:06:24 -07002023 funcName = token.image;
2024 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002025 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07002026 {
2027 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07002028 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07002029 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07002030 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002031 if(arg2 != null){
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002032 addDataverse(arg1.toString());
2033 addDataset(name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002034 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002035 addDataset(defaultDataverse + "." + name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002036 }
Till Westmann14a20a72013-05-09 00:06:24 -07002037 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002038 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07002039 {
Till Westmann1f7a2362013-05-24 08:43:40 -07002040 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2041 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2042 if (signature == null) {
2043 signature = new FunctionSignature(dataverse, funcName, 1);
2044 }
2045 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07002046 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07002047 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07002048 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002049}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002050
vinayakb38b7ca42012-03-05 05:44:15 +00002051Expression ParenthesizedExpression() throws ParseException:
2052{
2053 Expression expr;
2054}
2055{
2056 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2057 {
2058 return expr;
2059 }
2060}
2061
2062Expression IfThenElse() throws ParseException:
2063{
2064 Expression condExpr;
2065 Expression thenExpr;
2066 Expression elseExpr;
2067 IfExpr ifExpr = new IfExpr();
2068}
2069{
Till Westmann96c1f172013-08-01 02:05:48 -07002070 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002071
2072 {
2073 ifExpr.setCondExpr(condExpr);
2074 ifExpr.setThenExpr(thenExpr);
2075 ifExpr.setElseExpr(elseExpr);
2076 return ifExpr;
2077 }
2078}
2079
2080Expression FLWOGR() throws ParseException:
2081{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002082 FLWOGRExpression flworg = new FLWOGRExpression();
2083 List<Clause> clauseList = new ArrayList<Clause>();
2084 Expression returnExpr;
2085 Clause tmp;
2086 createNewScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002087}
2088{
2089 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08002090 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002091
2092 {
2093 flworg.setClauseList(clauseList);
2094 flworg.setReturnExpr(returnExpr);
2095 removeCurrentScope();
2096 return flworg;
2097 }
2098}
2099
2100Clause Clause()throws ParseException :
2101{
2102 Clause clause;
2103}
2104{
2105 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002106 clause = ForClause()
2107 | clause = LetClause()
2108 | clause = WhereClause()
2109 | clause = OrderbyClause()
2110 | clause = GroupClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002111 | clause = LimitClause()
2112 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002113 )
2114 {
2115 return clause;
2116 }
2117}
2118
2119Clause ForClause()throws ParseException :
2120{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002121 ForClause fc = new ForClause();
2122 VariableExpr varExp;
2123 VariableExpr varPos = null;
2124 Expression inExp;
2125 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002126}
2127{
buyingyi2fd7fa62014-11-24 19:31:55 -08002128 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00002129 {
2130 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07002131 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002132 fc.setInExpr(inExp);
2133 if (varPos != null) {
2134 fc.setPosExpr(varPos);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002135 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002136 }
2137 return fc;
2138 }
2139}
2140
2141Clause LetClause() throws ParseException:
2142{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002143 LetClause lc = new LetClause();
2144 VariableExpr varExp;
2145 Expression beExp;
2146 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002147}
2148{
buyingyi2fd7fa62014-11-24 19:31:55 -08002149 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002150 {
2151 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002152 lc.setVarExpr(varExp);
2153 lc.setBeExpr(beExp);
2154 return lc;
2155 }
2156}
2157
2158Clause WhereClause()throws ParseException :
2159{
2160 WhereClause wc = new WhereClause();
2161 Expression whereExpr;
2162}
2163{
salsubaieedf89fbc2013-12-21 19:51:42 -08002164 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002165 {
2166 wc.setWhereExpr(whereExpr);
2167 return wc;
2168 }
2169}
2170
2171Clause OrderbyClause()throws ParseException :
2172{
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002173 OrderbyClause oc = new OrderbyClause();
2174 Expression orderbyExpr;
2175 List<Expression> orderbyList = new ArrayList<Expression>();
2176 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2177 int numOfOrderby = 0;
vinayakb38b7ca42012-03-05 05:44:15 +00002178}
2179{
2180 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002181 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002182 {
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002183 String hint = getHint(token);
2184 if (hint != null) {
2185 if (hint.startsWith(INMEMORY_HINT)) {
2186 String splits[] = hint.split(" +");
2187 int numFrames = Integer.parseInt(splits[1]);
2188 int numTuples = Integer.parseInt(splits[2]);
2189 oc.setNumFrames(numFrames);
2190 oc.setNumTuples(numTuples);
2191 }
2192 if (hint.startsWith(RANGE_HINT)) {
2193 oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
2194 }
2195 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002196 }
Till Westmann96c1f172013-08-01 02:05:48 -07002197 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002198 {
2199 orderbyList.add(orderbyExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002200 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
vinayakb38b7ca42012-03-05 05:44:15 +00002201 }
Till Westmann96c1f172013-08-01 02:05:48 -07002202 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2203 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002204 {
2205 modifierList.add(modif);
2206 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002207
Till Westmann96c1f172013-08-01 02:05:48 -07002208 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002209 {
2210 orderbyList.add(orderbyExpr);
2211 modif = OrderbyClause.OrderModifier.ASC;
2212 }
Till Westmann96c1f172013-08-01 02:05:48 -07002213 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2214 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002215 {
2216 modifierList.add(modif);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002217 }
vinayakb38b7ca42012-03-05 05:44:15 +00002218 )*
2219)
2220 {
2221 oc.setModifierList(modifierList);
2222 oc.setOrderbyList(orderbyList);
2223 return oc;
2224 }
2225}
2226Clause GroupClause()throws ParseException :
2227{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002228 GroupbyClause gbc = new GroupbyClause();
2229 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2230 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
vinayakb38b7ca42012-03-05 05:44:15 +00002231 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002232 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2233 VariableExpr var = null;
2234 VariableExpr withVar = null;
2235 Expression expr = null;
2236 VariableExpr decorVar = null;
2237 Expression decorExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002238}
2239{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002240 {
2241 Scope newScope = extendCurrentScopeNoPush(true);
2242 // extendCurrentScope(true);
2243 }
Till Westmann96c1f172013-08-01 02:05:48 -07002244 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002245 {
2246 String hint = getHint(token);
2247 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002248 gbc.setHashGroupByHint(true);
2249 }
2250 }
Till Westmann96c1f172013-08-01 02:05:48 -07002251 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002252 {
2253 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002254 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002255 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002256 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002257 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002258 vePairList.add(pair1);
2259 }
Till Westmann96c1f172013-08-01 02:05:48 -07002260 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002261 {
2262 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002263 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002264 expr = Expression()
2265 {
2266 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002267 vePairList.add(pair2);
2268 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002269 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002270 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002271 {
2272 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002273 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2274 decorPairList.add(pair3);
2275 }
Till Westmann96c1f172013-08-01 02:05:48 -07002276 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002277 {
2278 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002279 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002280 decorPairList.add(pair4);
vinayakb38b7ca42012-03-05 05:44:15 +00002281 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002282 )*
2283 )?
buyingyi3ca46d02015-01-27 23:22:09 -08002284 (<WITH>|<KEEPING>) withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002285 {
2286 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002287 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002288 withVarList.add(withVar);
2289 newScope.addNewVarSymbolToScope(withVar.getVar());
2290 }
Till Westmann96c1f172013-08-01 02:05:48 -07002291 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002292 {
2293 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002294 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002295 withVarList.add(withVar);
2296 newScope.addNewVarSymbolToScope(withVar.getVar());
2297 })*
2298 {
2299 gbc.setGbyPairList(vePairList);
2300 gbc.setDecorPairList(decorPairList);
2301 gbc.setWithVarList(withVarList);
2302 replaceCurrentScope(newScope);
2303 return gbc;
2304 }
2305}
2306
2307
2308LimitClause LimitClause() throws ParseException:
2309{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002310 LimitClause lc = new LimitClause();
2311 Expression expr;
2312 pushForbiddenScope(getCurrentScope());
vinayakb38b7ca42012-03-05 05:44:15 +00002313}
2314{
Till Westmann96c1f172013-08-01 02:05:48 -07002315 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2316 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002317
2318 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002319 popForbiddenScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002320 return lc;
2321 }
2322}
2323
2324DistinctClause DistinctClause() throws ParseException:
2325{
2326 List<Expression> exprs = new ArrayList<Expression>();
2327 Expression expr;
2328}
2329{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002330 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002331 {
2332 exprs.add(expr);
2333 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002334 (<COMMA> expr = Expression()
2335 {
2336 exprs.add(expr);
2337 }
vinayakb38b7ca42012-03-05 05:44:15 +00002338 )*
2339 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002340 return new DistinctClause(exprs);
vinayakb38b7ca42012-03-05 05:44:15 +00002341 }
2342}
2343
vinayakb38b7ca42012-03-05 05:44:15 +00002344QuantifiedExpression QuantifiedExpression()throws ParseException:
2345{
2346 QuantifiedExpression qc = new QuantifiedExpression();
2347 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2348 Expression satisfiesExpr;
2349 VariableExpr var;
2350 Expression inExpr;
2351 QuantifiedPair pair;
2352}
2353{
2354 {
2355 createNewScope();
2356 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002357
Till Westmann96c1f172013-08-01 02:05:48 -07002358 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002359 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2360 var = Variable() <IN> inExpr = Expression()
2361 {
vinayakb38b7ca42012-03-05 05:44:15 +00002362 pair = new QuantifiedPair(var, inExpr);
2363 getCurrentScope().addNewVarSymbolToScope(var.getVar());
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002364 quantifiedList.add(pair);
2365 }
2366 (
2367 <COMMA> var = Variable() <IN> inExpr = Expression()
2368 {
2369 pair = new QuantifiedPair(var, inExpr);
2370 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2371 quantifiedList.add(pair);
2372 }
2373 )*
2374 <SATISFIES> satisfiesExpr = Expression()
2375 {
2376 qc.setSatisfiesExpr(satisfiesExpr);
2377 qc.setQuantifiedList(quantifiedList);
2378 removeCurrentScope();
2379 return qc;
2380 }
vinayakb38b7ca42012-03-05 05:44:15 +00002381}
2382
2383TOKEN_MGR_DECLS:
2384{
Till Westmann96c1f172013-08-01 02:05:48 -07002385 public int commentDepth = 0;
2386 public IntStack lexerStateStack = new IntStack();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002387
Till Westmann96c1f172013-08-01 02:05:48 -07002388 public void pushState() {
2389 lexerStateStack.push( curLexState );
2390 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002391
Till Westmannfd733ee2014-07-10 00:57:37 -07002392 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002393 if (lexerStateStack.size() > 0) {
2394 SwitchTo( lexerStateStack.pop() );
2395 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002396 int errorLine = input_stream.getEndLine();
2397 int errorColumn = input_stream.getEndColumn();
2398 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2399 + "\" but state stack is empty.";
2400 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002401 }
2402 }
vinayakb38b7ca42012-03-05 05:44:15 +00002403}
2404
Till Westmann96c1f172013-08-01 02:05:48 -07002405<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002406TOKEN :
2407{
Till Westmann5df7b452013-08-02 13:07:16 -07002408 <ASC : "asc">
2409 | <AT : "at">
2410 | <BY : "by">
2411 | <DATASET : "dataset">
2412 | <DECOR : "decor">
2413 | <DESC : "desc">
2414 | <DISTINCT : "distinct">
2415 | <ELSE : "else">
2416 | <EVERY : "every">
2417 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002418 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002419 | <GROUP : "group">
2420 | <IF : "if">
2421 | <IN : "in">
2422 | <LET : "let">
2423 | <LIMIT : "limit">
2424 | <OFFSET : "offset">
2425 | <ORDER : "order">
2426 | <RETURN : "return">
2427 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002428 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002429 | <SOME : "some">
2430 | <THEN : "then">
2431 | <UNION : "union">
2432 | <WHERE : "where">
2433 | <WITH : "with">
buyingyi3ca46d02015-01-27 23:22:09 -08002434 | <KEEPING : "keeping">
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 <CARET : "^">
2441 | <DIV : "/">
2442 | <IDIV : "idiv">
2443 | <MINUS : "-">
2444 | <MOD : "%">
2445 | <MUL : "*">
2446 | <PLUS : "+">
2447
2448 | <LEFTPAREN : "(">
2449 | <RIGHTPAREN : ")">
2450 | <LEFTBRACKET : "[">
2451 | <RIGHTBRACKET : "]">
2452
2453 | <COLON : ":">
2454 | <COMMA : ",">
2455 | <DOT : ".">
2456 | <QUES : "?">
2457
2458 | <LT : "<">
2459 | <GT : ">">
2460 | <LE : "<=">
2461 | <GE : ">=">
2462 | <EQ : "=">
2463 | <NE : "!=">
2464 | <SIMILAR : "~=">
2465 | <ASSIGN : ":=">
2466
2467 | <AND : "and">
2468 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002469}
2470
Till Westmann96c1f172013-08-01 02:05:48 -07002471<DEFAULT,IN_DBL_BRACE>
2472TOKEN :
2473{
Till Westmann5df7b452013-08-02 13:07:16 -07002474 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002475}
2476
2477<DEFAULT>
2478TOKEN :
2479{
Till Westmannfd733ee2014-07-10 00:57:37 -07002480 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002481}
2482
Till Westmann96c1f172013-08-01 02:05:48 -07002483<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002484TOKEN :
2485{
Till Westmann5df7b452013-08-02 13:07:16 -07002486 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002487}
2488
Till Westmann96c1f172013-08-01 02:05:48 -07002489<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002490TOKEN :
2491{
Till Westmannfd733ee2014-07-10 00:57:37 -07002492 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002493}
2494
Till Westmann96c1f172013-08-01 02:05:48 -07002495<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002496TOKEN :
2497{
Till Westmann5df7b452013-08-02 13:07:16 -07002498 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002499}
2500
Till Westmann96c1f172013-08-01 02:05:48 -07002501<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002502TOKEN :
2503{
Till Westmann5df7b452013-08-02 13:07:16 -07002504 <NULL : "null">
2505 | <TRUE : "true">
2506 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002507}
2508
Till Westmann96c1f172013-08-01 02:05:48 -07002509<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002510TOKEN :
2511{
Till Westmann5df7b452013-08-02 13:07:16 -07002512 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002513}
2514
Till Westmann96c1f172013-08-01 02:05:48 -07002515<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002516TOKEN:
2517{
Till Westmann5df7b452013-08-02 13:07:16 -07002518 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002519 | <DIGITS> ( "." <DIGITS> )?
2520 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002521 >
2522 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002523 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2524 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002525 >
2526 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002527}
2528
Till Westmann96c1f172013-08-01 02:05:48 -07002529<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002530TOKEN :
2531{
Till Westmann5df7b452013-08-02 13:07:16 -07002532 <#LETTER : ["A" - "Z", "a" - "z"]>
2533 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002534}
2535
Till Westmann96c1f172013-08-01 02:05:48 -07002536<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002537TOKEN :
2538{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002539 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2540 <STRING_LITERAL : ("\"" (
2541 <EscapeQuot>
2542 | <EscapeBslash>
2543 | <EscapeSlash>
2544 | <EscapeBspace>
2545 | <EscapeFormf>
2546 | <EscapeNl>
2547 | <EscapeCr>
2548 | <EscapeTab>
2549 | ~["\"","\\"])* "\"")
2550 | ("\'"(
2551 <EscapeApos>
2552 | <EscapeBslash>
2553 | <EscapeSlash>
2554 | <EscapeBspace>
2555 | <EscapeFormf>
2556 | <EscapeNl>
2557 | <EscapeCr>
2558 | <EscapeTab>
2559 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002560 | < #EscapeQuot: "\\\"" >
2561 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002562 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002563 | < #EscapeSlash: "\\/" >
2564 | < #EscapeBspace: "\\b" >
2565 | < #EscapeFormf: "\\f" >
2566 | < #EscapeNl: "\\n" >
2567 | < #EscapeCr: "\\r" >
2568 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002569}
2570
Till Westmann96c1f172013-08-01 02:05:48 -07002571<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002572TOKEN :
2573{
Till Westmann5df7b452013-08-02 13:07:16 -07002574 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002575}
2576
Till Westmann96c1f172013-08-01 02:05:48 -07002577<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002578TOKEN :
2579{
Till Westmann5df7b452013-08-02 13:07:16 -07002580 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002581}
2582
Till Westmann96c1f172013-08-01 02:05:48 -07002583<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002584SKIP:
2585{
2586 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002587 | "\t"
2588 | "\r"
2589 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002590}
2591
Till Westmann96c1f172013-08-01 02:05:48 -07002592<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002593SKIP:
2594{
Till Westmann5df7b452013-08-02 13:07:16 -07002595 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002596}
2597
Till Westmann96c1f172013-08-01 02:05:48 -07002598<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002599SKIP:
2600{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002601 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002602}
2603
Till Westmann96c1f172013-08-01 02:05:48 -07002604<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002605SKIP:
2606{
Till Westmann96c1f172013-08-01 02:05:48 -07002607 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002608}
2609
2610<INSIDE_COMMENT>
2611SPECIAL_TOKEN:
2612{
Till Westmann5df7b452013-08-02 13:07:16 -07002613 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002614}
2615
2616<INSIDE_COMMENT>
2617SKIP:
2618{
Till Westmann96c1f172013-08-01 02:05:48 -07002619 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002620}
2621
2622<INSIDE_COMMENT>
2623SKIP:
2624{
Till Westmannfd733ee2014-07-10 00:57:37 -07002625 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002626 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002627}