-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Runji Wang <[email protected]> Co-authored-by: Runji Wang <[email protected]>
- Loading branch information
1 parent
084daa8
commit 9c98d26
Showing
12 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
query I | ||
select array_min(array[1, 2, 3]); | ||
---- | ||
1 | ||
|
||
query I | ||
select array_min(array[2, 3, 5, 2, 4]); | ||
---- | ||
2 | ||
|
||
query I | ||
select array_min(array[114514, 123456]); | ||
---- | ||
114514 | ||
|
||
query I | ||
select array_min(array['a', 'b', 'c', 'a']); | ||
---- | ||
a | ||
|
||
query I | ||
select array_min(array['e💩a', 'f🤔️e', 'c🥵c', 'g🥳g', 'e💩e']); | ||
---- | ||
c🥵c | ||
|
||
query I | ||
select array_min(array['901😅🤔😅️109', '114🥵514', '3🤣🥳3', '5🥵💩💩🥵5']); | ||
---- | ||
114🥵514 | ||
|
||
query error invalid digit found in string | ||
select array_min(array['a', 'b', 'c', 114514]); | ||
|
||
query error invalid digit found in string | ||
select array_min(array[114514, 'a', 'b', 'c']); | ||
|
||
# i32::MIN & i32::MIN - 1 & i32::MAX | ||
query I | ||
select array_min(array[-2147483648, 2147483647, -2147483649]); | ||
---- | ||
-2147483649 | ||
|
||
# i64::MIN & i64::MIN - 1 & i64::MAX | ||
query I | ||
select array_min(array[-9223372036854775808, 9223372036854775807, -9223372036854775809]); | ||
---- | ||
-9223372036854775809 | ||
|
||
query I | ||
select array_min(array['a', '', 'c']); | ||
---- | ||
(empty) | ||
|
||
query I | ||
select array_min(array[3.14, 1.14, 1.14514]); | ||
---- | ||
1.14 | ||
|
||
query I | ||
select array_min(array[3.1415926, 191.14, 114514, 1313.1414]); | ||
---- | ||
3.1415926 | ||
|
||
query I | ||
select array_min(array[1e-4, 1.14514e5, 1.14514e-5]); | ||
---- | ||
0.0000114514 | ||
|
||
query I | ||
select array_min(array[date'2002-10-30', date'2023-09-06', date'2017-06-18']); | ||
---- | ||
2002-10-30 | ||
|
||
query I | ||
select array_min( | ||
array[ | ||
'2002-10-30 00:00:00'::timestamp, | ||
'2023-09-06 13:10:00'::timestamp, | ||
'2017-06-18 12:00:00'::timestamp | ||
] | ||
); | ||
---- | ||
2002-10-30 00:00:00 | ||
|
||
query I | ||
select array_min(array['\xDE'::bytea, '\xDF'::bytea, '\xDC'::bytea]); | ||
---- | ||
\xdc | ||
|
||
query I | ||
select array_min(array[NULL, 'a', 'b']); | ||
---- | ||
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::array::*; | ||
use risingwave_common::types::{DefaultOrdered, Scalar, ToOwnedDatum}; | ||
use risingwave_expr_macro::function; | ||
|
||
use crate::Result; | ||
|
||
#[function("array_min(list) -> *int")] | ||
#[function("array_min(list) -> *float")] | ||
#[function("array_min(list) -> decimal")] | ||
#[function("array_min(list) -> serial")] | ||
#[function("array_min(list) -> int256")] | ||
#[function("array_min(list) -> date")] | ||
#[function("array_min(list) -> time")] | ||
#[function("array_min(list) -> timestamp")] | ||
#[function("array_min(list) -> timestamptz")] | ||
#[function("array_min(list) -> varchar")] | ||
#[function("array_min(list) -> bytea")] | ||
pub fn array_min<T: Scalar>(list: ListRef<'_>) -> Result<Option<T>> { | ||
let min_value = list.iter().flatten().map(DefaultOrdered).min(); | ||
match min_value.map(|v| v.0).to_owned_datum() { | ||
Some(s) => Ok(Some(s.try_into()?)), | ||
None => Ok(None), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters