def _parse_where(sql, example, anonymize_values):
  """Parse the part relative to the WHERE clause of the SQL query."""
  successful_copy = True
  for item in sql:
    if item.ttype == sqlparse.tokens.Text.Whitespace:
      continue

    if _is_keyword(item) and item.value.lower() in ('where',):
      _add_simple_step(item, example)
      continue

    if _is_comparison(item):
      successful_copy = _parse_comparison(item, example,
                                          anonymize_values) and successful_copy
      continue

    if _is_comparison_operator(item):
      _add_simple_step(item, example)
      continue

    if _is_identifier(item):
      successful_copy = _parse_identifier(item, example,
                                          anonymize_values) and successful_copy
      continue

    if _is_identifier_list(item):
      successful_copy = _parse_identifier_list(
          item, example, anonymize_values) and successful_copy
      continue

    if _is_keyword(item) and item.value.lower() in ('between', 'and', 'or'):
      _add_simple_step(item, example)
      continue

    if _is_keyword(item) and item.value.lower() in ('not', 'in', 'intersect'):
      _add_simple_step(item, example)
      continue

    if _is_keyword(item) and item.value.lower() in ('distinct',):
      _add_simple_step(item, example)
      continue

    if _is_integer(item):
      prev_len = len(example.gold_sql_query.actions)
      successful_copy = _add_simple_value(item, example,
                                          anonymize_values) and successful_copy
      if len(example.gold_sql_query.actions) == prev_len:
        raise ValueError(
            'Gold query did not change length when adding simple value!')
      continue

    # Like '%asd%'
    if _is_keyword(item) and item.value.lower() in ('like',):
      _add_simple_step(item, example)
      continue

    if _is_literal(item):
      prev_len = len(example.gold_sql_query.actions)
      successful_copy = _add_simple_value(item, example,
                                          anonymize_values) and successful_copy
      if len(example.gold_sql_query.actions) == prev_len:
        raise ValueError(
            'Gold query did not change length when adding simple value!')
      continue

    if _is_keyword(item) and item.value.lower() in ('join', 'on'):
      _add_simple_step(item, example)
      continue

    if _is_parenthesis(item):
      successful_copy = populate_sql(item, example,
                                     anonymize_values) and successful_copy
      continue

    if _is_select(item) or _is_from(item):
      _add_simple_step(item, example)
      continue

    _debug_sql_item(item)
    raise ParseError('Incomplete _parse_where')
  return successful_copy
Parse the part relative to the WHERE clause of the SQL query.
language/xsp/data_preprocessing/sql_parsing.py