Skip to content

Implement physical planner support for DATE +/- INTERVAL - #2357

Merged
andygrove merged 6 commits into
apache:masterfrom
andygrove:cast-daytime-date32
May 1, 2022
Merged

andygrove merged 6 commits into
apache:masterfrom
andygrove:cast-daytime-date32

Conversation

@andygrove

@andygrove andygrove commented Apr 27, 2022 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #2236

Rationale for this change

Increasing our SQL support.

What changes are included in this PR?

  • Implement DateIntervalExpr physical expression. Note that for now it only supports scalar inputs. This is enough to support SQL expressions such as cast('1999-4-01' as date) + INTERVAL '60 DAYS' which get simplified during optimization and replaced with a scalar value.

Are there any user-facing changes?

No

let plan = ctx.create_logical_plan(sql).expect(&msg);
let plan = ctx
.create_logical_plan(sql)
.map_err(|e| format!("{:?} at {}", e, msg))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the tests show the actual error that happened so makes debugging much easier

@andygrove
andygrove marked this pull request as draft April 27, 2022 16:01
@andygrove andygrove changed the title simplify_expressions no longer panics on unsupported evaluations WIP: simplify_expressions no longer panics on unsupported evaluations Apr 27, 2022
pub(crate) fn evaluate_to_scalar(&self, expr: &Expr) -> Result<ScalarValue> {
if let Expr::Literal(s) = expr {
return Ok(s);
return Ok(s.clone());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone is unfortunate -- I wonder if there is some way to pass it back. Like for example a signature such as he following (aka return the Expr as the error if the evaluation doesn't work)?

Maybe with some debugging messages on error (via debug!) would be sufficent?

    pub(crate) fn evaluate_to_scalar(&self, expr: Expr) -> std::result::Result<ScalarValue, Expr> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb I reverted this change and actually completely changed direction on this PR ... please see the updated PR description.

@andygrove andygrove changed the title WIP: simplify_expressions no longer panics on unsupported evaluations WIP: Implement DateIntervalExpr physical expression Apr 29, 2022
@andygrove andygrove changed the title WIP: Implement DateIntervalExpr physical expression WIP: Implement physical planner support for DATE +/- INTERVAL Apr 29, 2022
@andygrove andygrove changed the title WIP: Implement physical planner support for DATE +/- INTERVAL Implement physical planner support for DATE +/- INTERVAL Apr 29, 2022
@andygrove
andygrove marked this pull request as ready for review April 29, 2022 18:32
execution_props,
)?;
binary(lhs, *op, rhs, input_schema)
match (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach to use a specialized operator

I think over the long term, the ideal outcome would be to extend the arrow temporal kernels https://github.com/apache/arrow-rs/blob/master/arrow/src/compute/kernels/temporal.rs with the actual calculation logic.

However, incubating the kernels within datafusion seems like a great idea

@yjshen yjshen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andygrove
andygrove merged commit 98ce80f into apache:master May 1, 2022
@andygrove
andygrove deleted the cast-daytime-date32 branch May 1, 2022 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement physical planner support for DATE +/- INTERVAL

3 participants