-
Notifications
You must be signed in to change notification settings - Fork 280
fix(spark-expr): handle array length mismatch in datediff for dictionary-backed timestamps #3278
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,9 +71,22 @@ impl ScalarUDFImpl for SparkDateDiff { | |
| fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> { | ||
| let [end_date, start_date] = take_function_args(self.name(), args.args)?; | ||
|
|
||
| // Convert scalars to arrays for uniform processing | ||
| let end_arr = end_date.into_array(1)?; | ||
| let start_arr = start_date.into_array(1)?; | ||
| // Determine target length (broadcast scalars to column length) | ||
| let len = match (&end_date, &start_date) { | ||
| (ColumnarValue::Array(a), _) => a.len(), | ||
| (_, ColumnarValue::Array(a)) => a.len(), | ||
| _ => 1, | ||
| }; | ||
|
|
||
| // Convert both arguments to arrays of the same length | ||
| let end_arr = end_date.into_array(len)?; | ||
| let start_arr = start_date.into_array(len)?; | ||
|
|
||
| // Normalize dictionary arrays (important for Iceberg) | ||
| let end_arr = arrow::compute::cast(&end_arr, &DataType::Date32) | ||
| .map_err(|e| DataFusionError::Execution(e.to_string()))?; | ||
| let start_arr = arrow::compute::cast(&start_arr, &DataType::Date32) | ||
| .map_err(|e| DataFusionError::Execution(e.to_string()))?; | ||
|
|
||
| let end_date_array = end_arr | ||
| .as_any() | ||
|
|
@@ -97,8 +110,4 @@ impl ScalarUDFImpl for SparkDateDiff { | |
|
|
||
| Ok(ColumnarValue::Array(Arc::new(result))) | ||
| } | ||
|
|
||
| fn aliases(&self) -> &[String] { | ||
| &self.aliases | ||
| } | ||
| } | ||
|
Comment on lines
110
to
113
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed?