Michael Blow | 82464fb | 2017-03-28 18:48:13 -0400 | [diff] [blame^] | 1 | // |
| 2 | // Licensed to the Apache Software Foundation (ASF) under one |
| 3 | // or more contributor license agreements. See the NOTICE file |
| 4 | // distributed with this work for additional information |
| 5 | // regarding copyright ownership. The ASF licenses this file |
| 6 | // to you under the Apache License, Version 2.0 (the |
| 7 | // "License"); you may not use this file except in compliance |
| 8 | // with the License. You may obtain a copy of the License at |
| 9 | // |
| 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | // |
| 12 | // Unless required by applicable law or agreed to in writing, |
| 13 | // software distributed under the License is distributed on an |
| 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | // KIND, either express or implied. See the License for the |
| 16 | // specific language governing permissions and limitations |
| 17 | // under the License. |
| 18 | // |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 19 | options { |
| 20 | |
| 21 | |
| 22 | STATIC = false; |
| 23 | |
| 24 | } |
| 25 | |
| 26 | |
| 27 | PARSER_BEGIN(AQLParser) |
| 28 | |
| 29 | package org.apache.asterix.lang.aql.parser; |
| 30 | |
| 31 | // For AQLParserTokenManager |
Till Westmann | e9b2adf | 2016-10-15 12:39:01 -0700 | [diff] [blame] | 32 | import java.util.ArrayDeque; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 33 | |
| 34 | import java.io.BufferedReader; |
| 35 | import java.io.File; |
| 36 | import java.io.FileInputStream; |
| 37 | import java.io.FileNotFoundException; |
| 38 | import java.io.IOException; |
| 39 | import java.io.InputStreamReader; |
| 40 | import java.io.Reader; |
| 41 | import java.io.StringReader; |
| 42 | import java.util.ArrayList; |
| 43 | import java.util.HashMap; |
| 44 | import java.util.LinkedHashMap; |
| 45 | import java.util.List; |
| 46 | import java.util.Map; |
| 47 | |
| 48 | import org.apache.asterix.common.annotations.AutoDataGen; |
| 49 | import org.apache.asterix.common.annotations.DateBetweenYearsDataGen; |
| 50 | import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen; |
| 51 | import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen; |
| 52 | import org.apache.asterix.common.annotations.FieldIntervalDataGen; |
| 53 | import org.apache.asterix.common.annotations.FieldValFileDataGen; |
| 54 | import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen; |
| 55 | import org.apache.asterix.common.annotations.IRecordFieldDataGen; |
| 56 | import org.apache.asterix.common.annotations.InsertRandIntDataGen; |
| 57 | import org.apache.asterix.common.annotations.ListDataGen; |
| 58 | import org.apache.asterix.common.annotations.ListValFileDataGen; |
| 59 | import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation; |
| 60 | import org.apache.asterix.common.annotations.TypeDataGen; |
| 61 | import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen; |
| 62 | import org.apache.asterix.common.config.DatasetConfig.DatasetType; |
| 63 | import org.apache.asterix.common.config.DatasetConfig.IndexType; |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 64 | import org.apache.asterix.common.exceptions.CompilationException; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 65 | import org.apache.asterix.common.functions.FunctionSignature; |
| 66 | import org.apache.asterix.lang.aql.clause.DistinctClause; |
| 67 | import org.apache.asterix.lang.aql.clause.ForClause; |
| 68 | import org.apache.asterix.lang.aql.expression.FLWOGRExpression; |
| 69 | import org.apache.asterix.lang.aql.expression.UnionExpr; |
| 70 | import org.apache.asterix.lang.aql.util.RangeMapBuilder; |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 71 | import org.apache.asterix.lang.aql.util.AQLFormatPrintUtil; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 72 | import org.apache.asterix.lang.common.base.Clause; |
| 73 | import org.apache.asterix.lang.common.base.Expression; |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 74 | import org.apache.asterix.lang.common.base.ILangExpression; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 75 | import org.apache.asterix.lang.common.base.IParser; |
| 76 | import org.apache.asterix.lang.common.base.Literal; |
| 77 | import org.apache.asterix.lang.common.base.Statement; |
| 78 | import org.apache.asterix.lang.common.clause.GroupbyClause; |
| 79 | import org.apache.asterix.lang.common.clause.LetClause; |
| 80 | import org.apache.asterix.lang.common.clause.LimitClause; |
| 81 | import org.apache.asterix.lang.common.clause.OrderbyClause; |
| 82 | import org.apache.asterix.lang.common.clause.UpdateClause; |
| 83 | import org.apache.asterix.lang.common.clause.WhereClause; |
| 84 | import org.apache.asterix.lang.common.context.RootScopeFactory; |
| 85 | import org.apache.asterix.lang.common.context.Scope; |
| 86 | import org.apache.asterix.lang.common.expression.AbstractAccessor; |
| 87 | import org.apache.asterix.lang.common.expression.CallExpr; |
| 88 | import org.apache.asterix.lang.common.expression.FieldAccessor; |
| 89 | import org.apache.asterix.lang.common.expression.FieldBinding; |
| 90 | import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair; |
| 91 | import org.apache.asterix.lang.common.expression.IfExpr; |
| 92 | import org.apache.asterix.lang.common.expression.IndexAccessor; |
| 93 | import org.apache.asterix.lang.common.expression.ListConstructor; |
| 94 | import org.apache.asterix.lang.common.expression.LiteralExpr; |
| 95 | import org.apache.asterix.lang.common.expression.OperatorExpr; |
| 96 | import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition; |
| 97 | import org.apache.asterix.lang.common.expression.QuantifiedExpression; |
| 98 | import org.apache.asterix.lang.common.expression.RecordConstructor; |
| 99 | import org.apache.asterix.lang.common.expression.RecordTypeDefinition; |
| 100 | import org.apache.asterix.lang.common.expression.TypeExpression; |
| 101 | import org.apache.asterix.lang.common.expression.TypeReferenceExpression; |
| 102 | import org.apache.asterix.lang.common.expression.UnaryExpr; |
| 103 | import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition; |
| 104 | import org.apache.asterix.lang.common.expression.VariableExpr; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 105 | import org.apache.asterix.lang.common.literal.DoubleLiteral; |
| 106 | import org.apache.asterix.lang.common.literal.FalseLiteral; |
| 107 | import org.apache.asterix.lang.common.literal.FloatLiteral; |
| 108 | import org.apache.asterix.lang.common.literal.LongIntegerLiteral; |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 109 | import org.apache.asterix.lang.common.literal.MissingLiteral; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 110 | import org.apache.asterix.lang.common.literal.NullLiteral; |
| 111 | import org.apache.asterix.lang.common.literal.StringLiteral; |
| 112 | import org.apache.asterix.lang.common.literal.TrueLiteral; |
| 113 | import org.apache.asterix.lang.common.parser.ScopeChecker; |
| 114 | import org.apache.asterix.lang.common.statement.CompactStatement; |
| 115 | import org.apache.asterix.lang.common.statement.ConnectFeedStatement; |
| 116 | import org.apache.asterix.lang.common.statement.CreateDataverseStatement; |
| 117 | import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement; |
| 118 | import org.apache.asterix.lang.common.statement.CreateFeedStatement; |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 119 | import org.apache.asterix.lang.common.statement.StartFeedStatement; |
| 120 | import org.apache.asterix.lang.common.statement.StopFeedStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 121 | import org.apache.asterix.lang.common.statement.CreateFunctionStatement; |
| 122 | import org.apache.asterix.lang.common.statement.CreateIndexStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 123 | import org.apache.asterix.lang.common.statement.DatasetDecl; |
| 124 | import org.apache.asterix.lang.common.statement.DataverseDecl; |
| 125 | import org.apache.asterix.lang.common.statement.DataverseDropStatement; |
| 126 | import org.apache.asterix.lang.common.statement.DeleteStatement; |
| 127 | import org.apache.asterix.lang.common.statement.DisconnectFeedStatement; |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 128 | import org.apache.asterix.lang.common.statement.DropDatasetStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 129 | import org.apache.asterix.lang.common.statement.ExternalDetailsDecl; |
| 130 | import org.apache.asterix.lang.common.statement.FeedDropStatement; |
Abdullah Alamoudi | 5dc73ed | 2016-07-28 05:03:13 +0300 | [diff] [blame] | 131 | import org.apache.asterix.lang.common.statement.FeedPolicyDropStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 132 | import org.apache.asterix.lang.common.statement.FunctionDecl; |
| 133 | import org.apache.asterix.lang.common.statement.FunctionDropStatement; |
| 134 | import org.apache.asterix.lang.common.statement.IndexDropStatement; |
| 135 | import org.apache.asterix.lang.common.statement.InsertStatement; |
| 136 | import org.apache.asterix.lang.common.statement.InternalDetailsDecl; |
| 137 | import org.apache.asterix.lang.common.statement.LoadStatement; |
| 138 | import org.apache.asterix.lang.common.statement.NodeGroupDropStatement; |
| 139 | import org.apache.asterix.lang.common.statement.NodegroupDecl; |
| 140 | import org.apache.asterix.lang.common.statement.Query; |
| 141 | import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement; |
| 142 | import org.apache.asterix.lang.common.statement.RunStatement; |
| 143 | import org.apache.asterix.lang.common.statement.SetStatement; |
| 144 | import org.apache.asterix.lang.common.statement.TypeDecl; |
| 145 | import org.apache.asterix.lang.common.statement.TypeDropStatement; |
| 146 | import org.apache.asterix.lang.common.statement.UpdateStatement; |
Abdullah Alamoudi | 5dc958c | 2016-01-30 11:15:23 +0300 | [diff] [blame] | 147 | import org.apache.asterix.lang.common.statement.UpsertStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 148 | import org.apache.asterix.lang.common.statement.WriteStatement; |
| 149 | import org.apache.asterix.lang.common.struct.Identifier; |
| 150 | import org.apache.asterix.lang.common.struct.QuantifiedPair; |
| 151 | import org.apache.asterix.lang.common.struct.VarIdentifier; |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 152 | import org.apache.asterix.metadata.utils.MetadataConstants; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 153 | import org.apache.hyracks.algebricks.common.utils.Pair; |
| 154 | import org.apache.hyracks.algebricks.common.utils.Triple; |
| 155 | import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation; |
| 156 | import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation; |
| 157 | import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; |
| 158 | |
| 159 | |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 160 | class AQLParser extends ScopeChecker implements IParser { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 161 | |
| 162 | // optimizer hints |
| 163 | private static final String AUTO_HINT = "auto"; |
| 164 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
| 165 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 166 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 167 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 168 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 169 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 170 | private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl"; |
| 171 | private static final String INMEMORY_HINT = "inmem"; |
| 172 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 173 | private static final String INTERVAL_HINT = "interval"; |
| 174 | private static final String LIST_HINT = "list"; |
| 175 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 176 | private static final String RANGE_HINT = "range"; |
| 177 | private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index"; |
| 178 | private static final String VAL_FILE_HINT = "val-files"; |
| 179 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 180 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 181 | // data generator hints |
| 182 | private static final String DGEN_HINT = "dgen"; |
| 183 | |
| 184 | private static class IndexParams { |
| 185 | public IndexType type; |
| 186 | public int gramLength; |
| 187 | |
| 188 | public IndexParams(IndexType type, int gramLength) { |
| 189 | this.type = type; |
| 190 | this.gramLength = gramLength; |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | private static class FunctionName { |
| 195 | public String dataverse = null; |
| 196 | public String library = null; |
| 197 | public String function = null; |
| 198 | public String hint = null; |
| 199 | } |
| 200 | |
| 201 | private static String getHint(Token t) { |
| 202 | if (t.specialToken == null) { |
| 203 | return null; |
| 204 | } |
| 205 | String s = t.specialToken.image; |
| 206 | int n = s.length(); |
| 207 | if (n < 2) { |
| 208 | return null; |
| 209 | } |
| 210 | return s.substring(1).trim(); |
| 211 | } |
| 212 | |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 213 | private static void checkBindingVariable(Expression returnExpression, VariableExpr var, |
| 214 | ILangExpression bodyExpression) throws ParseException { |
| 215 | if (returnExpression != null && var == null) { |
| 216 | try { |
| 217 | throw new ParseException("Need a binding variable for the enclosed expression: " + |
| 218 | AQLFormatPrintUtil.toString(bodyExpression)); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 219 | } catch (CompilationException e){ |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 220 | throw new ParseException(e.getLocalizedMessage()); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 225 | private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException { |
| 226 | IRecordFieldDataGen rfdg = null; |
| 227 | String splits[] = hint.split(" +"); |
| 228 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 229 | File[] valFiles = new File[splits.length - 1]; |
| 230 | for (int k=1; k<splits.length; k++) { |
| 231 | valFiles[k-1] = new File(splits[k]); |
| 232 | } |
| 233 | rfdg = new FieldValFileDataGen(valFiles); |
| 234 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 235 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 236 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 237 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 238 | } else if (splits[0].equals(LIST_HINT)) { |
| 239 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 240 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 241 | FieldIntervalDataGen.ValueType vt; |
| 242 | if (splits[1].equals("int")) { |
| 243 | vt = FieldIntervalDataGen.ValueType.INT; |
| 244 | } else if (splits[1].equals("long")) { |
| 245 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 246 | } else if (splits[1].equals("float")) { |
| 247 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 248 | } else if (splits[1].equals("double")) { |
| 249 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 250 | } else { |
| 251 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 252 | } |
| 253 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 254 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 255 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 256 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 257 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 258 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 259 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 260 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 261 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 262 | } else if (splits[0].equals(AUTO_HINT)) { |
| 263 | rfdg = new AutoDataGen(splits[1]); |
| 264 | } |
| 265 | return rfdg; |
| 266 | } |
| 267 | |
| 268 | public AQLParser(String s){ |
| 269 | this(new StringReader(s)); |
| 270 | super.setInput(s); |
| 271 | } |
| 272 | |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 273 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 274 | File file = new File(args[0]); |
| 275 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 276 | AQLParser parser = new AQLParser(fis); |
| 277 | List<Statement> st = parser.parse(); |
| 278 | //st.accept(new AQLPrintVisitor(), 0); |
| 279 | } |
| 280 | |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 281 | public List<Statement> parse() throws CompilationException { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 282 | try { |
| 283 | return Statement(); |
| 284 | } catch (Error e) { |
| 285 | // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled |
| 286 | // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes) |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 287 | throw new CompilationException(new ParseException(e.getMessage())); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 288 | } catch (ParseException e){ |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 289 | throw new CompilationException(e.getMessage()); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | PARSER_END(AQLParser) |
| 295 | |
| 296 | |
| 297 | List<Statement> Statement() throws ParseException: |
| 298 | { |
| 299 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 300 | List<Statement> decls = new ArrayList<Statement>(); |
| 301 | Statement stmt = null; |
| 302 | } |
| 303 | { |
| 304 | ( stmt = SingleStatement() (";") ? |
| 305 | { |
| 306 | decls.add(stmt); |
| 307 | } |
| 308 | )* |
Till Westmann | 81870d7 | 2017-03-16 18:11:23 -0700 | [diff] [blame] | 309 | (";") * |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 310 | <EOF> |
| 311 | { |
| 312 | return decls; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | Statement SingleStatement() throws ParseException: |
| 317 | { |
| 318 | Statement stmt = null; |
| 319 | } |
| 320 | { |
| 321 | ( |
| 322 | stmt = DataverseDeclaration() |
| 323 | | stmt = FunctionDeclaration() |
| 324 | | stmt = CreateStatement() |
| 325 | | stmt = LoadStatement() |
| 326 | | stmt = DropStatement() |
| 327 | | stmt = WriteStatement() |
| 328 | | stmt = SetStatement() |
| 329 | | stmt = InsertStatement() |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 330 | | stmt = UpsertStatement() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 331 | | stmt = DeleteStatement() |
| 332 | | stmt = UpdateStatement() |
| 333 | | stmt = FeedStatement() |
| 334 | | stmt = CompactStatement() |
| 335 | | stmt = Query() |
| 336 | | stmt = RefreshExternalDatasetStatement() |
| 337 | | stmt = RunStatement() |
| 338 | ) |
| 339 | { |
| 340 | return stmt; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 345 | { |
| 346 | String dvName = null; |
| 347 | } |
| 348 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 349 | <USE> <DATAVERSE> dvName = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 350 | { |
| 351 | defaultDataverse = dvName; |
| 352 | return new DataverseDecl(new Identifier(dvName)); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | Statement CreateStatement() throws ParseException: |
| 357 | { |
| 358 | String hint = null; |
| 359 | boolean dgen = false; |
| 360 | Statement stmt = null; |
| 361 | } |
| 362 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 363 | <CREATE> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 364 | ( |
| 365 | { |
| 366 | hint = getHint(token); |
| 367 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 368 | dgen = true; |
| 369 | } |
| 370 | } |
| 371 | stmt = TypeSpecification(hint, dgen) |
| 372 | | stmt = NodegroupSpecification() |
| 373 | | stmt = DatasetSpecification() |
| 374 | | stmt = IndexSpecification() |
| 375 | | stmt = DataverseSpecification() |
| 376 | | stmt = FunctionSpecification() |
| 377 | | stmt = FeedSpecification() |
| 378 | | stmt = FeedPolicySpecification() |
| 379 | ) |
| 380 | { |
| 381 | return stmt; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException: |
| 386 | { |
| 387 | Pair<Identifier,Identifier> nameComponents = null; |
| 388 | boolean ifNotExists = false; |
| 389 | TypeExpression typeExpr = null; |
| 390 | } |
| 391 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 392 | <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists() |
| 393 | <AS> typeExpr = TypeExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 394 | { |
| 395 | long numValues = -1; |
| 396 | String filename = null; |
| 397 | if (dgen) { |
| 398 | String splits[] = hint.split(" +"); |
| 399 | if (splits.length != 3) { |
| 400 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 401 | } |
| 402 | filename = splits[1]; |
| 403 | numValues = Long.parseLong(splits[2]); |
| 404 | } |
| 405 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
| 406 | return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | |
| 411 | NodegroupDecl NodegroupSpecification() throws ParseException: |
| 412 | { |
| 413 | String name = null; |
| 414 | String tmp = null; |
| 415 | boolean ifNotExists = false; |
| 416 | List<Identifier>ncNames = null; |
| 417 | } |
| 418 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 419 | <NODEGROUP> name = Identifier() |
| 420 | ifNotExists = IfNotExists() <ON> tmp = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 421 | { |
| 422 | ncNames = new ArrayList<Identifier>(); |
| 423 | ncNames.add(new Identifier(tmp)); |
| 424 | } |
| 425 | ( <COMMA> tmp = Identifier() |
| 426 | { |
| 427 | ncNames.add(new Identifier(tmp)); |
| 428 | } |
| 429 | )* |
| 430 | { |
| 431 | return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | DatasetDecl DatasetSpecification() throws ParseException: |
| 436 | { |
| 437 | Pair<Identifier,Identifier> nameComponents = null; |
| 438 | boolean ifNotExists = false; |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 439 | Pair<Identifier,Identifier> typeComponents = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 440 | String adapterName = null; |
| 441 | Map<String,String> properties = null; |
| 442 | Map<String,String> compactionPolicyProperties = null; |
| 443 | FunctionSignature appliedFunction = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 444 | Pair<List<Integer>, List<List<String>>> primaryKeyFields = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 445 | String nodeGroupName = null; |
| 446 | Map<String,String> hints = new HashMap<String,String>(); |
| 447 | DatasetDecl dsetDecl = null; |
| 448 | boolean autogenerated = false; |
| 449 | String compactionPolicy = null; |
| 450 | boolean temp = false; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 451 | Pair<Integer, List<String>> filterField = null; |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 452 | Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 453 | } |
| 454 | { |
| 455 | ( |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 456 | <EXTERNAL> <DATASET> nameComponents = QualifiedName() |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 457 | <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 458 | ifNotExists = IfNotExists() |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 459 | <USING> adapterName = AdapterName() properties = Configuration() |
| 460 | ( <ON> nodeGroupName = Identifier() )? |
| 461 | ( <HINTS> hints = Properties() )? |
| 462 | ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 463 | { |
| 464 | ExternalDetailsDecl edd = new ExternalDetailsDecl(); |
| 465 | edd.setAdapter(adapterName); |
| 466 | edd.setProperties(properties); |
| 467 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 468 | nameComponents.second, |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 469 | typeComponents.first, |
| 470 | typeComponents.second, |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 471 | metaTypeComponents.first, |
| 472 | metaTypeComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 473 | nodeGroupName != null? new Identifier(nodeGroupName): null, |
| 474 | compactionPolicy, |
| 475 | compactionPolicyProperties, |
| 476 | hints, |
| 477 | DatasetType.EXTERNAL, |
| 478 | edd, |
| 479 | ifNotExists); |
| 480 | } |
| 481 | |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 482 | | (<INTERNAL> | <TEMPORARY> { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 483 | temp = token.image.toLowerCase().equals("temporary"); |
| 484 | } |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 485 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 486 | <DATASET> nameComponents = QualifiedName() |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 487 | <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN> |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 488 | ( |
| 489 | { String name; } |
| 490 | <WITH> |
| 491 | name = Identifier() |
| 492 | { |
| 493 | if(!name.equals("meta")){ |
| 494 | throw new ParseException("We can only support one additional associated field called \"meta\"."); |
| 495 | } |
| 496 | } |
| 497 | <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN> |
| 498 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 499 | ifNotExists = IfNotExists() |
| 500 | primaryKeyFields = PrimaryKey() |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 501 | ( <AUTOGENERATED> { autogenerated = true; } )? |
| 502 | ( <ON> nodeGroupName = Identifier() )? |
| 503 | ( <HINTS> hints = Properties() )? |
| 504 | ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )? |
| 505 | ( <WITH> <FILTER> <ON> filterField = NestedField() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 506 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 507 | if(filterField!=null && filterField.first!=0){ |
| 508 | throw new ParseException("A filter field can only be a field in the main record of the dataset."); |
| 509 | } |
| 510 | InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second, |
| 511 | primaryKeyFields.first, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 512 | autogenerated, |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 513 | filterField == null? null : filterField.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 514 | temp); |
| 515 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 516 | nameComponents.second, |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 517 | typeComponents.first, |
| 518 | typeComponents.second, |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 519 | metaTypeComponents.first, |
| 520 | metaTypeComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 521 | nodeGroupName != null ? new Identifier(nodeGroupName) : null, |
| 522 | compactionPolicy, |
| 523 | compactionPolicyProperties, |
| 524 | hints, |
| 525 | DatasetType.INTERNAL, |
| 526 | idd, |
| 527 | ifNotExists); |
| 528 | } |
| 529 | ) |
| 530 | { |
| 531 | return dsetDecl; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException: |
| 536 | { |
| 537 | RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement(); |
| 538 | Pair<Identifier,Identifier> nameComponents = null; |
| 539 | String datasetName = null; |
| 540 | } |
| 541 | { |
Abdullah Alamoudi | 806f7d2 | 2016-07-23 18:02:55 +0300 | [diff] [blame] | 542 | ( |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 543 | <REFRESH> <EXTERNAL> <DATASET> nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 544 | { |
| 545 | redss.setDataverseName(nameComponents.first); |
| 546 | redss.setDatasetName(nameComponents.second); |
| 547 | return redss; |
| 548 | } |
Abdullah Alamoudi | 806f7d2 | 2016-07-23 18:02:55 +0300 | [diff] [blame] | 549 | ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | RunStatement RunStatement() throws ParseException: |
| 553 | { |
| 554 | String system = null; |
| 555 | String tmp; |
| 556 | ArrayList<String> parameters = new ArrayList<String>(); |
| 557 | Pair<Identifier,Identifier> nameComponentsFrom = null; |
| 558 | Pair<Identifier,Identifier> nameComponentsTo = null; |
| 559 | } |
| 560 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 561 | <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>] |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 562 | { |
| 563 | parameters.add(tmp); |
| 564 | } |
| 565 | )*<RIGHTPAREN> |
| 566 | <FROM> <DATASET> nameComponentsFrom = QualifiedName() |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 567 | <TO> <DATASET> nameComponentsTo = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 568 | { |
| 569 | return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | CreateIndexStatement IndexSpecification() throws ParseException: |
| 574 | { |
| 575 | CreateIndexStatement cis = new CreateIndexStatement(); |
| 576 | String indexName = null; |
| 577 | boolean ifNotExists = false; |
| 578 | Pair<Identifier,Identifier> nameComponents = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 579 | Pair<Integer, Pair<List<String>, TypeExpression>> fieldPair = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 580 | IndexParams indexType = null; |
| 581 | boolean enforced = false; |
| 582 | } |
| 583 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 584 | <INDEX> indexName = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 585 | ifNotExists = IfNotExists() |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 586 | <ON> nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 587 | <LEFTPAREN> ( fieldPair = OpenField() |
| 588 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 589 | cis.addFieldExprPair(fieldPair.second); |
| 590 | cis.addFieldIndexIndicator(fieldPair.first); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 591 | } |
| 592 | ) (<COMMA> fieldPair = OpenField() |
| 593 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 594 | cis.addFieldExprPair(fieldPair.second); |
| 595 | cis.addFieldIndexIndicator(fieldPair.first); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 596 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 597 | )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 598 | { |
| 599 | cis.setIndexName(new Identifier(indexName)); |
| 600 | cis.setIfNotExists(ifNotExists); |
| 601 | cis.setDataverseName(nameComponents.first); |
| 602 | cis.setDatasetName(nameComponents.second); |
| 603 | if (indexType != null) { |
| 604 | cis.setIndexType(indexType.type); |
| 605 | cis.setGramLength(indexType.gramLength); |
| 606 | } |
| 607 | cis.setEnforced(enforced); |
| 608 | return cis; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | String CompactionPolicy() throws ParseException : |
| 613 | { |
| 614 | String compactionPolicy = null; |
| 615 | } |
| 616 | { |
| 617 | compactionPolicy = Identifier() |
| 618 | { |
| 619 | return compactionPolicy; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | String FilterField() throws ParseException : |
| 624 | { |
| 625 | String filterField = null; |
| 626 | } |
| 627 | { |
| 628 | filterField = Identifier() |
| 629 | { |
| 630 | return filterField; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | IndexParams IndexType() throws ParseException: |
| 635 | { |
| 636 | IndexType type = null; |
| 637 | int gramLength = 0; |
| 638 | } |
| 639 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 640 | ( |
| 641 | <BTREE> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 642 | { |
| 643 | type = IndexType.BTREE; |
| 644 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 645 | |<RTREE> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 646 | { |
| 647 | type = IndexType.RTREE; |
| 648 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 649 | |<KEYWORD> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 650 | { |
| 651 | type = IndexType.LENGTH_PARTITIONED_WORD_INVIX; |
| 652 | } |
Taewoo Kim | c49405a | 2017-01-04 00:30:43 -0800 | [diff] [blame] | 653 | |<FULLTEXT> |
| 654 | { |
| 655 | type = IndexType.SINGLE_PARTITION_WORD_INVIX; |
| 656 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 657 | |<NGRAM> <LEFTPAREN> <INTEGER_LITERAL> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 658 | { |
| 659 | type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX; |
| 660 | gramLength = Integer.valueOf(token.image); |
| 661 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 662 | <RIGHTPAREN> |
| 663 | ) |
| 664 | { |
| 665 | return new IndexParams(type, gramLength); |
| 666 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | CreateDataverseStatement DataverseSpecification() throws ParseException : |
| 670 | { |
| 671 | String dvName = null; |
| 672 | boolean ifNotExists = false; |
| 673 | String format = null; |
| 674 | } |
| 675 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 676 | <DATAVERSE> dvName = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 677 | ifNotExists = IfNotExists() |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 678 | ( <WITH> <FORMAT> format = StringLiteral() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 679 | { |
| 680 | return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | CreateFunctionStatement FunctionSpecification() throws ParseException: |
| 685 | { |
| 686 | FunctionSignature signature; |
| 687 | boolean ifNotExists = false; |
| 688 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 689 | String functionBody; |
| 690 | VarIdentifier var = null; |
| 691 | Expression functionBodyExpr; |
| 692 | Token beginPos; |
| 693 | Token endPos; |
| 694 | FunctionName fctName = null; |
| 695 | |
| 696 | createNewScope(); |
| 697 | } |
| 698 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 699 | <FUNCTION> fctName = FunctionName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 700 | ifNotExists = IfNotExists() |
| 701 | paramList = ParameterList() |
| 702 | <LEFTBRACE> |
| 703 | { |
| 704 | beginPos = token; |
| 705 | } |
| 706 | functionBodyExpr = Expression() <RIGHTBRACE> |
| 707 | { |
| 708 | endPos = token; |
| 709 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
| 710 | // TODO use fctName.library |
| 711 | signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size()); |
| 712 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 713 | removeCurrentScope(); |
| 714 | return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | CreateFeedStatement FeedSpecification() throws ParseException: |
| 719 | { |
| 720 | Pair<Identifier,Identifier> nameComponents = null; |
| 721 | boolean ifNotExists = false; |
| 722 | String adapterName = null; |
| 723 | Map<String,String> properties = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 724 | CreateFeedStatement cfs = null; |
| 725 | Pair<Identifier,Identifier> sourceNameComponents = null; |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 726 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 727 | } |
| 728 | { |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 729 | <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists() |
| 730 | <USING> adapterName = AdapterName() properties = Configuration() |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 731 | { |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 732 | cfs = new CreateFeedStatement(nameComponents, adapterName, properties, ifNotExists); |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 733 | return cfs; |
| 734 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException: |
| 738 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 739 | String policyName = null; |
| 740 | String basePolicyName = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 741 | String sourcePolicyFile = null; |
| 742 | String definition = null; |
| 743 | boolean ifNotExists = false; |
| 744 | Map<String,String> properties = null; |
| 745 | CreateFeedPolicyStatement cfps = null; |
| 746 | } |
| 747 | { |
| 748 | ( |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 749 | <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists() |
| 750 | <FROM> |
| 751 | ( |
| 752 | <POLICY> basePolicyName = Identifier() properties = Configuration() ( <DEFINITION> definition = StringLiteral())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 753 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 754 | cfps = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 755 | } |
Abdullah Alamoudi | 5dc73ed | 2016-07-28 05:03:13 +0300 | [diff] [blame] | 756 | |<PATH> sourcePolicyFile = StringLiteral() (<DEFINITION> definition = StringLiteral())? |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 757 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 758 | cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists); |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 759 | } |
| 760 | ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 761 | ) |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 762 | { |
| 763 | return cfps; |
| 764 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | |
| 768 | |
| 769 | List<VarIdentifier> ParameterList() throws ParseException: |
| 770 | { |
| 771 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 772 | VarIdentifier var = null; |
| 773 | } |
| 774 | { |
| 775 | <LEFTPAREN> (<VARIABLE> |
| 776 | { |
| 777 | var = new VarIdentifier(); |
| 778 | var.setValue(token.image); |
| 779 | paramList.add(var); |
| 780 | getCurrentScope().addNewVarSymbolToScope(var); |
| 781 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 782 | ( <COMMA> <VARIABLE> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 783 | { |
| 784 | var = new VarIdentifier(); |
| 785 | var.setValue(token.image); |
| 786 | paramList.add(var); |
| 787 | getCurrentScope().addNewVarSymbolToScope(var); |
| 788 | } |
| 789 | )*)? <RIGHTPAREN> |
| 790 | { |
| 791 | return paramList; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | boolean IfNotExists() throws ParseException: |
| 796 | { |
| 797 | } |
| 798 | { |
Yingyi Bu | dcd9112 | 2016-08-10 12:13:36 -0700 | [diff] [blame] | 799 | ( |
| 800 | LOOKAHEAD(1) |
| 801 | <IF> |
| 802 | <IDENTIFIER> |
| 803 | ( |
| 804 | { |
| 805 | if(!token.image.equals("not")){ |
| 806 | throw new ParseException("Expect word \"not\" at line " + token.beginLine + ", column " |
| 807 | + token.beginColumn +"!"); |
| 808 | } |
| 809 | } |
| 810 | ) |
| 811 | <EXISTS> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 812 | { |
| 813 | return true; |
| 814 | } |
| 815 | )? |
| 816 | { |
| 817 | return false; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | FunctionSignature ApplyFunction() throws ParseException: |
| 822 | { |
| 823 | FunctionName functioName = null; |
| 824 | FunctionSignature funcSig = null; |
| 825 | } |
| 826 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 827 | <APPLY> <FUNCTION> functioName = FunctionName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 828 | { |
| 829 | String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function; |
| 830 | return new FunctionSignature(functioName.dataverse, fqFunctionName, 1); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | String GetPolicy() throws ParseException: |
| 835 | { |
| 836 | String policy = null; |
| 837 | } |
| 838 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 839 | <USING> <POLICY> policy = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 840 | { |
| 841 | return policy; |
| 842 | } |
| 843 | |
| 844 | } |
| 845 | |
| 846 | FunctionSignature FunctionSignature() throws ParseException: |
| 847 | { |
| 848 | FunctionName fctName = null; |
| 849 | int arity = 0; |
| 850 | } |
| 851 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 852 | fctName = FunctionName() <SYMBOLAT> <INTEGER_LITERAL> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 853 | { |
| 854 | arity = new Integer(token.image); |
| 855 | if (arity < 0 && arity != FunctionIdentifier.VARARGS) { |
| 856 | throw new ParseException(" invalid arity:" + arity); |
| 857 | } |
| 858 | |
| 859 | // TODO use fctName.library |
| 860 | String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function; |
| 861 | return new FunctionSignature(fctName.dataverse, fqFunctionName, arity); |
| 862 | } |
| 863 | } |
| 864 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 865 | Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 866 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 867 | Pair<Integer, List<String>> tmp = null; |
| 868 | List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>(); |
| 869 | List<List<String>> primaryKeyFields = new ArrayList<List<String>>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 870 | } |
| 871 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 872 | <PRIMARY> <KEY> tmp = NestedField() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 873 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 874 | keyFieldSourceIndicators.add(tmp.first); |
| 875 | primaryKeyFields.add(tmp.second); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 876 | } |
| 877 | ( <COMMA> tmp = NestedField() |
| 878 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 879 | keyFieldSourceIndicators.add(tmp.first); |
| 880 | primaryKeyFields.add(tmp.second); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 881 | } |
| 882 | )* |
| 883 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 884 | return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | Statement DropStatement() throws ParseException: |
| 889 | { |
| 890 | String id = null; |
| 891 | Pair<Identifier,Identifier> pairId = null; |
| 892 | Triple<Identifier,Identifier,Identifier> tripleId = null; |
| 893 | FunctionSignature funcSig = null; |
| 894 | boolean ifExists = false; |
| 895 | Statement stmt = null; |
| 896 | } |
| 897 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 898 | <DROP> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 899 | ( |
| 900 | <DATASET> pairId = QualifiedName() ifExists = IfExists() |
| 901 | { |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 902 | stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 903 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 904 | | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 905 | { |
| 906 | stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists); |
| 907 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 908 | | <NODEGROUP> id = Identifier() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 909 | { |
| 910 | stmt = new NodeGroupDropStatement(new Identifier(id), ifExists); |
| 911 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 912 | | <TYPE> pairId = TypeName() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 913 | { |
| 914 | stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists); |
| 915 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 916 | | <DATAVERSE> id = Identifier() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 917 | { |
| 918 | stmt = new DataverseDropStatement(new Identifier(id), ifExists); |
| 919 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 920 | | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 921 | { |
| 922 | stmt = new FunctionDropStatement(funcSig, ifExists); |
| 923 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 924 | | <FEED> pairId = QualifiedName() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 925 | { |
| 926 | stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists); |
| 927 | } |
Abdullah Alamoudi | 5dc73ed | 2016-07-28 05:03:13 +0300 | [diff] [blame] | 928 | | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists() |
| 929 | { |
| 930 | stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists); |
| 931 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 932 | ) |
| 933 | { |
| 934 | return stmt; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | boolean IfExists() throws ParseException : |
| 939 | { |
| 940 | } |
| 941 | { |
Yingyi Bu | dcd9112 | 2016-08-10 12:13:36 -0700 | [diff] [blame] | 942 | ( |
| 943 | LOOKAHEAD(1) |
| 944 | <IF> <EXISTS> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 945 | { |
| 946 | return true; |
| 947 | } |
| 948 | )? |
| 949 | { |
| 950 | return false; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | InsertStatement InsertStatement() throws ParseException: |
| 955 | { |
| 956 | Pair<Identifier,Identifier> nameComponents = null; |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 957 | VariableExpr var = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 958 | Query query; |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 959 | Expression returnExpression = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 960 | } |
| 961 | { |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 962 | <INSERT> <INTO> <DATASET> nameComponents = QualifiedName() |
Steven Glenn Jacobs | afa909a | 2016-10-16 10:35:30 -0700 | [diff] [blame] | 963 | (<AS> var = Variable())? |
| 964 | { |
| 965 | if(var != null){ |
| 966 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 967 | } |
| 968 | } |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 969 | query = Query() ( <RETURNING> returnExpression = Expression())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 970 | { |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 971 | checkBindingVariable(returnExpression, var, query); |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 972 | query.setTopLevel(true); |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 973 | return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var, |
| 974 | returnExpression); |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | UpsertStatement UpsertStatement() throws ParseException: |
| 979 | { |
| 980 | Pair<Identifier,Identifier> nameComponents = null; |
| 981 | VariableExpr var = null; |
| 982 | Query query; |
| 983 | Expression returnExpression = null; |
| 984 | } |
| 985 | { |
| 986 | <UPSERT> <INTO> <DATASET> nameComponents = QualifiedName() |
| 987 | (<AS> var = Variable())? |
| 988 | { |
| 989 | if(var != null){ |
| 990 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 991 | } |
| 992 | } |
| 993 | query = Query() ( <RETURNING> returnExpression = Expression())? |
| 994 | { |
| 995 | checkBindingVariable(returnExpression, var, query); |
| 996 | query.setTopLevel(true); |
| 997 | return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var, |
| 998 | returnExpression); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | DeleteStatement DeleteStatement() throws ParseException: |
| 1003 | { |
| 1004 | VariableExpr var = null; |
| 1005 | Expression condition = null; |
| 1006 | Pair<Identifier, Identifier> nameComponents; |
| 1007 | // This is related to the new metadata lock management |
| 1008 | setDataverses(new ArrayList<String>()); |
| 1009 | setDatasets(new ArrayList<String>()); |
| 1010 | |
| 1011 | } |
| 1012 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1013 | <DELETE> var = Variable() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1014 | { |
| 1015 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 1016 | } |
| 1017 | <FROM> <DATASET> nameComponents = QualifiedName() |
| 1018 | (<WHERE> condition = Expression())? |
| 1019 | { |
| 1020 | // First we get the dataverses and datasets that we want to lock |
| 1021 | List<String> dataverses = getDataverses(); |
| 1022 | List<String> datasets = getDatasets(); |
| 1023 | // we remove the pointer to the dataverses and datasets |
| 1024 | setDataverses(null); |
| 1025 | setDatasets(null); |
| 1026 | return new DeleteStatement(var, nameComponents.first, nameComponents.second, |
| 1027 | condition, getVarCounter(), dataverses, datasets); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | UpdateStatement UpdateStatement() throws ParseException: |
| 1032 | { |
| 1033 | VariableExpr vars; |
| 1034 | Expression target; |
| 1035 | Expression condition; |
| 1036 | UpdateClause uc; |
| 1037 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
| 1038 | } |
| 1039 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1040 | <UPDATE> vars = Variable() <IN> target = Expression() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1041 | <WHERE> condition = Expression() |
| 1042 | <LEFTPAREN> (uc = UpdateClause() |
| 1043 | { |
| 1044 | ucs.add(uc); |
| 1045 | } |
| 1046 | (<COMMA> uc = UpdateClause() |
| 1047 | { |
| 1048 | ucs.add(uc); |
| 1049 | } |
| 1050 | )*) <RIGHTPAREN> |
| 1051 | { |
| 1052 | return new UpdateStatement(vars, target, condition, ucs); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | UpdateClause UpdateClause() throws ParseException: |
| 1057 | { |
| 1058 | Expression target = null; |
| 1059 | Expression value = null ; |
| 1060 | InsertStatement is = null; |
| 1061 | DeleteStatement ds = null; |
| 1062 | UpdateStatement us = null; |
| 1063 | Expression condition = null; |
| 1064 | UpdateClause ifbranch = null; |
| 1065 | UpdateClause elsebranch = null; |
| 1066 | } |
| 1067 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1068 | (<SET> target = Expression() <ASSIGN> value = Expression() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1069 | | is = InsertStatement() |
| 1070 | | ds = DeleteStatement() |
| 1071 | | us = UpdateStatement() |
| 1072 | | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN> |
| 1073 | <THEN> ifbranch = UpdateClause() |
| 1074 | [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()] |
| 1075 | { |
| 1076 | return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch); |
| 1077 | } |
| 1078 | ) |
| 1079 | } |
| 1080 | |
| 1081 | Statement SetStatement() throws ParseException: |
| 1082 | { |
| 1083 | String pn = null; |
| 1084 | String pv = null; |
| 1085 | } |
| 1086 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1087 | <SET> pn = Identifier() pv = StringLiteral() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1088 | { |
| 1089 | return new SetStatement(pn, pv); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | Statement WriteStatement() throws ParseException: |
| 1094 | { |
| 1095 | String nodeName = null; |
| 1096 | String fileName = null; |
| 1097 | Query query; |
| 1098 | String writerClass = null; |
| 1099 | Pair<Identifier,Identifier> nameComponents = null; |
| 1100 | } |
| 1101 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1102 | <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = StringLiteral() |
| 1103 | ( <USING> writerClass = StringLiteral() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1104 | { |
| 1105 | return new WriteStatement(new Identifier(nodeName), fileName, writerClass); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | LoadStatement LoadStatement() throws ParseException: |
| 1110 | { |
| 1111 | Identifier dataverseName = null; |
| 1112 | Identifier datasetName = null; |
| 1113 | boolean alreadySorted = false; |
| 1114 | String adapterName; |
| 1115 | Map<String,String> properties; |
| 1116 | Pair<Identifier,Identifier> nameComponents = null; |
| 1117 | } |
| 1118 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1119 | <LOAD> <DATASET> nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1120 | { |
| 1121 | dataverseName = nameComponents.first; |
| 1122 | datasetName = nameComponents.second; |
| 1123 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1124 | <USING> adapterName = AdapterName() properties = Configuration() |
| 1125 | (<PRESORTED> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1126 | { |
| 1127 | alreadySorted = true; |
| 1128 | } |
| 1129 | )? |
| 1130 | { |
| 1131 | return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | String AdapterName() throws ParseException : |
| 1137 | { |
| 1138 | String adapterName = null; |
| 1139 | } |
| 1140 | { |
| 1141 | adapterName = Identifier() |
| 1142 | { |
| 1143 | return adapterName; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | Statement CompactStatement() throws ParseException: |
| 1148 | { |
| 1149 | Pair<Identifier,Identifier> nameComponents = null; |
| 1150 | Statement stmt = null; |
| 1151 | } |
| 1152 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1153 | <COMPACT> <DATASET> nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1154 | { |
| 1155 | stmt = new CompactStatement(nameComponents.first, nameComponents.second); |
| 1156 | } |
| 1157 | { |
| 1158 | return stmt; |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | Statement FeedStatement() throws ParseException: |
| 1163 | { |
| 1164 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1165 | Pair<Identifier,Identifier> datasetNameComponents = null; |
| 1166 | |
| 1167 | Map<String,String> configuration = null; |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1168 | FunctionSignature appliedFunction = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1169 | Statement stmt = null; |
| 1170 | String policy = null; |
| 1171 | } |
| 1172 | { |
| 1173 | ( |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1174 | <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> <DATASET> datasetNameComponents = QualifiedName() |
| 1175 | (appliedFunction = ApplyFunction())? (policy = GetPolicy())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1176 | { |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1177 | stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunction, policy, getVarCounter()); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1178 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1179 | | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1180 | { |
| 1181 | stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents); |
| 1182 | } |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1183 | | <START> <FEED> feedNameComponents = QualifiedName() |
| 1184 | { |
| 1185 | stmt = new StartFeedStatement (feedNameComponents); |
| 1186 | } |
| 1187 | | <STOP> <FEED> feedNameComponents = QualifiedName() |
| 1188 | { |
| 1189 | stmt = new StopFeedStatement (feedNameComponents); |
| 1190 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1191 | ) |
| 1192 | { |
| 1193 | return stmt; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | Map<String,String> Configuration() throws ParseException : |
| 1198 | { |
| 1199 | Map<String,String> configuration = new LinkedHashMap<String,String>(); |
| 1200 | Pair<String, String> keyValuePair = null; |
| 1201 | } |
| 1202 | { |
| 1203 | <LEFTPAREN> ( keyValuePair = KeyValuePair() |
| 1204 | { |
| 1205 | configuration.put(keyValuePair.first, keyValuePair.second); |
| 1206 | } |
| 1207 | ( <COMMA> keyValuePair = KeyValuePair() |
| 1208 | { |
| 1209 | configuration.put(keyValuePair.first, keyValuePair.second); |
| 1210 | } |
| 1211 | )* )? <RIGHTPAREN> |
| 1212 | { |
| 1213 | return configuration; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | Pair<String, String> KeyValuePair() throws ParseException: |
| 1218 | { |
| 1219 | String key; |
| 1220 | String value; |
| 1221 | } |
| 1222 | { |
| 1223 | <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN> |
| 1224 | { |
| 1225 | return new Pair<String, String>(key, value); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | Map<String,String> Properties() throws ParseException: |
| 1230 | { |
| 1231 | Map<String,String> properties = new HashMap<String,String>(); |
| 1232 | Pair<String, String> property; |
| 1233 | } |
| 1234 | { |
| 1235 | ( <LEFTPAREN> property = Property() |
| 1236 | { |
| 1237 | properties.put(property.first, property.second); |
| 1238 | } |
| 1239 | ( <COMMA> property = Property() |
| 1240 | { |
| 1241 | properties.put(property.first, property.second); |
| 1242 | } |
| 1243 | )* <RIGHTPAREN> )? |
| 1244 | { |
| 1245 | return properties; |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | Pair<String, String> Property() throws ParseException: |
| 1250 | { |
| 1251 | String key; |
| 1252 | String value; |
| 1253 | } |
| 1254 | { |
| 1255 | key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL> |
| 1256 | { |
| 1257 | try { |
| 1258 | value = "" + Long.valueOf(token.image); |
| 1259 | } catch (NumberFormatException nfe) { |
| 1260 | throw new ParseException("inapproriate value: " + token.image); |
| 1261 | } |
| 1262 | } |
| 1263 | ) |
| 1264 | { |
| 1265 | return new Pair<String, String>(key.toUpperCase(), value); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | TypeExpression IndexedTypeExpr() throws ParseException: |
| 1270 | { |
| 1271 | TypeExpression typeExpr = null; |
| 1272 | } |
| 1273 | { |
| 1274 | ( |
| 1275 | typeExpr = TypeReference() |
| 1276 | | typeExpr = OrderedListTypeDef() |
| 1277 | | typeExpr = UnorderedListTypeDef() |
| 1278 | ) |
| 1279 | { |
| 1280 | return typeExpr; |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | TypeExpression TypeExpr() throws ParseException: |
| 1285 | { |
| 1286 | TypeExpression typeExpr = null; |
| 1287 | } |
| 1288 | { |
| 1289 | ( |
| 1290 | typeExpr = RecordTypeDef() |
| 1291 | | typeExpr = TypeReference() |
| 1292 | | typeExpr = OrderedListTypeDef() |
| 1293 | | typeExpr = UnorderedListTypeDef() |
| 1294 | ) |
| 1295 | { |
| 1296 | return typeExpr; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 1301 | { |
| 1302 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 1303 | RecordTypeDefinition.RecordKind recordKind = null; |
| 1304 | } |
| 1305 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1306 | ( <CLOSED>{ recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 1307 | | <OPEN>{ recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1308 | <LEFTBRACE> |
| 1309 | { |
| 1310 | String hint = getHint(token); |
| 1311 | if (hint != null) { |
| 1312 | String splits[] = hint.split(" +"); |
| 1313 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 1314 | if (splits.length != 5) { |
| 1315 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 1316 | } |
| 1317 | if (!splits[1].equals("int")) { |
| 1318 | throw new ParseException("The only supported type for gen-fields is int."); |
| 1319 | } |
| 1320 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 1321 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 1322 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | } |
| 1327 | ( |
| 1328 | RecordField(recType) |
| 1329 | ( <COMMA> RecordField(recType) )* |
| 1330 | )? |
| 1331 | <RIGHTBRACE> |
| 1332 | { |
| 1333 | if (recordKind == null) { |
| 1334 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 1335 | } |
| 1336 | recType.setRecordKind(recordKind); |
| 1337 | return recType; |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 1342 | { |
| 1343 | String fieldName; |
| 1344 | TypeExpression type = null; |
| 1345 | boolean nullable = false; |
| 1346 | } |
| 1347 | { |
| 1348 | fieldName = Identifier() |
| 1349 | { |
| 1350 | String hint = getHint(token); |
| 1351 | IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null; |
| 1352 | } |
| 1353 | <COLON> type = TypeExpr() (<QUES> { nullable = true; } )? |
| 1354 | { |
| 1355 | recType.addField(fieldName, type, nullable, rfdg); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | TypeReferenceExpression TypeReference() throws ParseException: |
| 1360 | { |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1361 | Pair<Identifier,Identifier> id = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1362 | } |
| 1363 | { |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1364 | id = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1365 | { |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1366 | if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) { |
| 1367 | id.second.setValue("int64"); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1370 | return new TypeReferenceExpression(id); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1375 | { |
| 1376 | TypeExpression type = null; |
| 1377 | } |
| 1378 | { |
| 1379 | <LEFTBRACKET> |
| 1380 | ( type = TypeExpr() ) |
| 1381 | <RIGHTBRACKET> |
| 1382 | { |
| 1383 | return new OrderedListTypeDefinition(type); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1389 | { |
| 1390 | TypeExpression type = null; |
| 1391 | } |
| 1392 | { |
| 1393 | <LEFTDBLBRACE> |
| 1394 | ( type = TypeExpr() ) |
| 1395 | <RIGHTDBLBRACE> |
| 1396 | { |
| 1397 | return new UnorderedListTypeDefinition(type); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | FunctionName FunctionName() throws ParseException: |
| 1402 | { |
| 1403 | String first = null; |
| 1404 | String second = null; |
| 1405 | String third = null; |
| 1406 | boolean secondAfterDot = false; |
| 1407 | } |
| 1408 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 1409 | first = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1410 | { |
| 1411 | FunctionName result = new FunctionName(); |
| 1412 | result.hint = getHint(token); |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 1413 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1414 | ( <DOT> second = Identifier() |
| 1415 | { |
| 1416 | secondAfterDot = true; |
| 1417 | } |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1418 | ( <SYMBOLHASH> third = Identifier())? | <SYMBOLHASH> second = Identifier() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1419 | { |
| 1420 | if (second == null) { |
| 1421 | result.dataverse = defaultDataverse; |
| 1422 | result.library = null; |
| 1423 | result.function = first; |
| 1424 | } else if (third == null) { |
| 1425 | if (secondAfterDot) { |
| 1426 | result.dataverse = first; |
| 1427 | result.library = null; |
| 1428 | result.function = second; |
| 1429 | } else { |
| 1430 | result.dataverse = defaultDataverse; |
| 1431 | result.library = first; |
| 1432 | result.function = second; |
| 1433 | } |
| 1434 | } else { |
| 1435 | result.dataverse = first; |
| 1436 | result.library = second; |
| 1437 | result.function = third; |
| 1438 | } |
| 1439 | |
| 1440 | if (result.function.equalsIgnoreCase("int")) { |
| 1441 | result.function = "int64"; |
| 1442 | } |
| 1443 | return result; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | Pair<Identifier,Identifier> TypeName() throws ParseException: |
| 1449 | { |
| 1450 | Pair<Identifier,Identifier> name = null; |
| 1451 | } |
| 1452 | { |
| 1453 | name = QualifiedName() |
| 1454 | { |
| 1455 | if (name.first == null) { |
| 1456 | name.first = new Identifier(defaultDataverse); |
| 1457 | } |
| 1458 | return name; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | String Identifier() throws ParseException: |
| 1463 | { |
| 1464 | String lit = null; |
| 1465 | } |
| 1466 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1467 | ((<IDENTIFIER>) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1468 | { |
| 1469 | return token.image; |
| 1470 | } |
| 1471 | | lit = StringLiteral() |
| 1472 | { |
| 1473 | return lit; |
| 1474 | } |
| 1475 | ) |
| 1476 | } |
| 1477 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1478 | Pair<Integer, Pair<List<String>, TypeExpression>> OpenField() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1479 | { |
| 1480 | TypeExpression fieldType = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1481 | Pair<Integer, List<String>> fieldList = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1482 | } |
| 1483 | { |
| 1484 | fieldList = NestedField() |
Mike Carey | af8e19d | 2016-08-25 17:55:17 -0700 | [diff] [blame] | 1485 | ( <COLON> fieldType = IndexedTypeExpr() <QUES>)? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1486 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1487 | return new Pair<Integer, Pair<List<String>, TypeExpression>> |
| 1488 | (fieldList.first, new Pair<List<String>, TypeExpression>(fieldList.second, fieldType)); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1492 | Pair<Integer, List<String>> NestedField() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1493 | { |
| 1494 | List<String> exprList = new ArrayList<String>(); |
| 1495 | String lit = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1496 | int source = 0; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1497 | } |
| 1498 | { |
| 1499 | lit = Identifier() |
| 1500 | { |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1501 | boolean meetParens = false; |
| 1502 | } |
| 1503 | ( |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1504 | LOOKAHEAD(1) |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1505 | <LEFTPAREN><RIGHTPAREN> |
| 1506 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1507 | if(!lit.equals("meta")){ |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1508 | throw new ParseException("The string before () has to be \"meta\"."); |
| 1509 | } |
| 1510 | meetParens = true; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1511 | source = 1; |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1512 | } |
| 1513 | )? |
| 1514 | { |
| 1515 | if(!meetParens){ |
| 1516 | exprList.add(lit); |
| 1517 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1518 | } |
| 1519 | (<DOT> |
| 1520 | lit = Identifier() |
| 1521 | { |
| 1522 | exprList.add(lit); |
| 1523 | } |
| 1524 | )* |
| 1525 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1526 | return new Pair<Integer, List<String>>(source, exprList); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | String StringLiteral() throws ParseException: |
| 1533 | { |
| 1534 | } |
| 1535 | { |
| 1536 | <STRING_LITERAL> |
| 1537 | { |
| 1538 | return removeQuotesAndEscapes(token.image); |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | Pair<Identifier,Identifier> QualifiedName() throws ParseException: |
| 1543 | { |
| 1544 | String first = null; |
| 1545 | String second = null; |
| 1546 | } |
| 1547 | { |
| 1548 | first = Identifier() (<DOT> second = Identifier())? |
| 1549 | { |
| 1550 | Identifier id1 = null; |
| 1551 | Identifier id2 = null; |
| 1552 | if (second == null) { |
| 1553 | id2 = new Identifier(first); |
| 1554 | } else |
| 1555 | { |
| 1556 | id1 = new Identifier(first); |
| 1557 | id2 = new Identifier(second); |
| 1558 | } |
| 1559 | return new Pair<Identifier,Identifier>(id1, id2); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException: |
| 1564 | { |
| 1565 | String first = null; |
| 1566 | String second = null; |
| 1567 | String third = null; |
| 1568 | } |
| 1569 | { |
| 1570 | first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())? |
| 1571 | { |
| 1572 | Identifier id1 = null; |
| 1573 | Identifier id2 = null; |
| 1574 | Identifier id3 = null; |
| 1575 | if (third == null) { |
| 1576 | id2 = new Identifier(first); |
| 1577 | id3 = new Identifier(second); |
| 1578 | } else { |
| 1579 | id1 = new Identifier(first); |
| 1580 | id2 = new Identifier(second); |
| 1581 | id3 = new Identifier(third); |
| 1582 | } |
| 1583 | return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3); |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1588 | { |
| 1589 | FunctionDecl funcDecl; |
| 1590 | FunctionSignature signature; |
| 1591 | String functionName; |
| 1592 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1593 | Expression funcBody; |
| 1594 | createNewScope(); |
| 1595 | } |
| 1596 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 1597 | <DECLARE> <FUNCTION> functionName = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1598 | paramList = ParameterList() |
| 1599 | <LEFTBRACE> funcBody = Expression() <RIGHTBRACE> |
| 1600 | { |
| 1601 | signature = new FunctionSignature(defaultDataverse, functionName, paramList.size()); |
| 1602 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1603 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
| 1604 | removeCurrentScope(); |
| 1605 | return funcDecl; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | |
| 1610 | Query Query() throws ParseException: |
| 1611 | { |
Till Westmann | ef3f027 | 2016-07-27 18:34:01 -0700 | [diff] [blame] | 1612 | Query query = new Query(false); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1613 | // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked |
| 1614 | setDataverses(query.getDataverses()); |
| 1615 | setDatasets(query.getDatasets()); |
| 1616 | Expression expr; |
| 1617 | } |
| 1618 | { |
| 1619 | expr = Expression() |
| 1620 | { |
| 1621 | query.setBody(expr); |
| 1622 | query.setVarCounter(getVarCounter()); |
| 1623 | // we remove the pointers to the locked entities before we return the query object |
| 1624 | setDataverses(null); |
| 1625 | setDatasets(null); |
| 1626 | return query; |
| 1627 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | Expression Expression(): |
| 1633 | { |
| 1634 | Expression expr = null; |
| 1635 | Expression exprP = null; |
| 1636 | } |
| 1637 | { |
| 1638 | ( |
| 1639 | |
| 1640 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1641 | expr = OperatorExpr() |
| 1642 | | expr = IfThenElse() |
| 1643 | | expr = FLWOGR() |
| 1644 | | expr = QuantifiedExpression() |
| 1645 | |
| 1646 | |
| 1647 | ) |
| 1648 | { |
| 1649 | return (exprP==null) ? expr : exprP; |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | Expression OperatorExpr()throws ParseException: |
| 1656 | { |
| 1657 | OperatorExpr op = null; |
| 1658 | Expression operand = null; |
| 1659 | } |
| 1660 | { |
| 1661 | operand = AndExpr() |
| 1662 | ( |
| 1663 | |
| 1664 | <OR> |
| 1665 | { |
| 1666 | if (op == null) { |
| 1667 | op = new OperatorExpr(); |
| 1668 | op.addOperand(operand); |
| 1669 | op.setCurrentop(true); |
| 1670 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1671 | try{ |
| 1672 | op.addOperator(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1673 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1674 | throw new ParseException(e.getMessage()); |
| 1675 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | operand = AndExpr() |
| 1679 | { |
| 1680 | op.addOperand(operand); |
| 1681 | } |
| 1682 | |
| 1683 | )* |
| 1684 | |
| 1685 | { |
| 1686 | return op==null? operand: op; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | Expression AndExpr()throws ParseException: |
| 1691 | { |
| 1692 | OperatorExpr op = null; |
| 1693 | Expression operand = null; |
| 1694 | } |
| 1695 | { |
| 1696 | operand = RelExpr() |
| 1697 | ( |
| 1698 | |
| 1699 | <AND> |
| 1700 | { |
| 1701 | if (op == null) { |
| 1702 | op = new OperatorExpr(); |
| 1703 | op.addOperand(operand); |
| 1704 | op.setCurrentop(true); |
| 1705 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1706 | try{ |
| 1707 | op.addOperator(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1708 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1709 | throw new ParseException(e.getMessage()); |
| 1710 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | operand = RelExpr() |
| 1714 | { |
| 1715 | op.addOperand(operand); |
| 1716 | } |
| 1717 | |
| 1718 | )* |
| 1719 | |
| 1720 | { |
| 1721 | return op==null? operand: op; |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | Expression RelExpr()throws ParseException: |
| 1728 | { |
| 1729 | OperatorExpr op = null; |
| 1730 | Expression operand = null; |
| 1731 | boolean broadcast = false; |
| 1732 | IExpressionAnnotation annotation = null; |
| 1733 | } |
| 1734 | { |
| 1735 | operand = AddExpr() |
| 1736 | { |
| 1737 | if (operand instanceof VariableExpr) { |
| 1738 | String hint = getHint(token); |
| 1739 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1740 | broadcast = true; |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | ( |
| 1746 | LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>) |
| 1747 | { |
| 1748 | String mhint = getHint(token); |
| 1749 | if (mhint != null) { |
| 1750 | if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1751 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1752 | } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 1753 | annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE; |
| 1754 | } |
| 1755 | } |
| 1756 | if (op == null) { |
| 1757 | op = new OperatorExpr(); |
| 1758 | op.addOperand(operand, broadcast); |
| 1759 | op.setCurrentop(true); |
| 1760 | broadcast = false; |
| 1761 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1762 | try{ |
| 1763 | op.addOperator(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1764 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1765 | throw new ParseException(e.getMessage()); |
| 1766 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | operand = AddExpr() |
| 1770 | { |
| 1771 | broadcast = false; |
| 1772 | if (operand instanceof VariableExpr) { |
| 1773 | String hint = getHint(token); |
| 1774 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1775 | broadcast = true; |
| 1776 | } |
| 1777 | } |
| 1778 | op.addOperand(operand, broadcast); |
| 1779 | } |
| 1780 | )? |
| 1781 | |
| 1782 | { |
| 1783 | if (annotation != null) { |
| 1784 | op.addHint(annotation); |
| 1785 | } |
| 1786 | return op==null? operand: op; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | Expression AddExpr()throws ParseException: |
| 1791 | { |
| 1792 | OperatorExpr op = null; |
| 1793 | Expression operand = null; |
| 1794 | } |
| 1795 | { |
| 1796 | operand = MultExpr() |
| 1797 | |
| 1798 | ( (<PLUS> | <MINUS>) |
| 1799 | { |
| 1800 | if (op == null) { |
| 1801 | op = new OperatorExpr(); |
| 1802 | op.addOperand(operand); |
| 1803 | op.setCurrentop(true); |
| 1804 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1805 | try{ |
| 1806 | ((OperatorExpr)op).addOperator(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1807 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1808 | throw new ParseException(e.getMessage()); |
| 1809 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | operand = MultExpr() |
| 1813 | { |
| 1814 | op.addOperand(operand); |
| 1815 | } |
| 1816 | )* |
| 1817 | |
| 1818 | { |
| 1819 | return op==null? operand: op; |
| 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | Expression MultExpr()throws ParseException: |
| 1824 | { |
| 1825 | OperatorExpr op = null; |
| 1826 | Expression operand = null; |
| 1827 | } |
| 1828 | { |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1829 | operand = ExponentExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1830 | |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1831 | (( <MUL> | <DIV> | <MOD> | <IDIV>) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1832 | { |
| 1833 | if (op == null) { |
| 1834 | op = new OperatorExpr(); |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1835 | op.addOperand(operand); |
| 1836 | op.setCurrentop(true); |
| 1837 | } |
| 1838 | try{ |
| 1839 | op.addOperator(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1840 | } catch (CompilationException e){ |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1841 | throw new ParseException(e.getMessage()); |
| 1842 | } |
| 1843 | } |
| 1844 | operand = ExponentExpr() |
| 1845 | { |
| 1846 | op.addOperand(operand); |
| 1847 | } |
| 1848 | )* |
| 1849 | |
| 1850 | { |
| 1851 | return op==null?operand:op; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | Expression ExponentExpr()throws ParseException: |
| 1856 | { |
| 1857 | OperatorExpr op = null; |
| 1858 | Expression operand = null; |
| 1859 | } |
| 1860 | { |
| 1861 | operand = UnionExpr() |
| 1862 | |
| 1863 | ( <CARET> |
| 1864 | { |
| 1865 | if (op == null) { |
| 1866 | op = new OperatorExpr(); |
| 1867 | op.addOperand(operand); |
| 1868 | op.setCurrentop(true); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1869 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1870 | try{ |
| 1871 | op.addOperator(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1872 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1873 | throw new ParseException(e.getMessage()); |
| 1874 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1875 | } |
| 1876 | operand = UnionExpr() |
| 1877 | { |
| 1878 | op.addOperand(operand); |
| 1879 | } |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1880 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1881 | |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1882 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1883 | return op==null?operand:op; |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 1884 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | Expression UnionExpr() throws ParseException: |
| 1888 | { |
| 1889 | UnionExpr union = null; |
| 1890 | Expression operand1 = null; |
| 1891 | Expression operand2 = null; |
| 1892 | } |
| 1893 | { |
| 1894 | operand1 = UnaryExpr() |
| 1895 | (<UNION> |
| 1896 | (operand2 = UnaryExpr()) { |
| 1897 | if (union == null) { |
| 1898 | union = new UnionExpr(); |
| 1899 | union.addExpr(operand1); |
| 1900 | } |
| 1901 | union.addExpr(operand2); |
| 1902 | } )* |
| 1903 | { |
| 1904 | return (union == null)? operand1: union; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | Expression UnaryExpr() throws ParseException: |
| 1909 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1910 | UnaryExpr uexpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1911 | Expression expr = null; |
| 1912 | } |
| 1913 | { |
| 1914 | ( (<PLUS> | <MINUS>) |
| 1915 | { |
| 1916 | uexpr = new UnaryExpr(); |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1917 | try{ |
| 1918 | uexpr.setExprType(token.image); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1919 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1920 | throw new ParseException(e.getMessage()); |
| 1921 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1922 | } |
| 1923 | )? |
| 1924 | |
| 1925 | expr = ValueExpr() |
| 1926 | { |
| 1927 | if(uexpr!=null){ |
| 1928 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1929 | return uexpr; |
| 1930 | } |
| 1931 | else{ |
| 1932 | return expr; |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | Expression ValueExpr()throws ParseException: |
| 1938 | { |
| 1939 | Expression expr = null; |
| 1940 | Identifier ident = null; |
| 1941 | AbstractAccessor fa = null; |
| 1942 | Expression indexExpr = null; |
| 1943 | } |
| 1944 | { |
| 1945 | expr = PrimaryExpr() ( ident = Field() |
| 1946 | { |
| 1947 | fa = (fa == null ? new FieldAccessor(expr, ident) |
| 1948 | : new FieldAccessor(fa, ident)); |
| 1949 | } |
| 1950 | | indexExpr = Index() |
| 1951 | { |
| 1952 | fa = (fa == null ? new IndexAccessor(expr, indexExpr) |
| 1953 | : new IndexAccessor(fa, indexExpr)); |
| 1954 | } |
| 1955 | )* |
| 1956 | { |
| 1957 | return fa == null ? expr : fa; |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | Identifier Field() throws ParseException: |
| 1962 | { |
| 1963 | String ident = null; |
| 1964 | } |
| 1965 | { |
| 1966 | <DOT> ident = Identifier() |
| 1967 | { |
| 1968 | return new Identifier(ident); |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | Expression Index() throws ParseException: |
| 1973 | { |
| 1974 | Expression expr = null; |
| 1975 | } |
| 1976 | { |
| 1977 | <LEFTBRACKET> ( expr = Expression() |
| 1978 | { |
| 1979 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1980 | { |
| 1981 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 1982 | if(lit.getLiteralType() != Literal.Type.INTEGER && |
| 1983 | lit.getLiteralType() != Literal.Type.LONG) { |
| 1984 | throw new ParseException("Index should be an INTEGER"); |
| 1985 | } |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | | <QUES> // ANY |
| 1990 | |
| 1991 | ) |
| 1992 | |
| 1993 | <RIGHTBRACKET> |
| 1994 | { |
| 1995 | return expr; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | |
| 2000 | Expression PrimaryExpr()throws ParseException: |
| 2001 | { |
| 2002 | Expression expr = null; |
| 2003 | } |
| 2004 | { |
| 2005 | ( LOOKAHEAD(2) |
| 2006 | expr = FunctionCallExpr() |
| 2007 | | expr = Literal() |
| 2008 | | expr = DatasetAccessExpression() |
| 2009 | | expr = VariableRef() |
| 2010 | { |
| 2011 | if(((VariableExpr)expr).getIsNewVar() == true) |
| 2012 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
| 2013 | } |
| 2014 | | expr = ListConstructor() |
| 2015 | | expr = RecordConstructor() |
| 2016 | | expr = ParenthesizedExpression() |
| 2017 | ) |
| 2018 | { |
| 2019 | return expr; |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | Expression Literal() throws ParseException: |
| 2024 | { |
| 2025 | LiteralExpr lit = new LiteralExpr(); |
| 2026 | String str = null; |
| 2027 | } |
| 2028 | { |
| 2029 | ( str = StringLiteral() |
| 2030 | { |
| 2031 | lit.setValue(new StringLiteral(str)); |
| 2032 | } |
| 2033 | | <INTEGER_LITERAL> |
| 2034 | { |
| 2035 | lit.setValue(new LongIntegerLiteral(new Long(token.image))); |
| 2036 | } |
| 2037 | | <FLOAT_LITERAL> |
| 2038 | { |
| 2039 | lit.setValue(new FloatLiteral(new Float(token.image))); |
| 2040 | } |
| 2041 | | <DOUBLE_LITERAL> |
| 2042 | { |
| 2043 | lit.setValue(new DoubleLiteral(new Double(token.image))); |
| 2044 | } |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 2045 | | <MISSING> |
| 2046 | { |
| 2047 | lit.setValue(MissingLiteral.INSTANCE); |
| 2048 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2049 | | <NULL> |
| 2050 | { |
| 2051 | lit.setValue(NullLiteral.INSTANCE); |
| 2052 | } |
| 2053 | | <TRUE> |
| 2054 | { |
| 2055 | lit.setValue(TrueLiteral.INSTANCE); |
| 2056 | } |
| 2057 | | <FALSE> |
| 2058 | { |
| 2059 | lit.setValue(FalseLiteral.INSTANCE); |
| 2060 | } |
| 2061 | ) |
| 2062 | { |
| 2063 | return lit; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | VariableExpr VariableRef() throws ParseException: |
| 2069 | { |
| 2070 | VariableExpr varExp = new VariableExpr(); |
| 2071 | VarIdentifier var = new VarIdentifier(); |
| 2072 | } |
| 2073 | { |
| 2074 | <VARIABLE> |
| 2075 | { |
| 2076 | String varName = token.image; |
| 2077 | Identifier ident = lookupSymbol(varName); |
| 2078 | if (isInForbiddenScopes(varName)) { |
| 2079 | 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."); |
| 2080 | } |
| 2081 | if(ident != null) { // exist such ident |
| 2082 | varExp.setIsNewVar(false); |
| 2083 | varExp.setVar((VarIdentifier)ident); |
| 2084 | } else { |
| 2085 | varExp.setVar(var); |
| 2086 | } |
| 2087 | var.setValue(varName); |
| 2088 | return varExp; |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | VariableExpr Variable() throws ParseException: |
| 2094 | { |
| 2095 | VariableExpr varExp = new VariableExpr(); |
| 2096 | VarIdentifier var = new VarIdentifier(); |
| 2097 | } |
| 2098 | { |
| 2099 | <VARIABLE> |
| 2100 | { |
| 2101 | Identifier ident = lookupSymbol(token.image); |
| 2102 | if(ident != null) { // exist such ident |
| 2103 | varExp.setIsNewVar(false); |
| 2104 | } |
| 2105 | varExp.setVar(var); |
| 2106 | var.setValue(token.image); |
| 2107 | return varExp; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | Expression ListConstructor() throws ParseException: |
| 2112 | { |
| 2113 | Expression expr = null; |
| 2114 | } |
| 2115 | { |
| 2116 | ( |
| 2117 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 2118 | ) |
| 2119 | |
| 2120 | { |
| 2121 | return expr; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | |
| 2126 | ListConstructor OrderedListConstructor() throws ParseException: |
| 2127 | { |
| 2128 | ListConstructor expr = new ListConstructor(); |
| 2129 | List<Expression> exprList = null; |
| 2130 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 2131 | } |
| 2132 | { |
| 2133 | <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET> |
| 2134 | { |
| 2135 | expr.setExprList(exprList); |
| 2136 | return expr; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 2141 | { |
| 2142 | ListConstructor expr = new ListConstructor(); |
| 2143 | List<Expression> exprList = null; |
| 2144 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 2145 | } |
| 2146 | { |
| 2147 | <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE> |
| 2148 | { |
| 2149 | expr.setExprList(exprList); |
| 2150 | return expr; |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | List<Expression> ExpressionList() throws ParseException: |
| 2155 | { |
| 2156 | Expression expr = null; |
| 2157 | List<Expression> list = null; |
| 2158 | List<Expression> exprList = new ArrayList<Expression>(); |
| 2159 | } |
| 2160 | { |
| 2161 | ( |
| 2162 | expr = Expression() { exprList.add(expr); } |
| 2163 | (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })? |
| 2164 | )? |
| 2165 | (LOOKAHEAD(1) Comma())? |
| 2166 | { |
| 2167 | return exprList; |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | void Comma(): |
| 2172 | {} |
| 2173 | { |
| 2174 | <COMMA> |
| 2175 | } |
| 2176 | |
| 2177 | RecordConstructor RecordConstructor() throws ParseException: |
| 2178 | { |
| 2179 | RecordConstructor expr = new RecordConstructor(); |
| 2180 | FieldBinding tmp = null; |
| 2181 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 2182 | } |
| 2183 | { |
| 2184 | <LEFTBRACE> (tmp = FieldBinding() |
| 2185 | { |
| 2186 | fbList.add(tmp); |
| 2187 | } |
| 2188 | (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE> |
| 2189 | { |
| 2190 | expr.setFbList(fbList); |
| 2191 | return expr; |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | FieldBinding FieldBinding() throws ParseException: |
| 2196 | { |
| 2197 | FieldBinding fb = new FieldBinding(); |
| 2198 | Expression left, right; |
| 2199 | } |
| 2200 | { |
| 2201 | left = Expression() <COLON> right = Expression() |
| 2202 | { |
| 2203 | fb.setLeftExpr(left); |
| 2204 | fb.setRightExpr(right); |
| 2205 | return fb; |
| 2206 | } |
| 2207 | } |
| 2208 | |
| 2209 | |
| 2210 | Expression FunctionCallExpr() throws ParseException: |
| 2211 | { |
| 2212 | CallExpr callExpr; |
| 2213 | List<Expression> argList = new ArrayList<Expression>(); |
| 2214 | Expression tmp; |
| 2215 | int arity = 0; |
| 2216 | FunctionName funcName = null; |
| 2217 | String hint = null; |
| 2218 | } |
| 2219 | { |
| 2220 | funcName = FunctionName() |
| 2221 | { |
| 2222 | hint = funcName.hint; |
| 2223 | } |
| 2224 | <LEFTPAREN> (tmp = Expression() |
| 2225 | { |
| 2226 | argList.add(tmp); |
| 2227 | arity ++; |
| 2228 | } |
| 2229 | (<COMMA> tmp = Expression() |
| 2230 | { |
| 2231 | argList.add(tmp); |
| 2232 | arity++; |
| 2233 | } |
| 2234 | )*)? <RIGHTPAREN> |
| 2235 | { |
| 2236 | // TODO use funcName.library |
| 2237 | String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function; |
| 2238 | FunctionSignature signature |
| 2239 | = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity); |
| 2240 | if (signature == null) { |
| 2241 | signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity); |
| 2242 | } |
| 2243 | callExpr = new CallExpr(signature,argList); |
| 2244 | if (hint != null) { |
| 2245 | if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 2246 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 2247 | } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 2248 | callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE); |
| 2249 | } |
| 2250 | } |
| 2251 | return callExpr; |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | |
| 2256 | Expression DatasetAccessExpression() throws ParseException: |
| 2257 | { |
| 2258 | String funcName; |
| 2259 | String arg1 = null; |
| 2260 | String arg2 = null; |
| 2261 | Expression nameArg; |
| 2262 | } |
| 2263 | { |
| 2264 | <DATASET> |
| 2265 | { |
| 2266 | funcName = token.image; |
| 2267 | } |
| 2268 | ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? ) |
| 2269 | { |
| 2270 | String name = arg2 == null ? arg1 : arg1 + "." + arg2; |
| 2271 | LiteralExpr ds = new LiteralExpr(); |
| 2272 | ds.setValue( new StringLiteral(name) ); |
| 2273 | nameArg = ds; |
| 2274 | if(arg2 != null){ |
| 2275 | addDataverse(arg1.toString()); |
| 2276 | addDataset(name); |
| 2277 | } else { |
| 2278 | addDataset(defaultDataverse + "." + name); |
| 2279 | } |
| 2280 | } |
| 2281 | | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) ) |
| 2282 | { |
| 2283 | String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; |
| 2284 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1); |
| 2285 | if (signature == null) { |
| 2286 | signature = new FunctionSignature(dataverse, funcName, 1); |
| 2287 | } |
| 2288 | List<Expression> argList = new ArrayList<Expression>(); |
| 2289 | argList.add(nameArg); |
| 2290 | return new CallExpr(signature, argList); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | Expression ParenthesizedExpression() throws ParseException: |
| 2295 | { |
| 2296 | Expression expr; |
| 2297 | } |
| 2298 | { |
| 2299 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 2300 | { |
| 2301 | return expr; |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | Expression IfThenElse() throws ParseException: |
| 2306 | { |
| 2307 | Expression condExpr; |
| 2308 | Expression thenExpr; |
| 2309 | Expression elseExpr; |
| 2310 | IfExpr ifExpr = new IfExpr(); |
| 2311 | } |
| 2312 | { |
| 2313 | <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression() |
| 2314 | |
| 2315 | { |
| 2316 | ifExpr.setCondExpr(condExpr); |
| 2317 | ifExpr.setThenExpr(thenExpr); |
| 2318 | ifExpr.setElseExpr(elseExpr); |
| 2319 | return ifExpr; |
| 2320 | } |
| 2321 | } |
| 2322 | |
Taewoo Kim | 92c0bac | 2017-02-11 16:38:44 -0800 | [diff] [blame] | 2323 | // Note: if you modify this part: "tmp = LetClause() {clauseList.add(tmp);}", please also apply the necessary |
| 2324 | // change to the AQLPlusExtension.jj file since it refers to this string part and may behave incorrectly if this |
| 2325 | // part is modified. For more details, please refer to AQLPlusExtension.jj file. |
Abdullah Alamoudi | 806f7d2 | 2016-07-23 18:02:55 +0300 | [diff] [blame] | 2326 | Expression FLWOGR() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2327 | { |
| 2328 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 2329 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 2330 | Expression returnExpr; |
| 2331 | Clause tmp; |
| 2332 | createNewScope(); |
| 2333 | } |
| 2334 | { |
| 2335 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
| 2336 | (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression() |
| 2337 | |
| 2338 | { |
| 2339 | flworg.setClauseList(clauseList); |
| 2340 | flworg.setReturnExpr(returnExpr); |
| 2341 | removeCurrentScope(); |
| 2342 | return flworg; |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | Clause Clause()throws ParseException : |
| 2347 | { |
| 2348 | Clause clause; |
| 2349 | } |
| 2350 | { |
| 2351 | ( |
| 2352 | clause = ForClause() |
| 2353 | | clause = LetClause() |
| 2354 | | clause = WhereClause() |
| 2355 | | clause = OrderbyClause() |
| 2356 | | clause = GroupClause() |
| 2357 | | clause = LimitClause() |
| 2358 | | clause = DistinctClause() |
| 2359 | ) |
| 2360 | { |
| 2361 | return clause; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | Clause ForClause()throws ParseException : |
| 2366 | { |
| 2367 | ForClause fc = new ForClause(); |
| 2368 | VariableExpr varExp; |
| 2369 | VariableExpr varPos = null; |
| 2370 | Expression inExp; |
| 2371 | extendCurrentScope(); |
| 2372 | } |
| 2373 | { |
| 2374 | (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() ) |
| 2375 | { |
| 2376 | fc.setVarExpr(varExp); |
| 2377 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 2378 | fc.setInExpr(inExp); |
| 2379 | if (varPos != null) { |
| 2380 | fc.setPosExpr(varPos); |
| 2381 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
| 2382 | } |
| 2383 | return fc; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | Clause LetClause() throws ParseException: |
| 2388 | { |
| 2389 | LetClause lc = new LetClause(); |
| 2390 | VariableExpr varExp; |
| 2391 | Expression beExp; |
| 2392 | extendCurrentScope(); |
| 2393 | } |
| 2394 | { |
| 2395 | (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression() |
| 2396 | { |
| 2397 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 2398 | lc.setVarExpr(varExp); |
| 2399 | lc.setBindingExpr(beExp); |
| 2400 | return lc; |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | Clause WhereClause()throws ParseException : |
| 2405 | { |
| 2406 | WhereClause wc = new WhereClause(); |
| 2407 | Expression whereExpr; |
| 2408 | } |
| 2409 | { |
| 2410 | <WHERE> whereExpr = Expression() |
| 2411 | { |
| 2412 | wc.setWhereExpr(whereExpr); |
| 2413 | return wc; |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | Clause OrderbyClause()throws ParseException : |
| 2418 | { |
| 2419 | OrderbyClause oc = new OrderbyClause(); |
| 2420 | Expression orderbyExpr; |
| 2421 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 2422 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 2423 | int numOfOrderby = 0; |
| 2424 | } |
| 2425 | { |
| 2426 | ( |
| 2427 | <ORDER> |
| 2428 | { |
| 2429 | String hint = getHint(token); |
| 2430 | if (hint != null) { |
| 2431 | if (hint.startsWith(INMEMORY_HINT)) { |
| 2432 | String splits[] = hint.split(" +"); |
| 2433 | int numFrames = Integer.parseInt(splits[1]); |
| 2434 | int numTuples = Integer.parseInt(splits[2]); |
| 2435 | oc.setNumFrames(numFrames); |
| 2436 | oc.setNumTuples(numTuples); |
| 2437 | } |
| 2438 | if (hint.startsWith(RANGE_HINT)) { |
| 2439 | try{ |
| 2440 | oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length()))); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 2441 | } catch (CompilationException e) { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2442 | throw new ParseException(e.getMessage()); |
| 2443 | } |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | <BY> orderbyExpr = Expression() |
| 2448 | { |
| 2449 | orderbyList.add(orderbyExpr); |
| 2450 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 2451 | } |
| 2452 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2453 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2454 | { |
| 2455 | modifierList.add(modif); |
| 2456 | } |
| 2457 | |
| 2458 | (<COMMA> orderbyExpr = Expression() |
| 2459 | { |
| 2460 | orderbyList.add(orderbyExpr); |
| 2461 | modif = OrderbyClause.OrderModifier.ASC; |
| 2462 | } |
| 2463 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2464 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2465 | { |
| 2466 | modifierList.add(modif); |
| 2467 | } |
| 2468 | )* |
| 2469 | ) |
| 2470 | { |
| 2471 | oc.setModifierList(modifierList); |
| 2472 | oc.setOrderbyList(orderbyList); |
| 2473 | return oc; |
| 2474 | } |
| 2475 | } |
| 2476 | Clause GroupClause()throws ParseException : |
| 2477 | { |
Abdullah Alamoudi | 806f7d2 | 2016-07-23 18:02:55 +0300 | [diff] [blame] | 2478 | GroupbyClause gbc = new GroupbyClause(); |
| 2479 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 2480 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2481 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
Yingyi Bu | 8671ddf | 2016-08-14 23:58:43 -0700 | [diff] [blame] | 2482 | Map<Expression, VariableExpr> withVarMap = new HashMap<Expression, VariableExpr>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2483 | VariableExpr var = null; |
| 2484 | VariableExpr withVar = null; |
| 2485 | Expression expr = null; |
| 2486 | VariableExpr decorVar = null; |
| 2487 | Expression decorExpr = null; |
| 2488 | } |
| 2489 | { |
| 2490 | { |
| 2491 | Scope newScope = extendCurrentScopeNoPush(true); |
| 2492 | // extendCurrentScope(true); |
| 2493 | } |
| 2494 | <GROUP> |
| 2495 | { |
| 2496 | String hint = getHint(token); |
| 2497 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 2498 | gbc.setHashGroupByHint(true); |
| 2499 | } |
| 2500 | } |
| 2501 | <BY> (LOOKAHEAD(2) var = Variable() |
| 2502 | { |
| 2503 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 2504 | } <ASSIGN>)? |
| 2505 | expr = Expression() |
| 2506 | { |
| 2507 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 2508 | vePairList.add(pair1); |
| 2509 | } |
| 2510 | (<COMMA> ( LOOKAHEAD(2) var = Variable() |
| 2511 | { |
| 2512 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 2513 | } <ASSIGN>)? |
| 2514 | expr = Expression() |
| 2515 | { |
| 2516 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 2517 | vePairList.add(pair2); |
| 2518 | } |
| 2519 | )* |
| 2520 | (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression() |
| 2521 | { |
| 2522 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 2523 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 2524 | decorPairList.add(pair3); |
| 2525 | } |
| 2526 | (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression() |
| 2527 | { |
| 2528 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 2529 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 2530 | decorPairList.add(pair4); |
| 2531 | } |
| 2532 | )* |
| 2533 | )? |
| 2534 | (<WITH>|<KEEPING>) withVar = VariableRef() |
| 2535 | { |
| 2536 | if(withVar.getIsNewVar()==true) |
| 2537 | throw new ParseException("can't find variable " + withVar.getVar()); |
Yingyi Bu | 8671ddf | 2016-08-14 23:58:43 -0700 | [diff] [blame] | 2538 | withVarMap.put(withVar, withVar); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2539 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2540 | } |
| 2541 | (<COMMA> withVar = VariableRef() |
| 2542 | { |
| 2543 | if(withVar.getIsNewVar()==true) |
| 2544 | throw new ParseException("can't find variable " + withVar.getVar()); |
Yingyi Bu | 8671ddf | 2016-08-14 23:58:43 -0700 | [diff] [blame] | 2545 | withVarMap.put(withVar, withVar); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2546 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2547 | })* |
| 2548 | { |
| 2549 | gbc.setGbyPairList(vePairList); |
| 2550 | gbc.setDecorPairList(decorPairList); |
Yingyi Bu | 8671ddf | 2016-08-14 23:58:43 -0700 | [diff] [blame] | 2551 | gbc.setWithVarMap(withVarMap); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2552 | replaceCurrentScope(newScope); |
| 2553 | return gbc; |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | |
| 2558 | LimitClause LimitClause() throws ParseException: |
| 2559 | { |
| 2560 | LimitClause lc = new LimitClause(); |
| 2561 | Expression expr; |
| 2562 | pushForbiddenScope(getCurrentScope()); |
| 2563 | } |
| 2564 | { |
| 2565 | <LIMIT> expr = Expression() { lc.setLimitExpr(expr); } |
| 2566 | (<OFFSET> expr = Expression() { lc.setOffset(expr); })? |
| 2567 | |
| 2568 | { |
| 2569 | popForbiddenScope(); |
| 2570 | return lc; |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | DistinctClause DistinctClause() throws ParseException: |
| 2575 | { |
| 2576 | List<Expression> exprs = new ArrayList<Expression>(); |
| 2577 | Expression expr; |
| 2578 | } |
| 2579 | { |
| 2580 | <DISTINCT> <BY> expr = Expression() |
| 2581 | { |
| 2582 | exprs.add(expr); |
| 2583 | } |
| 2584 | (<COMMA> expr = Expression() |
| 2585 | { |
| 2586 | exprs.add(expr); |
| 2587 | } |
| 2588 | )* |
| 2589 | { |
| 2590 | return new DistinctClause(exprs); |
| 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2595 | { |
| 2596 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2597 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2598 | Expression satisfiesExpr; |
| 2599 | VariableExpr var; |
| 2600 | Expression inExpr; |
| 2601 | QuantifiedPair pair; |
| 2602 | } |
| 2603 | { |
| 2604 | { |
| 2605 | createNewScope(); |
| 2606 | } |
| 2607 | |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2608 | ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2609 | | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2610 | var = Variable() <IN> inExpr = Expression() |
| 2611 | { |
| 2612 | pair = new QuantifiedPair(var, inExpr); |
| 2613 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2614 | quantifiedList.add(pair); |
| 2615 | } |
| 2616 | ( |
| 2617 | <COMMA> var = Variable() <IN> inExpr = Expression() |
| 2618 | { |
| 2619 | pair = new QuantifiedPair(var, inExpr); |
| 2620 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2621 | quantifiedList.add(pair); |
| 2622 | } |
| 2623 | )* |
| 2624 | <SATISFIES> satisfiesExpr = Expression() |
| 2625 | { |
| 2626 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2627 | qc.setQuantifiedList(quantifiedList); |
| 2628 | removeCurrentScope(); |
| 2629 | return qc; |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | TOKEN_MGR_DECLS: |
| 2634 | { |
| 2635 | public int commentDepth = 0; |
Till Westmann | e9b2adf | 2016-10-15 12:39:01 -0700 | [diff] [blame] | 2636 | public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2637 | |
| 2638 | public void pushState() { |
| 2639 | lexerStateStack.push( curLexState ); |
| 2640 | } |
| 2641 | |
| 2642 | public void popState(String token) { |
| 2643 | if (lexerStateStack.size() > 0) { |
| 2644 | SwitchTo( lexerStateStack.pop() ); |
| 2645 | } else { |
| 2646 | int errorLine = input_stream.getEndLine(); |
| 2647 | int errorColumn = input_stream.getEndColumn(); |
| 2648 | String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token |
| 2649 | + "\" but state stack is empty."; |
| 2650 | throw new TokenMgrError(msg, -1); |
| 2651 | } |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | <DEFAULT,IN_DBL_BRACE> |
| 2656 | TOKEN : |
| 2657 | { |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2658 | <APPLY : "apply"> |
| 2659 | | <AS : "as"> |
| 2660 | | <ASC : "asc"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2661 | | <AT : "at"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2662 | | <AUTOGENERATED : "autogenerated"> |
| 2663 | | <BTREE : "btree"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2664 | | <BY : "by"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2665 | | <CLOSED : "closed"> |
| 2666 | | <COMPACT : "compact"> |
| 2667 | | <COMPACTION : "compaction"> |
| 2668 | | <CONNECT : "connect"> |
| 2669 | | <CREATE : "create"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2670 | | <DATASET : "dataset"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2671 | | <DATAVERSE : "dataverse"> |
| 2672 | | <DECLARE : "declare"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2673 | | <DECOR : "decor"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2674 | | <DEFINITION : "definition"> |
| 2675 | | <DELETE : "delete"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2676 | | <DESC : "desc"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2677 | | <DISCONNECT : "disconnect"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2678 | | <DISTINCT : "distinct"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2679 | | <DROP : "drop"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2680 | | <ELSE : "else"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2681 | | <ENFORCED : "enforced"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2682 | | <EVERY : "every"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2683 | | <EXISTS : "exists"> |
| 2684 | | <EXTERNAL : "external"> |
| 2685 | | <FEED : "feed"> |
| 2686 | | <FILTER : "filter"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2687 | | <FOR : "for"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2688 | | <FORMAT : "format"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2689 | | <FROM : "from"> |
Taewoo Kim | c49405a | 2017-01-04 00:30:43 -0800 | [diff] [blame] | 2690 | | <FULLTEXT : "fulltext"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2691 | | <FUNCTION : "function"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2692 | | <GROUP : "group"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2693 | | <HINTS : "hints"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2694 | | <IF : "if"> |
| 2695 | | <IN : "in"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2696 | | <INDEX : "index"> |
| 2697 | | <INGESTION : "ingestion"> |
| 2698 | | <INSERT : "insert"> |
| 2699 | | <INTERNAL : "internal"> |
| 2700 | | <INTO : "into"> |
| 2701 | | <KEY : "key"> |
| 2702 | | <KEYWORD : "keyword"> |
| 2703 | | <KEEPING : "keeping"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2704 | | <LET : "let"> |
| 2705 | | <LIMIT : "limit"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2706 | | <LOAD : "load"> |
| 2707 | | <NGRAM : "ngram"> |
| 2708 | | <NODEGROUP : "nodegroup"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2709 | | <OFFSET : "offset"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2710 | | <ON : "on"> |
| 2711 | | <OPEN : "open"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2712 | | <ORDER : "order"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2713 | | <OUTPUT : "output"> |
| 2714 | | <PATH : "path"> |
| 2715 | | <POLICY : "policy"> |
| 2716 | | <PRESORTED : "pre-sorted"> |
| 2717 | | <PRIMARY : "primary"> |
| 2718 | | <REFRESH : "refresh"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2719 | | <RETURN : "return"> |
Steven Glenn Jacobs | afa909a | 2016-10-16 10:35:30 -0700 | [diff] [blame] | 2720 | | <RETURNING : "returning"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2721 | | <RTREE : "rtree"> |
| 2722 | | <RUN : "run"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2723 | | <SATISFIES : "satisfies"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2724 | | <SECONDARY : "secondary"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2725 | | <SELECT : "select"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2726 | | <SET : "set"> |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 2727 | | <START: "start"> |
| 2728 | | <STOP: "stop"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2729 | | <SOME : "some"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2730 | | <TEMPORARY : "temporary"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2731 | | <THEN : "then"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2732 | | <TO : "to"> |
| 2733 | | <TYPE : "type"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2734 | | <UNION : "union"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2735 | | <UPDATE : "update"> |
| 2736 | | <UPSERT : "upsert"> |
| 2737 | | <USE : "use"> |
| 2738 | | <USING : "using"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2739 | | <WHERE : "where"> |
| 2740 | | <WITH : "with"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2741 | | <WRITE : "write"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | <DEFAULT,IN_DBL_BRACE> |
| 2745 | TOKEN : |
| 2746 | { |
| 2747 | <CARET : "^"> |
| 2748 | | <DIV : "/"> |
| 2749 | | <IDIV : "idiv"> |
| 2750 | | <MINUS : "-"> |
| 2751 | | <MOD : "%"> |
| 2752 | | <MUL : "*"> |
| 2753 | | <PLUS : "+"> |
| 2754 | |
| 2755 | | <LEFTPAREN : "("> |
| 2756 | | <RIGHTPAREN : ")"> |
| 2757 | | <LEFTBRACKET : "["> |
| 2758 | | <RIGHTBRACKET : "]"> |
| 2759 | |
| 2760 | | <COLON : ":"> |
| 2761 | | <COMMA : ","> |
| 2762 | | <DOT : "."> |
| 2763 | | <QUES : "?"> |
| 2764 | |
| 2765 | | <LT : "<"> |
| 2766 | | <GT : ">"> |
| 2767 | | <LE : "<="> |
| 2768 | | <GE : ">="> |
| 2769 | | <EQ : "="> |
| 2770 | | <NE : "!="> |
| 2771 | | <SIMILAR : "~="> |
| 2772 | | <ASSIGN : ":="> |
| 2773 | |
| 2774 | | <AND : "and"> |
| 2775 | | <OR : "or"> |
Abdullah Alamoudi | e6e54f3 | 2016-07-12 20:40:15 +0400 | [diff] [blame] | 2776 | |
| 2777 | | <SYMBOLAT : "@"> |
| 2778 | | <SYMBOLHASH : "#"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | <DEFAULT,IN_DBL_BRACE> |
| 2782 | TOKEN : |
| 2783 | { |
| 2784 | <LEFTBRACE : "{"> { pushState(); } : DEFAULT |
| 2785 | } |
| 2786 | |
| 2787 | <DEFAULT> |
| 2788 | TOKEN : |
| 2789 | { |
| 2790 | <RIGHTBRACE : "}"> { popState("}"); } |
| 2791 | } |
| 2792 | |
| 2793 | <DEFAULT,IN_DBL_BRACE> |
| 2794 | TOKEN : |
| 2795 | { |
| 2796 | <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE |
| 2797 | } |
| 2798 | |
| 2799 | <IN_DBL_BRACE> |
| 2800 | TOKEN : |
| 2801 | { |
| 2802 | <RIGHTDBLBRACE : "}}"> { popState("}}"); } |
| 2803 | } |
| 2804 | |
| 2805 | <DEFAULT,IN_DBL_BRACE> |
| 2806 | TOKEN : |
| 2807 | { |
| 2808 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2809 | } |
| 2810 | |
| 2811 | <DEFAULT,IN_DBL_BRACE> |
| 2812 | TOKEN : |
| 2813 | { |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 2814 | < MISSING : "missing"> |
| 2815 | | <NULL : "null"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2816 | | <TRUE : "true"> |
| 2817 | | <FALSE : "false"> |
| 2818 | } |
| 2819 | |
| 2820 | <DEFAULT,IN_DBL_BRACE> |
| 2821 | TOKEN : |
| 2822 | { |
| 2823 | <#DIGIT : ["0" - "9"]> |
| 2824 | } |
| 2825 | |
| 2826 | <DEFAULT,IN_DBL_BRACE> |
| 2827 | TOKEN: |
| 2828 | { |
| 2829 | < DOUBLE_LITERAL: <DIGITS> |
| 2830 | | <DIGITS> ( "." <DIGITS> )? |
| 2831 | | "." <DIGITS> |
| 2832 | > |
| 2833 | | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" ) |
| 2834 | | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )? |
| 2835 | | "." <DIGITS> ( "f" | "F" ) |
| 2836 | > |
| 2837 | | <DIGITS : (<DIGIT>)+ > |
| 2838 | } |
| 2839 | |
| 2840 | <DEFAULT,IN_DBL_BRACE> |
| 2841 | TOKEN : |
| 2842 | { |
| 2843 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2844 | | <SPECIALCHARS : ["$", "_", "-"]> |
| 2845 | } |
| 2846 | |
| 2847 | <DEFAULT,IN_DBL_BRACE> |
| 2848 | TOKEN : |
| 2849 | { |
| 2850 | // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream |
| 2851 | <STRING_LITERAL : ("\"" ( |
| 2852 | <EscapeQuot> |
| 2853 | | <EscapeBslash> |
| 2854 | | <EscapeSlash> |
| 2855 | | <EscapeBspace> |
| 2856 | | <EscapeFormf> |
| 2857 | | <EscapeNl> |
| 2858 | | <EscapeCr> |
| 2859 | | <EscapeTab> |
| 2860 | | ~["\"","\\"])* "\"") |
| 2861 | | ("\'"( |
| 2862 | <EscapeApos> |
| 2863 | | <EscapeBslash> |
| 2864 | | <EscapeSlash> |
| 2865 | | <EscapeBspace> |
| 2866 | | <EscapeFormf> |
| 2867 | | <EscapeNl> |
| 2868 | | <EscapeCr> |
| 2869 | | <EscapeTab> |
| 2870 | | ~["\'","\\"])* "\'")> |
| 2871 | | < #EscapeQuot: "\\\"" > |
| 2872 | | < #EscapeApos: "\\\'" > |
| 2873 | | < #EscapeBslash: "\\\\" > |
| 2874 | | < #EscapeSlash: "\\/" > |
| 2875 | | < #EscapeBspace: "\\b" > |
| 2876 | | < #EscapeFormf: "\\f" > |
| 2877 | | < #EscapeNl: "\\n" > |
| 2878 | | < #EscapeCr: "\\r" > |
| 2879 | | < #EscapeTab: "\\t" > |
| 2880 | } |
| 2881 | |
| 2882 | <DEFAULT,IN_DBL_BRACE> |
| 2883 | TOKEN : |
| 2884 | { |
| 2885 | <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 2886 | } |
| 2887 | |
| 2888 | <DEFAULT,IN_DBL_BRACE> |
| 2889 | TOKEN : |
| 2890 | { |
| 2891 | <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*> |
| 2892 | } |
| 2893 | |
| 2894 | <DEFAULT,IN_DBL_BRACE> |
| 2895 | SKIP: |
| 2896 | { |
| 2897 | " " |
| 2898 | | "\t" |
| 2899 | | "\r" |
| 2900 | | "\n" |
| 2901 | } |
| 2902 | |
| 2903 | <DEFAULT,IN_DBL_BRACE> |
| 2904 | SKIP: |
| 2905 | { |
| 2906 | <"//" (~["\n"])* "\n"> |
| 2907 | } |
| 2908 | |
| 2909 | <DEFAULT,IN_DBL_BRACE> |
| 2910 | SKIP: |
| 2911 | { |
| 2912 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 2913 | } |
| 2914 | |
| 2915 | <DEFAULT,IN_DBL_BRACE> |
| 2916 | SKIP: |
| 2917 | { |
| 2918 | <"/*"> { pushState(); } : INSIDE_COMMENT |
| 2919 | } |
| 2920 | |
| 2921 | <INSIDE_COMMENT> |
| 2922 | SPECIAL_TOKEN: |
| 2923 | { |
| 2924 | <"+"(" ")*(~["*"])*> |
| 2925 | } |
| 2926 | |
| 2927 | <INSIDE_COMMENT> |
| 2928 | SKIP: |
| 2929 | { |
| 2930 | <"/*"> { pushState(); } |
| 2931 | } |
| 2932 | |
| 2933 | <INSIDE_COMMENT> |
| 2934 | SKIP: |
| 2935 | { |
| 2936 | <"*/"> { popState("*/"); } |
| 2937 | | <~[]> |
| 2938 | } |