This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new c5c7ec0502 Fix for issue #7346 (#7347)
c5c7ec0502 is described below
commit c5c7ec0502cc0e0db35d58b5a5a54c06321015df
Author: Matt Casters <[email protected]>
AuthorDate: Thu Jun 25 09:17:18 2026 +0200
Fix for issue #7346 (#7347)
---
.../apache/hop/core/row/value/ValueMetaBase.java | 17 +---------------
.../hop/core/row/value/ValueMetaBaseTest.java | 23 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git
a/core/src/main/java/org/apache/hop/core/row/value/ValueMetaBase.java
b/core/src/main/java/org/apache/hop/core/row/value/ValueMetaBase.java
index 492a7daf6c..8ce22730d2 100644
--- a/core/src/main/java/org/apache/hop/core/row/value/ValueMetaBase.java
+++ b/core/src/main/java/org/apache/hop/core/row/value/ValueMetaBase.java
@@ -4272,22 +4272,7 @@ public class ValueMetaBase implements IValueMeta {
break;
case TYPE_BINARY:
- byte[] b1 = (byte[]) data1;
- byte[] b2 = (byte[]) data2;
-
- int byteLength = Math.min(b1.length, b2.length);
-
- cmp = b1.length - b2.length;
- if (cmp == 0) {
- for (int i = 0; i < byteLength; i++) {
- cmp = b1[i] - b2[i];
- if (cmp != 0) {
- cmp = cmp < 0 ? -1 : 1;
- break;
- }
- }
- }
-
+ cmp = Integer.signum(Arrays.compareUnsigned((byte[]) data1, (byte[])
data2));
break;
default:
throw new HopValueException(
diff --git
a/core/src/test/java/org/apache/hop/core/row/value/ValueMetaBaseTest.java
b/core/src/test/java/org/apache/hop/core/row/value/ValueMetaBaseTest.java
index db42227080..eb8cdade3f 100644
--- a/core/src/test/java/org/apache/hop/core/row/value/ValueMetaBaseTest.java
+++ b/core/src/test/java/org/apache/hop/core/row/value/ValueMetaBaseTest.java
@@ -646,6 +646,29 @@ class ValueMetaBaseTest {
assertEquals(0, dateMeta.compare(value1, value1));
}
+ @Test
+ void testCompareBinaryUnsignedAndLength() throws HopValueException {
+ IValueMeta binaryMeta = new ValueMetaBinary("hash");
+
+ // Unsigned byte comparison: 0xFF (255) > 0x00 (0)
+ byte[] highByte = new byte[] {(byte) 0xFF};
+ byte[] lowByte = new byte[] {0};
+ assertEquals(1, binaryMeta.compare(highByte, lowByte));
+ assertEquals(-1, binaryMeta.compare(lowByte, highByte));
+
+ // Compare common prefix before length (matches PostgreSQL bytea ORDER BY)
+ byte[] shorterHigher = new byte[] {2};
+ byte[] longerLower = new byte[] {1, 0};
+ assertEquals(1, binaryMeta.compare(shorterHigher, longerLower));
+ assertEquals(-1, binaryMeta.compare(longerLower, shorterHigher));
+
+ // Shorter value is smaller when it is a prefix of the longer value
+ byte[] prefix = new byte[] {1, 2, 3};
+ byte[] extended = new byte[] {1, 2, 3, 4};
+ assertEquals(-1, binaryMeta.compare(prefix, extended));
+ assertEquals(1, binaryMeta.compare(extended, prefix));
+ }
+
@Test
void testDateParsing8601() throws Exception {
ValueMetaDate dateMeta = new ValueMetaDate("date");