This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 624c63aec7 [INLONG-11214][SDK] Modify the problem of incomplete
division in DivisionParser (#11215)
624c63aec7 is described below
commit 624c63aec770a3371c78035924c09134d0dff7d6
Author: Zkplo <[email protected]>
AuthorDate: Tue Oct 8 18:55:44 2024 +0800
[INLONG-11214][SDK] Modify the problem of incomplete division in
DivisionParser (#11215)
Co-authored-by: ZKpLo <[email protected]>
---
.../sdk/transform/process/parser/DivisionParser.java | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git
a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/parser/DivisionParser.java
b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/parser/DivisionParser.java
index 343481372e..14eb92c37b 100644
---
a/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/parser/DivisionParser.java
+++
b/inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/parser/DivisionParser.java
@@ -24,10 +24,10 @@ import
org.apache.inlong.sdk.transform.process.operator.OperatorTools;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import java.math.BigDecimal;
+import java.math.RoundingMode;
/**
* DivisionParser
- *
*/
@TransformParser(values = Division.class)
public class DivisionParser implements ValueParser {
@@ -36,23 +36,24 @@ public class DivisionParser implements ValueParser {
private ValueParser right;
+ private final int DEFAULT_SCALE_DIFFERENCE = 4;
+
public DivisionParser(Division expr) {
this.left = OperatorTools.buildParser(expr.getLeftExpression());
this.right = OperatorTools.buildParser(expr.getRightExpression());
}
- /**
- * parse
- * @param sourceData
- * @param rowIndex
- * @return
- */
@Override
public Object parse(SourceData sourceData, int rowIndex, Context context) {
Object leftObj = this.left.parse(sourceData, rowIndex, context);
Object rightObj = this.right.parse(sourceData, rowIndex, context);
BigDecimal leftValue = OperatorTools.parseBigDecimal(leftObj);
BigDecimal rightValue = OperatorTools.parseBigDecimal(rightObj);
- return leftValue.divide(rightValue);
+ try {
+ return leftValue.divide(rightValue);
+ } catch (Exception e) {
+ int scale = Math.max(leftValue.scale(), rightValue.scale()) +
DEFAULT_SCALE_DIFFERENCE;
+ return leftValue.divide(rightValue, scale, RoundingMode.HALF_UP);
+ }
}
}