berkaysynnada opened a new pull request, #5764:
URL: https://github.com/apache/arrow-datafusion/pull/5764
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #5704 and #194.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
We can handle such queries now:
`SELECT val, ts1 - ts2 AS ts_diff FROM table_a`
`SELECT val, interval1 - interval2 AS interval_diff FROM table_a`
`SELECT val, ts1 - interval1 AS ts_interval_diff FROM table_a`
`SELECT val, interval1 + ts1 AS interval_ts_sub FROM table_a`
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
| - | +
-- | -- | --
timestamp op timestamp (same type) | OK: second and millisecond types give
results in daytime(day+millisecond), microsecond and nanosecond types give
result in monthdaynano(month+day+nano, but month field is not used) | N/A
timestamp op timestamp (different types) | N/A | N/A
interval op interval (same type) | OK: operations are done field by field,
gives the same type | OK: operations are done field by field, gives the same
type
interval op interval (different types) | OK: give result in monthdaynano
type | OK: give result in monthdaynano type
timestamp op interval | OK: give result in the type of the timestamp | OK:
give result in the type of the timestamp
interval op timestamp | N/A | OK: the same of timestamp + interval
Some match expressions in planner.rs, binary.rs, and datetime.rs are
extended. Coerced types and allowable operations are shown in the table.
I try to use existing scalar value functions as much as possible to not
duplicate. However, in arrow.rs, subtraction and addition functions are for
numeric types, hence I need to add some functions to call with `binary`
function.
In datetime.rs, the `evaluate` function was written to accept only "Array +
Scalar" or "Scalar + Scalar" values to evaluate. It is extended to accept
"Array + Array", and 4 different variations of that case (Timestamp op
Timestamp, Interval op Interval, Timestamp op Interval, Interval op Timestamp)
are implemented. "Array + Scalar" evaluations are done with `unary` function in
arrow.rs, and I follow the similar pattern with `try_binary_op` function.
`try_binary_op` function is a modified version of `binary` function in
arrow-rs. The only difference is that it returns `Result` and creates the
buffer with `try_from_trusted_len_iter`. Otherwise, we had to unwrap the op
function sent to binary.
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
Yes, there are tests for each match in timestamp.slt. However, tables with
intervals cannot be created like `INTERVAL '1 second'`, since some work is
needed in arrow-rs for casting. Timestamp difference case with timezone is also
left in timestamp.rs because of a similar reason.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
--
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]