(toks, start_idx, tables_with_alias, schema)
| 496 | |
| 497 | |
| 498 | def parse_sql(toks, start_idx, tables_with_alias, schema): |
| 499 | isBlock = False # indicate whether this is a block of sql/sub-sql |
| 500 | len_ = len(toks) |
| 501 | idx = start_idx |
| 502 | |
| 503 | sql = {} |
| 504 | if toks[idx] == '(': |
| 505 | isBlock = True |
| 506 | idx += 1 |
| 507 | |
| 508 | # parse from clause in order to get default tables |
| 509 | from_end_idx, table_units, conds, default_tables = parse_from(toks, start_idx, tables_with_alias, schema) |
| 510 | sql['from'] = {'table_units': table_units, 'conds': conds} |
| 511 | # select clause |
| 512 | _, select_col_units = parse_select(toks, idx, tables_with_alias, schema, default_tables) |
| 513 | idx = from_end_idx |
| 514 | sql['select'] = select_col_units |
| 515 | # where clause |
| 516 | idx, where_conds = parse_where(toks, idx, tables_with_alias, schema, default_tables) |
| 517 | sql['where'] = where_conds |
| 518 | # group by clause |
| 519 | idx, group_col_units = parse_group_by(toks, idx, tables_with_alias, schema, default_tables) |
| 520 | sql['groupBy'] = group_col_units |
| 521 | # having clause |
| 522 | idx, having_conds = parse_having(toks, idx, tables_with_alias, schema, default_tables) |
| 523 | sql['having'] = having_conds |
| 524 | # order by clause |
| 525 | idx, order_col_units = parse_order_by(toks, idx, tables_with_alias, schema, default_tables) |
| 526 | sql['orderBy'] = order_col_units |
| 527 | # limit clause |
| 528 | idx, limit_val = parse_limit(toks, idx) |
| 529 | sql['limit'] = limit_val |
| 530 | |
| 531 | idx = skip_semicolon(toks, idx) |
| 532 | if isBlock: |
| 533 | assert toks[idx] == ')' |
| 534 | idx += 1 # skip ')' |
| 535 | idx = skip_semicolon(toks, idx) |
| 536 | |
| 537 | # intersect/union/except clause |
| 538 | for op in SQL_OPS: # initialize IUE |
| 539 | sql[op] = None |
| 540 | if idx < len_ and toks[idx] in SQL_OPS: |
| 541 | sql_op = toks[idx] |
| 542 | idx += 1 |
| 543 | idx, IUE_sql = parse_sql(toks, idx, tables_with_alias, schema) |
| 544 | sql[sql_op] = IUE_sql |
| 545 | return idx, sql |
| 546 | |
| 547 | |
| 548 | def load_data(fpath): |
no test coverage detected