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

Function parse_from

hardness_eval.py:395–435  ·  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

393
394
395def parse_from(toks, start_idx, tables_with_alias, schema):
396 """
397 Assume in the from clause, all table units are combined with join
398 """
399 assert 'from' in toks[start_idx:], "'from' not found"
400
401 len_ = len(toks)
402 idx = toks.index('from', start_idx) + 1
403 default_tables = []
404 table_units = []
405 conds = []
406
407 while idx < len_:
408 isBlock = False
409 if toks[idx] == '(':
410 isBlock = True
411 idx += 1
412
413 if toks[idx] == 'select':
414 idx, sql = parse_sql(toks, idx, tables_with_alias, schema)
415 table_units.append((TABLE_TYPE['sql'], sql))
416 else:
417 if idx < len_ and toks[idx] == 'join':
418 idx += 1 # skip join
419 idx, table_unit, table_name = parse_table_unit(toks, idx, tables_with_alias, schema)
420 table_units.append((TABLE_TYPE['table_unit'], table_unit))
421 default_tables.append(table_name)
422 if idx < len_ and toks[idx] == "on":
423 idx += 1 # skip on
424 idx, this_conds = parse_condition(toks, idx, tables_with_alias, schema, default_tables)
425 if len(conds) > 0:
426 conds.append('and')
427 conds.extend(this_conds)
428
429 if isBlock:
430 assert toks[idx] == ')'
431 idx += 1
432 if idx < len_ and (toks[idx] in CLAUSE_KEYWORDS or toks[idx] in (")", ";")):
433 break
434
435 return idx, table_units, conds, default_tables
436
437
438def 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