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

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


The following commit(s) were added to refs/heads/main by this push:
     new bb256437cd [CALCITE-6766] Move DATEADD and DATEDIFF from PostgreSQL to 
Redshift library
bb256437cd is described below

commit bb256437cd9f02d0d0afd015b61604688f671dc7
Author: Zhe Hu <[email protected]>
AuthorDate: Wed Jan 8 20:39:38 2025 +0800

    [CALCITE-6766] Move DATEADD and DATEDIFF from PostgreSQL to Redshift library
---
 babel/src/test/java/org/apache/calcite/test/BabelParserTest.java  | 4 ++--
 .../main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java | 4 ++--
 site/_docs/reference.md                                           | 8 ++------
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java 
b/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java
index fa645fe784..11fa5489be 100644
--- a/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java
+++ b/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java
@@ -189,8 +189,8 @@ class BabelParserTest extends SqlParserTest {
     sql("select date(x) from t").ok(expected);
   }
 
-  /** In Redshift, PostgreSQL the DATEADD, DATEDIFF and DATE_PART functions 
have
-   * ordinary function syntax except that its first argument is a time unit
+  /** The DATEADD, DATEDIFF (in Redshift, Snowflake) and DATE_PART (in 
PostgreSQL)
+   * functions have ordinary function syntax  except that its first argument 
is a time unit
    * (e.g. DAY). We must not parse that first argument as an identifier. */
   @Test void testRedshiftFunctionsWithDateParts() {
     final String sql = "SELECT DATEADD(day, 1, t),\n"
diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 9dbb0d8334..9028e16c7b 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -128,7 +128,7 @@ public abstract class SqlLibraryOperators {
 
   /** The "DATEADD(timeUnit, numeric, datetime)" function
    * (Microsoft SQL Server, Redshift, Snowflake). */
-  @LibraryOperator(libraries = {MSSQL, POSTGRESQL})
+  @LibraryOperator(libraries = {MSSQL, REDSHIFT, SNOWFLAKE})
   public static final SqlFunction DATEADD =
       new SqlTimestampAddFunction("DATEADD");
 
@@ -162,7 +162,7 @@ public abstract class SqlLibraryOperators {
    * <p>MySQL has "DATEDIFF(date, date2)" and "TIMEDIFF(time, time2)" functions
    * but Calcite does not implement these because they have no "timeUnit"
    * argument. */
-  @LibraryOperator(libraries = {MSSQL, POSTGRESQL})
+  @LibraryOperator(libraries = {MSSQL, REDSHIFT, SNOWFLAKE})
   public static final SqlFunction DATEDIFF =
       new SqlTimestampDiffFunction("DATEDIFF",
           OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATE,
diff --git a/site/_docs/reference.md b/site/_docs/reference.md
index 16713d8efd..168687ae85 100644
--- a/site/_docs/reference.md
+++ b/site/_docs/reference.md
@@ -2851,8 +2851,8 @@ In the following:
 | b | DATE(timestampLtz, timeZone)                   | Extracts the DATE from 
*timestampLtz* (an instant; BigQuery's TIMESTAMP type) in *timeZone*
 | b | DATE(string)                                   | Equivalent to 
`CAST(string AS DATE)`
 | b | DATE(year, month, day)                         | Returns a DATE value 
for *year*, *month*, and *day* (all of type INTEGER)
-| p q r | DATEADD(timeUnit, integer, datetime)       | Equivalent to 
`TIMESTAMPADD(timeUnit, integer, datetime)`
-| p q r | DATEDIFF(timeUnit, datetime, datetime2)    | Equivalent to 
`TIMESTAMPDIFF(timeUnit, datetime, datetime2)`
+| q r f | DATEADD(timeUnit, integer, datetime)       | Equivalent to 
`TIMESTAMPADD(timeUnit, integer, datetime)`
+| q r f | DATEDIFF(timeUnit, datetime, datetime2)    | Equivalent to 
`TIMESTAMPDIFF(timeUnit, datetime, datetime2)`
 | q | DATEPART(timeUnit, datetime)                   | Equivalent to 
`EXTRACT(timeUnit FROM  datetime)`
 | b | DATETIME(date, time)                           | Converts *date* and 
*time* to a TIMESTAMP
 | b | DATETIME(date)                                 | Converts *date* to a 
TIMESTAMP value (at midnight)
@@ -3035,10 +3035,6 @@ In the following:
 
 Note:
 
-* Calcite has no Redshift library, so the Postgres library
-  is used instead. The functions `DATEADD`, `DATEDIFF` are
-  implemented in Redshift and not Postgres but nevertheless
-  appear in Calcite's Postgres library
 * Functions `DATEADD`, `DATEDIFF`, `DATE_PART` require the Babel parser
 * `JSON_TYPE` / `JSON_DEPTH` / `JSON_PRETTY` / `JSON_STORAGE_SIZE` return null 
if the argument is null
 * `JSON_LENGTH` / `JSON_KEYS` / `JSON_REMOVE` return null if the first 
argument is null

Reply via email to