Skip to content

Commit

Permalink
test cases for time
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingkuo committed Aug 15, 2022
1 parent 15a9a4b commit 839b777
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions datafusion/core/tests/sql/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,57 @@ async fn cast_string_to_time() {
);
}

#[tokio::test]
async fn time_comparison() -> Result<()> {
let ctx = SessionContext::new();

let sql = "SELECT TIME '00:00:00' = TIME '00:00:00'";
let results = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+--------------------------------------------------------------------------------------------+",
"| CAST(Utf8(\"00:00:00\") AS Time64(Nanosecond)) = CAST(Utf8(\"00:00:00\") AS Time64(Nanosecond))|",
"+--------------------------------------------------------------------------------------------+",
"| true |",
"+--------------------------------------------------------------------------------------------+",
];
assert_batches_eq!(expected, &results);

let sql = "SELECT TIME '00:00:00' = TIME '00:00:01'";
let results = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+--------------------------------------------------------------------------------------------+",
"| CAST(Utf8(\"00:00:00\") AS Time64(Nanosecond)) = CAST(Utf8(\"00:00:01\") AS Time64(Nanosecond))|",
"+--------------------------------------------------------------------------------------------+",
"| false |",
"+--------------------------------------------------------------------------------------------+",
];
assert_batches_eq!(expected, &results);

let sql = "SELECT TIME '00:00:00' < TIME '00:00:01'";
let results = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+--------------------------------------------------------------------------------------------+",
"| CAST(Utf8(\"00:00:00\") AS Time64(Nanosecond)) < CAST(Utf8(\"00:00:01\") AS Time64(Nanosecond))|",
"+--------------------------------------------------------------------------------------------+",
"| true |",
"+--------------------------------------------------------------------------------------------+",
];
assert_batches_eq!(expected, &results);

let sql = "SELECT TIME '00:00:00' > TIME '00:00:01'";
let results = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+--------------------------------------------------------------------------------------------+",
"| CAST(Utf8(\"00:00:00\") AS Time64(Nanosecond)) > CAST(Utf8(\"00:00:01\") AS Time64(Nanosecond))|",
"+--------------------------------------------------------------------------------------------+",
"| false |",
"+--------------------------------------------------------------------------------------------+",
];
assert_batches_eq!(expected, &results);

Ok(())
}

#[tokio::test]
async fn cast_to_timestamp_twice() -> Result<()> {
let ctx = SessionContext::new();
Expand Down

0 comments on commit 839b777

Please sign in to comment.