forked from gluesql/gluesql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GREATEST function (gluesql#1312)
The GREATEST function in SQL is used to select the largest (maximum) value from a list of expressions. It compares each value and returns the highest value. e.g. GREATEST (expr1, expr2, expr3, ..., expr_n) SELECT GREATEST (5, 10, 15);
- Loading branch information
1 parent
f39316a
commit 9666367
Showing
11 changed files
with
164 additions
and
9 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
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
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,80 @@ | ||
use { | ||
crate::*, | ||
gluesql_core::{ | ||
error::{EvaluateError, TranslateError}, | ||
prelude::Value::*, | ||
}, | ||
}; | ||
|
||
test_case!(greatest, async move { | ||
test!( | ||
"SELECT GREATEST(1,6,9,7,0,10) AS goat;", | ||
Ok(select!( | ||
"goat"; I64; 10 | ||
)) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST(1.2,6.8,9.6,7.4,0.1,10.5) AS goat;", | ||
Ok(select!( | ||
"goat" ; F64; 10.5 | ||
)) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST('bibibik', 'babamba', 'melona') AS goat;", | ||
Ok(select!( | ||
"goat"; Str; "melona".to_owned() | ||
)) | ||
); | ||
|
||
macro_rules! date { | ||
($date: expr) => { | ||
$date.parse().unwrap() | ||
}; | ||
} | ||
|
||
test!( | ||
"SELECT GREATEST( | ||
DATE '2023-07-17', | ||
DATE '2022-07-17', | ||
DATE '2023-06-17', | ||
DATE '2024-07-17', | ||
DATE '2024-07-18') AS goat;", | ||
Ok(select!( | ||
"goat"; Date; date!("2024-07-18") | ||
)) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST() AS goat;", | ||
Err(TranslateError::FunctionArgsLengthNotMatchingMin { | ||
name: "GREATEST".to_owned(), | ||
expected_minimum: 2, | ||
found: 0, | ||
} | ||
.into()) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST(1, 2, 'bibibik') AS goat;", | ||
Err(EvaluateError::NonComparableArgumentError("GREATEST".to_owned()).into()) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST(NULL, 'bibibik', 'babamba', 'melona') AS goat;", | ||
Err(EvaluateError::NonComparableArgumentError("GREATEST".to_owned()).into()) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST(NULL, NULL, NULL) AS goat;", | ||
Err(EvaluateError::NonComparableArgumentError("GREATEST".to_owned()).into()) | ||
); | ||
|
||
test!( | ||
"SELECT GREATEST(true, false) AS goat;", | ||
Ok(select!( | ||
"goat"; Bool; true | ||
)) | ||
); | ||
}); |
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