def _evaluate_union( opcall: irast.OperatorCall, schema: s_schema.Schema) -> irast.ConstExpr: elements: List[irast.BaseConstant] = [] for arg in opcall.args: val = evaluate(arg.expr, schema=schema) if isinstance(val, irast.ConstantSet): elements.extend(val.elements) elif isinstance(val, irast.EmptySet): empty_set = val elif isinstance(val, irast.BaseConstant): elements.append(val) else: raise UnsupportedExpressionError( f'{val!r} not supported in UNION', context=opcall.context) if elements: return irast.ConstantSet( elements=tuple(elements), typeref=next(iter(elements)).typeref, ) else: # We get an empty set if the UNION was exclusivly empty set # literals. If that happens, grab one of the empty sets # that we saw and return it. return empty_set
def _evaluate_union(opcall: irast.OperatorCall, schema: s_schema.Schema) -> irast.ConstantSet: elements = [] for arg in opcall.args: val = evaluate(arg.expr, schema=schema) if isinstance(val, irast.ConstantSet): elements.extend(val.elements) else: elements.append(val) return irast.ConstantSet( elements=tuple(elements), typeref=next(iter(elements)).typeref, )