def select_only_columns(query: sa.Select, *names: str) -> sa.Select:
    """Returns query selecting defined columns only."""
    if not names:
        return query

    cols: list[ColT] = []
    for name in names:
        col = get_query_column(query, name)
        if col is None:
            raise ValueError(f"Column '{name}' not found in query")
        cols.append(col)

    return query.with_only_columns(*cols)
Returns query selecting defined columns only.
src/datachain/query/utils.py