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