sdf-jkl commented on issue #18319: URL: https://github.com/apache/datafusion/issues/18319#issuecomment-3916823216
> [@sdf-jkl](https://github.com/sdf-jkl) I have a couple questions I'm hoping you can help me out with: > > 1. for `take_function_args` for `date_trunc` function, do I get the comparison operator? I need to know for example if the predicate is an inequality and which direction (<= vs < and >= vs >). > 2. in `preimage` for `date_part` you used `part_normalization` and change the `part` argument to a simplified string. I assume I should expect the same argument for `date_trunc`? As in, I should convert the `part` to a string in a similar manner? > > Thanks! @drin, 1. No, you don't need the comparison operator. `preimage` should return an `Interval` and [`rewrite_with_preimage`](https://github.com/apache/datafusion/blob/468b690d71350bc19c7e7bafd5dc61800973d91e/datafusion/optimizer/src/simplify_expressions/udf_preimage.rs#L29) can determine which bound to use (lower or upper). The comparison operator is outside the function call, so it's not one of the function arguments, you can't retrieve it with `take_function_args`. 2. In `date_part`, we simplify the string to make sure we can parse an `IntervalUnit` from it. `date_trunc`, on the other hand, uses its own `DateTruncGranularity` struct instead of `IntervalUnit` and not doing any extra cleanup in `invoke_with_args` other than `lower()`. You could do the same. ```rust let granularity = DateTruncGranularity::from_str(&granularity_str)?; ``` > For example: > > // lhs(>) --> column >= next_interval(part, const_rhs) > // lhs(<=) --> column < next_interval(part, const_rhs) > If I have date_trunc('month', col('date')) > '2025-12-03', I need to know the > from the predicate in order to know whether the resulting preimage range begins with 2025-12-01 or if it begins with 2026-01-01. The operator will be checked during the `preimage_in_comparison` [rule](https://github.com/apache/datafusion/blob/468b690d71350bc19c7e7bafd5dc61800973d91e/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs#L2004) in `expr_simplifier`, so there is no need to worry about it. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
