class UnionSelect implements AnalyzedRelation {

    private final AnalyzedRelation left;
    private final AnalyzedRelation right;
    private final List<ScopedSymbol> outputs;
    private final RelationName name;
    private final boolean isDistinct;

    public UnionSelect(AnalyzedRelation left, AnalyzedRelation right, boolean isDistinct) {
        if (left.outputs().size() != right.outputs().size()) {
            throw new UnsupportedOperationException("Number of output columns must be the same for all parts of a UNION");
        }
        this.left = left;
        this.right = right;
        this.name = new RelationName(null, UUIDs.dirtyUUID().toString());
        // SQL semantics dictate that UNION uses the column names from the first relation (top or left side)
        var leftOutputs = left.outputs();
        var rightOutputs = right.outputs();
        ArrayList<ScopedSymbol> outputs = new ArrayList<>(leftOutputs.size());
        for (int i = 0; i < leftOutputs.size(); i++) {
            var l = leftOutputs.get(i);
            var r = rightOutputs.get(i);
            try {
                outputs.add(new ScopedSymbol(name, Symbols.pathFromSymbol(l), merge(l.valueType(), r.valueType())));
            } catch (IllegalArgumentException e) {
                throw new UnsupportedOperationException(
                    "Output columns at position " + (i + 1) +
                    " must be compatible for all parts of a UNION. " +
                    "Got `" + l.valueType().getName() + "` and `" + r.valueType().getName() + "`");
            }
        }
        this.outputs = List.copyOf(outputs);
        this.isDistinct = isDistinct;
    }

    public AnalyzedRelation left() {
        return left;
    }

    public AnalyzedRelation right() {
        return right;
    }

    @Override
    public <C, R> R accept(AnalyzedRelationVisitor<C, R> visitor, C context) {
        return visitor.visitUnionSelect(this, context);
    }

    @Override
    public Symbol getField(ColumnIdent column, Operation operation, boolean errorOnUnknownObjectKey) throws AmbiguousColumnException, ColumnUnknownException, UnsupportedOperationException {<FILL_FUNCTION_BODY>}

    @Override
    public RelationName relationName() {
        return name;
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @NotNull
    @Override
    public List<Symbol> outputs() {
        return (List<Symbol>)(List) outputs;
    }

    @Override
    public String toString() {
        return left + " UNION " + (isDistinct ? "DISTINCT " : "ALL ") + right;
    }

    public boolean isDistinct() {
        return isDistinct;
    }
}

        Symbol field = null;
        for (var output : outputs) {
            if (output.column().equals(column)) {
                if (field != null) {
                    throw new AmbiguousColumnException(output.column(), output);
                }
                field = output;
            }
        }
        return field;
    
<no_super_class>