|
20 | 20 | package org.apache.druid.segment; |
21 | 21 |
|
22 | 22 | 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; |
23 | 26 | import org.apache.druid.data.input.Rows; |
24 | 27 | import org.apache.druid.java.util.common.parsers.ParseException; |
25 | 28 | import org.apache.druid.math.expr.ExprEval; |
@@ -340,6 +343,45 @@ public Class classOfObject() |
340 | 343 | return Object.class; |
341 | 344 | } |
342 | 345 |
|
| 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 | + |
343 | 385 | @Override |
344 | 386 | public void inspectRuntimeShape(RuntimeShapeInspector inspector) |
345 | 387 | { |
@@ -499,7 +541,13 @@ public Object getObject() |
499 | 541 |
|
500 | 542 | if (expressionType != null && !expressionType.is(ExprType.COMPLEX)) { |
501 | 543 | 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 | + } |
503 | 551 | } |
504 | 552 | catch (Exception e) { |
505 | 553 | if (throwParseExceptions) { |
|
0 commit comments