vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1 | options { |
| 2 | |
| 3 | |
| 4 | STATIC = false; |
| 5 | |
| 6 | } |
| 7 | |
| 8 | |
| 9 | PARSER_BEGIN(AQLParser) |
| 10 | |
| 11 | package edu.uci.ics.asterix.aql.parser; |
| 12 | |
| 13 | import java.io.*; |
| 14 | import java.util.List; |
| 15 | import java.util.ArrayList; |
| 16 | import java.util.Stack; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.HashMap; |
| 20 | import edu.uci.ics.asterix.aql.literal.FloatLiteral; |
| 21 | import edu.uci.ics.asterix.aql.literal.DoubleLiteral; |
| 22 | import edu.uci.ics.asterix.aql.literal.FalseLiteral; |
| 23 | import edu.uci.ics.asterix.aql.base.ILiteral; |
| 24 | import edu.uci.ics.asterix.aql.literal.IntegerLiteral; |
| 25 | import edu.uci.ics.asterix.aql.literal.NullLiteral; |
| 26 | import edu.uci.ics.asterix.aql.literal.StringLiteral; |
| 27 | import edu.uci.ics.asterix.aql.literal.TrueLiteral; |
| 28 | |
| 29 | import edu.uci.ics.asterix.aql.base.*; |
| 30 | import edu.uci.ics.asterix.aql.expression.*; |
| 31 | import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType; |
| 32 | import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType; |
| 33 | import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor; |
| 34 | import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign; |
| 35 | import edu.uci.ics.asterix.aql.base.Statement.Kind; |
| 36 | import edu.uci.ics.asterix.aql.context.Scope; |
| 37 | import edu.uci.ics.asterix.aql.context.RootScopeFactory; |
| 38 | import edu.uci.ics.asterix.common.annotations.*; |
| 39 | import edu.uci.ics.asterix.common.exceptions.AsterixException; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 40 | import edu.uci.ics.asterix.om.functions.AsterixFunction; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 41 | |
| 42 | |
| 43 | public class AQLParser extends ScopeChecker { |
| 44 | |
| 45 | /* |
| 46 | private void printHints(Token t) { |
| 47 | //System.err.println("token="+t.image+"\t special="+t.specialToken); |
| 48 | if (t.specialToken == null) return; |
| 49 | Token tmp_t = t.specialToken; |
| 50 | while (tmp_t.specialToken != null) tmp_t = tmp_t.specialToken; |
| 51 | while (tmp_t != null) { |
| 52 | System.out.println(tmp_t.image); |
| 53 | tmp_t = tmp_t.next; |
| 54 | } |
| 55 | } |
| 56 | */ |
| 57 | |
| 58 | // optimizer hints |
| 59 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 60 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
| 61 | private static final String INMEMORY_HINT = "inmem"; |
| 62 | private static final String VAL_FILE_HINT = "val-files"; |
| 63 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
| 64 | private static final String INTERVAL_HINT = "interval"; |
| 65 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 66 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 67 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 68 | private static final String LIST_HINT = "list"; |
| 69 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 70 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 71 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 72 | private static final String AUTO_HINT = "auto"; |
| 73 | |
| 74 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
| 75 | |
| 76 | // data generator hints |
| 77 | private static final String DGEN_HINT = "dgen"; |
| 78 | |
| 79 | private static String getHint(Token t) { |
| 80 | if (t.specialToken == null) { |
| 81 | return null; |
| 82 | } |
| 83 | String s = t.specialToken.image; |
| 84 | int n = s.length(); |
| 85 | if (n < 2) { |
| 86 | return null; |
| 87 | } |
| 88 | return s.substring(1).trim(); |
| 89 | } |
| 90 | |
| 91 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException { |
| 92 | File file = new File(args[0]); |
| 93 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 94 | AQLParser parser = new AQLParser(fis); |
| 95 | Statement st = parser.Statement(); |
| 96 | st.accept(new AQLPrintVisitor(), 0); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | } |
| 101 | |
| 102 | PARSER_END(AQLParser) |
| 103 | |
| 104 | |
| 105 | Statement Statement() throws ParseException: |
| 106 | { |
| 107 | Query query = null; |
| 108 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 109 | List<Statement> decls = new ArrayList<Statement>(); |
| 110 | } |
| 111 | { |
| 112 | ( |
| 113 | ( |
| 114 | ( |
| 115 | "use" |
| 116 | { |
| 117 | decls.add(DataverseDeclaration()); |
| 118 | } |
| 119 | | "declare" "function" { |
| 120 | decls.add(FunctionDeclaration()); |
| 121 | } |
| 122 | | "create" ( |
| 123 | { |
| 124 | String hint = getHint(token); |
| 125 | boolean dgen = false; |
| 126 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 127 | dgen = true; |
| 128 | } |
| 129 | } |
| 130 | "type" |
| 131 | { |
| 132 | decls.add(TypeDeclaration(dgen, hint)); |
| 133 | } |
| 134 | | "nodegroup" |
| 135 | { |
| 136 | decls.add(NodegroupDeclaration()); |
| 137 | } |
| 138 | | "external" <DATASET> |
| 139 | { |
| 140 | decls.add(DatasetDeclaration(DatasetType.EXTERNAL)); |
| 141 | } |
| 142 | | "feed" <DATASET> |
| 143 | { |
| 144 | decls.add(DatasetDeclaration(DatasetType.FEED)); |
| 145 | } |
| 146 | | <DATASET> |
| 147 | { |
| 148 | decls.add(DatasetDeclaration(DatasetType.INTERNAL)); |
| 149 | } |
| 150 | | "index" |
| 151 | { |
| 152 | decls.add(CreateIndexStatement()); |
| 153 | } |
| 154 | | "dataverse" |
| 155 | { |
| 156 | decls.add(CreateDataverseStatement()); |
| 157 | } |
| 158 | | "function" |
| 159 | { |
| 160 | decls.add(FunctionCreation()); |
| 161 | } |
| 162 | ) |
| 163 | | "load" { |
| 164 | decls.add(LoadStatement()); |
| 165 | } |
| 166 | |
| 167 | | "drop" |
| 168 | ( |
| 169 | <DATASET> |
| 170 | { |
| 171 | decls.add(DropStatement()); |
| 172 | } |
| 173 | | "index" |
| 174 | { |
| 175 | decls.add(IndexDropStatement()); |
| 176 | } |
| 177 | | "nodegroup" |
| 178 | { |
| 179 | decls.add(NodeGroupDropStatement()); |
| 180 | } |
| 181 | | "type" |
| 182 | { |
| 183 | decls.add(TypeDropStatement()); |
| 184 | } |
| 185 | | "dataverse" |
| 186 | { |
| 187 | decls.add(DataverseDropStatement()); |
| 188 | } |
| 189 | ) |
| 190 | | "write" { |
| 191 | decls.add(WriteStatement()); |
| 192 | } |
| 193 | | "set" { |
| 194 | decls.add(SetStatement()); |
| 195 | } |
| 196 | | "insert" { |
| 197 | decls.add(InsertStatement()); |
| 198 | } |
| 199 | | "delete" { |
| 200 | decls.add(DeleteStatement()); |
| 201 | } |
| 202 | | "update" { |
| 203 | decls.add(UpdateStatement()); |
| 204 | } |
| 205 | | "begin" "feed" <IDENTIFIER> { |
| 206 | Identifier datasetName = new Identifier(token.image); |
| 207 | decls.add(new BeginFeedStatement(datasetName, getVarCounter())); |
| 208 | } ";" |
| 209 | | "suspend" "feed" <IDENTIFIER> { |
| 210 | datasetName = new Identifier(token.image); |
| 211 | decls.add(new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, datasetName)); |
| 212 | } ";" |
| 213 | | "resume" "feed" <IDENTIFIER> { |
| 214 | datasetName = new Identifier(token.image); |
| 215 | decls.add(new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, datasetName)); |
| 216 | } ";" |
| 217 | | "end" "feed" <IDENTIFIER> { |
| 218 | datasetName = new Identifier(token.image); |
| 219 | decls.add(new ControlFeedStatement(ControlFeedStatement.OperationType.END, datasetName)); |
| 220 | } ";" |
| 221 | | "alter" "feed" <IDENTIFIER> { |
| 222 | datasetName = new Identifier(token.image); |
| 223 | decls.add(AlterFeedDeclaration(datasetName)); |
| 224 | } |
| 225 | |
| 226 | )* |
| 227 | (query = Query())? |
| 228 | ) |
| 229 | |
| 230 | <EOF> |
| 231 | ) |
| 232 | { |
| 233 | if (query == null) { |
| 234 | query = new Query(true); |
| 235 | } |
| 236 | query.setPrologDeclList(decls); |
| 237 | |
| 238 | return query; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | InsertStatement InsertStatement() throws ParseException: |
| 243 | { |
| 244 | Identifier datasetName; |
| 245 | Query query; |
| 246 | } |
| 247 | { |
| 248 | "into" <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 249 | <LEFTPAREN> query = Query() <RIGHTPAREN> ";" |
| 250 | {return new InsertStatement(datasetName, query, getVarCounter());} |
| 251 | } |
| 252 | |
| 253 | DeleteStatement DeleteStatement() throws ParseException: |
| 254 | { |
| 255 | VariableExpr var = null; |
| 256 | Identifier datasetName = null; |
| 257 | Expression condition = null; |
| 258 | Clause dieClause = null; |
| 259 | } |
| 260 | { |
| 261 | var = Variable() { getCurrentScope().addNewVarSymbolToScope(var.getVar()); } |
| 262 | "from" <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 263 | ("where" condition = Expression())? (dieClause = DieClause())? ";" |
| 264 | {return new DeleteStatement(var, datasetName, condition, dieClause, getVarCounter()); } |
| 265 | } |
| 266 | |
| 267 | UpdateStatement UpdateStatement() throws ParseException: |
| 268 | { |
| 269 | VariableExpr vars; |
| 270 | Expression target; |
| 271 | Expression condition; |
| 272 | UpdateClause uc; |
| 273 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
| 274 | } |
| 275 | { |
| 276 | vars = Variable() "in" target = Expression() |
| 277 | "where" condition = Expression() |
| 278 | <LEFTPAREN> (uc=UpdateClause() {ucs.add(uc); } ("," uc=UpdateClause() {ucs.add(uc); } )*) <RIGHTPAREN> ";" |
| 279 | {return new UpdateStatement(vars, target, condition, ucs);} |
| 280 | } |
| 281 | |
| 282 | |
| 283 | |
| 284 | UpdateClause UpdateClause() throws ParseException: |
| 285 | { |
| 286 | Expression target = null; |
| 287 | Expression value = null ; |
| 288 | InsertStatement is = null; |
| 289 | DeleteStatement ds = null; |
| 290 | UpdateStatement us = null; |
| 291 | Expression condition = null; |
| 292 | UpdateClause ifbranch = null; |
| 293 | UpdateClause elsebranch = null; |
| 294 | } |
| 295 | { |
| 296 | "set" target = Expression() ":=" value = Expression() |
| 297 | | "insert" is = InsertStatement() |
| 298 | | "delete" ds = DeleteStatement() |
| 299 | | "update" us = UpdateStatement() |
| 300 | | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN> "then" ifbranch = UpdateClause() [LOOKAHEAD(1) "else" elsebranch = UpdateClause()] |
| 301 | {return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);} |
| 302 | } |
| 303 | |
| 304 | |
| 305 | Statement SetStatement() throws ParseException: |
| 306 | { |
| 307 | String pn = null; |
| 308 | Statement stmt = null; |
| 309 | } |
| 310 | { |
| 311 | <IDENTIFIER> { pn = token.image; } |
| 312 | <STRING_LITERAL> |
| 313 | { String pv = removeQuotesAndEscapes(token.image); } |
| 314 | ";" |
| 315 | { |
| 316 | return new SetStatement(pn, pv); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | Statement WriteStatement() throws ParseException: |
| 321 | { |
| 322 | Identifier nodeName = null; |
| 323 | String fileName = null; |
| 324 | Identifier datasetName = null; |
| 325 | Statement stmt = null; |
| 326 | Query query; |
| 327 | String writerClass = null; |
| 328 | } |
| 329 | { |
| 330 | (( "output" "to" |
| 331 | <IDENTIFIER> { nodeName = new Identifier(token.image); } |
| 332 | ":" <STRING_LITERAL> { fileName = removeQuotesAndEscapes(token.image); } |
| 333 | ( "using" <STRING_LITERAL> { writerClass = removeQuotesAndEscapes(token.image); } )? |
| 334 | { |
| 335 | stmt = new WriteStatement(nodeName, fileName, writerClass); |
| 336 | } ) |
| 337 | | |
| 338 | ( "into" |
| 339 | <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 340 | <LEFTPAREN> query = Query() <RIGHTPAREN> |
| 341 | { |
| 342 | stmt = new WriteFromQueryResultStatement(datasetName, query, getVarCounter()); |
| 343 | } )) |
| 344 | |
| 345 | ";" |
| 346 | { |
| 347 | return stmt; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | CreateIndexStatement CreateIndexStatement() throws ParseException: |
| 352 | { |
| 353 | CreateIndexStatement cis = new CreateIndexStatement(); |
| 354 | } |
| 355 | { |
| 356 | <IDENTIFIER> { cis.setIndexName(new Identifier(token.image)); } |
| 357 | ( |
| 358 | "if not exists" |
| 359 | { |
| 360 | cis.setIfNotExists(true); |
| 361 | } |
| 362 | )? |
| 363 | "on" |
| 364 | <IDENTIFIER> { cis.setDatasetName(new Identifier(token.image)); } |
| 365 | <LEFTPAREN> |
| 366 | ( <IDENTIFIER> { cis.addFieldExpr(token.image); } ) |
| 367 | ("," <IDENTIFIER> { cis.addFieldExpr(token.image); })* |
| 368 | <RIGHTPAREN> |
| 369 | ("type" |
| 370 | ("btree" { cis.setIndexType(IndexType.BTREE); } |
| 371 | | "keyword" { cis.setIndexType(IndexType.KEYWORD); } |
| 372 | | "qgram" { cis.setIndexType(IndexType.QGRAM); } |
| 373 | | "rtree" { cis.setIndexType(IndexType.RTREE); } |
| 374 | ) |
| 375 | ";" |
| 376 | | ";" |
| 377 | ) |
| 378 | { |
| 379 | return cis; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 384 | { |
| 385 | Identifier dvName = null; |
| 386 | } |
| 387 | { |
| 388 | "dataverse" <IDENTIFIER> { dvName = new Identifier(token.image); } |
| 389 | ";" |
| 390 | { |
| 391 | return new DataverseDecl(dvName); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | DropStatement DropStatement() throws ParseException : |
| 396 | { |
| 397 | Identifier datasetName = null; |
| 398 | boolean ifExists = false; |
| 399 | } |
| 400 | { |
| 401 | < IDENTIFIER > |
| 402 | { |
| 403 | datasetName = new Identifier(token.image); |
| 404 | } |
| 405 | ( |
| 406 | "if exists" |
| 407 | { |
| 408 | ifExists = true; |
| 409 | } |
| 410 | )? ";" |
| 411 | { |
| 412 | return new DropStatement(datasetName, ifExists); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | IndexDropStatement IndexDropStatement() throws ParseException : |
| 417 | { |
| 418 | Identifier datasetName = null; |
| 419 | Identifier indexName = null; |
| 420 | boolean ifExists = false; |
| 421 | } |
| 422 | { |
| 423 | < IDENTIFIER > |
| 424 | { |
| 425 | datasetName = new Identifier(token.image); |
| 426 | } |
| 427 | "." < IDENTIFIER > |
| 428 | { |
| 429 | indexName = new Identifier(token.image); |
| 430 | } |
| 431 | ( |
| 432 | "if exists" |
| 433 | { |
| 434 | ifExists = true; |
| 435 | } |
| 436 | )? ";" |
| 437 | { |
| 438 | return new IndexDropStatement(datasetName, indexName, ifExists); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | NodeGroupDropStatement NodeGroupDropStatement() throws ParseException : |
| 443 | { |
| 444 | Identifier groupName = null; |
| 445 | boolean ifExists = false; |
| 446 | } |
| 447 | { |
| 448 | < IDENTIFIER > |
| 449 | { |
| 450 | groupName = new Identifier(token.image); |
| 451 | } |
| 452 | ( |
| 453 | "if exists" |
| 454 | { |
| 455 | ifExists = true; |
| 456 | } |
| 457 | )? ";" |
| 458 | { |
| 459 | return new NodeGroupDropStatement(groupName, ifExists); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | TypeDropStatement TypeDropStatement() throws ParseException : |
| 464 | { |
| 465 | Identifier typeName = null; |
| 466 | boolean ifExists = false; |
| 467 | } |
| 468 | { |
| 469 | < IDENTIFIER > |
| 470 | { |
| 471 | typeName = new Identifier(token.image); |
| 472 | } |
| 473 | ( |
| 474 | "if exists" |
| 475 | { |
| 476 | ifExists = true; |
| 477 | } |
| 478 | )? ";" |
| 479 | { |
| 480 | return new TypeDropStatement(typeName, ifExists); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | DataverseDropStatement DataverseDropStatement() throws ParseException : |
| 485 | { |
| 486 | Identifier dataverseName = null; |
| 487 | boolean ifExists = false; |
| 488 | } |
| 489 | { |
| 490 | < IDENTIFIER > |
| 491 | { |
| 492 | dataverseName = new Identifier(token.image); |
| 493 | } |
| 494 | ( |
| 495 | "if exists" |
| 496 | { |
| 497 | ifExists = true; |
| 498 | } |
| 499 | )? ";" |
| 500 | { |
| 501 | return new DataverseDropStatement(dataverseName, ifExists); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | CreateDataverseStatement CreateDataverseStatement() throws ParseException : |
| 506 | { |
| 507 | Identifier dvName = null; |
| 508 | boolean ifNotExists = false; |
| 509 | String format = null; |
| 510 | } |
| 511 | { |
| 512 | < IDENTIFIER > |
| 513 | { |
| 514 | dvName = new Identifier(token.image); |
| 515 | } |
| 516 | ( |
| 517 | "if not exists" |
| 518 | { |
| 519 | ifNotExists = true; |
| 520 | } |
| 521 | )? |
| 522 | ( |
| 523 | "with format" < STRING_LITERAL > |
| 524 | { |
| 525 | format = removeQuotesAndEscapes(token.image); |
| 526 | } |
| 527 | )? |
| 528 | ";" |
| 529 | { |
| 530 | return new CreateDataverseStatement(dvName, format, ifNotExists); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | LoadFromFileStatement LoadStatement() throws ParseException: |
| 535 | { |
| 536 | Identifier datasetName = null; |
| 537 | boolean alreadySorted = false; |
| 538 | String adapterClassname; |
| 539 | Map<String,String> properties; |
| 540 | } |
| 541 | { |
| 542 | <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 543 | |
| 544 | "using" |
| 545 | |
| 546 | <STRING_LITERAL> |
| 547 | { |
| 548 | adapterClassname = removeQuotesAndEscapes(token.image); |
| 549 | } |
| 550 | |
| 551 | { |
| 552 | properties = getConfiguration(); |
| 553 | } |
| 554 | |
| 555 | ("pre-sorted" |
| 556 | { alreadySorted = true; } |
| 557 | )? |
| 558 | |
| 559 | ";" |
| 560 | { |
| 561 | return new LoadFromFileStatement(datasetName, adapterClassname, properties, alreadySorted); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | |
| 566 | |
| 567 | DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException : |
| 568 | { |
| 569 | DatasetDecl dd = null; |
| 570 | Identifier datasetName = null; |
| 571 | Identifier itemTypeName = null; |
| 572 | boolean ifNotExists = false; |
| 573 | IDatasetDetailsDecl idd = null; |
| 574 | } |
| 575 | { |
| 576 | < IDENTIFIER > |
| 577 | { |
| 578 | datasetName = new Identifier(token.image); |
| 579 | } |
| 580 | ( |
| 581 | "if not exists" |
| 582 | { |
| 583 | ifNotExists = true; |
| 584 | } |
| 585 | )? |
| 586 | ( |
| 587 | < LEFTPAREN > < IDENTIFIER > |
| 588 | { |
| 589 | itemTypeName = new Identifier(token.image); |
| 590 | } |
| 591 | < RIGHTPAREN > |
| 592 | )? |
| 593 | { |
| 594 | if(datasetType == DatasetType.INTERNAL) { |
| 595 | idd = InternalDatasetDeclaration(); |
| 596 | dd = new DatasetDecl(datasetName, itemTypeName, idd, ifNotExists); |
| 597 | } |
| 598 | else if(datasetType == DatasetType.EXTERNAL) { |
| 599 | idd = ExternalDatasetDeclaration(); |
| 600 | dd = new DatasetDecl(datasetName, itemTypeName, idd,ifNotExists); |
| 601 | } |
| 602 | else if(datasetType == DatasetType.FEED) { |
| 603 | idd = FeedDatasetDeclaration(); |
| 604 | dd = new DatasetDecl(datasetName, itemTypeName, idd,ifNotExists); |
| 605 | } |
| 606 | dd.setDatasetType(datasetType); |
| 607 | } |
| 608 | { |
| 609 | return dd; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | InternalDetailsDecl InternalDatasetDeclaration() throws ParseException : |
| 614 | { |
| 615 | InternalDetailsDecl idd = null; |
| 616 | } |
| 617 | { |
| 618 | { |
| 619 | idd = new InternalDetailsDecl(); |
| 620 | } |
| 621 | "partitioned" "by" "key" |
| 622 | < IDENTIFIER > |
| 623 | { |
| 624 | idd.addPartitioningExpr(token.image); |
| 625 | } |
| 626 | ( |
| 627 | "," < IDENTIFIER > |
| 628 | { |
| 629 | idd.addPartitioningExpr(token.image); |
| 630 | } |
| 631 | )* |
| 632 | ( |
| 633 | "on" < IDENTIFIER > |
| 634 | { |
| 635 | idd.setNodegroupName(new Identifier(token.image)); |
| 636 | } |
| 637 | )? |
| 638 | ";" |
| 639 | { |
| 640 | return idd; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException : |
| 645 | { |
| 646 | ExternalDetailsDecl edd = null; |
| 647 | String adapterClassname = null; |
| 648 | Map < String, String > properties; |
| 649 | } |
| 650 | { |
| 651 | { |
| 652 | edd = new ExternalDetailsDecl(); |
| 653 | } |
| 654 | |
| 655 | "using" |
| 656 | |
| 657 | <STRING_LITERAL> |
| 658 | { |
| 659 | adapterClassname = removeQuotesAndEscapes(token.image); |
| 660 | } |
| 661 | |
| 662 | { |
| 663 | properties = getConfiguration(); |
| 664 | } |
| 665 | |
| 666 | { |
| 667 | edd = new ExternalDetailsDecl(); |
| 668 | edd.setAdapter(adapterClassname); |
| 669 | edd.setProperties(properties); |
| 670 | } |
| 671 | ";" |
| 672 | |
| 673 | { |
| 674 | return edd; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | FeedDetailsDecl FeedDatasetDeclaration() throws ParseException : |
| 679 | { |
| 680 | FeedDetailsDecl fdd = null; |
| 681 | String adapterClassname = null; |
| 682 | Map < String, String > properties; |
| 683 | } |
| 684 | { |
| 685 | { |
| 686 | fdd = new FeedDetailsDecl(); |
| 687 | } |
| 688 | |
| 689 | "using" |
| 690 | |
| 691 | <STRING_LITERAL> |
| 692 | { |
| 693 | adapterClassname = removeQuotesAndEscapes(token.image); |
| 694 | } |
| 695 | |
| 696 | { |
| 697 | properties = getConfiguration(); |
| 698 | } |
| 699 | |
| 700 | ("apply" "function" |
| 701 | < IDENTIFIER > |
| 702 | { |
| 703 | fdd.setFunctionIdentifier(token.image); |
| 704 | } |
| 705 | )? |
| 706 | |
| 707 | "partitioned" "by" "key" |
| 708 | < IDENTIFIER > |
| 709 | { |
| 710 | fdd.addPartitioningExpr(token.image); |
| 711 | } |
| 712 | ( |
| 713 | "," < IDENTIFIER > |
| 714 | { |
| 715 | fdd.addPartitioningExpr(token.image); |
| 716 | } |
| 717 | )* |
| 718 | ( |
| 719 | "on" < IDENTIFIER > |
| 720 | { |
| 721 | fdd.setNodegroupName(new Identifier(token.image)); |
| 722 | } |
| 723 | )? |
| 724 | ";" |
| 725 | { |
| 726 | fdd.setAdapterClassname(adapterClassname); |
| 727 | fdd.setProperties(properties); |
| 728 | return fdd; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | ControlFeedStatement AlterFeedDeclaration(Identifier datasetName) throws ParseException : |
| 733 | { |
| 734 | String name = null; |
| 735 | String value = null; |
| 736 | Map < String, String > configuration = new HashMap < String, String > (); |
| 737 | } |
| 738 | { |
| 739 | "set" |
| 740 | { |
| 741 | configuration = getConfiguration(); |
| 742 | } |
| 743 | ";" |
| 744 | { |
| 745 | return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, datasetName, configuration); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | Map<String,String> getConfiguration() throws ParseException : |
| 750 | { |
| 751 | Map<String,String> configuration = new HashMap<String,String>(); |
| 752 | String key; |
| 753 | String value; |
| 754 | } |
| 755 | { |
| 756 | |
| 757 | <LEFTPAREN> |
| 758 | ( |
| 759 | ( |
| 760 | <LEFTPAREN> |
| 761 | ( |
| 762 | <STRING_LITERAL> |
| 763 | { |
| 764 | key = removeQuotesAndEscapes(token.image); |
| 765 | } |
| 766 | "=" <STRING_LITERAL> |
| 767 | { |
| 768 | value = removeQuotesAndEscapes(token.image); |
| 769 | } |
| 770 | ) |
| 771 | <RIGHTPAREN> |
| 772 | { |
| 773 | configuration.put(key, value); |
| 774 | } |
| 775 | ) |
| 776 | ( |
| 777 | "," <LEFTPAREN> |
| 778 | ( |
| 779 | <STRING_LITERAL> |
| 780 | { |
| 781 | key = removeQuotesAndEscapes(token.image); |
| 782 | } |
| 783 | "=" <STRING_LITERAL> |
| 784 | { |
| 785 | value = removeQuotesAndEscapes(token.image); |
| 786 | } |
| 787 | ) |
| 788 | <RIGHTPAREN> |
| 789 | { |
| 790 | configuration.put(key, value); |
| 791 | } |
| 792 | )* |
| 793 | )? |
| 794 | <RIGHTPAREN> |
| 795 | { |
| 796 | return configuration; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | |
| 801 | NodegroupDecl NodegroupDeclaration() throws ParseException : |
| 802 | { |
| 803 | Identifier name = null; |
| 804 | List < Identifier > ncNames = new ArrayList < Identifier > (); |
| 805 | boolean ifNotExists = false; |
| 806 | } |
| 807 | { |
| 808 | < IDENTIFIER > |
| 809 | { |
| 810 | name = new Identifier(token.image); |
| 811 | } |
| 812 | ( |
| 813 | "if not exists" |
| 814 | { |
| 815 | ifNotExists = true; |
| 816 | } |
| 817 | )? |
| 818 | "on" < IDENTIFIER > |
| 819 | { |
| 820 | ncNames.add(new Identifier(token.image)); |
| 821 | } |
| 822 | ( |
| 823 | "," < IDENTIFIER > |
| 824 | { |
| 825 | ncNames.add(new Identifier(token.image)); |
| 826 | } |
| 827 | )* |
| 828 | ";" |
| 829 | { |
| 830 | return new NodegroupDecl(name, ncNames, ifNotExists); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | |
| 835 | TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException: |
| 836 | { |
| 837 | Identifier ident; |
| 838 | TypeExpression typeExpr; |
| 839 | boolean ifNotExists = false; |
| 840 | } |
| 841 | { |
| 842 | <IDENTIFIER> |
| 843 | { |
| 844 | ident = new Identifier(token.image.toString()); |
| 845 | } |
| 846 | ( |
| 847 | "if not exists" |
| 848 | { |
| 849 | ifNotExists = true; |
| 850 | } |
| 851 | )? |
| 852 | "as" |
| 853 | ( typeExpr = TypeExpr() ) |
| 854 | { |
| 855 | long numValues = -1; |
| 856 | String filename = null; |
| 857 | if (dgen) { |
| 858 | String splits[] = hint.split(" +"); |
| 859 | if (splits.length != 3) { |
| 860 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 861 | } |
| 862 | filename = splits[1]; |
| 863 | numValues = Long.parseLong(splits[2]); |
| 864 | } |
| 865 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
| 866 | return new TypeDecl(ident, typeExpr, tddg, ifNotExists); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | TypeExpression TypeExpr() throws ParseException: |
| 871 | { |
| 872 | TypeExpression typeExpr = null; |
| 873 | } |
| 874 | { |
| 875 | ( |
| 876 | typeExpr = RecordTypeDef() |
| 877 | | typeExpr = TypeReference() |
| 878 | | typeExpr = OrderedListTypeDef() |
| 879 | | typeExpr = UnorderedListTypeDef() |
| 880 | ) |
| 881 | { |
| 882 | return typeExpr; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 887 | { |
| 888 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 889 | RecordTypeDefinition.RecordKind recordKind = null; |
| 890 | } |
| 891 | { |
| 892 | ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 893 | | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 894 | "{" |
| 895 | { |
| 896 | String hint = getHint(token); |
| 897 | if (hint != null) { |
| 898 | String splits[] = hint.split(" +"); |
| 899 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 900 | if (splits.length != 5) { |
| 901 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 902 | } |
| 903 | if (!splits[1].equals("int")) { |
| 904 | throw new ParseException("The only supported type for gen-fields is int."); |
| 905 | } |
| 906 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 907 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 908 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | } |
| 913 | ( |
| 914 | RecordField(recType) |
| 915 | ( "," RecordField(recType) )* |
| 916 | )? |
| 917 | "}" |
| 918 | { |
| 919 | if (recordKind == null) { |
| 920 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 921 | } |
| 922 | recType.setRecordKind(recordKind); |
| 923 | return recType; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 928 | { |
| 929 | String fieldName; |
| 930 | TypeExpression type = null; |
| 931 | boolean nullable = false; |
| 932 | } |
| 933 | { |
| 934 | <IDENTIFIER> |
| 935 | { |
| 936 | Token t = getToken(0); |
| 937 | fieldName = t.toString(); |
| 938 | String hint = getHint(t); |
| 939 | IRecordFieldDataGen rfdg = null; |
| 940 | if (hint != null) { |
| 941 | String splits[] = hint.split(" +"); |
| 942 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 943 | File[] valFiles = new File[splits.length - 1]; |
| 944 | for (int k=1; k<splits.length; k++) { |
| 945 | valFiles[k-1] = new File(splits[k]); |
| 946 | } |
| 947 | rfdg = new FieldValFileDataGen(valFiles); |
| 948 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 949 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 950 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 951 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 952 | } else if (splits[0].equals(LIST_HINT)) { |
| 953 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 954 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 955 | FieldIntervalDataGen.ValueType vt; |
| 956 | if (splits[1].equals("int")) { |
| 957 | vt = FieldIntervalDataGen.ValueType.INT; |
| 958 | } else if (splits[1].equals("long")) { |
| 959 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 960 | } else if (splits[1].equals("float")) { |
| 961 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 962 | } else if (splits[1].equals("double")) { |
| 963 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 964 | } else { |
| 965 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 966 | } |
| 967 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 968 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 969 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 970 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 971 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 972 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 973 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 974 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 975 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 976 | } else if (splits[0].equals(AUTO_HINT)) { |
| 977 | rfdg = new AutoDataGen(splits[1]); |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | ":" |
| 982 | ( type = TypeExpr() ) |
| 983 | ("?" { nullable = true; } )? |
| 984 | { |
| 985 | recType.addField(fieldName, type, nullable, rfdg); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | TypeReferenceExpression TypeReference() throws ParseException: |
| 990 | {} |
| 991 | { |
| 992 | <IDENTIFIER> |
| 993 | { |
| 994 | Token t = getToken(0); |
| 995 | Identifier id = new Identifier(t.toString()); |
| 996 | return new TypeReferenceExpression(id); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1001 | { |
| 1002 | TypeExpression type = null; |
| 1003 | } |
| 1004 | { |
| 1005 | "[" |
| 1006 | ( type = TypeExpr() ) |
| 1007 | "]" |
| 1008 | { |
| 1009 | return new OrderedListTypeDefinition(type); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1015 | { |
| 1016 | TypeExpression type = null; |
| 1017 | } |
| 1018 | { |
| 1019 | "{{" |
| 1020 | ( type = TypeExpr() ) |
| 1021 | "}}" |
| 1022 | { |
| 1023 | return new UnorderedListTypeDefinition(type); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1029 | { |
| 1030 | FunctionDecl func = new FunctionDecl(); |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1031 | AsterixFunction ident; |
| 1032 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1033 | int arity = 0; |
| 1034 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1035 | Expression funcBody; |
| 1036 | VarIdentifier var = null; |
| 1037 | createNewScope(); |
| 1038 | } |
| 1039 | { |
| 1040 | |
| 1041 | <IDENTIFIER> |
| 1042 | { |
| 1043 | Token t = getToken(0); |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1044 | functionName = t.toString(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1045 | } |
| 1046 | <LEFTPAREN> (<VARIABLE> |
| 1047 | { |
| 1048 | var = new VarIdentifier(); |
| 1049 | var.setValue(getToken(0).toString()); |
| 1050 | paramList.add(var); |
| 1051 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1052 | arity++; |
| 1053 | } |
| 1054 | ("," <VARIABLE> |
| 1055 | { |
| 1056 | var = new VarIdentifier(); |
| 1057 | var.setValue(getToken(0).toString()); |
| 1058 | paramList.add(var); |
| 1059 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1060 | arity++; |
| 1061 | })*)? <RIGHTPAREN> "{" funcBody = Expression() "}" |
| 1062 | |
| 1063 | { |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1064 | ident = new AsterixFunction(functionName,arity); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1065 | getCurrentScope().addFunctionDescriptor(ident, false); |
| 1066 | func.setIdent(ident); |
| 1067 | func.setFuncBody(funcBody); |
| 1068 | func.setParamList(paramList); |
| 1069 | return func; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | CreateFunctionStatement FunctionCreation() throws ParseException: |
| 1074 | { |
| 1075 | CreateFunctionStatement cfs = null; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1076 | AsterixFunction ident; |
| 1077 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1078 | int arity = 0; |
| 1079 | boolean ifNotExists = false; |
| 1080 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1081 | String funcBody; |
| 1082 | VarIdentifier var = null; |
| 1083 | createNewScope(); |
| 1084 | } |
| 1085 | { |
| 1086 | |
| 1087 | <IDENTIFIER> |
| 1088 | { |
| 1089 | Token t = getToken(0); |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1090 | functionName= t.toString(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | ( |
| 1094 | "if not exists" |
| 1095 | { |
| 1096 | ifNotExists = true; |
| 1097 | } |
| 1098 | )? |
| 1099 | |
| 1100 | <LEFTPAREN> (<VARIABLE> |
| 1101 | { |
| 1102 | var = new VarIdentifier(); |
| 1103 | var.setValue(getToken(0).toString()); |
| 1104 | paramList.add(var); |
| 1105 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1106 | arity++; |
| 1107 | } |
| 1108 | ("," <VARIABLE> |
| 1109 | { |
| 1110 | var = new VarIdentifier(); |
| 1111 | var.setValue(getToken(0).toString()); |
| 1112 | paramList.add(var); |
| 1113 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1114 | arity++; |
| 1115 | })*)? <RIGHTPAREN> "{" <STRING_LITERAL> |
| 1116 | { |
| 1117 | funcBody = removeQuotesAndEscapes(token.image); |
| 1118 | } |
| 1119 | "}" |
| 1120 | { |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1121 | ident = new AsterixFunction(functionName, arity); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1122 | getCurrentScope().addFunctionDescriptor(ident, false); |
| 1123 | cfs = new CreateFunctionStatement(ident, paramList, funcBody, ifNotExists); |
| 1124 | return cfs; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | Query Query()throws ParseException: |
| 1131 | { |
| 1132 | Query query = new Query(); |
| 1133 | Expression expr; |
| 1134 | } |
| 1135 | { |
| 1136 | expr = Expression() |
| 1137 | |
| 1138 | { |
| 1139 | query.setBody(expr); |
| 1140 | return query; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | Expression Expression(): |
| 1147 | { |
| 1148 | Expression expr = null; |
| 1149 | Expression exprP = null; |
| 1150 | } |
| 1151 | { |
| 1152 | ( |
| 1153 | |
| 1154 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1155 | expr = OperatorExpr() |
| 1156 | | expr = IfThenElse() |
| 1157 | | expr = FLWOGR() |
| 1158 | | expr = QuantifiedExpression() |
| 1159 | |
| 1160 | |
| 1161 | ) |
| 1162 | { |
| 1163 | return (exprP==null) ? expr : exprP; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | Expression OperatorExpr()throws ParseException: |
| 1170 | { |
| 1171 | OperatorExpr op = null; |
| 1172 | Expression operand = null; |
| 1173 | } |
| 1174 | { |
| 1175 | operand = AndExpr() |
| 1176 | ( |
| 1177 | |
| 1178 | "or" |
| 1179 | { |
| 1180 | if (op == null) { |
| 1181 | op = new OperatorExpr(); |
| 1182 | op.addOperand(operand); |
| 1183 | op.setCurrentop(true); |
| 1184 | } |
| 1185 | Token t = getToken(0); |
| 1186 | op.addOperator(t.toString()); |
| 1187 | } |
| 1188 | |
| 1189 | operand = AndExpr() |
| 1190 | { |
| 1191 | op.addOperand(operand); |
| 1192 | } |
| 1193 | |
| 1194 | )* |
| 1195 | |
| 1196 | { |
| 1197 | return op==null? operand: op; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | Expression AndExpr()throws ParseException: |
| 1202 | { |
| 1203 | OperatorExpr op = null; |
| 1204 | Expression operand = null; |
| 1205 | } |
| 1206 | { |
| 1207 | operand = RelExpr() |
| 1208 | ( |
| 1209 | |
| 1210 | "and" |
| 1211 | { |
| 1212 | if (op == null) { |
| 1213 | op = new OperatorExpr(); |
| 1214 | op.addOperand(operand); |
| 1215 | op.setCurrentop(true); |
| 1216 | } |
| 1217 | Token t = getToken(0); |
| 1218 | op.addOperator(t.toString()); |
| 1219 | } |
| 1220 | |
| 1221 | operand = RelExpr() |
| 1222 | { |
| 1223 | op.addOperand(operand); |
| 1224 | } |
| 1225 | |
| 1226 | )* |
| 1227 | |
| 1228 | { |
| 1229 | return op==null? operand: op; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | Expression RelExpr()throws ParseException: |
| 1236 | { |
| 1237 | OperatorExpr op = null; |
| 1238 | Expression operand = null; |
| 1239 | boolean broadcast = false; |
| 1240 | } |
| 1241 | { |
| 1242 | operand = AddExpr() |
| 1243 | { |
| 1244 | if (operand instanceof VariableExpr) { |
| 1245 | String hint = getHint(token); |
| 1246 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1247 | broadcast = true; |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | ( |
| 1253 | LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=") |
| 1254 | { |
| 1255 | if (op == null) { |
| 1256 | op = new OperatorExpr(); |
| 1257 | op.addOperand(operand, broadcast); |
| 1258 | op.setCurrentop(true); |
| 1259 | broadcast = false; |
| 1260 | } |
| 1261 | Token t = getToken(0); |
| 1262 | op.addOperator(t.toString()); |
| 1263 | } |
| 1264 | |
| 1265 | operand = AddExpr() |
| 1266 | { |
| 1267 | broadcast = false; |
| 1268 | if (operand instanceof VariableExpr) { |
| 1269 | String hint = getHint(token); |
| 1270 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1271 | broadcast = true; |
| 1272 | } |
| 1273 | } |
| 1274 | op.addOperand(operand, broadcast); |
| 1275 | } |
| 1276 | )? |
| 1277 | |
| 1278 | { |
| 1279 | return op==null? operand: op; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | Expression AddExpr()throws ParseException: |
| 1284 | { |
| 1285 | OperatorExpr op = null; |
| 1286 | Expression operand = null; |
| 1287 | } |
| 1288 | { |
| 1289 | operand = MultExpr() |
| 1290 | |
| 1291 | ( ("+" | "-") |
| 1292 | { |
| 1293 | if (op == null) { |
| 1294 | op = new OperatorExpr(); |
| 1295 | op.addOperand(operand); |
| 1296 | op.setCurrentop(true); |
| 1297 | } |
| 1298 | Token t = getToken(0); |
| 1299 | ((OperatorExpr)op).addOperator(t.toString()); |
| 1300 | } |
| 1301 | |
| 1302 | operand = MultExpr() |
| 1303 | { |
| 1304 | op.addOperand(operand); |
| 1305 | } |
| 1306 | )* |
| 1307 | |
| 1308 | { |
| 1309 | return op==null? operand: op; |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | Expression MultExpr()throws ParseException: |
| 1314 | { |
| 1315 | OperatorExpr op = null; |
| 1316 | Expression operand = null; |
| 1317 | } |
| 1318 | { |
| 1319 | operand = UnionExpr() |
| 1320 | |
| 1321 | (( "*" | "/" | "%" | <CARET> | "idiv") |
| 1322 | { |
| 1323 | if (op == null) { |
| 1324 | op = new OperatorExpr(); |
| 1325 | op.addOperand(operand); |
| 1326 | op.setCurrentop(true); |
| 1327 | } |
| 1328 | Token t = getToken(0); |
| 1329 | op.addOperator(t.toString()); |
| 1330 | } |
| 1331 | operand = UnionExpr() |
| 1332 | { |
| 1333 | op.addOperand(operand); |
| 1334 | } |
| 1335 | )* |
| 1336 | |
| 1337 | { |
| 1338 | return op==null?operand:op; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | Expression UnionExpr() throws ParseException: |
| 1343 | { |
| 1344 | UnionExpr union = null; |
| 1345 | Expression operand1 = null; |
| 1346 | Expression operand2 = null; |
| 1347 | } |
| 1348 | { |
| 1349 | operand1 = UnaryExpr() |
| 1350 | ("union" |
| 1351 | (operand2 = UnaryExpr()) { |
| 1352 | if (union == null) { |
| 1353 | union = new UnionExpr(); |
| 1354 | union.addExpr(operand1); |
| 1355 | } |
| 1356 | union.addExpr(operand2); |
| 1357 | } )* |
| 1358 | { |
| 1359 | return (union == null)? operand1: union; |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | Expression UnaryExpr() throws ParseException: |
| 1364 | { |
| 1365 | Expression uexpr = null; |
| 1366 | Expression expr = null; |
| 1367 | } |
| 1368 | { |
| 1369 | (( "+"|"-") |
| 1370 | { |
| 1371 | uexpr = new UnaryExpr(); |
| 1372 | Token t = getToken(0); |
| 1373 | if("+".equals(t.toString())) |
| 1374 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
| 1375 | else if("-".equals(t.toString())) |
| 1376 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 1377 | else |
| 1378 | throw new ParseException(); |
| 1379 | } |
| 1380 | )? |
| 1381 | |
| 1382 | expr = ValueExpr() |
| 1383 | { |
| 1384 | if(uexpr!=null){ |
| 1385 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1386 | return uexpr; |
| 1387 | } |
| 1388 | else{ |
| 1389 | return expr; |
| 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | Expression ValueExpr() throws ParseException: |
| 1395 | { |
| 1396 | Expression expr; |
| 1397 | } |
| 1398 | { |
| 1399 | expr = FieldOrIndexAccessor() |
| 1400 | { |
| 1401 | return expr; |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | Expression FieldOrIndexAccessor()throws ParseException: |
| 1407 | { |
| 1408 | Expression expr = null; |
| 1409 | Identifier ident = null; |
| 1410 | AbstractAccessor fa = null; |
| 1411 | int index; |
| 1412 | |
| 1413 | } |
| 1414 | { |
| 1415 | ( expr = PrimaryExpr() |
| 1416 | |
| 1417 | ) |
| 1418 | |
| 1419 | |
| 1420 | ( |
| 1421 | ( |
| 1422 | ident = Field() |
| 1423 | { |
| 1424 | if(fa == null) |
| 1425 | fa = new FieldAccessor(expr, ident); |
| 1426 | else |
| 1427 | fa = new FieldAccessor(fa, ident); |
| 1428 | } |
| 1429 | ) |
| 1430 | | ( |
| 1431 | index = Index() |
| 1432 | { |
| 1433 | if(fa == null) |
| 1434 | fa = new IndexAccessor(expr, index); |
| 1435 | else |
| 1436 | fa = new IndexAccessor(fa, index); |
| 1437 | } |
| 1438 | ) |
| 1439 | )* |
| 1440 | |
| 1441 | |
| 1442 | { |
| 1443 | return fa==null?expr:fa; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | Identifier Field() throws ParseException: |
| 1448 | { |
| 1449 | Identifier ident = null; |
| 1450 | |
| 1451 | } |
| 1452 | { |
| 1453 | "." < IDENTIFIER > |
| 1454 | { |
| 1455 | |
| 1456 | ident = new Identifier(); |
| 1457 | ident.setValue(getToken(0).toString()); |
| 1458 | |
| 1459 | return ident; |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | int Index() throws ParseException: |
| 1464 | { |
| 1465 | Expression expr = null; |
| 1466 | int idx = -2; |
| 1467 | } |
| 1468 | { |
| 1469 | "[" ( expr = Expression() |
| 1470 | { |
| 1471 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1472 | { |
| 1473 | ILiteral lit = ((LiteralExpr)expr).getValue(); |
| 1474 | if(lit.getLiteralType() == ILiteral.Type.INTEGER) { |
| 1475 | idx = Integer.valueOf(lit.getStringValue()); |
| 1476 | } |
| 1477 | else { |
| 1478 | throw new ParseException("Index should be an INTEGER"); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | } |
| 1483 | |
| 1484 | | "?" |
| 1485 | { |
| 1486 | idx = IndexAccessor.ANY; |
| 1487 | // ANY |
| 1488 | } |
| 1489 | |
| 1490 | ) |
| 1491 | |
| 1492 | "]" |
| 1493 | { |
| 1494 | return idx; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | Expression PrimaryExpr()throws ParseException: |
| 1500 | { |
| 1501 | Expression expr = null; |
| 1502 | } |
| 1503 | { |
| 1504 | //ILiteral | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression |
| 1505 | ( |
| 1506 | expr =Literal() |
| 1507 | | expr = FunctionCallExpr() |
| 1508 | | expr =VariableRef() |
| 1509 | |
| 1510 | { |
| 1511 | if(((VariableExpr)expr).getIsNewVar() == true) |
| 1512 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
| 1513 | } |
| 1514 | | expr = ListConstructor() |
| 1515 | | expr = RecordConstructor() |
| 1516 | | expr = ParenthesizedExpression() |
| 1517 | ) |
| 1518 | { |
| 1519 | return expr; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | Expression Literal() throws ParseException: |
| 1524 | { |
| 1525 | |
| 1526 | LiteralExpr lit = new LiteralExpr(); |
| 1527 | Token t; |
| 1528 | } |
| 1529 | { |
| 1530 | ( |
| 1531 | <STRING_LITERAL> |
| 1532 | { |
| 1533 | t= getToken(0); |
| 1534 | lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image))); |
| 1535 | } |
| 1536 | |
| 1537 | | <INTEGER_LITERAL> |
| 1538 | { |
| 1539 | t= getToken(0); |
| 1540 | lit.setValue(new IntegerLiteral(new Integer(t.image))); |
| 1541 | } |
| 1542 | | < FLOAT_LITERAL > |
| 1543 | { |
| 1544 | t= getToken(0); |
| 1545 | lit.setValue(new FloatLiteral(new Float(t.image))); |
| 1546 | } |
| 1547 | | < DOUBLE_LITERAL > |
| 1548 | { |
| 1549 | t= getToken(0); |
| 1550 | lit.setValue(new DoubleLiteral(new Double(t.image))); |
| 1551 | } |
| 1552 | | <NULL> |
| 1553 | { |
| 1554 | t= getToken(0); |
| 1555 | lit.setValue(NullLiteral.INSTANCE); |
| 1556 | } |
| 1557 | | <TRUE> |
| 1558 | { |
| 1559 | t= getToken(0); |
| 1560 | lit.setValue(TrueLiteral.INSTANCE); |
| 1561 | } |
| 1562 | | <FALSE> |
| 1563 | { |
| 1564 | t= getToken(0); |
| 1565 | lit.setValue(FalseLiteral.INSTANCE); |
| 1566 | } |
| 1567 | ) |
| 1568 | { |
| 1569 | return lit; |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | |
| 1574 | VariableExpr VariableRef() throws ParseException: |
| 1575 | { |
| 1576 | VariableExpr varExp = new VariableExpr(); |
| 1577 | VarIdentifier var = new VarIdentifier(); |
| 1578 | Token t; |
| 1579 | } |
| 1580 | { |
| 1581 | <VARIABLE> |
| 1582 | { |
| 1583 | t = getToken(0);//get current token |
| 1584 | String varName = t.toString(); |
| 1585 | Identifier ident = lookupSymbol(varName); |
| 1586 | if (isInForbiddenScopes(varName)) { |
| 1587 | 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."); |
| 1588 | } |
| 1589 | if(ident != null) { // exist such ident |
| 1590 | varExp.setIsNewVar(false); |
| 1591 | varExp.setVar((VarIdentifier)ident); |
| 1592 | } else { |
| 1593 | varExp.setVar(var); |
| 1594 | } |
| 1595 | var.setValue(t.toString()); |
| 1596 | return varExp; |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | |
| 1601 | VariableExpr Variable() throws ParseException: |
| 1602 | { |
| 1603 | VariableExpr varExp = new VariableExpr(); |
| 1604 | VarIdentifier var = new VarIdentifier(); |
| 1605 | Token t; |
| 1606 | } |
| 1607 | { |
| 1608 | <VARIABLE> |
| 1609 | { |
| 1610 | t = getToken(0);//get current token |
| 1611 | Identifier ident = lookupSymbol(t.toString()); |
| 1612 | if(ident != null) { // exist such ident |
| 1613 | varExp.setIsNewVar(false); |
| 1614 | } |
| 1615 | varExp.setVar(var); |
| 1616 | var.setValue(t.toString()); |
| 1617 | return varExp; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | Expression ListConstructor() throws ParseException: |
| 1622 | { |
| 1623 | Expression expr = null; |
| 1624 | } |
| 1625 | { |
| 1626 | ( |
| 1627 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 1628 | ) |
| 1629 | |
| 1630 | { |
| 1631 | return expr; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | |
| 1636 | ListConstructor OrderedListConstructor() throws ParseException: |
| 1637 | { |
| 1638 | ListConstructor expr = new ListConstructor(); |
| 1639 | Expression tmp = null; |
| 1640 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1641 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 1642 | } |
| 1643 | { |
| 1644 | |
| 1645 | "[" |
| 1646 | ( tmp = Expression() |
| 1647 | { |
| 1648 | exprList.add(tmp); |
| 1649 | } |
| 1650 | |
| 1651 | ("," tmp = Expression() { exprList.add(tmp); })* |
| 1652 | )? |
| 1653 | |
| 1654 | "]" |
| 1655 | |
| 1656 | { |
| 1657 | expr.setExprList(exprList); |
| 1658 | return expr; |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 1663 | { |
| 1664 | ListConstructor expr = new ListConstructor(); |
| 1665 | Expression tmp = null; |
| 1666 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1667 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 1668 | } |
| 1669 | { |
| 1670 | |
| 1671 | "{{" ( tmp = Expression() |
| 1672 | { |
| 1673 | exprList.add(tmp); |
| 1674 | } |
| 1675 | ("," tmp = Expression() { exprList.add(tmp); })*)? "}}" |
| 1676 | { |
| 1677 | expr.setExprList(exprList); |
| 1678 | return expr; |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | RecordConstructor RecordConstructor() throws ParseException: |
| 1683 | { |
| 1684 | RecordConstructor expr = new RecordConstructor(); |
| 1685 | FieldBinding tmp = null; |
| 1686 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 1687 | } |
| 1688 | { |
| 1689 | "{" (tmp = FieldBinding() |
| 1690 | { |
| 1691 | fbList.add(tmp); |
| 1692 | } |
| 1693 | ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}" |
| 1694 | { |
| 1695 | expr.setFbList(fbList); |
| 1696 | return expr; |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | FieldBinding FieldBinding() throws ParseException: |
| 1701 | { |
| 1702 | FieldBinding fb = new FieldBinding(); |
| 1703 | Expression left, right; |
| 1704 | } |
| 1705 | { |
| 1706 | left = Expression() ":" right = Expression() |
| 1707 | { |
| 1708 | fb.setLeftExpr(left); |
| 1709 | fb.setRightExpr(right); |
| 1710 | return fb; |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | Expression FunctionCallExpr() throws ParseException: |
| 1715 | { |
| 1716 | CallExpr pf = new CallExpr(); |
| 1717 | List<Expression > argList = new ArrayList<Expression >(); |
| 1718 | Expression tmp; |
| 1719 | int arity = 0; |
| 1720 | Token funcName; |
| 1721 | } |
| 1722 | { |
| 1723 | ( <IDENTIFIER> | <DATASET> ) |
| 1724 | { |
| 1725 | funcName = getToken(0); |
| 1726 | } |
| 1727 | <LEFTPAREN> (tmp = Expression() |
| 1728 | { |
| 1729 | argList.add(tmp); |
| 1730 | arity ++; |
| 1731 | } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN> |
| 1732 | |
| 1733 | { |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1734 | AsterixFunction fd = lookupFunctionSignature(funcName.toString(), arity); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1735 | if(fd == null) |
| 1736 | { |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1737 | fd = new AsterixFunction(funcName.toString(), arity); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1738 | // notFoundFunctionList.add(fd); |
| 1739 | } |
| 1740 | // throw new ParseException("can't find function "+ funcName.toString() + "@" + arity); |
| 1741 | pf.setIdent(fd); |
| 1742 | pf.setExprList(argList); |
| 1743 | return pf; |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | |
| 1748 | Expression ParenthesizedExpression() throws ParseException: |
| 1749 | { |
| 1750 | Expression expr; |
| 1751 | } |
| 1752 | { |
| 1753 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 1754 | { |
| 1755 | return expr; |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | Expression IfThenElse() throws ParseException: |
| 1760 | { |
| 1761 | Expression condExpr; |
| 1762 | Expression thenExpr; |
| 1763 | Expression elseExpr; |
| 1764 | IfExpr ifExpr = new IfExpr(); |
| 1765 | } |
| 1766 | { |
| 1767 | "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression() |
| 1768 | |
| 1769 | { |
| 1770 | ifExpr.setCondExpr(condExpr); |
| 1771 | ifExpr.setThenExpr(thenExpr); |
| 1772 | ifExpr.setElseExpr(elseExpr); |
| 1773 | return ifExpr; |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | Expression FLWOGR() throws ParseException: |
| 1778 | { |
| 1779 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 1780 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 1781 | Expression returnExpr; |
| 1782 | Clause tmp; |
| 1783 | createNewScope(); |
| 1784 | } |
| 1785 | { |
| 1786 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
| 1787 | (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression() |
| 1788 | |
| 1789 | { |
| 1790 | flworg.setClauseList(clauseList); |
| 1791 | flworg.setReturnExpr(returnExpr); |
| 1792 | removeCurrentScope(); |
| 1793 | return flworg; |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | Clause Clause()throws ParseException : |
| 1798 | { |
| 1799 | Clause clause; |
| 1800 | } |
| 1801 | { |
| 1802 | ( |
| 1803 | clause = ForClause() |
| 1804 | | clause = LetClause() |
| 1805 | | clause = WhereClause() |
| 1806 | | clause = OrderbyClause() |
| 1807 | | clause = GroupClause() |
| 1808 | | clause = LimitClause() |
| 1809 | | clause = DistinctClause() |
| 1810 | | clause = DieClause() |
| 1811 | ) |
| 1812 | { |
| 1813 | return clause; |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | Clause ForClause()throws ParseException : |
| 1818 | { |
| 1819 | ForClause fc = new ForClause(); |
| 1820 | VariableExpr varExp; |
| 1821 | VariableExpr varPos = null; |
| 1822 | Expression inExp; |
| 1823 | extendCurrentScope(); |
| 1824 | } |
| 1825 | { |
| 1826 | "for" varExp = Variable() |
| 1827 | { |
| 1828 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 1829 | } |
| 1830 | ("at" varPos = Variable() |
| 1831 | { |
| 1832 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
| 1833 | } |
| 1834 | )? |
| 1835 | "in" ( inExp = Expression() ) |
| 1836 | { |
| 1837 | fc.setVarExpr(varExp); |
| 1838 | fc.setInExpr(inExp); |
| 1839 | if (varPos != null) { |
| 1840 | fc.setPosExpr(varPos); |
| 1841 | } |
| 1842 | return fc; |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | Clause LetClause() throws ParseException: |
| 1847 | { |
| 1848 | LetClause lc = new LetClause(); |
| 1849 | VariableExpr varExp; |
| 1850 | Expression beExp; |
| 1851 | extendCurrentScope(); |
| 1852 | } |
| 1853 | { |
| 1854 | "let" varExp = Variable() |
| 1855 | { |
| 1856 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 1857 | } |
| 1858 | ":=" beExp = Expression() |
| 1859 | { |
| 1860 | lc.setVarExpr(varExp); |
| 1861 | lc.setBeExpr(beExp); |
| 1862 | return lc; |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | Clause WhereClause()throws ParseException : |
| 1867 | { |
| 1868 | WhereClause wc = new WhereClause(); |
| 1869 | Expression whereExpr; |
| 1870 | } |
| 1871 | { |
| 1872 | "where" whereExpr = Expression() |
| 1873 | { |
| 1874 | wc.setWhereExpr(whereExpr); |
| 1875 | return wc; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | Clause OrderbyClause()throws ParseException : |
| 1880 | { |
| 1881 | OrderbyClause oc = new OrderbyClause(); |
| 1882 | Expression orderbyExpr; |
| 1883 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 1884 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 1885 | int numOfOrderby = 0; |
| 1886 | } |
| 1887 | { |
| 1888 | ( |
| 1889 | "order" |
| 1890 | { |
| 1891 | String hint = getHint(token); |
| 1892 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
| 1893 | String splits[] = hint.split(" +"); |
| 1894 | int numFrames = Integer.parseInt(splits[1]); |
| 1895 | int numTuples = Integer.parseInt(splits[2]); |
| 1896 | oc.setNumFrames(numFrames); |
| 1897 | oc.setNumTuples(numTuples); |
| 1898 | } |
| 1899 | } |
| 1900 | "by" orderbyExpr = Expression() |
| 1901 | { |
| 1902 | orderbyList.add(orderbyExpr); |
| 1903 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 1904 | } |
| 1905 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1906 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1907 | { |
| 1908 | modifierList.add(modif); |
| 1909 | } |
| 1910 | |
| 1911 | ("," orderbyExpr = Expression() |
| 1912 | { |
| 1913 | orderbyList.add(orderbyExpr); |
| 1914 | modif = OrderbyClause.OrderModifier.ASC; |
| 1915 | } |
| 1916 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1917 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1918 | { |
| 1919 | modifierList.add(modif); |
| 1920 | } |
| 1921 | )* |
| 1922 | ) |
| 1923 | { |
| 1924 | oc.setModifierList(modifierList); |
| 1925 | oc.setOrderbyList(orderbyList); |
| 1926 | return oc; |
| 1927 | } |
| 1928 | } |
| 1929 | Clause GroupClause()throws ParseException : |
| 1930 | { |
| 1931 | GroupbyClause gbc = new GroupbyClause(); |
| 1932 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 1933 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1934 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1935 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 1936 | VariableExpr var = null; |
| 1937 | VariableExpr withVar = null; |
| 1938 | Expression expr = null; |
| 1939 | VariableExpr decorVar = null; |
| 1940 | Expression decorExpr = null; |
| 1941 | } |
| 1942 | { |
| 1943 | { |
| 1944 | Scope newScope = extendCurrentScopeNoPush(true); |
| 1945 | // extendCurrentScope(true); |
| 1946 | } |
| 1947 | "group" |
| 1948 | { |
| 1949 | String hint = getHint(token); |
| 1950 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 1951 | gbc.setHashGroupByHint(true); |
| 1952 | } |
| 1953 | } |
| 1954 | "by" (LOOKAHEAD(2) var = Variable() |
| 1955 | { |
| 1956 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1957 | } ":=")? |
| 1958 | expr = Expression() |
| 1959 | { |
| 1960 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 1961 | vePairList.add(pair1); |
| 1962 | } |
| 1963 | ("," ( LOOKAHEAD(2) var = Variable() |
| 1964 | { |
| 1965 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1966 | } ":=")? |
| 1967 | expr = Expression() |
| 1968 | { |
| 1969 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 1970 | vePairList.add(pair2); |
| 1971 | } |
| 1972 | )* |
| 1973 | ("decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1974 | { |
| 1975 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1976 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1977 | decorPairList.add(pair3); |
| 1978 | } |
| 1979 | ("," "decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1980 | { |
| 1981 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1982 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1983 | decorPairList.add(pair4); |
| 1984 | } |
| 1985 | )* |
| 1986 | )? |
| 1987 | "with" withVar = VariableRef() |
| 1988 | { |
| 1989 | if(withVar.getIsNewVar()==true) |
| 1990 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 1991 | withVarList.add(withVar); |
| 1992 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1993 | } |
| 1994 | ("," withVar = VariableRef() |
| 1995 | { |
| 1996 | if(withVar.getIsNewVar()==true) |
| 1997 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 1998 | withVarList.add(withVar); |
| 1999 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2000 | })* |
| 2001 | { |
| 2002 | gbc.setGbyPairList(vePairList); |
| 2003 | gbc.setDecorPairList(decorPairList); |
| 2004 | gbc.setWithVarList(withVarList); |
| 2005 | replaceCurrentScope(newScope); |
| 2006 | return gbc; |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | |
| 2011 | LimitClause LimitClause() throws ParseException: |
| 2012 | { |
| 2013 | LimitClause lc = new LimitClause(); |
| 2014 | Expression expr; |
| 2015 | pushForbiddenScope(getCurrentScope()); |
| 2016 | } |
| 2017 | { |
| 2018 | "limit" expr = Expression() { lc.setLimitExpr(expr); } |
| 2019 | ("offset" expr = Expression() { lc.setOffset(expr); })? |
| 2020 | |
| 2021 | { |
| 2022 | popForbiddenScope(); |
| 2023 | return lc; |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | DistinctClause DistinctClause() throws ParseException: |
| 2028 | { |
| 2029 | List<Expression> exprs = new ArrayList<Expression>(); |
| 2030 | Expression expr; |
| 2031 | } |
| 2032 | { |
| 2033 | "distinct" "by" expr = Expression() |
| 2034 | { |
| 2035 | exprs.add(expr); |
| 2036 | } |
| 2037 | ("," expr = Expression() |
| 2038 | { |
| 2039 | exprs.add(expr); |
| 2040 | } |
| 2041 | )* |
| 2042 | { |
| 2043 | return new DistinctClause(exprs); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | DieClause DieClause() throws ParseException: |
| 2048 | { |
| 2049 | DieClause lc = new DieClause(); |
| 2050 | Expression expr; |
| 2051 | pushForbiddenScope(getCurrentScope()); |
| 2052 | } |
| 2053 | { |
| 2054 | "die" "after" expr = Expression() { lc.setDieExpr(expr); } |
| 2055 | { |
| 2056 | popForbiddenScope(); |
| 2057 | return lc; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | |
| 2062 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2063 | { |
| 2064 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2065 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2066 | Expression satisfiesExpr; |
| 2067 | VariableExpr var; |
| 2068 | Expression inExpr; |
| 2069 | QuantifiedPair pair; |
| 2070 | } |
| 2071 | { |
| 2072 | { |
| 2073 | createNewScope(); |
| 2074 | } |
| 2075 | |
| 2076 | ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2077 | | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 2078 | var = Variable() "in" inExpr = Expression() |
| 2079 | { |
| 2080 | pair = new QuantifiedPair(var, inExpr); |
| 2081 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2082 | quantifiedList.add(pair); |
| 2083 | } |
| 2084 | ( |
| 2085 | "," var = Variable() "in" inExpr = Expression() |
| 2086 | { |
| 2087 | pair = new QuantifiedPair(var, inExpr); |
| 2088 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2089 | quantifiedList.add(pair); |
| 2090 | } |
| 2091 | )* |
| 2092 | "satisfies" satisfiesExpr = Expression() |
| 2093 | { |
| 2094 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2095 | qc.setQuantifiedList(quantifiedList); |
| 2096 | removeCurrentScope(); |
| 2097 | return qc; |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | TOKEN_MGR_DECLS: |
| 2102 | { |
| 2103 | public int commentDepth = 0; |
| 2104 | } |
| 2105 | |
| 2106 | <DEFAULT> |
| 2107 | TOKEN : |
| 2108 | { |
| 2109 | <CARET : "^" > |
| 2110 | } |
| 2111 | |
| 2112 | <DEFAULT> |
| 2113 | TOKEN : |
| 2114 | { |
| 2115 | <DATASET : "dataset" > |
| 2116 | } |
| 2117 | |
| 2118 | <DEFAULT> |
| 2119 | TOKEN : |
| 2120 | { |
| 2121 | <LEFTPAREN : "(" > |
| 2122 | } |
| 2123 | |
| 2124 | <DEFAULT> |
| 2125 | TOKEN : |
| 2126 | { |
| 2127 | <RIGHTPAREN : ")" > |
| 2128 | } |
| 2129 | |
| 2130 | |
| 2131 | <DEFAULT> |
| 2132 | TOKEN : |
| 2133 | { |
| 2134 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2135 | } |
| 2136 | |
| 2137 | |
| 2138 | <DEFAULT> |
| 2139 | TOKEN : |
| 2140 | { |
| 2141 | <NULL : "null"> |
| 2142 | } |
| 2143 | |
| 2144 | <DEFAULT> |
| 2145 | TOKEN : |
| 2146 | { |
| 2147 | <TRUE : "true"> |
| 2148 | } |
| 2149 | |
| 2150 | <DEFAULT> |
| 2151 | TOKEN : |
| 2152 | { |
| 2153 | <FALSE : "false"> |
| 2154 | } |
| 2155 | |
| 2156 | <DEFAULT> |
| 2157 | TOKEN : |
| 2158 | { |
| 2159 | <#DIGIT : ["0" - "9"]> |
| 2160 | } |
| 2161 | |
| 2162 | |
| 2163 | TOKEN: |
| 2164 | { |
| 2165 | < DOUBLE_LITERAL: <INTEGER> |
| 2166 | | <INTEGER> ( "." <INTEGER> )? |
| 2167 | | "." <INTEGER> |
| 2168 | > |
| 2169 | | |
| 2170 | < FLOAT_LITERAL: <INTEGER> ( "f" | "F" ) |
| 2171 | | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )? |
| 2172 | | "." <INTEGER> ( "f" | "F" ) |
| 2173 | > |
| 2174 | | |
| 2175 | <INTEGER : (<DIGIT>)+ > |
| 2176 | } |
| 2177 | |
| 2178 | <DEFAULT> |
| 2179 | TOKEN : |
| 2180 | { |
| 2181 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2182 | } |
| 2183 | |
| 2184 | <DEFAULT> |
| 2185 | TOKEN : |
| 2186 | { |
| 2187 | <SPECIALCHARS : ["$", "_", "-"] > |
| 2188 | } |
| 2189 | |
| 2190 | <DEFAULT> |
| 2191 | TOKEN : |
| 2192 | { |
| 2193 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 2194 | | |
| 2195 | < #EscapeQuot: "\\\"" > |
| 2196 | | |
| 2197 | < #EscapeApos: "\\\'" > |
| 2198 | } |
| 2199 | |
| 2200 | <DEFAULT> |
| 2201 | TOKEN : |
| 2202 | { |
| 2203 | <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 2204 | } |
| 2205 | |
| 2206 | <DEFAULT> |
| 2207 | TOKEN : |
| 2208 | { |
| 2209 | <VARIABLE : "$" <IDENTIFIER> > |
| 2210 | } |
| 2211 | |
| 2212 | SKIP: |
| 2213 | { |
| 2214 | " " |
| 2215 | | "\t" |
| 2216 | | "\r" |
| 2217 | | "\n" |
| 2218 | } |
| 2219 | |
| 2220 | SKIP: |
| 2221 | { |
| 2222 | <"//" (~["\n"])* "\n"> |
| 2223 | } |
| 2224 | |
| 2225 | SKIP: |
| 2226 | { |
| 2227 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 2228 | } |
| 2229 | |
| 2230 | |
| 2231 | SKIP: |
| 2232 | { |
| 2233 | <"/*"> {commentDepth=1;}: INSIDE_COMMENT |
| 2234 | } |
| 2235 | |
| 2236 | <INSIDE_COMMENT> |
| 2237 | SPECIAL_TOKEN: |
| 2238 | { |
| 2239 | <"+"(" ")*(~["*"])*> |
| 2240 | } |
| 2241 | |
| 2242 | <INSIDE_COMMENT> |
| 2243 | SKIP: |
| 2244 | { |
| 2245 | <"/*"> {commentDepth++;} |
| 2246 | } |
| 2247 | |
| 2248 | <INSIDE_COMMENT> |
| 2249 | SKIP: |
| 2250 | { |
| 2251 | <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);} |
| 2252 | | <~[]> |
| 2253 | } |