[ https://issues.apache.org/jira/browse/KYLIN-3385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16569726#comment-16569726 ]
ASF GitHub Bot commented on KYLIN-3385: --------------------------------------- shaofengshi closed pull request #184: KYLIN-3385 fix sum1 error URL: https://github.com/apache/kylin/pull/184 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java index d93ada403f..c34d06c595 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java @@ -158,7 +158,7 @@ public DataType getRewriteFieldType() { if (isMax() || isMin()) { return parameter.getColRefs().get(0).getType(); } else if (isSum()) { - return parameter.getColRefs().get(0).getType(); + return parameter.isColumnType() ? parameter.getColRefs().get(0).getType() : DataType.getType("bigint"); } else if (isCount()) { return DataType.getType("bigint"); } else { @@ -249,7 +249,7 @@ public String getExpression() { public void setExpression(String expression) { this.expression = expression; } - + public ParameterDesc getParameter() { return parameter; } diff --git a/core-metadata/src/test/java/org/apache/kylin/metadata/model/FunctionDescTest.java b/core-metadata/src/test/java/org/apache/kylin/metadata/model/FunctionDescTest.java new file mode 100644 index 0000000000..5676d33731 --- /dev/null +++ b/core-metadata/src/test/java/org/apache/kylin/metadata/model/FunctionDescTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kylin.metadata.model; + +import static org.junit.Assert.assertEquals; + +import org.apache.kylin.common.KylinConfig; +import org.apache.kylin.common.util.LocalFileMetadataTestCase; +import org.apache.kylin.metadata.datatype.DataType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class FunctionDescTest { + + @Before + public void setUp() throws Exception { + System.setProperty(KylinConfig.KYLIN_CONF, LocalFileMetadataTestCase.LOCALMETA_TEST_DATA); + } + + @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", ""); + + 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("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()); + } + + @After + public void tearDown() throws Exception { + System.clearProperty(KylinConfig.KYLIN_CONF); + } +} \ No newline at end of file ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > when the cube contain sum(1) measure, tables in "Query" page cannot be load > --------------------------------------------------------------------------- > > Key: KYLIN-3385 > URL: https://issues.apache.org/jira/browse/KYLIN-3385 > Project: Kylin > Issue Type: Bug > Reporter: Yifei Wu > Assignee: Yifei Wu > Priority: Major > Fix For: v2.5.0 > > Attachments: 0001-KYLIN-3385-fix-sum-1.patch > > > In the current version, the sum(1), equals with count(*) actually, is > allowed to add to cube Measures. > However, if you add, it will cause some errors, such as tables in "Query" > page cannot be load and the query like this cannot run. > {code:java} > select sum(1) from kylin_fact > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)