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

Function parse_condition

evaluation/test-suite-sql-eval/process_sql.py:304–338  ·  view source on GitHub ↗
(toks, start_idx, tables_with_alias, schema, default_tables=None)

Source from the content-addressed store, hash-verified

302
303
304def parse_condition(toks, start_idx, tables_with_alias, schema, default_tables=None):
305 idx = start_idx
306 len_ = len(toks)
307 conds = []
308
309 while idx < len_:
310 idx, val_unit = parse_val_unit(toks, idx, tables_with_alias, schema, default_tables)
311 not_op = False
312 if toks[idx] == 'not':
313 not_op = True
314 idx += 1
315
316 assert idx < len_ and toks[idx] in WHERE_OPS, "Error condition: idx: {}, tok: {}".format(idx, toks[idx])
317 op_id = WHERE_OPS.index(toks[idx])
318 idx += 1
319 val1 = val2 = None
320 if op_id == WHERE_OPS.index('between'): # between..and... special case: dual values
321 idx, val1 = parse_value(toks, idx, tables_with_alias, schema, default_tables)
322 assert toks[idx] == 'and'
323 idx += 1
324 idx, val2 = parse_value(toks, idx, tables_with_alias, schema, default_tables)
325 else: # normal case: single value
326 idx, val1 = parse_value(toks, idx, tables_with_alias, schema, default_tables)
327 val2 = None
328
329 conds.append((not_op, op_id, val_unit, val1, val2))
330
331 if idx < len_ and (toks[idx] in CLAUSE_KEYWORDS or toks[idx] in (")", ";") or toks[idx] in JOIN_KEYWORDS):
332 break
333
334 if idx < len_ and toks[idx] in COND_OPS:
335 conds.append(toks[idx])
336 idx += 1 # skip and/or
337
338 return idx, conds
339
340
341def 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