[ 
https://issues.apache.org/jira/browse/CALCITE-5548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17703327#comment-17703327
 ] 

Askar Bozcan commented on CALCITE-5548:
---------------------------------------

LGTM. I pulled in your changes into PR fork.

> Add support for MSSQL CONVERT function
> --------------------------------------
>
>                 Key: CALCITE-5548
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5548
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Askar Bozcan
>            Assignee: Askar Bozcan
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Add support for MSSQL CONVERT function (which is the same as CAST, with 
> optional formatting)
> More info: 
> [https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver16]
>  Example usage:
> {{SELECT CONVERT(DATETIME, '2017-08-25', 101)}}
> PR TEXT:
> This PR adds partial support for [MSSQL CONVERT 
> function|https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver16].
>  A function very similar to CAST that has an optional "style" operand to 
> support different kinds of date string formats, float decimal points in 
> string form, etc.
> The reason this PR is "partial", is because it simply adds a thin wrapper 
> around CAST operator and does not implement anything related to 'style' 
> operand other than allowing for its parsing.
> *Implemented*
>  * Add lookahead in parser to first token to make sure there are no clashes 
> with other unrelated CONVERT functions (including MSSQL CONVERT func)
>  * Add parser rule specifically for CONVERT to add support for its syntax
>  * SQLOperator (SqlConvertMssqlFunction) which utilizes 
> SqlOperator.rewriteCall() to delegate all the functionality to CAST
>  * Related Quidem tests in functions.iq
> *Not implemented*
>  * 'style' operand is ignored. It is parsed, however beyond that, any 
> functionality related to it is not implemented.
> *Difficulties & notes on implementing 'style' operator*
> Almost everywhere in the codebase, the operand order for CAST is hard-coded, 
> which is not a bad assumption at all; yet because of it it seems impossible 
> to fully implement CONVERT unless it's properly added as its own operator.
> For reference on CAST-related functionality:
> [RexImpTable.CastImplementor|https://github.com/apache/calcite/blob/ee9b80b0b68d442991dfaa142722e3488ec73e79/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java#L2918]
> [StandardConvertletTable.convertCast|https://github.com/apache/calcite/blob/ee9b80b0b68d442991dfaa142722e3488ec73e79/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java#L595]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to