Fix error assuming a Complex Type that is a Number is a double (#15272)

* Fix error assuming a Complex Type that is a Number is a double
In the case where a complex type is a number, it may not be castable to double. It can safely be case as Number first to get to the doubleValue.
This commit is contained in:
Ben Sykes 2023-10-29 21:22:52 -07:00 committed by GitHub
parent 039b05585c
commit 275c1ec64c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 1 deletions

View File

@ -189,7 +189,7 @@ public class PredicateValueMatcherFactory implements ColumnProcessorFactory<Valu
return getFloatPredicate().applyFloat((float) rowValue);
} else if (rowValue instanceof Number) {
// Double or some other non-int, non-long, non-float number.
return getDoublePredicate().applyDouble((double) rowValue);
return getDoublePredicate().applyDouble(((Number) rowValue).doubleValue());
} else if (rowValue instanceof Object[]) {
return getArrayPredicate().apply((Object[]) rowValue);
} else {

View File

@ -157,6 +157,82 @@ public class PredicateValueMatcherFactoryTest extends InitializedNullHandlingTes
Assert.assertFalse(matcher.matches(false));
}
@Test
public void testNumberProcessorMatchingValue()
{
Double num = 2.;
final TestColumnValueSelector<Number> columnValueSelector = TestColumnValueSelector.of(
Number.class,
ImmutableList.of(new Number() {
@Override
public int intValue()
{
return num.intValue();
}
@Override
public long longValue()
{
return num.longValue();
}
@Override
public float floatValue()
{
return num.floatValue();
}
@Override
public double doubleValue()
{
return num;
}
}),
DateTimes.nowUtc()
);
columnValueSelector.advance();
final ValueMatcher matcher = forSelector("2").makeComplexProcessor(columnValueSelector);
Assert.assertTrue(matcher.matches(false));
}
@Test
public void testNumberProcessorNotMatchingValue()
{
Double num = 2.;
final TestColumnValueSelector<Double> columnValueSelector = TestColumnValueSelector.of(
Double.class,
ImmutableList.of(new Number() {
@Override
public int intValue()
{
return num.intValue();
}
@Override
public long longValue()
{
return num.longValue();
}
@Override
public float floatValue()
{
return num.floatValue();
}
@Override
public double doubleValue()
{
return num;
}
}),
DateTimes.nowUtc()
);
columnValueSelector.advance();
final ValueMatcher matcher = forSelector("5").makeComplexProcessor(columnValueSelector);
Assert.assertFalse(matcher.matches(false));
}
@Test
public void testLongProcessorMatchingValue()
{