Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static int compareLiteral(DataType type, Object v1, Object v2) {

private static int compare(byte[] first, byte[] second) {
for (int x = 0; x < min(first.length, second.length); x++) {
int cmp = first[x] - second[x];
int cmp = Byte.toUnsignedInt(first[x]) - Byte.toUnsignedInt(second[x]);
if (cmp != 0) {
return cmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ public void testEqual() {
assertThat(predicate.negate().orElse(null)).isEqualTo(builder.notEqual(0, 5));
}

@Test
public void testBinaryUnsignedComparison() {
PredicateBuilder builder = new PredicateBuilder(RowType.of(DataTypes.BYTES()));

Predicate greaterThan = builder.greaterThan(0, new byte[] {(byte) 0x7F});
assertThat(greaterThan.test(GenericRow.of((Object) new byte[] {(byte) 0x80}))).isTrue();
assertThat(greaterThan.test(GenericRow.of((Object) new byte[] {(byte) 0x7E}))).isFalse();

Predicate greaterThanLow = builder.greaterThan(0, new byte[] {(byte) 0x01});
assertThat(greaterThanLow.test(GenericRow.of((Object) new byte[] {(byte) 0xFF}))).isTrue();

Predicate lessThan = builder.lessThan(0, new byte[] {(byte) 0x80});
assertThat(lessThan.test(GenericRow.of((Object) new byte[] {(byte) 0x01}))).isTrue();
assertThat(lessThan.test(GenericRow.of((Object) new byte[] {(byte) 0xFF}))).isFalse();

Predicate between = builder.between(0, new byte[] {(byte) 0x70}, new byte[] {(byte) 0x90});
assertThat(between.test(GenericRow.of((Object) new byte[] {(byte) 0x80}))).isTrue();
assertThat(between.test(GenericRow.of((Object) new byte[] {(byte) 0x60}))).isFalse();
}

@Test
public void testEqualNull() {
PredicateBuilder builder = new PredicateBuilder(RowType.of(new IntType()));
Expand Down