Skip to content

Commit 67c6157

Browse files
committed
Additional casting in RowBasedColumnSelectorFactory.
1 parent b37e7e0 commit 67c6157

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
package org.apache.druid.segment;
2121

2222
import com.google.common.base.Preconditions;
23+
import com.google.common.collect.Iterables;
24+
import com.google.common.primitives.Doubles;
25+
import org.apache.druid.common.guava.GuavaUtils;
2326
import org.apache.druid.data.input.Rows;
2427
import org.apache.druid.java.util.common.parsers.ParseException;
2528
import org.apache.druid.math.expr.ExprEval;
@@ -340,6 +343,45 @@ public Class classOfObject()
340343
return Object.class;
341344
}
342345

346+
@Override
347+
public boolean isNull()
348+
{
349+
updateCurrentValues();
350+
return DimensionHandlerUtils.isNumericNull(getObject());
351+
}
352+
353+
@Override
354+
public float getFloat()
355+
{
356+
updateCurrentValues();
357+
return (float) getDouble();
358+
}
359+
360+
@Override
361+
public double getDouble()
362+
{
363+
updateCurrentValues();
364+
365+
// Below is safe since isNull() returned true.
366+
final String str = Iterables.getOnlyElement(dimensionValues);
367+
return Doubles.tryParse(str);
368+
}
369+
370+
@Override
371+
public long getLong()
372+
{
373+
updateCurrentValues();
374+
375+
// Below is safe since isNull() returned true.
376+
final String str = Iterables.getOnlyElement(dimensionValues);
377+
final Long n = GuavaUtils.tryParseLong(str);
378+
if (n != null) {
379+
return n;
380+
} else {
381+
return (long) getDouble();
382+
}
383+
}
384+
343385
@Override
344386
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
345387
{
@@ -499,7 +541,13 @@ public Object getObject()
499541

500542
if (expressionType != null && !expressionType.is(ExprType.COMPLEX)) {
501543
try {
502-
return ExprEval.bestEffortOf(currentValue).castTo(expressionType).value();
544+
final Object val = ExprEval.bestEffortOf(currentValue).castTo(expressionType).value();
545+
if (val != null && expressionType.is(ExprType.DOUBLE) && numberType == ValueType.FLOAT) {
546+
// Adjustment for FLOAT. Expressions don't speak float, so we need to cast it ourselves.
547+
return ((Number) val).floatValue();
548+
} else {
549+
return val;
550+
}
503551
}
504552
catch (Exception e) {
505553
if (throwParseExceptions) {

0 commit comments

Comments
 (0)