:returns next idx, column id
(toks, start_idx, tables_with_alias, schema, default_tables=None)
| 173 | |
| 174 | |
| 175 | def parse_col(toks, start_idx, tables_with_alias, schema, default_tables=None): |
| 176 | """ |
| 177 | :returns next idx, column id |
| 178 | """ |
| 179 | tok = toks[start_idx] |
| 180 | if tok == "*": |
| 181 | return start_idx + 1, schema.id_map[tok] |
| 182 | if tok in CONST_COLUMN: |
| 183 | return start_idx + 1, tok |
| 184 | |
| 185 | if g_is_nl2sql_dataset: |
| 186 | fn_check = lambda tok: '.' in tok and tok.startswith('table_') |
| 187 | else: |
| 188 | fn_check = lambda tok: '.' in tok |
| 189 | if fn_check(tok): # if token is a composite |
| 190 | alias, col = tok.split('.', 1) |
| 191 | key = tables_with_alias[alias] + "." + col |
| 192 | return start_idx + 1, schema.id_map[key] |
| 193 | |
| 194 | assert default_tables is not None and len(default_tables) > 0, "Default tables should not be None or empty" |
| 195 | |
| 196 | for alias in default_tables: |
| 197 | table = tables_with_alias[alias] |
| 198 | if tok in schema.schema[table]: |
| 199 | key = table + "." + tok |
| 200 | return start_idx + 1, schema.id_map[key] |
| 201 | |
| 202 | raise RuntimeError("Error col: {} from {}".format(tok, toks)) |
| 203 | |
| 204 | |
| 205 | def parse_col_unit(toks, start_idx, tables_with_alias, schema, default_tables=None): |