From 9f64e93bace7516f5dcf99fe0ae9f6e3541cce12 Mon Sep 17 00:00:00 2001 From: jon-chuang <9093549+jon-chuang@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:42:57 +0800 Subject: [PATCH] fix(frontend): `display_for_explain` for `ListValue` (#7571) I believe this bug was not caught before: https://github.com/risingwavelabs/risingwave/pull/7541 because Array is treated as a function. But const_eval would force the Array to be evaluated into the List DataType Anw, let's fix it as it's clearly a bug. After https://github.com/risingwavelabs/risingwave/pull/7541, the new planner test will be evaluated as an List literal, rather than as FunctionCall as per now. Approved-By: st1page Co-Authored-By: jon-chuang Co-Authored-By: jon-chuang <9093549+jon-chuang@users.noreply.github.com> --- src/common/src/array/list_array.rs | 9 +++++++-- src/frontend/planner_test/tests/testdata/expr.yaml | 6 ++++++ .../planner_test/tests/testdata/shared_views.yaml | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/common/src/array/list_array.rs b/src/common/src/array/list_array.rs index 02e05612de3d..1469548e9d83 100644 --- a/src/common/src/array/list_array.rs +++ b/src/common/src/array/list_array.rs @@ -297,12 +297,17 @@ impl Ord for ListValue { // Used to display ListValue in explain for better readibilty. pub fn display_for_explain(list: &ListValue) -> String { - // Example of ListValue display: ARRAY[1, 2] + // Example of ListValue display: ARRAY[1, 2, null] format!( "ARRAY[{}]", list.values .iter() - .map(|v| v.as_ref().unwrap().as_scalar_ref_impl().to_text()) + .map(|v| { + match v.as_ref() { + None => "null".into(), + Some(scalar) => scalar.as_scalar_ref_impl().to_text(), + } + }) .collect::>() .join(", ") ) diff --git a/src/frontend/planner_test/tests/testdata/expr.yaml b/src/frontend/planner_test/tests/testdata/expr.yaml index 0ebf8b1371c4..0c365da376e6 100644 --- a/src/frontend/planner_test/tests/testdata/expr.yaml +++ b/src/frontend/planner_test/tests/testdata/expr.yaml @@ -532,3 +532,9 @@ binder_error: |- Feature is not yet implemented: unsupported function "pg_teminate_backend", do you mean "pg_terminate_backend"? Tracking issue: https://github.com/risingwavelabs/risingwave/issues/112 +- name: regression (#7571) - literal debug display for array with NULL values + sql: | + select ARRAY[1, null] t; + logical_plan: | + LogicalProject { exprs: [Array(1:Int32, null:Int32)] } + └─LogicalValues { rows: [[]], schema: Schema { fields: [] } } diff --git a/src/frontend/planner_test/tests/testdata/shared_views.yaml b/src/frontend/planner_test/tests/testdata/shared_views.yaml index 0191bb22385d..fba887e52df4 100644 --- a/src/frontend/planner_test/tests/testdata/shared_views.yaml +++ b/src/frontend/planner_test/tests/testdata/shared_views.yaml @@ -1,3 +1,4 @@ +# This file is automatically generated. See `src/frontend/planner_test/README.md` for more information. - sql: | create table t1 (x int, y int); create view v1 as select x + y as z from t1 where y > 0; @@ -39,4 +40,4 @@ └─StreamShare { id = 207 } └─StreamProject { exprs: [(t1.x + t1.y), t1._row_id] } └─StreamFilter { predicate: (t1.y > 0:Int32) } - └─StreamTableScan { table: t1, columns: [t1.x, t1.y, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) } \ No newline at end of file + └─StreamTableScan { table: t1, columns: [t1.x, t1.y, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) }