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/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new b46b7c0ea2 Fix Display for List (#8261)
b46b7c0ea2 is described below
commit b46b7c0ea27e7c5ec63f5367ed04c9612a32d717
Author: Jay Zhan <[email protected]>
AuthorDate: Wed Nov 22 19:31:14 2023 +0800
Fix Display for List (#8261)
* fix display for list
Signed-off-by: jayzhan211 <[email protected]>
* fmt
Signed-off-by: jayzhan211 <[email protected]>
* address comment
Signed-off-by: jayzhan211 <[email protected]>
---------
Signed-off-by: jayzhan211 <[email protected]>
---
datafusion/common/src/scalar.rs | 21 +++++++++++++--------
datafusion/sqllogictest/test_files/explain.slt | 25 +++++++++++++++++++++++++
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index fd1ceb5fad..21cd50dea8 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -34,6 +34,7 @@ use crate::utils::array_into_list_array;
use arrow::buffer::{NullBuffer, OffsetBuffer};
use arrow::compute::kernels::numeric::*;
use arrow::datatypes::{i256, Fields, SchemaBuilder};
+use arrow::util::display::{ArrayFormatter, FormatOptions};
use arrow::{
array::*,
compute::kernels::cast::{cast_with_options, CastOptions},
@@ -2931,12 +2932,14 @@ impl fmt::Display for ScalarValue {
)?,
None => write!(f, "NULL")?,
},
- ScalarValue::List(arr) | ScalarValue::FixedSizeList(arr) => write!(
- f,
- "{}",
- arrow::util::pretty::pretty_format_columns("col",
&[arr.to_owned()])
- .unwrap()
- )?,
+ ScalarValue::List(arr) | ScalarValue::FixedSizeList(arr) => {
+ // ScalarValue List should always have a single element
+ assert_eq!(arr.len(), 1);
+ let options =
FormatOptions::default().with_display_error(true);
+ let formatter = ArrayFormatter::try_new(arr,
&options).unwrap();
+ let value_formatter = formatter.value(0);
+ write!(f, "{value_formatter}")?
+ }
ScalarValue::Date32(e) => format_option!(f, e)?,
ScalarValue::Date64(e) => format_option!(f, e)?,
ScalarValue::Time32Second(e) => format_option!(f, e)?,
@@ -3011,8 +3014,10 @@ impl fmt::Debug for ScalarValue {
}
ScalarValue::LargeBinary(None) => write!(f, "LargeBinary({self})"),
ScalarValue::LargeBinary(Some(_)) => write!(f,
"LargeBinary(\"{self}\")"),
- ScalarValue::FixedSizeList(arr) => write!(f,
"FixedSizeList([{arr:?}])"),
- ScalarValue::List(arr) => write!(f, "List([{arr:?}])"),
+ ScalarValue::FixedSizeList(_) => write!(f,
"FixedSizeList({self})"),
+ ScalarValue::List(_) => {
+ write!(f, "List({self})")
+ }
ScalarValue::Date32(_) => write!(f, "Date32(\"{self}\")"),
ScalarValue::Date64(_) => write!(f, "Date64(\"{self}\")"),
ScalarValue::Time32Second(_) => write!(f,
"Time32Second(\"{self}\")"),
diff --git a/datafusion/sqllogictest/test_files/explain.slt
b/datafusion/sqllogictest/test_files/explain.slt
index 129814767c..c8eff2f301 100644
--- a/datafusion/sqllogictest/test_files/explain.slt
+++ b/datafusion/sqllogictest/test_files/explain.slt
@@ -362,3 +362,28 @@ GlobalLimitExec: skip=0, fetch=10,
statistics=[Rows=Exact(8), Bytes=Absent, [(Co
statement ok
set datafusion.execution.collect_statistics = false;
+
+# Explain ArrayFuncions
+
+statement ok
+set datafusion.explain.physical_plan_only = false
+
+query TT
+explain select make_array(make_array(1, 2, 3), make_array(4, 5, 6));
+----
+logical_plan
+Projection: List([[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)))
+--EmptyRelation
+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)))]
+--EmptyExec: produce_one_row=true
+
+query TT
+explain select [[1, 2, 3], [4, 5, 6]];
+----
+logical_plan
+Projection: List([[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)))
+--EmptyRelation
+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)))]
+--EmptyExec: produce_one_row=true