def _get_sorted_col_indices(select_columns, column_names):
  """Transforms select_columns argument into sorted column indices."""
  names_to_indices = {n: i for i, n in enumerate(column_names)}
  num_cols = len(column_names)
  for i, v in enumerate(select_columns):
    if isinstance(v, int):
      if v < 0 or v >= num_cols:
        raise ValueError(
            "Column index %d specified in select_columns out of valid range." %
            v)
      continue
    if v not in names_to_indices:
      raise ValueError(
          "Value '%s' specified in select_columns not a valid column index or "
          "name." % v)
    select_columns[i] = names_to_indices[v]

  # Sort and ensure there are no duplicates
  result = sorted(set(select_columns))
  if len(result) != len(select_columns):
    raise ValueError("select_columns contains duplicate columns")
  return result