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

Function parse_sql

evaluation/ts_old/spider-master/process_sql.py:494–541  ·  view source on GitHub ↗
(toks, start_idx, tables_with_alias, schema)

Source from the content-addressed store, hash-verified

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