[ 
https://issues.apache.org/jira/browse/TRAFODION-3300?focusedWorklogId=232206&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-232206
 ]

ASF GitHub Bot logged work on TRAFODION-3300:
---------------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Apr/19 16:12
            Start Date: 24/Apr/19 16:12
    Worklog Time Spent: 10m 
      Work Description: DaveBirdsall commented on pull request #1831: 
[TRAFODION-3300] Fix overflow issues with extreme big nums + ROUND
URL: https://github.com/apache/trafodion/pull/1831#discussion_r278206583
 
 

 ##########
 File path: core/sql/generator/GenPreCode.cpp
 ##########
 @@ -10033,17 +10033,56 @@ ItemExpr * MathFunc::preCodeGen(Generator * 
generator)
   if (nodeIsPreCodeGenned())
     return this;
 
+  // for ROUND, if the first operand is a BigNum, don't cast
+  // the children to DOUBLE PRECISION; but do make sure the
+  // second operand is an integer
+  NABoolean castIt = TRUE;
+  if (getOperatorType() == ITM_ROUND)
+    {
+      const NAType &typ0 = child(0)->getValueId().getType();
+      if (((const NumericType &)typ0).isBigNum())
+        {
+          castIt = FALSE;
+
+          if (getArity() > 1)
+            {
+              const NumericType &typ1 = (const NumericType 
&)child(1)->getValueId().getType();
+              if (!typ1.isInteger() || 
+                  ((typ1.getFSDatatype() != REC_BIN8_SIGNED) &&
+                   (typ1.getFSDatatype() != REC_BIN8_UNSIGNED) && 
+                   (typ1.getFSDatatype() != REC_BIN16_SIGNED) &&
+                   (typ1.getFSDatatype() != REC_BIN16_UNSIGNED) &&
+                   (typ1.getFSDatatype() != REC_BIN32_SIGNED) &&
+                   (typ1.getFSDatatype() != REC_BIN32_UNSIGNED) &&
+                   (typ1.getFSDatatype() != REC_BIN64_SIGNED) &&
+                   (typ1.getFSDatatype() != REC_BIN64_UNSIGNED) ) )
+                {
 
 Review comment:
   Didn't know about this method. Just took a look at it. It includes 
REC_BPINT_UNSIGNED, which I had not added run-time support for. I'll add it and 
make this change.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 232206)
    Time Spent: 1h  (was: 50m)

> ROUND function on extreme data types fails with numeric overflows
> -----------------------------------------------------------------
>
>                 Key: TRAFODION-3300
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-3300
>             Project: Apache Trafodion
>          Issue Type: Bug
>          Components: sql-cmp, sql-exe
>    Affects Versions: 2.4
>            Reporter: David Wayne Birdsall
>            Assignee: David Wayne Birdsall
>            Priority: Major
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> The following script reproduces the failures.
> {quote}drop table if exists t;
> create table t (
> c1 numeric(128),
> c2 numeric(128,1),
> c3 numeric(128,2));
> insert into t values (
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678,
> 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.8,
> 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456.78
> );
> select * from t;
> select ROUND(c1, 1) from t;
> select ROUND(c2, 1) from t;
> select ROUND(c3, 1) from t;
> select ROUND(c1, 2) from t;
> select ROUND(c2, 2) from t;
> select ROUND(c3, 2) from t;
> select ROUND(c1, 3) from t;
> select ROUND(c2, 3) from t;
> select ROUND(c3, 3) from t;
> {quote}
> When run, some of the ROUND functions fail with numeric overflows. They all 
> should execute successfully.
> {quote}>>drop table if exists t;
> --- SQL operation complete.
> >>create table t (
> +>c1 numeric(128),
> +>c2 numeric(128,1),
> +>c3 numeric(128,2));
> --- SQL operation complete.
> >>
> >>insert into t values (
> +>12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678,
> +>1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.8,
> +>123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456.78
> +>);
> --- 1 row(s) inserted.
> >>select * from t;
> C1 C2 C3
> ---------------------------------------------------------------------------------------------------------------------------------
>  
> ----------------------------------------------------------------------------------------------------------------------------------
>  
> ----------------------------------------------------------------------------------------------------------------------------------
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
>  
> 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.8
>  
> 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456.78
> --- 1 row(s) selected.
> >>
> >>select ROUND(c1, 1) from t;
> (EXPR)
> ---------------------------------------------------------------------------------------------------------------------------------
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
> --- 1 row(s) selected.
> >>select ROUND(c2, 1) from t;
> *** ERROR[8411] A numeric overflow occurred during an arithmetic computation 
> or data conversion. Intermediate conversion of Source 
> Type:CHAR(REC_BYTE_F_ASCII,129 BYTES,ISO88591) Source 
> Value:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456780
>  to Target Type:NUMERIC(REC_NUM_BIG_SIGNED).
> --- 0 row(s) selected.
> >>select ROUND(c3, 1) from t;
> (EXPR)
> ----------------------------------------------------------------------------------------------------------------------------------
> 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456.80
> --- 1 row(s) selected.
> >>
> >>select ROUND(c1, 2) from t;
> (EXPR)
> ---------------------------------------------------------------------------------------------------------------------------------
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
> --- 1 row(s) selected.
> >>select ROUND(c2, 2) from t;
> *** ERROR[8411] A numeric overflow occurred during an arithmetic computation 
> or data conversion. Intermediate conversion of Source 
> Type:CHAR(REC_BYTE_F_ASCII,130 BYTES,ISO88591) Source 
> Value:1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567800
>  to Target Type:NUMERIC(REC_NUM_BIG_SIGNED).
> --- 0 row(s) selected.
> >>select ROUND(c3, 2) from t;
> *** ERROR[8411] A numeric overflow occurred during an arithmetic computation 
> or data conversion. Intermediate conversion of Source 
> Type:CHAR(REC_BYTE_F_ASCII,129 BYTES,ISO88591) Source 
> Value:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456780
>  to Target Type:NUMERIC(REC_NUM_BIG_SIGNED).
> --- 0 row(s) selected.
> >>
> >>select ROUND(c1, 3) from t;
> (EXPR)
> ---------------------------------------------------------------------------------------------------------------------------------
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
> --- 1 row(s) selected.
> >>select ROUND(c2, 3) from t;
> *** ERROR[8411] A numeric overflow occurred during an arithmetic computation 
> or data conversion. Intermediate conversion of Source 
> Type:CHAR(REC_BYTE_F_ASCII,131 BYTES,ISO88591) Source 
> Value:12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678000
>  to Target Type:NUMERIC(REC_NUM_BIG_SIGNED).
> --- 0 row(s) selected.
> >>select ROUND(c3, 3) from t;
> *** ERROR[8411] A numeric overflow occurred during an arithmetic computation 
> or data conversion. Intermediate conversion of Source 
> Type:CHAR(REC_BYTE_F_ASCII,130 BYTES,ISO88591) Source 
> Value:1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567800
>  to Target Type:NUMERIC(REC_NUM_BIG_SIGNED).
> --- 0 row(s) selected.
> >>exit;
> End of MXCI Session
> {quote}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to