Repository: calcite Updated Branches: refs/heads/master 3923ca3fc -> 952214a24 (forced update)
[CALCITE-1661] Support aggregation functions on DECIMAL in DruidAdapter * Fixes issue with family type identification Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/952214a2 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/952214a2 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/952214a2 Branch: refs/heads/master Commit: 952214a24fdc70c602500cac3b4d7b0e873f6399 Parents: 24df135 Author: Jesus Camacho Rodriguez <[email protected]> Authored: Fri Mar 3 11:46:00 2017 +0000 Committer: Jesus Camacho Rodriguez <[email protected]> Committed: Fri Mar 3 11:54:09 2017 +0000 ---------------------------------------------------------------------- .../apache/calcite/adapter/druid/DruidQuery.java | 19 ++++++++----------- .../apache/calcite/adapter/druid/DruidRules.java | 19 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/952214a2/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java ---------------------------------------------------------------------- diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java index c0a8a84..b76652c 100644 --- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java +++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java @@ -697,26 +697,23 @@ public class DruidQuery extends AbstractRelNode implements BindableRel { } final String only = Iterables.getFirst(list, null); final boolean fractional; - switch (aggCall.getType().getSqlTypeName().getFamily()) { - case APPROXIMATE_NUMERIC: + final RelDataType type = aggCall.getType(); + final SqlTypeName sqlTypeName = type.getSqlTypeName(); + if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(sqlTypeName)) { fractional = true; - break; - case INTEGER: + } else if (SqlTypeFamily.INTEGER.getTypeNames().contains(sqlTypeName)) { fractional = false; - break; - case EXACT_NUMERIC: + } else if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(sqlTypeName)) { // Decimal - RelDataType type = aggCall.getType(); - assert type.getSqlTypeName() == SqlTypeName.DECIMAL; + assert sqlTypeName == SqlTypeName.DECIMAL; if (type.getScale() == 0) { fractional = false; } else { fractional = true; } - break; - default: + } else { // Cannot handle this aggregate function type - throw new AssertionError("unknown aggregate type " + aggCall.getType()); + throw new AssertionError("unknown aggregate type " + type); } switch (aggCall.getAggregation().getKind()) { case COUNT: http://git-wip-us.apache.org/repos/asf/calcite/blob/952214a2/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java ---------------------------------------------------------------------- diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java index 0f3099f..0a81c47 100644 --- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java +++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java @@ -40,6 +40,7 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexShuttle; import org.apache.calcite.rex.RexUtil; import org.apache.calcite.runtime.PredicateImpl; +import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.Pair; @@ -88,23 +89,21 @@ public class DruidRules { case SUM0: case MIN: case MAX: - switch (aggregateCall.getType().getSqlTypeName().getFamily()) { - case APPROXIMATE_NUMERIC: - case INTEGER: + final RelDataType type = aggregateCall.getType(); + final SqlTypeName sqlTypeName = type.getSqlTypeName(); + if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(sqlTypeName) + || SqlTypeFamily.INTEGER.getTypeNames().contains(sqlTypeName)) { continue; - case EXACT_NUMERIC: + } else if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(sqlTypeName)) { // Decimal - RelDataType type = aggregateCall.getType(); - assert type.getSqlTypeName() == SqlTypeName.DECIMAL; + assert sqlTypeName == SqlTypeName.DECIMAL; if (type.getScale() == 0 || config.approximateDecimal()) { // If scale is zero or we allow approximating decimal, we can proceed continue; } - return true; - default: - // Cannot handle this aggregate function - return true; } + // Cannot handle this aggregate function + return true; default: // Cannot handle this aggregate function return true;
