This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-0.9 by this push:
new f79d44be99 [#7703] fix(types): Add precision check to Decimal.equals()
and unit tests (#7764)
f79d44be99 is described below
commit f79d44be994b2b4ab2944488183ed71340fb0780
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Jul 21 09:25:01 2025 +1000
[#7703] fix(types): Add precision check to Decimal.equals() and unit tests
(#7764)
### What changes were proposed in this pull request?
This PR modifies the `equals()` method in the `Decimal` class
(`Decimal.java`) to include a comparison of the `precision` field in
addition to `scale` and `value`.
This change ensures that two `Decimal` instances are only considered
equal if their precision, scale, and value match.
Additionally, a unit test has been added to `TestTypes.java` to validate
the correct behavior of the updated `equals()` method.
### Why are the changes needed?
Previously, the `equals()` method only compared the `scale` and `value`,
ignoring the `precision`.
This could result in incorrect equality results for two decimal types
with the same value and scale, but different precision.
Fixes: #7703
### Does this PR introduce _any_ user-facing change?
No, this PR does not introduce any user-facing API or configuration
change. It only improves internal logic correctness.
### How was this patch tested?
- Added a unit test in `TestTypes.java`:
- Confirmed that two decimal types with same scale and precision are
equal.
- Confirmed that two decimal types with different precision are not
equal.
- If the Gradle build fails due to JDK 21, code correctness was verified
manually.
Co-authored-by: Tarun <[email protected]>
---
api/src/main/java/org/apache/gravitino/rel/types/Decimal.java | 4 +++-
api/src/test/java/org/apache/gravitino/rel/TestTypes.java | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/api/src/main/java/org/apache/gravitino/rel/types/Decimal.java
b/api/src/main/java/org/apache/gravitino/rel/types/Decimal.java
index 3c9a52fc74..83bd875f47 100644
--- a/api/src/main/java/org/apache/gravitino/rel/types/Decimal.java
+++ b/api/src/main/java/org/apache/gravitino/rel/types/Decimal.java
@@ -127,7 +127,9 @@ public class Decimal {
return false;
}
Decimal decimal = (Decimal) o;
- return scale == decimal.scale && Objects.equals(value, decimal.value);
+ return scale == decimal.scale
+ && precision == decimal.precision
+ && Objects.equals(value, decimal.value);
}
@Override
diff --git a/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
b/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
index 1de911f93f..ddf70541f0 100644
--- a/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
+++ b/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
@@ -109,6 +109,8 @@ public class TestTypes {
Assertions.assertEquals(10, decimalType.scale());
Assertions.assertEquals("decimal(26,10)", decimalType.simpleString());
Assertions.assertEquals(decimalType, Types.DecimalType.of(26, 10));
+ Assertions.assertTrue(decimalType.equals(Types.DecimalType.of(26, 10)));
+ Assertions.assertFalse(decimalType.equals(Types.DecimalType.of(20, 10)));
Types.DateType dateType = Types.DateType.get();
Assertions.assertEquals(Type.Name.DATE, dateType.name());