[
https://issues.apache.org/jira/browse/CALCITE-5423?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17644518#comment-17644518
]
Julian Hyde edited comment on CALCITE-5423 at 12/7/22 9:33 PM:
---------------------------------------------------------------
The following examples illustrate the difference. I believe they are valid and
equivalent:
{code:sql}
# Built-in is called TIMESTAMPDIFF, and the time frame argument occurs first.
Returns INTERVAL.
TIMESTAMPDIFF(HOUR TIMESTAMP '2010-07-07 10:20:00', TIMESTAMP '2008-12-25
15:30:00')
# BigQuery-compatible version is called TIMESTAMP_DIFF, and the time frame
argument occurs last. Returns BIGINT.
TIMESTAMP_DIFF(TIMESTAMP '2010-07-07 10:20:00', TIMESTAMP '2008-12-25
15:30:00', HOUR)
{code}
So I think you can have two functions (let's call them
{{SqlStdOperatorTable.TIMESTAMP_DIFF}} and
{{SqlLibraryOperators.TIMESTAMP_DIFF3}}) that have different type signatures
({{SqlOperandTypeChecker}}) but have the same validation code and implementor.
To share validation code they should be instances of the same type,
{{SqlTimestampDiffFunction}}. The validation and implementation logic should
adapt based on whether the time frame is argument 0 or argument 2.
Both functions should support custom time frames.
was (Author: julianhyde):
The following examples illustrate the difference. I believe they are valid and
equivalent:
{code:sql}
# Built-in is called TIMESTAMPDIFF, and the time frame argument occurs first.
Returns INTERVAL.
TIMESTAMP_DIFF(HOUR TIMESTAMP '2010-07-07 10:20:00', TIMESTAMP '2008-12-25
15:30:00')
# BigQuery-compatible version is called TIMESTAMP_DIFF, and the time frame
argument occurs last. Returns BIGINT.
TIMESTAMP_DIFF(TIMESTAMP '2010-07-07 10:20:00', TIMESTAMP '2008-12-25
15:30:00', HOUR)
{code}
So I think you can have two functions (let's call them
{{SqlStdOperatorTable.TIMESTAMP_DIFF}} and
{{SqlLibraryOperators.TIMESTAMP_DIFF3}}) that have different type signatures
({{SqlOperandTypeChecker}}) but have the same validation code and implementor.
To share validation code they should be instances of the same type,
{{SqlTimestampDiffFunction}}. The validation and implementation logic should
adapt based on whether the time frame is argument 0 or argument 2.
Both functions should support custom time frames.
> Implement TIMESTAMP_DIFF function (compatible with BigQuery)
> ------------------------------------------------------------
>
> Key: CALCITE-5423
> URL: https://issues.apache.org/jira/browse/CALCITE-5423
> Project: Calcite
> Issue Type: Sub-task
> Reporter: Julian Hyde
> Assignee: Tanner Clary
> Priority: Major
>
> Implement TIMESTAMP_DIFF function (compatible with BigQuery).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)