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

Function parse_from

evaluation/test-suite-sql-eval/process_sql.py:366–406  ·  view source on GitHub ↗

Assume in the from clause, all table units are combined with join

(toks, start_idx, tables_with_alias, schema)

Source from the content-addressed store, hash-verified

364
365
366def parse_from(toks, start_idx, tables_with_alias, schema):
367 """
368 Assume in the from clause, all table units are combined with join
369 """
370 assert 'from' in toks[start_idx:], "'from' not found"
371
372 len_ = len(toks)
373 idx = toks.index('from', start_idx) + 1
374 default_tables = []
375 table_units = []
376 conds = []
377
378 while idx < len_:
379 isBlock = False
380 if toks[idx] == '(':
381 isBlock = True
382 idx += 1
383
384 if toks[idx] == 'select':
385 idx, sql = parse_sql(toks, idx, tables_with_alias, schema)
386 table_units.append((TABLE_TYPE['sql'], sql))
387 else:
388 if idx < len_ and toks[idx] == 'join':
389 idx += 1 # skip join
390 idx, table_unit, table_name = parse_table_unit(toks, idx, tables_with_alias, schema)
391 table_units.append((TABLE_TYPE['table_unit'],table_unit))
392 default_tables.append(table_name)
393 if idx < len_ and toks[idx] == "on":
394 idx += 1 # skip on
395 idx, this_conds = parse_condition(toks, idx, tables_with_alias, schema, default_tables)
396 if len(conds) > 0:
397 conds.append('and')
398 conds.extend(this_conds)
399
400 if isBlock:
401 assert toks[idx] == ')'
402 idx += 1
403 if idx < len_ and (toks[idx] in CLAUSE_KEYWORDS or toks[idx] in (")", ";")):
404 break
405
406 return idx, table_units, conds, default_tables
407
408
409def parse_where(toks, start_idx, tables_with_alias, schema, default_tables):

Callers 1

parse_sqlFunction · 0.70

Calls 3

parse_sqlFunction · 0.70
parse_table_unitFunction · 0.70
parse_conditionFunction · 0.70

Tested by

no test coverage detected