From 4275ac63537626be4d76003ea456b1bae70ffe8c Mon Sep 17 00:00:00 2001 From: caicancai <2356672992@qq.com> Date: Tue, 9 Jan 2024 23:45:15 +0800 Subject: [PATCH] Port tests in timestamp.rs to sqllogictest --- datafusion/core/tests/sql/timestamp.rs | 463 ------------------ .../sqllogictest/test_files/timestamps.slt | 53 ++ 2 files changed, 53 insertions(+), 463 deletions(-) diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index ada66503a1816..8463583e0017d 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -18,469 +18,6 @@ use super::*; use std::ops::Add; -#[tokio::test] -async fn test_current_timestamp_expressions() -> Result<()> { - let t1 = chrono::Utc::now().timestamp(); - let ctx = SessionContext::new(); - let actual = execute(&ctx, "SELECT NOW(), NOW() as t2").await; - let res1 = actual[0][0].as_str(); - let res2 = actual[0][1].as_str(); - let t3 = Utc::now().timestamp(); - let t2_naive = DateTime::parse_from_rfc3339(res1).unwrap(); - - let t2 = t2_naive.timestamp(); - assert!(t1 <= t2 && t2 <= t3); - assert_eq!(res2, res1); - - Ok(()) -} - -#[tokio::test] -async fn test_now_in_same_stmt_using_sql_function() -> Result<()> { - let ctx = SessionContext::new(); - - let df1 = ctx.sql("select now(), now() as now2").await?; - let result = result_vec(&df1.collect().await?); - assert_eq!(result[0][0], result[0][1]); - - Ok(()) -} - -#[tokio::test] -async fn test_now_across_statements() -> Result<()> { - let ctx = SessionContext::new(); - - let actual1 = execute(&ctx, "SELECT NOW()").await; - let res1 = actual1[0][0].as_str(); - - let actual2 = execute(&ctx, "SELECT NOW()").await; - let res2 = actual2[0][0].as_str(); - - assert!(res1 < res2); - - Ok(()) -} - -#[tokio::test] -async fn test_now_across_statements_using_sql_function() -> Result<()> { - let ctx = SessionContext::new(); - - let df1 = ctx.sql("select now()").await?; - let rb1 = df1.collect().await?; - let result1 = result_vec(&rb1); - let res1 = result1[0][0].as_str(); - - let df2 = ctx.sql("select now()").await?; - let rb2 = df2.collect().await?; - let result2 = result_vec(&rb2); - let res2 = result2[0][0].as_str(); - - assert!(res1 < res2); - - Ok(()) -} - -#[tokio::test] -async fn test_now_dataframe_api() -> Result<()> { - let ctx = SessionContext::new(); - let df = ctx.sql("select 1").await?; // use this to get a DataFrame - let df = df.select(vec![now(), now().alias("now2")])?; - let result = result_vec(&df.collect().await?); - assert_eq!(result[0][0], result[0][1]); - - Ok(()) -} - -#[tokio::test] -async fn test_now_dataframe_api_across_statements() -> Result<()> { - let ctx = SessionContext::new(); - let df = ctx.sql("select 1").await?; // use this to get a DataFrame - let df = df.select(vec![now()])?; - let result = result_vec(&df.collect().await?); - - let df = ctx.sql("select 1").await?; - let df = df.select(vec![now()])?; - let result2 = result_vec(&df.collect().await?); - - assert_ne!(result[0][0], result2[0][0]); - - Ok(()) -} - -#[tokio::test] -async fn test_now_in_view() -> Result<()> { - let ctx = SessionContext::new(); - let _df = ctx - .sql("create or replace view test_now as select now()") - .await? - .collect() - .await?; - - let df = ctx.sql("select * from test_now").await?; - let result = result_vec(&df.collect().await?); - - let df1 = ctx.sql("select * from test_now").await?; - let result2 = result_vec(&df1.collect().await?); - - assert_ne!(result[0][0], result2[0][0]); - - Ok(()) -} - -#[tokio::test] -async fn timestamp_minmax() -> Result<()> { - let ctx = SessionContext::new(); - let table_a = make_timestamp_tz_table::(None)?; - let table_b = - make_timestamp_tz_table::(Some("+00:00".into()))?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT MIN(table_a.ts), MAX(table_b.ts) FROM table_a, table_b"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = [ - "+-------------------------+-----------------------------+", - "| MIN(table_a.ts) | MAX(table_b.ts) |", - "+-------------------------+-----------------------------+", - "| 2020-09-08T11:42:29.190 | 2020-09-08T13:42:29.190855Z |", - "+-------------------------+-----------------------------+", - ]; - assert_batches_eq!(expected, &actual); - - Ok(()) -} - -#[tokio::test] -async fn timestamp_coercion() -> Result<()> { - { - let ctx = SessionContext::new(); - let table_a = - make_timestamp_tz_table::(Some("+00:00".into()))?; - let table_b = - make_timestamp_tz_table::(Some("+00:00".into()))?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------+--------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------+--------------------------+-------------------------+", - "| 2020-09-08T13:42:29Z | 2020-09-08T13:42:29.190Z | true |", - "| 2020-09-08T13:42:29Z | 2020-09-08T12:42:29.190Z | false |", - "| 2020-09-08T13:42:29Z | 2020-09-08T11:42:29.190Z | false |", - "| 2020-09-08T12:42:29Z | 2020-09-08T13:42:29.190Z | false |", - "| 2020-09-08T12:42:29Z | 2020-09-08T12:42:29.190Z | true |", - "| 2020-09-08T12:42:29Z | 2020-09-08T11:42:29.190Z | false |", - "| 2020-09-08T11:42:29Z | 2020-09-08T13:42:29.190Z | false |", - "| 2020-09-08T11:42:29Z | 2020-09-08T12:42:29.190Z | false |", - "| 2020-09-08T11:42:29Z | 2020-09-08T11:42:29.190Z | true |", - "+----------------------+--------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+---------------------+----------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+---------------------+----------------------------+-------------------------+", - "| 2020-09-08T13:42:29 | 2020-09-08T13:42:29.190855 | true |", - "| 2020-09-08T13:42:29 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T13:42:29 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T12:42:29 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T12:42:29 | 2020-09-08T12:42:29.190855 | true |", - "| 2020-09-08T12:42:29 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T11:42:29 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T11:42:29 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T11:42:29 | 2020-09-08T11:42:29.190855 | true |", - "+---------------------+----------------------------+-------------------------+", - - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+---------------------+----------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+---------------------+----------------------------+-------------------------+", - "| 2020-09-08T13:42:29 | 2020-09-08T13:42:29.190855 | true |", - "| 2020-09-08T13:42:29 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T13:42:29 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T12:42:29 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T12:42:29 | 2020-09-08T12:42:29.190855 | true |", - "| 2020-09-08T12:42:29 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T11:42:29 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T11:42:29 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T11:42:29 | 2020-09-08T11:42:29.190855 | true |", - "+---------------------+----------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+-------------------------+---------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+-------------------------+---------------------+-------------------------+", - "| 2020-09-08T13:42:29.190 | 2020-09-08T13:42:29 | true |", - "| 2020-09-08T13:42:29.190 | 2020-09-08T12:42:29 | false |", - "| 2020-09-08T13:42:29.190 | 2020-09-08T11:42:29 | false |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T13:42:29 | false |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T12:42:29 | true |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T11:42:29 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T13:42:29 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T12:42:29 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T11:42:29 | true |", - "+-------------------------+---------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+-------------------------+----------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+-------------------------+----------------------------+-------------------------+", - "| 2020-09-08T13:42:29.190 | 2020-09-08T13:42:29.190855 | true |", - "| 2020-09-08T13:42:29.190 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T13:42:29.190 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T12:42:29.190855 | true |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T11:42:29.190855 | true |", - "+-------------------------+----------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+-------------------------+----------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+-------------------------+----------------------------+-------------------------+", - "| 2020-09-08T13:42:29.190 | 2020-09-08T13:42:29.190855 | true |", - "| 2020-09-08T13:42:29.190 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T13:42:29.190 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T12:42:29.190855 | true |", - "| 2020-09-08T12:42:29.190 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190 | 2020-09-08T11:42:29.190855 | true |", - "+-------------------------+----------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+---------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------------+---------------------+-------------------------+", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:29 | true |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T12:42:29 | false |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T11:42:29 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T13:42:29 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:29 | true |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T11:42:29 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T13:42:29 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T12:42:29 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:29 | true |", - "+----------------------------+---------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+-------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------------+-------------------------+-------------------------+", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:29.190 | true |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T12:42:29.190 | false |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T11:42:29.190 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T13:42:29.190 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:29.190 | true |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T11:42:29.190 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T13:42:29.190 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T12:42:29.190 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:29.190 | true |", - "+----------------------------+-------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+----------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------------+----------------------------+-------------------------+", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:29.190855 | true |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:29.190855 | true |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:29.190855 | true |", - "+----------------------------+----------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+---------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------------+---------------------+-------------------------+", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:29 | true |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T12:42:29 | false |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T11:42:29 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T13:42:29 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:29 | true |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T11:42:29 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T13:42:29 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T12:42:29 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:29 | true |", - "+----------------------------+---------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+-------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------------+-------------------------+-------------------------+", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:29.190 | true |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T12:42:29.190 | false |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T11:42:29.190 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T13:42:29.190 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:29.190 | true |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T11:42:29.190 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T13:42:29.190 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T12:42:29.190 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:29.190 | true |", - "+----------------------------+-------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - { - let ctx = SessionContext::new(); - let table_a = make_timestamp_table::()?; - let table_b = make_timestamp_table::()?; - ctx.register_table("table_a", table_a)?; - ctx.register_table("table_b", table_b)?; - - let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc"; - let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+----------------------------+-------------------------+", - "| ts | ts | table_a.ts = table_b.ts |", - "+----------------------------+----------------------------+-------------------------+", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:29.190855 | true |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T13:42:29.190855 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:29.190855 | true |", - "| 2020-09-08T12:42:29.190855 | 2020-09-08T11:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T13:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T12:42:29.190855 | false |", - "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:29.190855 | true |", - "+----------------------------+----------------------------+-------------------------+", - ]; - assert_batches_eq!(expected, &actual); - } - - Ok(()) -} #[tokio::test] async fn group_by_timestamp_millis() -> Result<()> { diff --git a/datafusion/sqllogictest/test_files/timestamps.slt b/datafusion/sqllogictest/test_files/timestamps.slt index 8b0f50cedf052..7829ce53ac9a4 100644 --- a/datafusion/sqllogictest/test_files/timestamps.slt +++ b/datafusion/sqllogictest/test_files/timestamps.slt @@ -1894,3 +1894,56 @@ query B select arrow_cast(now(), 'Date64') < arrow_cast('2022-02-02 02:02:02', 'Timestamp(Nanosecond, None)'); ---- false + +########## +## Test query MAX Timestamp and MiN Timestamp +########## + +statement ok +create table table_a (val int, ts timestamp) as values (1, '2020-09-08T11:42:29.190'::timestamp), (2, '2000-02-01T00:00:00'::timestamp) + +query P +SELECT MIN(table_a.ts) FROM table_a; +---- +2000-02-01T00:00:00 + +query P +SELECT MAX(table_a.ts) FROM table_a; +---- +2020-09-08T11:42:29.190 + +statement ok +drop table table_a + +########## +## Test query MAX Timestamp and MiN Timestamp +########## + +statement ok +create table table_a (ts timestamp) as values + ('2020-09-08T11:42:29Z'::timestamp), + ('2020-09-08T12:42:29Z'::timestamp), + ('2020-09-08T13:42:29Z'::timestamp) + +statement ok +create table table_b (ts timestamp) as values + ('2020-09-08T11:42:29.190Z'::timestamp), + ('2020-09-08T13:42:29.190Z'::timestamp), + ('2020-09-08T12:42:29.190Z'::timestamp) + +query PPB +SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b order by table_a.ts desc, table_b.ts desc +---- +2020-09-08T13:42:29 2020-09-08T13:42:29.190 false +2020-09-08T13:42:29 2020-09-08T12:42:29.190 false +2020-09-08T13:42:29 2020-09-08T11:42:29.190 false +2020-09-08T12:42:29 2020-09-08T13:42:29.190 false +2020-09-08T12:42:29 2020-09-08T12:42:29.190 false +2020-09-08T12:42:29 2020-09-08T11:42:29.190 false +2020-09-08T11:42:29 2020-09-08T13:42:29.190 false +2020-09-08T11:42:29 2020-09-08T12:42:29.190 false +2020-09-08T11:42:29 2020-09-08T11:42:29.190 false + + + +