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