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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to