def _check_spans_against_schema(sql_spans, table_schemas):
  """Raises exception if sql_spans contains bad table or column name."""
  table_names_to_columns = {
      table.table_name: table.column_names for table in table_schemas
  }
  for sql_span in sql_spans:
    if sql_span.table_name:
      if sql_span.table_name not in table_names_to_columns:
        raise ParseError('Table name %s not in schema %s' %
                         (sql_span.table_name, table_schemas))
    elif sql_span.column:
      if sql_span.column.table_name not in table_names_to_columns:
        raise ParseError('Table name %s not in schema %s' %
                         (sql_span.column.table_name, table_schemas))
      else:
        column_names = table_names_to_columns[sql_span.column.table_name]
        if sql_span.column.column_name not in column_names:
          raise ParseError(
              'Column name %s not in schema %s for table %s for spans %s' %
              (sql_span.column.column_name, table_schemas,
               sql_span.column.table_name,
               sql_spans_to_string(sql_spans, sep=',')))
Raises exception if sql_spans contains bad table or column name.
language/xsp/data_preprocessing/abstract_sql.py