FunctionDesc implements Serializable { public DataType getRewriteFieldType() { if (getMeasureType() instanceof BasicMeasureType) { if (isMax() || isMin()) { return parameter.getColRefs().get(0).getType(); } else if (isSum()) { 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 { throw new IllegalArgumentException("unknown measure type " + getMeasureType()); } } else { return DataType.ANY; } }  static FunctionDesc newInstance(String expression, ParameterDesc param, String returnType); boolean isMrDict(); void setMrDict(boolean mrDict); void init(DataModelDesc model); MeasureType<?> getMeasureType(); boolean needRewrite(); boolean needRewriteField(); String getRewriteFieldName(); DataType getRewriteFieldType(); ColumnDesc newFakeRewriteColumn(TableDesc sourceTable); boolean isMin(); boolean isMax(); boolean isSum(); boolean isCount(); boolean isCountDistinct(); boolean isCountConstant(); String getFullExpression(); String getFullExpressionInAlphabetOrder(); boolean isDimensionAsMetric(); void setDimensionAsMetric(boolean isDimensionAsMetric); String getExpression(); void setExpression(String expression); ParameterDesc getParameter(); void setParameter(ParameterDesc parameter); int getParameterCount(); String getReturnType(); void setReturnType(String returnType); DataType getReturnDataType(); Map<String, String> getConfiguration(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final String FUNC_SUM; static final String FUNC_MIN; static final String FUNC_MAX; static final String FUNC_COUNT; static final String FUNC_COUNT_DISTINCT; static final String FUNC_INTERSECT_COUNT; static final String FUNC_GROUPING; static final String FUNC_PERCENTILE; static final Set<String> BUILT_IN_AGGREGATIONS; static final String PARAMETER_TYPE_CONSTANT; static final String PARAMETER_TYPE_COLUMN; }
@Test 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"); assertEquals(DataType.getType("decimal"), function.getRewriteFieldType()); function = FunctionDesc.newInstance(FunctionDesc.FUNC_PERCENTILE, ParameterDesc.newInstance(mockColOfDecimalType), "double"); assertEquals(DataType.ANY, function.getRewriteFieldType()); }