Skip to content

Conversation

@retikulum
Copy link
Contributor

Which issue does this PR close?

This is discussed in #3152.

Rationale for this change

This is the new PR of improving error handling for downcasting. In #4261 we found out that there is a downcast_value! macro which also covers our casting functions. Implementing as_xxx_array function with downcast_value! is nearly decided for now for future PRs. This PR is small compared to last two PR because I want to hear your feedback about if my implementation is correct/desired?

What changes are included in this PR?

  • Refactor previous casting functions. Old function:
pub fn as_int32_array(array: &dyn Array) -> Result<&Int32Array, DataFusionError> {
    array.as_any().downcast_ref::<Int32Array>().ok_or_else(|| {
        DataFusionError::Internal(format!(
            "Expected a Int32Array, got: {}",
            array.data_type()
        ))
    })

New function:

pub fn as_int32_array(array: &dyn Array) -> Result<&Int32Array, DataFusionError> {
    Ok(downcast_value!(array, Int32Array))
}
  • Refactor ListArray downcasting parts where following lines are used:
as_any().downcast_ref::<ListArray>().unwrap()

Are these changes tested?

These changes passed related tests.

@github-actions github-actions bot added core Core DataFusion crate physical-expr Changes to the physical-expr crates labels Nov 21, 2022
Copy link
Member

@xudong963 xudong963 left a comment

Choose a reason for hiding this comment

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

Nice clean!

@alamb alamb merged commit bfce076 into apache:master Nov 22, 2022
@alamb
Copy link
Contributor

alamb commented Nov 22, 2022

I love to see the code train chugging along!

@ursabot
Copy link

ursabot commented Nov 22, 2022

Benchmark runs are scheduled for baseline = 92325bf and contender = bfce076. bfce076 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

@retikulum retikulum deleted the 3152_refactor_with_downcastvalue branch November 23, 2022 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants