Repository: calcite Updated Branches: refs/heads/master 9a5cd2741 -> 6679353f2
[CALCITE-1881] Can't distinguish overloaded user-defined functions that have DATE and TIMESTAMP arguments (ä½å¯) Close apache/calcite#495 Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/6679353f Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/6679353f Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/6679353f Branch: refs/heads/master Commit: 6679353f2d77999daec372d4528ce50784018e29 Parents: 9a5cd27 Author: ä½å¯ <[email protected]> Authored: Mon Jul 10 21:47:59 2017 +0800 Committer: Julian Hyde <[email protected]> Committed: Thu Jul 13 13:46:56 2017 -0700 ---------------------------------------------------------------------- .../sql/type/SqlTypeExplicitPrecedenceList.java | 3 ++- .../java/org/apache/calcite/test/UdfTest.java | 26 ++++++++++++++++++++ .../java/org/apache/calcite/util/Smalls.java | 16 ++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/6679353f/core/src/main/java/org/apache/calcite/sql/type/SqlTypeExplicitPrecedenceList.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeExplicitPrecedenceList.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeExplicitPrecedenceList.java index 58b0707..b78e417 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeExplicitPrecedenceList.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeExplicitPrecedenceList.java @@ -87,7 +87,8 @@ public class SqlTypeExplicitPrecedenceList .put(SqlTypeName.VARBINARY, list(SqlTypeName.VARBINARY)) .put(SqlTypeName.DATE, list(SqlTypeName.DATE)) .put(SqlTypeName.TIME, list(SqlTypeName.TIME)) - .put(SqlTypeName.TIMESTAMP, list(SqlTypeName.TIMESTAMP)) + .put(SqlTypeName.TIMESTAMP, + list(SqlTypeName.TIMESTAMP, SqlTypeName.DATE, SqlTypeName.TIME)) .put(SqlTypeName.INTERVAL_YEAR, list(SqlTypeName.YEAR_INTERVAL_TYPES)) .put(SqlTypeName.INTERVAL_YEAR_MONTH, http://git-wip-us.apache.org/repos/asf/calcite/blob/6679353f/core/src/test/java/org/apache/calcite/test/UdfTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/UdfTest.java b/core/src/test/java/org/apache/calcite/test/UdfTest.java index 3d0879f..0c1de28 100644 --- a/core/src/test/java/org/apache/calcite/test/UdfTest.java +++ b/core/src/test/java/org/apache/calcite/test/UdfTest.java @@ -804,6 +804,32 @@ public class UdfTest { } /** Test case for + * <a href="https://issues.apache.org/jira/browse/CALCITE-1881">[CALCITE-1881] + * Can't distinguish overloaded user-defined functions that have DATE and + * TIMESTAMP arguments</a>. */ + @Test public void testDateAndTimestamp() { + final CalciteAssert.AssertThat with = withUdf(); + with.query("values \"adhoc\".\"toLong\"(DATE '1970-01-15')") + .returns("EXPR$0=1209600000\n"); + with.query("values \"adhoc\".\"toLong\"(DATE '2002-08-11')") + .returns("EXPR$0=1029024000000\n"); + with.query("values \"adhoc\".\"toLong\"(DATE '2003-04-11')") + .returns("EXPR$0=1050019200000\n"); + with.query("values \"adhoc\".\"toLong\"(TIMESTAMP '2003-04-11 00:00:00')") + .returns("EXPR$0=1050019200000\n"); + with.query("values \"adhoc\".\"toLong\"(TIMESTAMP '2003-04-11 00:00:06')") + .returns("EXPR$0=1050019206000\n"); + with.query("values \"adhoc\".\"toLong\"(TIMESTAMP '2003-04-18 01:20:00')") + .returns("EXPR$0=1050628800000\n"); + with.query("values \"adhoc\".\"toLong\"(TIME '00:20:00')") + .returns("EXPR$0=1200000\n"); + with.query("values \"adhoc\".\"toLong\"(TIME '00:20:10')") + .returns("EXPR$0=1210000\n"); + with.query("values \"adhoc\".\"toLong\"(TIME '01:20:00')") + .returns("EXPR$0=4800000\n"); + } + + /** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-1041">[CALCITE-1041] * User-defined function returns DATE or TIMESTAMP value</a>. */ @Test public void testReturnDate2() { http://git-wip-us.apache.org/repos/asf/calcite/blob/6679353f/core/src/test/java/org/apache/calcite/util/Smalls.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/util/Smalls.java b/core/src/test/java/org/apache/calcite/util/Smalls.java index be5bd3e..ba7bb8a 100644 --- a/core/src/test/java/org/apache/calcite/util/Smalls.java +++ b/core/src/test/java/org/apache/calcite/util/Smalls.java @@ -46,6 +46,9 @@ import org.apache.calcite.sql.type.SqlTypeName; import com.google.common.collect.ImmutableList; import java.lang.reflect.Method; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; import java.util.AbstractList; import java.util.Arrays; import java.util.List; @@ -484,6 +487,19 @@ public class Smalls { } } + /** Overloaded functions with DATE, TIMESTAMP and TIME arguments. */ + public static long toLong(Date date) { + return date == null ? 0 : SqlFunctions.toLong(date); + } + + public static long toLong(Timestamp timestamp) { + return timestamp == null ? 0 : SqlFunctions.toLong(timestamp); + } + + public static long toLong(Time time) { + return time == null ? 0 : SqlFunctions.toLong(time); + } + } /** Example of a user-defined aggregate function (UDAF). */
