use crate::utils::TestExecution;
mod utils;
static TEST_TABLE: &str = r#"
CREATE TABLE test_table (
utf8_col VARCHAR,
int64_col BIGINT,
float64_col DOUBLE,
date64_col DATE,
time64_col TIME
) AS VALUES
('apple', 1, 1.0, DATE '2021-01-01', TIME '01:00:00'),
('banana', 2, 2.0, DATE '2021-01-02', TIME '02:00:00'),
('apple', 2, 2.0, DATE '2021-01-02', TIME '02:00:00'),
('orange', 3, 3.0, DATE '2021-01-03', TIME '03:00:00'),
('banana', 3, 3.0, DATE '2021-01-03', TIME '03:00:00'),
('apple', 3, 3.0, DATE '2021-01-03', TIME '03:00:00'),
(NULL, NULL, NULL, NULL, NULL);
"#;
#[tokio::test]
async fn test_mode() {
let mut execution = TestExecution::new().await.unwrap().with_setup(TEST_TABLE).await;
let actual = execution.run_and_format("SELECT MODE(utf8_col) FROM test_table").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------------+
- "| mode(test_table.utf8_col) |"
- +---------------------------+
- "| apple |"
- +---------------------------+
"###);
let actual = execution.run_and_format("SELECT MODE(int64_col) FROM test_table").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----------------------------+
- "| mode(test_table.int64_col) |"
- +----------------------------+
- "| 3 |"
- +----------------------------+
"###);
let actual = execution
.run_and_format("SELECT MODE(float64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +------------------------------+
- "| mode(test_table.float64_col) |"
- +------------------------------+
- "| 3.0 |"
- +------------------------------+
"###);
let actual = execution
.run_and_format("SELECT MODE(date64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-----------------------------+
- "| mode(test_table.date64_col) |"
- +-----------------------------+
- "| 2021-01-03 |"
- +-----------------------------+
"###);
}
#[tokio::test]
async fn test_mode_time64() {
let mut execution = TestExecution::new().await.unwrap().with_setup(TEST_TABLE).await;
let actual = execution
.run_and_format("SELECT MODE(time64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-----------------------------+
- "| mode(test_table.time64_col) |"
- +-----------------------------+
- "| 03:00:00 |"
- +-----------------------------+
"###);
}
#[tokio::test]
async fn test_max_by_and_min_by() {
let mut execution = TestExecution::new().await.unwrap();
let actual = execution
.run_and_format("SELECT max_by(x, y) FROM VALUES (1, 10), (2, 5), (3, 15), (4, 8) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| max_by(tab.x,tab.y) |"
- +---------------------+
- "| 3 |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT min_by(x, y) FROM VALUES (1, 10), (2, 5), (3, 15), (4, 8) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| min_by(tab.x,tab.y) |"
- +---------------------+
- "| 2 |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT max_by(name, length(name)) FROM VALUES ('Alice'), ('Bob'), ('Charlie') as tab(name);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------------------------------+
- "| max_by(tab.name,character_length(tab.name)) |"
- +---------------------------------------------+
- "| Charlie |"
- +---------------------------------------------+
"###);
let actual = execution
.run_and_format("SELECT min_by(name, length(name)) FROM VALUES ('Alice'), ('Bob'), ('Charlie') as tab(name);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------------------------------+
- "| min_by(tab.name,character_length(tab.name)) |"
- +---------------------------------------------+
- "| Bob |"
- +---------------------------------------------+
"###);
let actual = execution
.run_and_format("SELECT max_by(x, y) FROM VALUES (1, 10), (2, null), (3, 15), (null, 8) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| max_by(tab.x,tab.y) |"
- +---------------------+
- "| 2 |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT min_by(x, y) FROM VALUES (1, 10), (2, null), (3, 15), (null, 8) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| min_by(tab.x,tab.y) |"
- +---------------------+
- "| 2 |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT max_by(x, y) FROM VALUES (1, 10) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| max_by(tab.x,tab.y) |"
- +---------------------+
- "| 1 |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT min_by(x, y) FROM VALUES (1, 10) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| min_by(tab.x,tab.y) |"
- +---------------------+
- "| 1 |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT max_by(x, y) FROM (SELECT * FROM (VALUES (1, 10)) WHERE 1=0) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| max_by(tab.x,tab.y) |"
- +---------------------+
- "| |"
- +---------------------+
"###);
let actual = execution
.run_and_format("SELECT min_by(x, y) FROM (SELECT * FROM (VALUES (1, 10)) WHERE 1=0) as tab(x, y);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +---------------------+
- "| min_by(tab.x,tab.y) |"
- +---------------------+
- "| |"
- +---------------------+
"###);
}
#[tokio::test]
async fn test_kurtosis_pop() {
let mut execution = TestExecution::new().await.unwrap().with_setup(TEST_TABLE).await;
let actual = execution
.run_and_format("SELECT kurtosis_pop(int64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +------------------------------------+
- "| kurtosis_pop(test_table.int64_col) |"
- +------------------------------------+
- "| -0.9599999999999755 |"
- +------------------------------------+
"###);
let actual = execution
.run_and_format("SELECT kurtosis_pop(float64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +--------------------------------------+
- "| kurtosis_pop(test_table.float64_col) |"
- +--------------------------------------+
- "| -0.9599999999999755 |"
- +--------------------------------------+
"###);
let actual = execution
.run_and_format("SELECT kurtosis_pop(col) FROM VALUES (1.0) as tab(col)")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-----------------------+
- "| kurtosis_pop(tab.col) |"
- +-----------------------+
- "| |"
- +-----------------------+
"###);
let actual = execution.run_and_format("SELECT kurtosis_pop(1.0)").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +--------------------------+
- "| kurtosis_pop(Float64(1)) |"
- +--------------------------+
- "| |"
- +--------------------------+
"###);
let actual = execution.run_and_format("SELECT kurtosis_pop(null)").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +--------------------+
- "| kurtosis_pop(NULL) |"
- +--------------------+
- "| |"
- +--------------------+
"###);
}
#[tokio::test]
async fn test_skewness() {
let mut execution = TestExecution::new().await.unwrap().with_setup(TEST_TABLE).await;
let actual = execution
.run_and_format("SELECT skewness(int64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +--------------------------------+
- "| skewness(test_table.int64_col) |"
- +--------------------------------+
- "| -0.8573214099741201 |"
- +--------------------------------+
"###);
let actual = execution
.run_and_format("SELECT skewness(float64_col) FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----------------------------------+
- "| skewness(test_table.float64_col) |"
- +----------------------------------+
- "| -0.8573214099741201 |"
- +----------------------------------+
"###);
let actual = execution.run_and_format("SELECT skewness(1.0)").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----------------------+
- "| skewness(Float64(1)) |"
- +----------------------+
- "| |"
- +----------------------+
"###);
let actual = execution
.run_and_format("SELECT skewness(col) FROM VALUES (1.0), (2.0) as tab(col)")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-------------------+
- "| skewness(tab.col) |"
- +-------------------+
- "| |"
- +-------------------+
"###);
}
#[tokio::test]
async fn test_kurtosis() {
let mut execution = TestExecution::new().await.unwrap();
let actual = execution
.run_and_format("SELECT kurtosis(col) FROM VALUES (1.0), (10.0), (100.0), (10.0), (1.0) as tab(col);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-------------------+
- "| kurtosis(tab.col) |"
- +-------------------+
- "| 4.777292927667962 |"
- +-------------------+
"###);
let actual = execution
.run_and_format("SELECT kurtosis(col) FROM VALUES ('1'), ('10'), ('100'), ('10'), ('1') as tab(col);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-------------------+
- "| kurtosis(tab.col) |"
- +-------------------+
- "| 4.777292927667962 |"
- +-------------------+
"###);
let actual = execution
.run_and_format("SELECT kurtosis(col) FROM VALUES (1.0), (2.0), (3.0) as tab(col);")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +-------------------+
- "| kurtosis(tab.col) |"
- +-------------------+
- "| |"
- +-------------------+
"###);
let actual = execution.run_and_format("SELECT kurtosis(1);").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +--------------------+
- "| kurtosis(Int64(1)) |"
- +--------------------+
- "| |"
- +--------------------+
"###);
let actual = execution.run_and_format("SELECT kurtosis(1.0);").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----------------------+
- "| kurtosis(Float64(1)) |"
- +----------------------+
- "| |"
- +----------------------+
"###);
let actual = execution.run_and_format("SELECT kurtosis(null);").await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----------------+
- "| kurtosis(NULL) |"
- +----------------+
- "| |"
- +----------------+
"###);
}