-
Notifications
You must be signed in to change notification settings - Fork 331
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
4121cdd
08f67c0
c9b27fb
395f863
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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| // under the License. | ||
|
|
||
| use arrow::array::{Array, Date32Array, Int32Array}; | ||
| use arrow::compute::cast; | ||
| use arrow::compute::kernels::arity::binary; | ||
| use arrow::datatypes::DataType; | ||
| use datafusion::common::{utils::take_function_args, DataFusionError, Result}; | ||
|
|
@@ -68,6 +69,10 @@ impl ScalarUDFImpl for SparkDateDiff { | |
| Ok(DataType::Int32) | ||
| } | ||
|
|
||
| fn aliases(&self) -> &[String] { | ||
| &self.aliases | ||
| } | ||
|
|
||
| fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> { | ||
| let [end_date, start_date] = take_function_args(self.name(), args.args)?; | ||
|
|
||
|
|
@@ -84,6 +89,12 @@ impl ScalarUDFImpl for SparkDateDiff { | |
| let end_arr = end_date.into_array(num_rows)?; | ||
| let start_arr = start_date.into_array(num_rows)?; | ||
|
|
||
| // Normalize dictionary arrays (important for Iceberg) | ||
| let end_arr = cast(&end_arr, &DataType::Date32) | ||
| .map_err(|e| DataFusionError::Execution(e.to_string()))?; | ||
| let start_arr = cast(&start_arr, &DataType::Date32) | ||
| .map_err(|e| DataFusionError::Execution(e.to_string()))?; | ||
|
|
||
| let end_date_array = end_arr | ||
| .as_any() | ||
| .downcast_ref::<Date32Array>() | ||
|
|
@@ -106,8 +117,4 @@ impl ScalarUDFImpl for SparkDateDiff { | |
|
|
||
| Ok(ColumnarValue::Array(Arc::new(result))) | ||
| } | ||
|
|
||
| fn aliases(&self) -> &[String] { | ||
| &self.aliases | ||
| } | ||
| } | ||
|
Comment on lines
117
to
120
|
||
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?