Skip to content

Commit

Permalink
KYLIN-3957 Fix exception cannot cast 'java.math.BigDecimal' to 'java.…
Browse files Browse the repository at this point in the history
…lang.Double'
  • Loading branch information
Wayne1c authored and nichunen committed Apr 16, 2019
1 parent cb96418 commit 595c4e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ public DataType getRewriteFieldType() {
if (isMax() || isMin()) {
return parameter.getColRefs().get(0).getType();
} else if (isSum()) {
return parameter.isColumnType() ? DataType.getType(returnType) : DataType.getType("bigint");
if (parameter.isColumnType()) {
if (parameter.getColRefs().get(0).getType().isIntegerFamily()) {
return DataType.getType("bigint");
} else {
return parameter.getColRefs().get(0).getType();
}
} else {
return DataType.getType("bigint");
}
} else if (isCount()) {
return DataType.getType("bigint");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public void setUp() throws Exception {
public void getRewriteFieldType() {
TblColRef mockColOfDoubleType = TblColRef.mockup(TableDesc.mockup("mock_table"), 0, "price", "double", "");
TblColRef mockColOfDecimalType = TblColRef.mockup(TableDesc.mockup("mock_table"), 1, "price", "decimal", "");
TblColRef mockColOfIntegerType = TblColRef.mockup(TableDesc.mockup("mock_table"), 2, "price", "integer", "");

FunctionDesc function = FunctionDesc.newInstance("SUM", ParameterDesc.newInstance("1"), "bigint");
assertEquals(DataType.getType("bigint"), function.getRewriteFieldType());
function = FunctionDesc.newInstance("COUNT", ParameterDesc.newInstance("1"), "bigint");
assertEquals(DataType.getType("bigint"), function.getRewriteFieldType());
function = FunctionDesc.newInstance("SUM", ParameterDesc.newInstance(mockColOfDoubleType), "double");
assertEquals(DataType.getType("double"), function.getRewriteFieldType());
function = FunctionDesc.newInstance("SUM", ParameterDesc.newInstance(mockColOfIntegerType), "bigint");
assertEquals(DataType.getType("bigint"), function.getRewriteFieldType());
function = FunctionDesc.newInstance("MAX", ParameterDesc.newInstance(mockColOfDecimalType), "double");
assertEquals(DataType.getType("decimal"), function.getRewriteFieldType());
function = FunctionDesc.newInstance("MIN", ParameterDesc.newInstance(mockColOfDecimalType), "double");
Expand Down

0 comments on commit 595c4e2

Please sign in to comment.