anoopsharma00 commented on a change in pull request #1831: [TRAFODION-3300] Fix 
overflow issues with extreme big nums + ROUND
URL: https://github.com/apache/trafodion/pull/1831#discussion_r277888341
 
 

 ##########
 File path: core/sql/regress/executor/TEST101
 ##########
 @@ -214,6 +214,97 @@ control query default BIGNUM_IO 'ON';
 select ROUND(( SUM(PG_RESULT)/SUM(PG_BUDGET) )*100,2) from t101;
 control query default BIGNUM_IO 'SYSTEM';
 
+-- white box test of new BigNum::round implementation
+
+drop table if exists t101big;
+
+create table t101big (a int not null, 
+                      b numeric(128,2),
+                      c numeric(128,2) unsigned, 
+                      d numeric(35,20),
+                      e int, 
+                      f decimal(6,2), 
+                      g decimal(6,0), 
+                      primary key (a));
+
+insert into t101big values
+(1,12.34,12.34,1234.01234567890123456789,1,1,1),
+(2,23.45,23.45,999999999999999.90000000000000000000,1,1,1),
+(3,-12.34,12.55,-999999999999999.90000000000000000000,1,1,1),
+(4,-0.12,0.12,0.12,1,1,1),
+(5,999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99,
+   
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99,
+   0,1,1,1),
+(6,null,null,null,1,1,1);
+
+-- round with 1 parameter; includes rounding a negative number to zero, round 
up and non-round up cases
+select a,round(b) from t101big where a < 5;
+select a,round(c) from t101big where a < 5;
+
+-- round with 1 parameter, with a round up that increases precision
+select a,round(d) from t101big;
+
+-- round with 1 parameter, with a round up that causes overflow
+select a,round(b) from t101big where a = 5;
+select a,round(c) from t101big where a = 5;
+
+-- round with 1 parameter of null value
+select a,round(b),round(c),round(d) from t101big where a = 6;
+
+-- round with 2 parameters
+select a,round(b,1) from t101big where a < 5;
+select a,round(c,1) from t101big where a < 5;
+select a,round(d,1) from t101big where a < 5;
+
+-- round with 2 parameters where the rounding value is a no-op
+select a,round(b,2) from t101big where a <> 5;
+select a,round(c,2) from t101big where a <> 5;
+select a,round(d,20) from t101big where a <> 5;
+
+-- round with 2 parameters where the rounding value is greater than scale; 
again a no-op
+select a,round(b,3) from t101big where a <> 5;
+select a,round(c,3) from t101big where a <> 5;
+select a,round(d,40) from t101big where a <> 5;
+
+-- round with 2 parameters with negative rounding value
+select a,round(b,-1) from t101big where a <> 5;
+select a,round(c,-1) from t101big where a <> 5;
+select a,round(d,-1) from t101big where a <> 5;
+select a,round(b,-4) from t101big where a <> 5;
+select a,round(c,-4) from t101big where a <> 5;
+select a,round(d,-4) from t101big where a <> 5;
+
+-- round with 2 parameters using a ridiculous but still sensible rounding value
+select a,round(b,-100) from t101big where a <> 5;
+select a,round(c,-100) from t101big where a <> 5;
+select a,round(d,-100) from t101big where a <> 5;
+
+-- round using an integer column for the rounding value
+select a,round(b,e) from t101big where a <> 5;
+select a,round(c,e) from t101big where a <> 5;
+select a,round(d,e) from t101big where a <> 5;
+
+-- round using an integer decimal column for the rounding value
+select a,round(b,g) from t101big where a <> 5;
+select a,round(c,g) from t101big where a <> 5;
+select a,round(d,g) from t101big where a <> 5;
+
+-- round using a null value for second operand (from a column or a constant)
+select a,round(b,null) from t101big; -- bind time error
+update t101big set e = null;
+select a,round(b,e) from t101big; -- returns null values
+
+-- negative test: round using a non-integer decimal column
+select a,round(b,f) from t101big;
+
+-- negative test: round using rounding values > max big num precision
+select a,round(b,129) from t101big;
+
+-- but -129 works fine
+select a,round(b,-129) from t101big;
+
+drop table t101big;
 
 Review comment:
   good to see extensive tests. These would probably catch more issues than 
visual code review.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to