Skip to content

Conversation

@andygrove
Copy link
Member

@andygrove andygrove commented Jul 13, 2022

Which issue does this PR close?

Part of #2907

Rationale for this change

I was hitting the following error when running a query due to common_subexpr_eliminate creating an invalid projection and this was hard to track down.

thread 'q11' panicked at 'index out of bounds: the len is 12 but the index is 12'

Rather than create the Projection struct directly, it is better to call a try_new constructor that can:

  • Perform some basic validation checks
  • Build the schema if none is provided to reduce boilerplate code for producing projection schemas

This gave a better error:

FAILURE: Plan("Projection has mismatch between number of expressions (12) and number of fields in schema (42)")

What changes are included in this PR?

Introduce try_new constructor and use that instead of creating structs directly

Are there any user-facing changes?

No, this is not a breaking change.

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules labels Jul 13, 2022
@andygrove andygrove changed the title MINOR: Add Projection::try_new MINOR: Add Projection::try_new and Projection::try_new_with_schema Jul 13, 2022
@andygrove andygrove changed the title MINOR: Add Projection::try_new and Projection::try_new_with_schema Add Projection::try_new and Projection::try_new_with_schema and fix invalid projection in common_subexpr_eliminate Jul 14, 2022
Comment on lines 292 to 293
let mut schema = DFSchema::new_with_metadata(fields, HashMap::new())?;
schema.merge(input.schema());
Copy link
Member Author

@andygrove andygrove Jul 14, 2022

Choose a reason for hiding this comment

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

This is the fix for #2907. This code is incorrect and is producing a projection output schema containing all the fields from the input schema. The code now just relies on the logic in Projection::try_new to produce a valid schema based on the projection expressions.

No, it wasn't the fix.

@andygrove andygrove changed the title Add Projection::try_new and Projection::try_new_with_schema and fix invalid projection in common_subexpr_eliminate Add Projection::try_new and Projection::try_new_with_schema Jul 14, 2022
@andygrove andygrove requested a review from alamb July 14, 2022 15:26
@andygrove
Copy link
Member Author

@jdye64 This is the first step in tackling the index out-of-bounds issue. Could you review?

@jdye64
Copy link
Contributor

jdye64 commented Jul 14, 2022

Sure thing, I'm cherry picking a few things to try on my local setup. If that all goes as planned will review the actual changes.

Copy link
Contributor

@jdye64 jdye64 left a comment

Choose a reason for hiding this comment

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

LGTM, will be handy to have this check and more clear errors.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks like a nice improvement to me (and we now have a test!)

To be clear this doesn't fix any underlying bugs (yet), it just is refactoring the code to make it easer to test, right (which I think is great ❤️ )

👍

}

#[test]
fn projection_expr_schema_mismatch() -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@andygrove andygrove merged commit 034678b into apache:master Jul 14, 2022
@andygrove andygrove deleted the projection-new branch July 14, 2022 17:01
@ursabot
Copy link

ursabot commented Jul 14, 2022

Benchmark runs are scheduled for baseline = 9401d6d and contender = 034678b. 034678b is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants