This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 0f994afff2 Support field access for literal Null (#10655)
0f994afff2 is described below
commit 0f994afff27a6240c7ad0831eda4e957bc55e7c4
Author: Andrew Lamb <[email protected]>
AuthorDate: Sat May 25 06:13:41 2024 -0400
Support field access for literal Null (#10655)
---
datafusion/core/tests/expr_api/mod.rs | 27 ++++++++++++++++++++++++---
datafusion/functions/src/core/getfield.rs | 7 +++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/datafusion/core/tests/expr_api/mod.rs
b/datafusion/core/tests/expr_api/mod.rs
index a4eeed1da6..a69f7bd484 100644
--- a/datafusion/core/tests/expr_api/mod.rs
+++ b/datafusion/core/tests/expr_api/mod.rs
@@ -20,7 +20,7 @@ use arrow_array::builder::{ListBuilder, StringBuilder};
use arrow_array::{ArrayRef, RecordBatch, StringArray, StructArray};
use arrow_schema::{DataType, Field};
use datafusion::prelude::*;
-use datafusion_common::DFSchema;
+use datafusion_common::{DFSchema, ScalarValue};
use datafusion_functions::core::expr_ext::FieldAccessor;
use datafusion_functions_array::expr_ext::{IndexAccessor, SliceAccessor};
/// Tests of using and evaluating `Expr`s outside the context of a LogicalPlan
@@ -78,6 +78,21 @@ fn test_get_field() {
);
}
+#[test]
+fn test_get_field_null() {
+ #[rustfmt::skip]
+ evaluate_expr_test(
+ lit(ScalarValue::Null).field("a"),
+ vec![
+ "+------+",
+ "| expr |",
+ "+------+",
+ "| |",
+ "+------+",
+ ],
+ );
+}
+
#[test]
fn test_nested_get_field() {
evaluate_expr_test(
@@ -98,11 +113,17 @@ fn test_nested_get_field() {
}
#[test]
-fn test_list() {
+fn test_list_index() {
+ #[rustfmt::skip]
evaluate_expr_test(
col("list").index(lit(1i64)),
vec![
- "+------+", "| expr |", "+------+", "| one |", "| two |", "|
five |",
+ "+------+",
+ "| expr |",
+ "+------+",
+ "| one |",
+ "| two |",
+ "| five |",
"+------+",
],
);
diff --git a/datafusion/functions/src/core/getfield.rs
b/datafusion/functions/src/core/getfield.rs
index 50c917548d..0013655e6d 100644
--- a/datafusion/functions/src/core/getfield.rs
+++ b/datafusion/functions/src/core/getfield.rs
@@ -106,6 +106,9 @@ impl ScalarUDFImpl for GetFieldFunc {
};
let access_schema = GetFieldAccessSchema::NamedStructField { name:
name.clone() };
let arg_dt = args[0].get_type(schema)?;
+ if arg_dt.is_null() {
+ return Ok(DataType::Null);
+ }
access_schema
.get_accessed_field(&arg_dt)
.map(|f| f.data_type().clone())
@@ -119,6 +122,10 @@ impl ScalarUDFImpl for GetFieldFunc {
);
}
+ if args[0].data_type().is_null() {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Null));
+ }
+
let arrays = ColumnarValue::values_to_arrays(args)?;
let array = arrays[0].clone();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]