Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sql/src/main/java/io/druid/sql/calcite/rel/QueryMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static ColumnMetaData.Rep rep(final SqlTypeName sqlType)
return ColumnMetaData.Rep.of(Integer.class);
} else if (sqlType == SqlTypeName.BIGINT) {
return ColumnMetaData.Rep.of(Long.class);
} else if (sqlType == SqlTypeName.FLOAT || sqlType == SqlTypeName.DOUBLE) {
} else if (sqlType == SqlTypeName.FLOAT || sqlType == SqlTypeName.DOUBLE || sqlType == SqlTypeName.DECIMAL) {
return ColumnMetaData.Rep.of(Double.class);
} else if (sqlType == SqlTypeName.OTHER) {
return ColumnMetaData.Rep.of(Object.class);
Expand Down Expand Up @@ -435,7 +435,7 @@ private Object coerce(final Object value, final SqlTypeName sqlType)
} else {
throw new ISE("Cannot coerce[%s] to %s", value.getClass().getName(), sqlType);
}
} else if (sqlType == SqlTypeName.FLOAT || sqlType == SqlTypeName.DOUBLE) {
} else if (sqlType == SqlTypeName.FLOAT || sqlType == SqlTypeName.DOUBLE || sqlType == SqlTypeName.DECIMAL) {
if (value instanceof String) {
coercedValue = Doubles.tryParse((String) value);
} else if (value instanceof Number) {
Expand Down
12 changes: 8 additions & 4 deletions sql/src/test/java/io/druid/sql/calcite/CalciteQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ public void testFilteredAggregations() throws Exception
public void testExpressionAggregations() throws Exception
{
testQuery(
"SELECT SUM(cnt * 3), LN(SUM(cnt) + SUM(m1)) FROM druid.foo",
"SELECT SUM(cnt * 3), LN(SUM(cnt) + SUM(m1)), SUM(cnt) / 0.25 FROM druid.foo",
ImmutableList.<Query>of(
Druids.newTimeseriesQueryBuilder()
.dataSource(CalciteTests.DATASOURCE1)
Expand All @@ -1361,14 +1361,18 @@ public void testExpressionAggregations() throws Exception
new LongSumAggregatorFactory("a1", "cnt", null),
new DoubleSumAggregatorFactory("a2", "m1", null)
))
.postAggregators(ImmutableList.<PostAggregator>of(
new ExpressionPostAggregator("a3", "log((\"a1\" + \"a2\"))")
.postAggregators(ImmutableList.of(
new ExpressionPostAggregator("a3", "log((\"a1\" + \"a2\"))"),
new ArithmeticPostAggregator("a4", "quotient", ImmutableList.of(
new FieldAccessPostAggregator(null, "a1"),
new ConstantPostAggregator(null, 0.25)
))
))
.context(TIMESERIES_CONTEXT_DEFAULT)
.build()
),
ImmutableList.of(
new Object[]{18L, 3.295836866004329}
new Object[]{18L, 3.295836866004329, 24.0}
)
);
}
Expand Down