examples/text_to_sql/RAT-SQL/text2sql/utils/dusql_evaluation.py
def parse_from(toks, start_idx, tables_with_alias, schema):
    """
    Assume in the from clause, all table units are combined with join
    """
    assert 'from' in toks[start_idx:], "'from' not found"

    len_ = len(toks)
    idx = toks.index('from', start_idx) + 1
    default_tables = []
    table_units = []
    conds = []
    last_table = None

    while idx < len_:
        isBlock = False
        if toks[idx] == '(':
            isBlock = True
            idx += 1

        if toks[idx] == 'select':
            idx, sql = parse_sql(toks, idx, tables_with_alias, schema)
            table_units.append((TABLE_TYPE['sql'], sql))
            last_table = sql['from']['table_units'][0][1].strip('_')
        else:
            if idx < len_ and toks[idx] == 'join':
                idx += 1  # skip join
            idx, table_unit, table_name = parse_table_unit(
                toks, idx, tables_with_alias, schema)
            table_units.append((TABLE_TYPE['table_unit'], table_unit))
            default_tables.append(table_name)
        if idx < len_ and toks[idx] == "on":
            idx += 1  # skip on
            idx, this_conds = parse_condition(toks, idx, tables_with_alias,
                                              schema, default_tables)
            if len(conds) > 0:
                conds.append('and')
            conds.extend(this_conds)

        if isBlock:
            assert toks[idx] == ')'
            idx += 1
        if idx < len_ and toks[idx] == 'a':
            assert last_table is not None, 'last_table should be a table name strin, not None'
            tables_with_alias['a'] = last_table
            idx += 2
        elif idx < len_ and toks[idx] == 'b':
            assert last_table is not None, 'last_table should be a table name strin, not None'
            tables_with_alias['b'] = last_table
            idx += 1
        if idx < len_ and (toks[idx] in CLAUSE_KEYWORDS or
                           toks[idx] in (")", ";")):
            break

    return [idx, table_units, conds, default_tables]

    Assume in the from clause, all table units are combined with join
    
Assume in the from clause, all table units are combined with join
Assume in the from clause all table units are combined with join
def parse_from(toks, start_idx, tables_with_alias, schema):
    assert 'from' in toks[start_idx:], "'from' not found"
    len_ = len(toks)
    idx = toks.index('from', start_idx) + 1
    default_tables = []
    table_units = []
    conds = []
    last_table = None
    while idx < len_:
        isBlock = False
        if toks[idx] == '(':
            isBlock = True
            idx += 1
        if toks[idx] == 'select':
            idx, sql = parse_sql(toks, idx, tables_with_alias, schema)
            table_units.append((TABLE_TYPE['sql'], sql))
            last_table = sql['from']['table_units'][0][1].strip('_')
        else:
            if idx < len_ and toks[idx] == 'join':
                idx += 1  
            idx, table_unit, table_name = parse_table_unit(
                toks, idx, tables_with_alias, schema)
            table_units.append((TABLE_TYPE['table_unit'], table_unit))
            default_tables.append(table_name)
        if idx < len_ and toks[idx] == "on":
            idx += 1  
            idx, this_conds = parse_condition(toks, idx, tables_with_alias,
                                              schema, default_tables)
            if len(conds) > 0:
                conds.append('and')
            conds.extend(this_conds)
        if isBlock:
            assert toks[idx] == ')'
            idx += 1
        if idx < len_ and toks[idx] == 'a':
            assert last_table is not None, 'last_table should be a table name strin, not None'
            tables_with_alias['a'] = last_table
            idx += 2
        elif idx < len_ and toks[idx] == 'b':
            assert last_table is not None, 'last_table should be a table name strin, not None'
            tables_with_alias['b'] = last_table
            idx += 1
        if idx < len_ and (toks[idx] in CLAUSE_KEYWORDS or
                           toks[idx] in (")", ";")):
            break
    return [idx, table_units, conds, default_tables]
def parse_from ( toks , start_idx , tables_with_alias , schema ) : assert 'from' in toks [ start_idx : ] , "'from' not found" len_ = len ( toks ) idx = toks . index ( 'from' , start_idx ) + 1 default_tables = [ ] table_units = [ ] conds = [ ] last_table = None while idx < len_ : isBlock = False if toks [ idx ] == '(' : isBlock = True idx += 1 if toks [ idx ] == 'select' : idx , sql = parse_sql ( toks , idx , tables_with_alias , schema ) table_units . append ( ( TABLE_TYPE [ 'sql' ] , sql ) ) last_table = sql [ 'from' ] [ 'table_units' ] [ 0 ] [ 1 ] . strip ( '_' ) else : if idx < len_ and toks [ idx ] == 'join' : idx += 1 idx , table_unit , table_name = parse_table_unit ( toks , idx , tables_with_alias , schema ) table_units . append ( ( TABLE_TYPE [ 'table_unit' ] , table_unit ) ) default_tables . append ( table_name ) if idx < len_ and toks [ idx ] == "on" : idx += 1 idx , this_conds = parse_condition ( toks , idx , tables_with_alias , schema , default_tables ) if len ( conds ) > 0 : conds . append ( 'and' ) conds . extend ( this_conds ) if isBlock : assert toks [ idx ] == ')' idx += 1 if idx < len_ and toks [ idx ] == 'a' : assert last_table is not None , 'last_table should be a table name strin, not None' tables_with_alias [ 'a' ] = last_table idx += 2 elif idx < len_ and toks [ idx ] == 'b' : assert last_table is not None , 'last_table should be a table name strin, not None' tables_with_alias [ 'b' ] = last_table idx += 1 if idx < len_ and ( toks [ idx ] in CLAUSE_KEYWORDS or toks [ idx ] in ( ")" , ";" ) ) : break return [ idx , table_units , conds , default_tables ]
Assume in the from clause, all table units are combined with join
Assume in the from clause all table units are combined with join
"""
    Assume in the from clause, all table units are combined with join
    """ # skip join # skip on
toks
start_idx
tables_with_alias
schema