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

Improve error handling and add some more types for proper downcasting #4352

Merged
merged 1 commit into from
Nov 27, 2022

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.

What changes are included in this PR?

  • Refactor previous casting functions.
  • Add some more types for downcasting.
  • I remove some macros and use my downcasting functions in string_expression.rs. Please review it carefully. I don't want to break crucial parts.

@github-actions github-actions bot added core Core DataFusion crate physical-expr Physical Expressions labels Nov 23, 2022
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.

I reviewed this PR carefully -- thank you @retikulum

@@ -720,7 +722,7 @@ fn get_dict_value<K: ArrowDictionaryKeyType>(
array: &ArrayRef,
index: usize,
) -> (&ArrayRef, Option<usize>) {
let dict_array = as_dictionary_array::<K>(array);
let dict_array = as_dictionary_array::<K>(array).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

for other reviewers, the rationale here is that arrow cast kernels used previously panic internally if the type is incorrect -- the ones in DataFusion return an error instead

.as_any()
.downcast_ref::<PrimitiveArray<Int32Type>>()
.unwrap(),
as_primitive_array::<Int32Type>(batch.column(*i)).unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

.ok_or(DataFusionError::Internal(
"median! macro failed to cast array to expected type".to_string(),
))?;
let array = as_primitive_array::<$TY>(&sorted)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

much nicer

@@ -50,43 +53,6 @@ macro_rules! downcast_string_arg {
}};
}

macro_rules! downcast_primitive_array_arg {
Copy link
Contributor

Choose a reason for hiding this comment

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

I reviewed the changes in this module carefully and they look good to me -- thank you @retikulum

@alamb alamb merged commit da54fa5 into apache:master Nov 27, 2022
@ursabot
Copy link

ursabot commented Nov 27, 2022

Benchmark runs are scheduled for baseline = 0496904 and contender = da54fa5. da54fa5 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_improve_error_handling branch November 29, 2022 07:21
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 Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants