[
https://issues.apache.org/jira/browse/PHOENIX-6741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17560951#comment-17560951
]
chaijunjie edited comment on PHOENIX-6741 at 6/30/22 9:50 AM:
--------------------------------------------------------------
*The maxLength and scale caculte method is confusing,any one can explain about
it? thanks*
was (Author: JIRAUSER286971):
*The maxLength and scale caculte method is confusing,any one can explain about
it? thanks*
*I think the default min scale should not be 0, for example we can set it as 6.*
private static Integer getScale(Integer lp, Integer rp, Integer ls, Integer rs)
{
// If we are adding a decimal with scale and precision to a decimal
// with no precision nor scale, the scale system does not apply.
if (ls == null || rs == null)
{ return null; }
*int val = Math.max(PDataType.MAX_PRECISION - lp + ls - rs, 6);*
return Math.min(PDataType.MAX_PRECISION, val);
}
> The result of DivideExpression is wrong when two decimal number divide
> ----------------------------------------------------------------------
>
> Key: PHOENIX-6741
> URL: https://issues.apache.org/jira/browse/PHOENIX-6741
> Project: Phoenix
> Issue Type: Bug
> Components: core
> Affects Versions: 5.1.2
> Reporter: chaijunjie
> Priority: Major
>
> When two number set precision and scale, and {*}the second scale is bigger
> or equal than the first{*},then the result will be scaled by 0.
> DROP TABLE IF EXISTS TEST;
> CREATE TABLE TEST (
> ID INTEGER NOT NULL PRIMARY KEY,
> A DECIMAL(28,8),
> B DECIMAL(38,9)
> );
> UPSERT INTO TEST VALUES(1,120,200.358);
> SELECT ID,A/B AS C FROM TEST;
> +-----+----+
> | ID | C |
> +-----+----+
> | 1 | 0 |
> +-----+----+
>
> DROP TABLE IF EXISTS TEST;
> CREATE TABLE TEST (
> ID INTEGER NOT NULL PRIMARY KEY,
> A DECIMAL(18,10),
> B DECIMAL(18,10)
> );
> UPSERT INTO TEST VALUES(1,100,200);
> SELECT ID,A/B AS C FROM TEST;
> 0: jdbc:phoenix:> SELECT ID,A/B AS C FROM TEST;
> {+}-{-}{{-}}{{-}}{{-}}{-}{{-}}{-}{-}{+}+
> |ID |C |
> {+}-{-}{{-}}{{-}}{{-}}{-}{{-}}{-}{-}{+}+
> |1 |0 |
> {+}-{-}{{-}}{{-}}{{-}}{-}{{-}}{-}{-}{+}+
>
> DROP TABLE IF EXISTS TEST;
> CREATE TABLE TEST (
> ID INTEGER NOT NULL PRIMARY KEY,
> A DECIMAL(38,10),
> B DECIMAL(18,10)
> );
> UPSERT INTO TEST VALUES(1,100,200);
> SELECT ID,A/B AS C FROM TEST;
> {+}---{-}{{-}}{-}{-}{+}--+
> |ID |C |
> {+}---{-}{{-}}{-}{-}{+}--+
> |1 |0 |
> {+}---{-}{{-}}{-}{-}{+}--+
>
> But, we need a precise result, so we need add a 1.00*, then the result will
> be right.
> 0: jdbc:phoenix:> SELECT ID,1.00*A/B AS C FROM TEST;
> {+}-{-}{{-}}{{-}}{{-}}{-}{{-}}{-}{-}{+}--+
> |ID | C |
> {+}-{-}{{-}}{{-}}{{-}}{-}{{-}}{-}{-}{+}--+
> |1 |0.5 |
> {+}-{-}{{-}}{{-}}{{-}}{-}{{-}}{-}{-}{+}--+
--
This message was sent by Atlassian Jira
(v8.20.10#820010)