def anonymize_aliases(sql):
  """Renames aliases to a consistent format (e.g., using T#)."""
  sql_tokens = list()
  tokens = SQLTokenizer().tokenize(sql)

  # First, split all TABLE.COLUMN examples into three tokens.
  for token in tokens:
    token = token.replace('"', '\'')
    if token != '.' and token.count('.') == 1 and not token.replace(
        '.', '', 1).isnumeric():
      table, column = token.split('.')
      sql_tokens.extend([table, '.', column])
    else:
      sql_tokens.append(token)

  # Create an alias dictionary that maps from table names to column names
  alias_dict = dict()
  for token in sql_tokens:
    if 'alias' in token and token not in alias_dict:
      alias_dict[token] = 'T' + str(len(alias_dict) + 1)

  # Reconstruct the SQL query, this time replacing old alias names with the new
  # assigned alias names.
  new_tokens = list()
  for token in sql_tokens:
    if token in alias_dict:
      new_tokens.append(alias_dict[token])
    else:
      new_tokens.append(token)

  return new_tokens
Renames aliases to a consistent format (e.g., using T#).
language/xsp/data_preprocessing/sql_utils.py