You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/01/12 08:01:36 UTC

kylin git commit: KYLIN-2383 let HLLC handle NULL input correctly

Repository: kylin
Updated Branches:
  refs/heads/master b0a406ff3 -> c6108a78e


KYLIN-2383 let HLLC handle NULL input correctly


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/c6108a78
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/c6108a78
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/c6108a78

Branch: refs/heads/master
Commit: c6108a78eeca8e4b906aeba4f94e28addd974676
Parents: b0a406f
Author: Li Yang <li...@apache.org>
Authored: Thu Jan 12 15:59:51 2017 +0800
Committer: Li Yang <li...@apache.org>
Committed: Thu Jan 12 16:01:17 2017 +0800

----------------------------------------------------------------------
 .../apache/kylin/measure/MeasureIngester.java   |  1 +
 .../org/apache/kylin/measure/MeasureType.java   |  1 +
 .../kylin/measure/hllc/HLLCMeasureType.java     | 20 ++++--
 .../kylin/measure/hllc/HLLCMeasureTypeTest.java | 65 ++++++++++++++++++++
 .../apache/kylin/rest/service/QueryService.java |  3 +
 5 files changed, 86 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/c6108a78/core-metadata/src/main/java/org/apache/kylin/measure/MeasureIngester.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/MeasureIngester.java b/core-metadata/src/main/java/org/apache/kylin/measure/MeasureIngester.java
index 26b7298..ed2cb02 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/MeasureIngester.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/MeasureIngester.java
@@ -26,6 +26,7 @@ import java.util.Collection;
 import java.util.Map;
 
 abstract public class MeasureIngester<V> implements java.io.Serializable {
+    private static final long serialVersionUID = 1L;
 
     public static MeasureIngester<?> create(MeasureDesc measure) {
         return measure.getFunction().getMeasureType().newIngester();

http://git-wip-us.apache.org/repos/asf/kylin/blob/c6108a78/core-metadata/src/main/java/org/apache/kylin/measure/MeasureType.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/MeasureType.java b/core-metadata/src/main/java/org/apache/kylin/measure/MeasureType.java
index 3338c8c..f609dd5 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/MeasureType.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/MeasureType.java
@@ -39,6 +39,7 @@ import java.util.Map;
  * @param <T> the Java type of aggregation data object, e.g. HLLCounter
  */
 abstract public class MeasureType<T> implements java.io.Serializable {
+    private static final long serialVersionUID = 1L;
 
     /* ============================================================================
      * Define

http://git-wip-us.apache.org/repos/asf/kylin/blob/c6108a78/core-metadata/src/main/java/org/apache/kylin/measure/hllc/HLLCMeasureType.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/hllc/HLLCMeasureType.java b/core-metadata/src/main/java/org/apache/kylin/measure/hllc/HLLCMeasureType.java
index de36b08..51c5a66 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/hllc/HLLCMeasureType.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/hllc/HLLCMeasureType.java
@@ -34,6 +34,7 @@ import org.apache.kylin.metadata.model.TblColRef;
 import com.google.common.collect.ImmutableMap;
 
 public class HLLCMeasureType extends MeasureType<HLLCounter> {
+    private static final long serialVersionUID = 1L;
 
     public static final String FUNC_COUNT_DISTINCT = FunctionDesc.FUNC_COUNT_DISTINCT;
     public static final String DATATYPE_HLLC = "hllc";
@@ -93,15 +94,26 @@ public class HLLCMeasureType extends MeasureType<HLLCounter> {
     @Override
     public MeasureIngester<HLLCounter> newIngester() {
         return new MeasureIngester<HLLCounter>() {
+            private static final long serialVersionUID = 1L;
+            
             HLLCounter current = new HLLCounter(dataType.getPrecision());
 
             @Override
             public HLLCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) {
                 HLLCounter hllc = current;
                 hllc.clear();
-                for (String v : values) {
-                    if (v != null)
-                        hllc.add(v);
+                if (values.length == 1) {
+                    if (values[0] != null)
+                        hllc.add(values[0]);
+                } else {
+                    boolean allNull = true;
+                    StringBuilder buf = new StringBuilder();
+                    for (String v : values) {
+                        allNull = (allNull && v == null);
+                        buf.append(v);
+                    }
+                    if (!allNull)
+                        hllc.add(buf.toString());
                 }
                 return hllc;
             }
@@ -133,5 +145,5 @@ public class HLLCMeasureType extends MeasureType<HLLCounter> {
     public static boolean isCountDistinct(FunctionDesc func) {
         return FUNC_COUNT_DISTINCT.equalsIgnoreCase(func.getExpression());
     }
-
+    
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/c6108a78/core-metadata/src/test/java/org/apache/kylin/measure/hllc/HLLCMeasureTypeTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/measure/hllc/HLLCMeasureTypeTest.java b/core-metadata/src/test/java/org/apache/kylin/measure/hllc/HLLCMeasureTypeTest.java
new file mode 100644
index 0000000..acd2ea3
--- /dev/null
+++ b/core-metadata/src/test/java/org/apache/kylin/measure/hllc/HLLCMeasureTypeTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.measure.hllc;
+
+import static org.junit.Assert.*;
+
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.apache.kylin.measure.MeasureIngester;
+import org.apache.kylin.measure.MeasureType;
+import org.apache.kylin.measure.MeasureTypeFactory;
+import org.apache.kylin.metadata.datatype.DataType;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HLLCMeasureTypeTest extends LocalFileMetadataTestCase {
+
+    @Before
+    public void setUp() throws Exception {
+        this.createTestMetadata();
+    }
+
+    @After
+    public void after() throws Exception {
+        this.cleanupTestMetadata();
+    }
+
+    @Test
+    public void testIngest() {
+        MeasureType<HLLCounter> mtype = (MeasureType<HLLCounter>) MeasureTypeFactory.create(HLLCMeasureType.FUNC_COUNT_DISTINCT, DataType.getType("hllc(10)"));
+        MeasureIngester<HLLCounter> ingester = mtype.newIngester();
+        HLLCounter hllc;
+        
+        hllc = ingester.valueOf(new String[] { null }, null, null);
+        assertEquals(0, hllc.getCountEstimate());
+        
+        hllc = ingester.valueOf(new String[] { null, null }, null, null);
+        assertEquals(0, hllc.getCountEstimate());
+        
+        hllc = ingester.valueOf(new String[] { "" }, null, null);
+        assertEquals(1, hllc.getCountEstimate());
+        
+        hllc = ingester.valueOf(new String[] { "", null }, null, null);
+        assertEquals(1, hllc.getCountEstimate());
+        
+        hllc = ingester.valueOf(new String[] { "abc" }, null, null);
+        assertEquals(1, hllc.getCountEstimate());
+    }
+}

http://git-wip-us.apache.org/repos/asf/kylin/blob/c6108a78/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
index bc644cc..98eb7cb 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
@@ -325,6 +325,9 @@ public class QueryService extends BasicService {
         if (!(Constant.SERVER_MODE_QUERY.equals(serverMode.toLowerCase()) || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase()))) {
             throw new InternalErrorException("Query is not allowed in " + serverMode + " mode.");
         }
+        if (StringUtils.isBlank(sqlRequest.getProject())) {
+            throw new InternalErrorException("Project cannot be empty. Please select a project.");
+        }
 
         final String queryId = UUID.randomUUID().toString();
         if (sqlRequest.getBackdoorToggles() != null)