You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/03/22 21:06:00 UTC

[jira] [Resolved] (CALCITE-5548) Add support for MSSQL CONVERT function

     [ https://issues.apache.org/jira/browse/CALCITE-5548?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julian Hyde resolved CALCITE-5548.
----------------------------------
    Fix Version/s: 1.35.0
       Resolution: Fixed

Fixed in [03fd95b97|https://github.com/apache/calcite/commit/03fd95b97c4c63819d3af9525c06b0f40963def9]; thanks for the PR, [~askarbozcan]!

> 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
>             Fix For: 1.35.0
>
>          Time Spent: 50m
>  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)