[ 
https://issues.apache.org/jira/browse/DRILL-6710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16597161#comment-16597161
 ] 

ASF GitHub Bot commented on DRILL-6710:
---------------------------------------

sohami commented on a change in pull request #1451: DRILL-6710: Disallow 
negative scale for VarDecimal
URL: https://github.com/apache/drill/pull/1451#discussion_r213928418
 
 

 ##########
 File path: 
exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
 ##########
 @@ -170,6 +170,8 @@ public void eval() {
               left.precision, left.scale,
               right.precision, right.scale);
 
+      // Do the verification of computed scale and precision here based on 
actual data
+      typeInference.verifyScaleAndPrecision();
 
 Review comment:
   I don't see moving the verification check here rather than doing in planning 
time helps. Since for each addition call we still increase the precision by 1, 
hence for 39 such additions precision will go beyond max allowed 38 and scale 
will become -1, hence throwing the error.
   
   I think instead what we can do is while passing `MathContext` to BigDecimal 
pass `adjusted precision` and `Math.max(0, adjusted_scale).` This will ensure 
that negative scale is never passed in context and if the operation is not 
possible in BigDecimal under given MathContext, it should throw Exception which 
Drill can in turn throw. I tried with that [temp 
change](https://github.com/sohami/drill/commits/DRILL-6710-2) and all the 
queries shared in the JIRA works with that.
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Disallow negative scale for VarDecimal
> --------------------------------------
>
>                 Key: DRILL-6710
>                 URL: https://issues.apache.org/jira/browse/DRILL-6710
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Execution - Relational Operators
>    Affects Versions: 1.14.0
>            Reporter: Robert Hou
>            Assignee: Sorabh Hamirwasia
>            Priority: Major
>             Fix For: 1.15.0
>
>
> Query is:
> select cast('999999999999999999' as decimal(18,0)) + 
> cast('9999999999999999999999999999999999999' as decimal(38,0)) from data 
> limit 1
> This is the error I get when my test program calls SQLExecDirect:
> The driver reported the following diagnostics whilst running SQLExecDirect
> HY000:1:40140:[MapR][Support] (40140) Scale can't be less than zero.



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

Reply via email to