Repository: calcite Updated Branches: refs/heads/master 24df135e9 -> 3923ca3fc
[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/3923ca3f Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/3923ca3f Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/3923ca3f Branch: refs/heads/master Commit: 3923ca3fc56d4ac26db683c188ece4941fe44809 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:46:35 2017 +0000 ---------------------------------------------------------------------- .../apache/calcite/adapter/druid/DruidQuery.java | 16 ++++++---------- .../apache/calcite/adapter/druid/DruidRules.java | 15 +++++++-------- 2 files changed, 13 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/3923ca3f/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..24e76ff 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,22 @@ 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(); + if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(type.getSqlTypeName())) { fractional = true; - break; - case INTEGER: + } else if (SqlTypeFamily.INTEGER.getTypeNames().contains(type.getSqlTypeName())) { fractional = false; - break; - case EXACT_NUMERIC: + } else if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(type.getSqlTypeName())) { // Decimal - RelDataType type = aggCall.getType(); assert type.getSqlTypeName() == 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/3923ca3f/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..fa9ed96 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,11 +89,11 @@ public class DruidRules { case SUM0: case MIN: case MAX: - switch (aggregateCall.getType().getSqlTypeName().getFamily()) { - case APPROXIMATE_NUMERIC: - case INTEGER: + final SqlTypeName sqlTypeName = aggregateCall.getType().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; @@ -100,11 +101,9 @@ public class DruidRules { // 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;
