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

xiong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new bb9045705 [CALCITE-5027] Incorrect format for timestamp literals in 
SqlDialect#quoteTimestampLiteral
bb9045705 is described below

commit bb90457051f85930004e1f4bc23148efc672ef1c
Author: NobiGo <[email protected]>
AuthorDate: Thu Apr 7 14:29:16 2022 +0800

    [CALCITE-5027] Incorrect format for timestamp literals in 
SqlDialect#quoteTimestampLiteral
---
 core/src/main/java/org/apache/calcite/sql/SqlDialect.java | 2 +-
 core/src/test/java/org/apache/calcite/util/UtilTest.java  | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java 
b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
index c89eaee17..8770f81e0 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
@@ -682,7 +682,7 @@ public class SqlDialect {
    * @return SQL timestamp literal
    */
   public String quoteTimestampLiteral(Timestamp timestamp) {
-    final SimpleDateFormat format = getDateFormatter("'TIMESTAMP' ''yyyy-MM-DD 
HH:mm:SS''");
+    final SimpleDateFormat format = getDateFormatter("'TIMESTAMP' ''yyyy-MM-dd 
HH:mm:ss''");
     return format.format(timestamp);
   }
 
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java 
b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index 6e7fd73f3..92078f289 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -745,6 +745,13 @@ class UtilTest {
     buf.literal(new Timestamp(0));
     assertEquals("TIMESTAMP '1970-01-01 00:00:00'", buf.getSqlAndClear());
 
+    buf.literal(new Timestamp(1261053296000L));
+    assertEquals("TIMESTAMP '2009-12-17 12:34:56'", buf.getSqlAndClear());
+
+    buf.append("select ");
+    buf.literal(new Timestamp(1261053296000L));
+    assertEquals("select TIMESTAMP '2009-12-17 12:34:56'", 
buf.getSqlAndClear());
+
     buf.clear();
     assertEquals(0, buf.length());
 

Reply via email to