Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not error in optimizer if resulting schema has different metadata #4347

Merged
merged 1 commit into from
Nov 26, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Nov 23, 2022

Which issue does this PR close?

Closes #4346

Note this PR is almost all tests

Rationale for this change

Optimizer passes do not necessarily keep nullability and metadata the same between passes

See #4346 for more detail

What changes are included in this PR?

  1. Make the check added in add a checker to confirm optimizer can keep plan schema immutable. #4233 less stringent by only checking field name and data type.

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added the optimizer Optimizer rules label Nov 23, 2022
fn generate_same_schema_different_metadata() {
// if the plan creates more metadata than previously (because
// some wrapping functions are removed, etc) do not error
let opt = Optimizer::with_rules(vec![Arc::new(GetTableScanRule {})]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test mimics what I was seeing in IOx

@@ -225,7 +225,7 @@ impl Optimizer {
let result = rule.try_optimize(&new_plan, optimizer_config);
match result {
Ok(Some(plan)) => {
if plan.schema() != new_plan.schema() {
if !plan.schema().equivalent_names_and_types(new_plan.schema()) {
Copy link
Contributor Author

@alamb alamb Nov 23, 2022

Choose a reason for hiding this comment

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

This is the actual change

@alamb alamb marked this pull request as draft November 23, 2022 20:54
@alamb
Copy link
Contributor Author

alamb commented Nov 23, 2022

@jackwener and @mingmwang can you please take a look?

@alamb alamb marked this pull request as ready for review November 23, 2022 21:05
&& f1.name() == f2.name()
})
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Some complex arrow types are nested types and can include other Fields.

    /// A list of some logical data type with variable length.
    List(Box<Field>),
    /// A list of some logical data type with fixed length.
    FixedSizeList(Box<Field>, i32),
    /// A list of some logical data type with variable length and 64-bit offsets.
    LargeList(Box<Field>),
    /// A nested datatype that contains a number of sub-fields.
    Struct(Vec<Field>),

https://github.com/apache/arrow-rs/blob/cea5146b69b3413a1d5caa946e0774ec8d834e95/arrow-schema/src/datatype.rs#L163-L187

@mingmwang
Copy link
Contributor

mingmwang commented Nov 24, 2022

I would suggest to add the schema equal method to arrow-rs add the new method for Field, DataType and Schema.
Maybe we can call the new method semantic_equals() or semantic_eq() .

@alamb
Copy link
Contributor Author

alamb commented Nov 24, 2022

I would suggest to add the schema equal method to arrow-rs add the new method for Field, DataType and Schema.
Maybe we can call the new method semantic_equals() or semantic_eq() .

This is a good idea -- I will do so

@alamb
Copy link
Contributor Author

alamb commented Nov 26, 2022

As this error is blocking my upgrade of DataFusion into IOx my plan is to file tickets for the follow on work and merge this one in (I will also try and prepare a PR to support the nested types as well)

@alamb
Copy link
Contributor Author

alamb commented Nov 26, 2022

Follow up in arrow-rs: apache/arrow-rs#3199 (will add this link in comments in a follow on PR)

@alamb alamb merged commit a61615b into apache:master Nov 26, 2022
@alamb alamb deleted the alamb/fix_schema_error branch November 26, 2022 11:16
@ursabot
Copy link

ursabot commented Nov 26, 2022

Benchmark runs are scheduled for baseline = ba73c81 and contender = a61615b. a61615b 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
optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimizer check errors if resulting schema has different metadata
3 participants