[
https://issues.apache.org/jira/browse/CALCITE-5838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17741843#comment-17741843
]
Benchao Li commented on CALCITE-5838:
-------------------------------------
You can extend Calcite to specify your own rule for deriving the precision for
decimal division, see {{RelDataTypeSystem#deriveDecimalDivideType}}.
I know some systems which do this, such as [Apache
Flink|https://github.com/apache/flink/blob/4cf2124d71a8dd0595e40f07c2dbcc4c85883b82/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/calcite/FlinkTypeSystem.java#L151-L155]
> derive wrong decimal divide type
> --------------------------------
>
> Key: CALCITE-5838
> URL: https://issues.apache.org/jira/browse/CALCITE-5838
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.34.0
> Reporter: pengfei.zhan
> Priority: Major
>
> Given a table metadata structure as follows:
> {code:sql}
> create table `tbl_test`(`CRR` decimal(38,2), `DT` varchar(4096)) ROW FORMAT
> DELIMITED FIELDS TERMINATED BY '\t';
> {code}
> If the following query is executed,
> {code:sql}
> select sum(CRR_0/1000000000.02) from (select sum(CRR) as CRR_0 from tbl_test
> where DT='20230705') T1
> {code}
> The RexCall CRR_0/1000000000.02 derived a decimal type of decimal(38, 0). I
> referred the derived type in spark, but it gives decimal(38, 4). It looks
> like the inferred type is more reasonable.
> [hive doc |
> https://cwiki.apache.org/confluence/download/attachments/27362075/Hive_Decimal_Precision_Scale_Support.pdf]
> [sql server doc | https://msdn.microsoft.com/en-us/library/ms190476.aspx]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)