mustafasrepo commented on code in PR #9273:
URL: https://github.com/apache/arrow-datafusion/pull/9273#discussion_r1495414929
##########
datafusion/physical-expr/src/equivalence/properties.rs:
##########
@@ -426,6 +426,71 @@ impl EquivalenceProperties {
(!meet.is_empty()).then_some(meet)
}
+ /// we substitute the ordering according to input expression type, this is
a simplified version
+ /// In this case, we just substitute when the expression satisfy the
following condition:
+ /// I. just have one column and is a CAST expression
+ /// TODO: Add one-to-ones analysis for monotonic ScalarFunctions.
+ /// TODO: we could precompute all the scenario that is computable, for
example: atan(x + 1000) should also be substituted if
+ /// x is DESC or ASC
+ /// After substitution, we may generate more than 1 `LexOrdering`. As an
example,
+ /// `[a ASC, b ASC]` will turn into `[a ASC, b ASC], [CAST(a) ASC, b ASC]`
when projection expressions `a, b, CAST(a)` is applied.
+ pub fn substitute_ordering_component(
+ &self,
+ mapping: &ProjectionMapping,
+ sort_expr: &[PhysicalSortExpr],
+ ) -> Result<Vec<Vec<PhysicalSortExpr>>> {
+ let new_orderings = sort_expr
+ .iter()
+ .map(|sort_expr| {
+ let referring_exprs: Vec<_> = mapping
+ .iter()
+ .map(|(source, _target)| source)
+ .filter(|source| expr_refers(source, &sort_expr.expr))
+ .cloned()
+ .collect();
+ let mut res = vec![sort_expr.clone()];
+ // TODO: Add one-to-ones analysis for ScalarFunctions.
+ for r_expr in referring_exprs {
+ // we check whether this expression is substitutable or not
+ if let Some(cast_expr) =
r_expr.as_any().downcast_ref::<CastExpr>() {
+ // we need to know whether the Cast Expr matches or not
+ let expr_type =
sort_expr.expr.data_type(&self.schema)?;
+ if cast_expr.expr.eq(&sort_expr.expr)
Review Comment:
For substitution, we need one-to-one ness condition as well as monotonicity
condition. One we have one-to-oneness support for ScalarFunctions we can add
this support. See my counter example in the
[discussion](https://github.com/apache/arrow-datafusion/pull/9127#issuecomment-1945936404).
However, given `[a ASC, b ASC]` is satisfied `[monotonic_fn(a) ASC]` is
still satisfied. (However, `[monotonic_fn(a) ASC, b ASC]` is not unless
monotonic_fn is not one-to-one function.)
And as far as I know, Datafusion can determine `[monotonic_fn(a) ASC]` is
satisfied currently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]