You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/08/01 20:35:00 UTC

[arrow-datafusion] branch master updated: add Timestamp::Second as signature for ToTimestampSeconds; similar as other units; add test cases (#3004)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 55a12869f add Timestamp::Second as signature for ToTimestampSeconds; similar as other units; add test cases (#3004)
55a12869f is described below

commit 55a12869f32644ed87d69d9b7617372db5103fb8
Author: Wei-Ting Kuo <wa...@gmail.com>
AuthorDate: Tue Aug 2 04:34:55 2022 +0800

    add Timestamp::Second as signature for ToTimestampSeconds; similar as other units; add test cases (#3004)
---
 datafusion/core/tests/sql/timestamp.rs | 81 ++++++++++++++++++++++++++++++++++
 datafusion/expr/src/function.rs        |  6 ++-
 2 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs
index 8452fcf81..8e293d035 100644
--- a/datafusion/core/tests/sql/timestamp.rs
+++ b/datafusion/core/tests/sql/timestamp.rs
@@ -984,3 +984,84 @@ async fn sub_interval_day() -> Result<()> {
 
     Ok(())
 }
+
+#[tokio::test]
+async fn cast_to_timestamp_twice() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql = "select to_timestamp(a) from (select to_timestamp(1) as a)A;";
+    let results = execute_to_batches(&ctx, sql).await;
+
+    let expected = vec![
+        "+-------------------------------+",
+        "| totimestamp(a.a)              |",
+        "+-------------------------------+",
+        "| 1970-01-01 00:00:00.000000001 |",
+        "+-------------------------------+",
+    ];
+
+    assert_batches_eq!(expected, &results);
+
+    Ok(())
+}
+
+#[tokio::test]
+async fn cast_to_timestamp_seconds_twice() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql =
+        "select to_timestamp_seconds(a) from (select to_timestamp_seconds(1) as a)A;";
+    let results = execute_to_batches(&ctx, sql).await;
+
+    let expected = vec![
+        "+-------------------------+",
+        "| totimestampseconds(a.a) |",
+        "+-------------------------+",
+        "| 1970-01-01 00:00:01     |",
+        "+-------------------------+",
+    ];
+
+    assert_batches_eq!(expected, &results);
+
+    Ok(())
+}
+
+#[tokio::test]
+async fn cast_to_timestamp_millis_twice() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql = "select to_timestamp_millis(a) from (select to_timestamp_millis(1) as a)A;";
+    let results = execute_to_batches(&ctx, sql).await;
+
+    let expected = vec![
+        "+-------------------------+",
+        "| totimestampmillis(a.a)  |",
+        "+-------------------------+",
+        "| 1970-01-01 00:00:00.001 |",
+        "+-------------------------+",
+    ];
+
+    assert_batches_eq!(expected, &results);
+
+    Ok(())
+}
+
+#[tokio::test]
+async fn cast_to_timestamp_micros_twice() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql = "select to_timestamp_micros(a) from (select to_timestamp_micros(1) as a)A;";
+    let results = execute_to_batches(&ctx, sql).await;
+
+    let expected = vec![
+        "+----------------------------+",
+        "| totimestampmicros(a.a)     |",
+        "+----------------------------+",
+        "| 1970-01-01 00:00:00.000001 |",
+        "+----------------------------+",
+    ];
+
+    assert_batches_eq!(expected, &results);
+
+    Ok(())
+}
diff --git a/datafusion/expr/src/function.rs b/datafusion/expr/src/function.rs
index 29158e234..45cd99d57 100644
--- a/datafusion/expr/src/function.rs
+++ b/datafusion/expr/src/function.rs
@@ -350,8 +350,9 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature {
             vec![
                 DataType::Utf8,
                 DataType::Int64,
-                DataType::Timestamp(TimeUnit::Millisecond, None),
+                DataType::Timestamp(TimeUnit::Nanosecond, None),
                 DataType::Timestamp(TimeUnit::Microsecond, None),
+                DataType::Timestamp(TimeUnit::Millisecond, None),
                 DataType::Timestamp(TimeUnit::Second, None),
             ],
             fun.volatility(),
@@ -363,6 +364,7 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature {
                 DataType::Int64,
                 DataType::Timestamp(TimeUnit::Nanosecond, None),
                 DataType::Timestamp(TimeUnit::Microsecond, None),
+                DataType::Timestamp(TimeUnit::Millisecond, None),
                 DataType::Timestamp(TimeUnit::Second, None),
             ],
             fun.volatility(),
@@ -373,6 +375,7 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature {
                 DataType::Utf8,
                 DataType::Int64,
                 DataType::Timestamp(TimeUnit::Nanosecond, None),
+                DataType::Timestamp(TimeUnit::Microsecond, None),
                 DataType::Timestamp(TimeUnit::Millisecond, None),
                 DataType::Timestamp(TimeUnit::Second, None),
             ],
@@ -386,6 +389,7 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature {
                 DataType::Timestamp(TimeUnit::Nanosecond, None),
                 DataType::Timestamp(TimeUnit::Microsecond, None),
                 DataType::Timestamp(TimeUnit::Millisecond, None),
+                DataType::Timestamp(TimeUnit::Second, None),
             ],
             fun.volatility(),
         ),