def populate_sql(sql, example, anonymize_values):
  """Creates a sequence of output / decoder actions from a raw SQL query.

  Args:
    sql: The SQL query to convert.
    example: The NLToSQLExample object to add output actions.
    anonymize_values: Whether to anonymize values by replacing with a
      placeholder.

  Raises:
    ParseError: if the SQL query can't be parsed.

  Returns:
    Boolean indicating whether all actions copying values from
    the input utterance were successfully completed.
  """
  successful_copy = True
  for item in sql:
    if item.ttype == sqlparse.tokens.Text.Whitespace:
      continue

    if _is_punctuation(item) and (item.value in ('(', ')')):
      _add_simple_step(item, example)
      continue

    if _is_punctuation(item) and (item.value in (',',)):
      _add_simple_step(item, example)
      continue

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

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

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

    if _is_where(item):
      successful_copy = _parse_where(item, example,
                                     anonymize_values) and successful_copy
      continue

    if _is_function(item):
      successful_copy = _parse_function(item, example,
                                        anonymize_values) and successful_copy
      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 ('group', 'order', 'by',
                                                    'having', 'order by',
                                                    'group by'):
      _add_simple_step(item, example)
      continue

    if _is_keyword(item) and item.value.lower() in ('count', 'avg', 'min',
                                                    'max', 'sum'):
      _add_simple_step(item, example)
      continue

    if _is_operation(item):
      successful_copy = _parse_operation(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_order(item):
      _add_simple_step(item, example)
      continue

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

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

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

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

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

    if (_is_integer(item) and
        example.gold_sql_query.actions[len(example.gold_sql_query.actions) -
                                       1].symbol in ('limit', 'between',
                                                     'and')):
      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_comparison(item):
      successful_copy = _parse_comparison(item, example,
                                          anonymize_values) and successful_copy
      continue

    _debug_state(item, example)
    raise ParseError('Incomplete _parse_sql')
  return successful_copy
Creates a sequence of output / decoder actions from a raw SQL query.

  Args:
    sql: The SQL query to convert.
    example: The NLToSQLExample object to add output actions.
    anonymize_values: Whether to anonymize values by replacing with a
      placeholder.

  Raises:
    ParseError: if the SQL query can't be parsed.

  Returns:
    Boolean indicating whether all actions copying values from
    the input utterance were successfully completed.
  
language/xsp/data_preprocessing/sql_parsing.py