API: Update Expressions to Support New Expression Spec #18629
Should the new bind also check and convert types, like the old bind does?
For example, if x is a long:
x < 5 binds to a LongLiteral.f(x) < 5, where f returns long: the 5 stays an int (IntegerLiteral). It is not converted to long.Also, upper(name) == 5 binds without error, but the old form name == 5 gives a ValidationException.
Expression is Serializable, but FunctionReference, BoundFunctionReference, and CatalogObjectIdentifier are not. Should these classes implement Serializable? Spark and Flink serialize filters, so a predicate with a function would fail with NotSerializableException.
Nit: Awkward sentence construction, could do
"Arguments the function accepts are not directly exposed as implementations ...."
I'm not sure I like the old classes absorbing the functionality from the new ValueExpressions things. It seems to be leading to a lot of branching where the classes have to behave differently based on their state and is going to push some errors into runtime that would otherwise be obvious.
I think it may make sense to have a parallel set of classes (UnboundValuePredicate and BoundValuePredicate) which represent the new hierarchy and live in parallel to the legacy classes (BoundSet, BoundLieteral, BoundUnary).
<img width="1171" height="869" alt="image" src="https://github.com/user-attachments/assets/89fc9f49-c4c6-4b7f-977d-5458138c889f" />
We could still expose Left(), right() in the older classes maybe through a shared interface?
I'm doing some prototyping to see what the damage actually is in this approach
I'm not sure I like the old classes absorbing the functionality from the new ValueExpressions things. It seems to be leading to a lot of branching where the classes have to behave differently based on their state and is going to push some errors into runtime that would otherwise be obvious.
I don't think this is necessarily true. Anywhere a expression is used currently remains the same and everything should continue to work (parsing/visitors/evaluators/etc). Anything that is parsed into the new expression grammar would work with the new value/predicate representation.
I think it may make sense to have a parallel set of classes (UnboundValuePredicate and BoundValuePredicate) which represent the new hierarchy and live in parallel to the legacy classes (BoundSet, BoundLieteral, BoundUnary).
The issue here is we would have to separate grammar structures and potentially need to support both or translate between the two.
> I'm doing some prototyping to see what the damage actually is in this approach
"and" uses a function binder to resolve function calls?
Will iceberg_functions also be resolved automatically or is the function binder responsible for that?
I would make this package-private until we want to expose FunctionBinder.
What is the downside to having an op for expression types? The addition of an APPLY operation makes sense to me, and I don't think it would be confusing to have ID_REF, NAMED_REF, and LITERAL as well.
The operation here allows us to collapse implementations into the same class (for instance, Predicate with multiple operations) and to be able to dispatch calls in visitors without going through a series of instanceof checks. Those uses are still valid so I don't think I would make this change.
Looks like the only literals that don't have a type are AboveMax and BelowMin. That's reasonable because those are not exposed outside of the package and are used for multiple types.
UnboundTerm is a ValueExpression, so I would expect this to set left to term and treat term like a ValueExpression in all cases. Otherwise, it looks like this keeps the existing term handling separate, which doesn't seem right.
We typically avoid validations that are used inline like this.
I am also not sure why this is needed. It looks like the intended behavior is to make term and ref throw an exception when they are accessed, but then this is called from BoundPredicate#eval and BoundPredicate#test, both of which do not require a term since a predicate could be created using a ValueExpression instead.
I think that BoundPredicate (and probably Predicate) needs to be updated so to use a term replacement (maybe child) natively, then implement term when possible.
huaxingao
danielcweeks
This PR is still __WIP / DRAFT__
This PR includes the changes necessary to update the class hierarchy for expressions to support the new expressions spec.
The goal is to
ValueExpressionside of the expressions with both unbound and bound variantsAs part of this change, the existing
Expressioninterface is promoted to be a super interface ofValueExpressionandPredicate. This is largely for implementation purposes where the spec allows for either anEXPRorPREDICATE(like function arguments).A high-level overview of bound/unbound is:
<img width="667" height="188" alt="image" src="https://github.com/user-attachments/assets/1bb6fe20-e86f-46bd-86c1-67eb3438ec5d" />
A a quick overview of the legacy vs. new interfaces for predicates is:
<img width="1021" height="188" alt="image" src="https://github.com/user-attachments/assets/62272163-792d-4c72-a0f6-14f3e7cad594" />
AI Disclosure: