[
https://issues.apache.org/jira/browse/CALCITE-5548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17702939#comment-17702939
]
Julian Hyde commented on CALCITE-5548:
--------------------------------------
[~askarbozcan], Thanks for this PR. I fixed some formatting, and moved the
logic from {{class SqlCastConvertFunction}} to {{{}SqlLibraryOperators{}}}.
Please review my changes in
[julianhyde/5548-mssql-convert|https://github.com/julianhyde/calcite/tree/5548-mssql-convert],
and if they're OK I'll merge.
> 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: 20m
> 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)