Skip to content

Commit

Permalink
fix(frontend): display_for_explain for ListValue (#7571)
Browse files Browse the repository at this point in the history
I believe this bug was not caught before: #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 #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 <jon-chuang@users.noreply.github.com>
Co-Authored-By: jon-chuang <9093549+jon-chuang@users.noreply.github.com>
  • Loading branch information
jon-chuang and jon-chuang authored Jan 30, 2023
1 parent 1d2bb32 commit 9f64e93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/common/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<String>>()
.join(", ")
)
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/planner_test/tests/testdata/expr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] } }
3 changes: 2 additions & 1 deletion src/frontend/planner_test/tests/testdata/shared_views.yaml
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) }
└─StreamTableScan { table: t1, columns: [t1.x, t1.y, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) }

0 comments on commit 9f64e93

Please sign in to comment.