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

WIP(iox-10891): patched df upgrade 202-05-20 #21

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions datafusion/core/tests/expr_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +76,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(
Expand All @@ -96,11 +111,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 |",
"+------+",
],
);
Expand Down
7 changes: 7 additions & 0 deletions datafusion/functions/src/core/getfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();

Expand Down