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

Fallback on null empty value in ExprBoundaries::try_from_column #8501

Merged
Merged
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
3 changes: 2 additions & 1 deletion datafusion/physical-expr/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl ExprBoundaries {
col_index: usize,
) -> Result<Self> {
let field = &schema.fields()[col_index];
let empty_field = ScalarValue::try_from(field.data_type())?;
let empty_field =
ScalarValue::try_from(field.data_type()).unwrap_or(ScalarValue::Null);
let interval = Interval::try_new(
col_stats
.min_value
Expand Down
21 changes: 21 additions & 0 deletions datafusion/sqllogictest/src/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ impl TestContext {
info!("Registering table with many types");
register_table_with_many_types(test_ctx.session_ctx()).await;
}
"explain.slt" => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I couldn't find a SQL syntax to create a table containing a map data type, I created it here in code.

info!("Registering table with map");
register_table_with_map(test_ctx.session_ctx()).await;
}
"avro.slt" => {
#[cfg(feature = "avro")]
{
Expand Down Expand Up @@ -268,6 +272,23 @@ pub async fn register_table_with_many_types(ctx: &SessionContext) {
.unwrap();
}

pub async fn register_table_with_map(ctx: &SessionContext) {
let key = Field::new("key", DataType::Int64, false);
let value = Field::new("value", DataType::Int64, true);
let map_field =
Field::new("entries", DataType::Struct(vec![key, value].into()), false);
let fields = vec![
Field::new("int_field", DataType::Int64, true),
Field::new("map_field", DataType::Map(map_field.into(), false), true),
];
let schema = Schema::new(fields);

let memory_table = MemTable::try_new(schema.into(), vec![vec![]]).unwrap();

ctx.register_table("table_with_map", Arc::new(memory_table))
.unwrap();
}

fn table_with_many_types() -> Arc<dyn TableProvider> {
let schema = Schema::new(vec![
Field::new("int32_col", DataType::Int32, false),
Expand Down
4 changes: 4 additions & 0 deletions datafusion/sqllogictest/test_files/explain.slt
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,7 @@ Projection: List([[1, 2, 3], [4, 5, 6]]) AS make_array(make_array(Int64(1),Int64
physical_plan
ProjectionExec: expr=[[[1, 2, 3], [4, 5, 6]] as make_array(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(4),Int64(5),Int64(6)))]
--PlaceholderRowExec

# Testing explain on a table with a map filter, registered in test_context.rs.
statement ok
explain select * from table_with_map where int_field > 0