def _find_all_entities(token,
                       example,
                       include_tables=True,
                       include_columns=True,
                       restrict_to_table=None):
  """Tries to find schema entities that match the token."""
  matching = list()
  if restrict_to_table:
    assert include_columns
    assert not include_tables
    for column in restrict_to_table.table_columns:
      if column.original_column_name.lower() == token.lower() and \
          include_columns:
        matching.append(column)
  else:
    for table in example.model_input.tables:
      # Allow lowercase matching because the schema and gold query may not match
      if table.original_table_name.lower() == token.lower() and include_tables:
        matching.append(table)

      for column in table.table_columns:
        if column.original_column_name.lower() == token.lower() and \
            include_columns:
          matching.append(column)

  return matching
Tries to find schema entities that match the token.
language/xsp/data_preprocessing/sql_parsing.py