mirror of https://github.com/apache/druid.git
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:
parent
039b05585c
commit
275c1ec64c
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue