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

Function parse_condition

hardness_eval.py:333–367  ·  view source on GitHub ↗
(toks, start_idx, tables_with_alias, schema, default_tables=None)

Source from the content-addressed store, hash-verified

331
332
333def parse_condition(toks, start_idx, tables_with_alias, schema, default_tables=None):
334 idx = start_idx
335 len_ = len(toks)
336 conds = []
337
338 while idx < len_:
339 idx, val_unit = parse_val_unit(toks, idx, tables_with_alias, schema, default_tables)
340 not_op = False
341 if toks[idx] == 'not':
342 not_op = True
343 idx += 1
344
345 assert idx < len_ and toks[idx] in WHERE_OPS, "Error condition: idx: {}, tok: {}".format(idx, toks[idx])
346 op_id = WHERE_OPS.index(toks[idx])
347 idx += 1
348 val1 = val2 = None
349 if op_id == WHERE_OPS.index('between'): # between..and... special case: dual values
350 idx, val1 = parse_value(toks, idx, tables_with_alias, schema, default_tables)
351 assert toks[idx] == 'and'
352 idx += 1
353 idx, val2 = parse_value(toks, idx, tables_with_alias, schema, default_tables)
354 else: # normal case: single value
355 idx, val1 = parse_value(toks, idx, tables_with_alias, schema, default_tables)
356 val2 = None
357
358 conds.append((not_op, op_id, val_unit, val1, val2))
359
360 if idx < len_ and (toks[idx] in CLAUSE_KEYWORDS or toks[idx] in (")", ";") or toks[idx] in JOIN_KEYWORDS):
361 break
362
363 if idx < len_ and toks[idx] in COND_OPS:
364 conds.append(toks[idx])
365 idx += 1 # skip and/or
366
367 return idx, conds
368
369
370def parse_select(toks, start_idx, tables_with_alias, schema, default_tables=None):

Callers 3

parse_fromFunction · 0.70
parse_whereFunction · 0.70
parse_havingFunction · 0.70

Calls 2

parse_val_unitFunction · 0.70
parse_valueFunction · 0.70

Tested by

no test coverage detected