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