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

Function parse_col

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

:returns next idx, column id

(toks, start_idx, tables_with_alias, schema, default_tables=None)

Source from the content-addressed store, hash-verified

173
174
175def 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
205def parse_col_unit(toks, start_idx, tables_with_alias, schema, default_tables=None):

Callers 1

parse_col_unitFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected