MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / parse_sql

Function parse_sql

NLP/Text2SQL-BASELINE/text2sql/utils/dusql_evaluation.py:582–634  ·  view source on GitHub ↗

Args: Returns:

(toks, start_idx, tables_with_alias, schema)

Source from the content-addressed store, hash-verified

580
581
582def parse_sql(toks, start_idx, tables_with_alias, schema):
583 """
584 Args:
585
586 Returns:
587 """
588 isBlock = False # indicate whether this is a block of sql/sub-sql
589 len_ = len(toks)
590 idx = start_idx
591
592 sql = {}
593 if toks[idx] == '(':
594 isBlock = True
595 idx += 1
596
597 # parse from clause in order to get default tables
598 from_end_idx, table_units, conds, default_tables = parse_from(toks, start_idx, tables_with_alias, schema)
599 sql['from'] = {'table_units': table_units, 'conds': conds}
600 # select clause
601 _, select_col_units = parse_select(toks, idx, tables_with_alias, schema, default_tables)
602 idx = from_end_idx
603 sql['select'] = select_col_units
604 # where clause
605 idx, where_conds = parse_where(toks, idx, tables_with_alias, schema, default_tables)
606 sql['where'] = where_conds
607 # group by clause
608 idx, group_col_units = parse_group_by(toks, idx, tables_with_alias, schema, default_tables)
609 sql['groupBy'] = group_col_units
610 # having clause
611 idx, having_conds = parse_having(toks, idx, tables_with_alias, schema, default_tables)
612 sql['having'] = having_conds
613 # order by clause
614 idx, order_col_units = parse_order_by(toks, idx, tables_with_alias, schema, default_tables)
615 sql['orderBy'] = order_col_units
616 # limit clause
617 idx, limit_val = parse_limit(toks, idx)
618 sql['limit'] = limit_val
619
620 idx = skip_semicolon(toks, idx)
621 if isBlock:
622 assert toks[idx] == ')'
623 idx += 1 # skip ')'
624 idx = skip_semicolon(toks, idx)
625
626 # intersect/union/except clause
627 for op in SQL_OPS: # initialize IUE
628 sql[op] = None
629 if idx < len_ and toks[idx] in SQL_OPS:
630 sql_op = toks[idx]
631 idx += 1
632 idx, IUE_sql = parse_sql(toks, idx, tables_with_alias, schema)
633 sql[sql_op] = IUE_sql
634 return idx, sql
635
636
637def 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