Skip to content

Commit c063940

Browse files
committed
avoid vec construction
Signed-off-by: Richard Chien <[email protected]>
1 parent b2c8255 commit c063940

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/expr/impl/src/scalar/array_flatten.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use itertools::Itertools;
15+
use itertools::Either;
1616
use risingwave_common::array::{ListRef, ListValue};
1717
use risingwave_common::types::ScalarRefImpl;
1818
use risingwave_expr::{Result, function};
@@ -40,11 +40,21 @@ use risingwave_expr::{Result, function};
4040
/// {1,2,3,4}
4141
///
4242
/// query T
43+
/// select array_flatten(array[array[array[1], array[2, null]], array[array[3, 4], null::int[]]]);
44+
/// ----
45+
/// {{1},{2,NULL},{3,4},NULL}
46+
///
47+
/// query T
4348
/// select array_flatten(array[[]]::int[][]);
4449
/// ----
4550
/// {}
4651
///
4752
/// query T
53+
/// select array_flatten(array[[null, 1]]::int[][]);
54+
/// ----
55+
/// {NULL,1}
56+
///
57+
/// query T
4858
/// select array_flatten(array[]::int[][]);
4959
/// ----
5060
/// {}
@@ -71,10 +81,10 @@ fn array_flatten(array: ListRef<'_>) -> Result<ListValue> {
7181
// Flatten all inner arrays
7282
.flat_map(|inner_array| {
7383
if let ScalarRefImpl::List(inner_list) = inner_array {
74-
inner_list.iter().collect_vec()
84+
Either::Left(inner_list.iter())
7585
} else {
7686
// This shouldn't happen but handle it gracefully
77-
vec![]
87+
Either::Right(std::iter::empty())
7888
}
7989
}),
8090
))

0 commit comments

Comments
 (0)