You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by li...@apache.org on 2026/08/23 01:12:43 UTC

(seatunnel) branch dev updated: [Bug][Transform-V2] Fix CEIL/FLOOR/ROUND/MOD/TRUNC silently corrupting BIGINT and DECIMAL values (#11696) (#11712)

This is an automated email from the ASF dual-hosted git repository.

davidzollo pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new db0ad74f6a [Bug][Transform-V2] Fix CEIL/FLOOR/ROUND/MOD/TRUNC silently corrupting BIGINT and DECIMAL values (#11696) (#11712)
db0ad74f6a is described below

commit db0ad74f6a3cb325e17abdd141cb7c3c38598c65
Author: water <67...@qq.com>
AuthorDate: Sun Aug 23 09:12:38 2026 +0800

    [Bug][Transform-V2] Fix CEIL/FLOOR/ROUND/MOD/TRUNC silently corrupting BIGINT and DECIMAL values (#11696) (#11712)
    
    Co-authored-by: waterWang <wa...@users.noreply.github.com>
    Co-authored-by: davidzollo <da...@users.noreply.github.com>
    Co-authored-by: davidzollo <da...@gmail.com>
---
 docs/en/connectors/source/MongoDB-CDC.md           |  2 +-
 docs/zh/connectors/source/MongoDB-CDC.md           |  2 +-
 .../transform/sql/SQLNumericFunctionsTest.java     |  2 +-
 .../sql/zeta/functions/NumericFunctionTest.java    | 26 +++++++++++++++++++++-
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/docs/en/connectors/source/MongoDB-CDC.md b/docs/en/connectors/source/MongoDB-CDC.md
index f3586311d8..401e09ca16 100644
--- a/docs/en/connectors/source/MongoDB-CDC.md
+++ b/docs/en/connectors/source/MongoDB-CDC.md
@@ -178,7 +178,7 @@ Applications can use change streams to subscribe to all data changes on a single
 
 **Lookup Full Document for Update Operations** is a feature provided by **Change Stream** which can configure the change stream to return the most current majority-committed version of the updated document. Because of this feature, we can easily collect the latest full document and convert the change log to Changelog Stream.
 
-The format of the data captured by delete events in change streams: [delete event](https://www.mongodb.com/docs/v5.0/reference/change-events/delete/)
+The format of the data captured by delete events in change streams: [delete event](https://www.mongodb.com/docs/manual/reference/change-events/delete/)
 ```
 {
    "_id": { <Resume Token> },
diff --git a/docs/zh/connectors/source/MongoDB-CDC.md b/docs/zh/connectors/source/MongoDB-CDC.md
index d1369d0acf..1785cfb724 100644
--- a/docs/zh/connectors/source/MongoDB-CDC.md
+++ b/docs/zh/connectors/source/MongoDB-CDC.md
@@ -178,7 +178,7 @@ source {
 
 **查找更新操作的完整文档**是**更改流**提供的一项功能,它可以配置更改流以返回更新文档的最新多数提交版本。由于此功能,我们可以轻松收集最新的完整文档,并将更改日志转换为Changelog流。
 
-更新流中删除事件捕获的数据格式:[delete 事件](https://www.mongodb.com/docs/v5.0/reference/change-events/delete/)
+更新流中删除事件捕获的数据格式:[delete 事件](https://www.mongodb.com/docs/manual/reference/change-events/delete/)
 ```
 {
    "_id": { <Resume Token> },
diff --git a/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java b/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java
index 223ba4ecb0..e4cd00e564 100644
--- a/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java
+++ b/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java
@@ -65,7 +65,7 @@ public class SQLNumericFunctionsTest {
 
         Assertions.assertEquals(3, outRow.getField(0));
         Assertions.assertEquals(-1, outRow.getField(1));
-        // CEIL/FLOOR keep the type of their argument, so a DOUBLE column yields a DOUBLE
+        // CEIL/FLOOR keep the type of their argument, so a DOUBLE column yields a DOUBLE.
         Assertions.assertEquals(2d, outRow.getField(2));
         Assertions.assertEquals(1d, outRow.getField(3));
     }
diff --git a/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java b/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java
index cfed353864..d8dee6b331 100644
--- a/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java
+++ b/seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java
@@ -154,11 +154,24 @@ public class NumericFunctionTest {
                         NumericFunction.mod(
                                 Arrays.asList(new BigDecimal("5.5"), new BigDecimal("2.0")));
         Assertions.assertEquals(new BigDecimal("1.5"), bdResult.stripTrailingZeros());
+
+        // BigDecimal precision is preserved (fix for #11696)
+        BigDecimal bigLeft = new BigDecimal("123456789012345678901234567890.123456");
+        BigDecimal bigRight = new BigDecimal("9876543210.987654");
+        BigDecimal bigMod = (BigDecimal) NumericFunction.mod(Arrays.asList(bigLeft, bigRight));
+        Assertions.assertEquals(
+                bigLeft.remainder(bigRight).stripTrailingZeros(), bigMod.stripTrailingZeros());
+
+        // Mod by a divisor that underflows to 0.0 in double should not throw (fix for #11696)
+        BigDecimal tinyDivisor = new BigDecimal("0.00000000000000000001");
+        BigDecimal tinyMod =
+                (BigDecimal) NumericFunction.mod(Arrays.asList(new BigDecimal("1"), tinyDivisor));
+        Assertions.assertEquals(0, tinyMod.compareTo(BigDecimal.ZERO));
     }
 
     @Test
     public void testCeilFloorRoundAndTrunc() {
-        // CEIL/FLOOR return the type of their argument, so a DOUBLE argument yields a DOUBLE
+        // CEIL/FLOOR return the type of their argument, so a DOUBLE argument yields a DOUBLE.
         Assertions.assertEquals(2d, NumericFunction.ceil(Arrays.asList(1.2d)));
         Assertions.assertEquals(-1d, NumericFunction.ceil(Arrays.asList(-1.8d)));
 
@@ -176,6 +189,17 @@ public class NumericFunctionTest {
 
         // negative scale for integer rounding
         Assertions.assertEquals(1200, NumericFunction.round(Arrays.asList(1234, -2)).intValue());
+
+        // Long inputs preserve Long return type (fix for #11696)
+        Assertions.assertEquals(10000000000L, NumericFunction.ceil(Arrays.asList(10000000000L)));
+        Assertions.assertEquals(10000000000L, NumericFunction.floor(Arrays.asList(10000000000L)));
+        Assertions.assertEquals(10000000000L, NumericFunction.trunc(Arrays.asList(10000000000L)));
+
+        // BigDecimal inputs preserve BigDecimal return type (fix for #11696)
+        BigDecimal bd = new BigDecimal("12345.6789");
+        Assertions.assertEquals(new BigDecimal("12346"), NumericFunction.ceil(Arrays.asList(bd)));
+        Assertions.assertEquals(new BigDecimal("12345"), NumericFunction.floor(Arrays.asList(bd)));
+        Assertions.assertEquals(new BigDecimal("12345"), NumericFunction.trunc(Arrays.asList(bd)));
     }
 
     @Test