You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kylin.apache.org by GitBox <gi...@apache.org> on 2018/08/06 04:44:42 UTC

[GitHub] shaofengshi closed pull request #184: KYLIN-3385 fix sum1 error

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:
users@infra.apache.org


With regards,
Apache Git Services