(toks, start_idx, tables_with_alias, schema)
| 525 | |
| 526 | |
| 527 | def parse_sql(toks, start_idx, tables_with_alias, schema): |
| 528 | isBlock = False # indicate whether this is a block of sql/sub-sql |
| 529 | len_ = len(toks) |
| 530 | idx = start_idx |
| 531 | |
| 532 | sql = {} |
| 533 | if toks[idx] == '(': |
| 534 | isBlock = True |
| 535 | idx += 1 |
| 536 | |
| 537 | # parse from clause in order to get default tables |
| 538 | from_end_idx, table_units, conds, default_tables = parse_from(toks, start_idx, tables_with_alias, schema) |
| 539 | sql['from'] = {'table_units': table_units, 'conds': conds} |
| 540 | # select clause |
| 541 | _, select_col_units = parse_select(toks, idx, tables_with_alias, schema, default_tables) |
| 542 | idx = from_end_idx |
| 543 | sql['select'] = select_col_units |
| 544 | # where clause |
| 545 | idx, where_conds = parse_where(toks, idx, tables_with_alias, schema, default_tables) |
| 546 | sql['where'] = where_conds |
| 547 | # group by clause |
| 548 | idx, group_col_units = parse_group_by(toks, idx, tables_with_alias, schema, default_tables) |
| 549 | sql['groupBy'] = group_col_units |
| 550 | # having clause |
| 551 | idx, having_conds = parse_having(toks, idx, tables_with_alias, schema, default_tables) |
| 552 | sql['having'] = having_conds |
| 553 | # order by clause |
| 554 | idx, order_col_units = parse_order_by(toks, idx, tables_with_alias, schema, default_tables) |
| 555 | sql['orderBy'] = order_col_units |
| 556 | # limit clause |
| 557 | idx, limit_val = parse_limit(toks, idx) |
| 558 | sql['limit'] = limit_val |
| 559 | |
| 560 | idx = skip_semicolon(toks, idx) |
| 561 | if isBlock: |
| 562 | assert toks[idx] == ')' |
| 563 | idx += 1 # skip ')' |
| 564 | idx = skip_semicolon(toks, idx) |
| 565 | |
| 566 | # intersect/union/except clause |
| 567 | for op in SQL_OPS: # initialize IUE |
| 568 | sql[op] = None |
| 569 | if idx < len_ and toks[idx] in SQL_OPS: |
| 570 | sql_op = toks[idx] |
| 571 | idx += 1 |
| 572 | idx, IUE_sql = parse_sql(toks, idx, tables_with_alias, schema) |
| 573 | sql[sql_op] = IUE_sql |
| 574 | return idx, sql |
| 575 | |
| 576 | |
| 577 | def load_data(fpath): |
no test coverage detected