[
https://issues.apache.org/jira/browse/CALCITE-7563?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Yu Xu resolved CALCITE-7563.
----------------------------
Fix Version/s: 1.43.0
Assignee: zzwqqq
Resolution: Fixed
Fixed in
[3fc5f46|https://github.com/apache/calcite/commit/3fc5f464ee087f69cd7b1f8dd54ee612050a917d]
Thank you for the fix [~zzwqqq]
> Oracle dialect generates invalid CAST to VARCHAR without precision
> ------------------------------------------------------------------
>
> Key: CALCITE-7563
> URL: https://issues.apache.org/jira/browse/CALCITE-7563
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: zzwqqq
> Assignee: zzwqqq
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.43.0
>
>
> OracleSqlDialect may generate invalid SQL when casting to VARCHAR without
> precision.
> Minimal reproduction:
> {code:sql}
> SELECT CAST("store_id" AS VARCHAR)
> FROM "foodmart"."expense_fact"
> {code}
> RelToSqlConverter with OracleSqlDialect currently may generate:
> {code:sql}
> SELECT CAST("store_id" AS VARCHAR)
> FROM "foodmart"."expense_fact"
> {code}
> Oracle rejects this because VARCHAR is currently synonymous with VARCHAR2,
> and VARCHAR2 requires a size (ORA-00906: missing left parenthesis,
> https://onecompiler.com/oracle/44qkw7vap).
> SqlFunctions that return VARCHAR without precision, such as
> SqlStdOperatorTable#REPLACE, can also trigger the issue.
> A possible fix is to update OracleSqlDialect#getCastSpec. If the target type
> is VARCHAR and precision is not specified, use the Oracle type system's max
> VARCHAR precision:
> {code:java}
> int precision = getTypeSystem().getMaxPrecision(SqlTypeName.VARCHAR);
> {code}
> Oracle documentation:
> * CAST type_name must be a built-in data type or collection type:
> https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CAST.html
> * VARCHAR2 syntax is VARCHAR2(size [BYTE | CHAR]), and Oracle documents that
> "You must specify size for VARCHAR2":
> https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html
> * VARCHAR is currently synonymous with VARCHAR2:
> https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html
--
This message was sent by Atlassian Jira
(v8.20.10#820010)