MCPcopy Create free account
hub / github.com/FlyingFeather/DEA-SQL / parse_sql

Function parse_sql

evaluation/test-suite-sql-eval/process_sql.py:498–545  ·  view source on GitHub ↗
(toks, start_idx, tables_with_alias, schema)

Source from the content-addressed store, hash-verified

496
497
498def 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
548def load_data(fpath):

Callers 3

parse_valueFunction · 0.70
parse_fromFunction · 0.70
get_sqlFunction · 0.70

Calls 8

parse_fromFunction · 0.70
parse_selectFunction · 0.70
parse_whereFunction · 0.70
parse_group_byFunction · 0.70
parse_havingFunction · 0.70
parse_order_byFunction · 0.70
parse_limitFunction · 0.70
skip_semicolonFunction · 0.70

Tested by

no test coverage detected