You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/04/15 02:55:52 UTC

[GitHub] [incubator-doris] wangbo opened a new pull request #3320: (#3319) support java version hyperloglog

wangbo opened a new pull request #3320: (#3319) support java version hyperloglog
URL: https://github.com/apache/incubator-doris/pull/3320
 
 
   #3319

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] chaoyli commented on issue #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
chaoyli commented on issue #3320: (#3319) support java version hyperloglog
URL: https://github.com/apache/incubator-doris/pull/3320#issuecomment-613884776
 
 
   You should describe you job in commit log

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman merged pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman commented on pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
morningman commented on pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320#issuecomment-619033944


   Is it possible to consider using some test data, comparing the hll data obtained from the C++ version with the java version to verify whether the two versions of the algorithm are consistent? And this verification can be put into unit tests.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] wangbo edited a comment on pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
wangbo edited a comment on pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320#issuecomment-619336137


   >Is it possible to consider using some test data, comparing the hll data obtained from the C++ version with the java version to verify whether the two versions of the algorithm are consistent? And this verification can be put into unit tests.
   
   @morningman Current UT has contains the case that the approximation from``` 0 to Short.MAX ```  is consistent with be. I'll try to find more special case


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] wangbo commented on pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
wangbo commented on pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320#issuecomment-619336137


   >Is it possible to consider using some test data, comparing the hll data obtained from the C++ version with the java version to verify whether the two versions of the algorithm are consistent? And this verification can be put into unit tests.
   @morningman Current UT has contains the case that the approximation from``` 0 to Short.MAX ```  is consistent with be. I'll try to find more special case


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman commented on a change in pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320#discussion_r441548250



##########
File path: fe/src/test/java/org/apache/doris/load/loadv2/HllTest.java
##########
@@ -0,0 +1,268 @@
+// 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.doris.load.loadv2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import static org.apache.doris.load.loadv2.Hll.*;
+
+public class HllTest {
+
+    @Test
+    public void testFindFirstNonZeroBitPosition() {
+        Assert.assertTrue(getLongTailZeroNum(0) == 0);
+        Assert.assertTrue(getLongTailZeroNum(1) == 0);
+        Assert.assertTrue(getLongTailZeroNum(1l << 30) == 30);
+        Assert.assertTrue(getLongTailZeroNum(1l << 62) == 62);
+    }
+
+    @Test
+    public void HllBasicTest() throws IOException {
+        // test empty
+        Hll emptyHll = new Hll();
+
+        Assert.assertTrue(emptyHll.getType() == HLL_DATA_EMPTY);
+        Assert.assertTrue(emptyHll.estimateCardinality() == 0);
+
+        ByteArrayOutputStream emptyOutputStream = new ByteArrayOutputStream();
+        DataOutput output = new DataOutputStream(emptyOutputStream);
+        emptyHll.serialize(output);
+        DataInputStream emptyInputStream = new DataInputStream(new ByteArrayInputStream(emptyOutputStream.toByteArray()));
+        Hll deserializedEmptyHll = new Hll();
+        deserializedEmptyHll.deserialize(emptyInputStream);
+        Assert.assertTrue(deserializedEmptyHll.getType() == HLL_DATA_EMPTY);
+
+        // test explicit
+        Hll explicitHll = new Hll();
+        for (int i = 0; i < HLL_EXPLICLIT_INT64_NUM; i++) {
+            explicitHll.updateWithHash(i);
+        }
+        Assert.assertTrue(explicitHll.getType() == HLL_DATA_EXPLICIT);
+        Assert.assertTrue(explicitHll.estimateCardinality() == HLL_EXPLICLIT_INT64_NUM);
+
+        ByteArrayOutputStream explicitOutputStream = new ByteArrayOutputStream();
+        DataOutput explicitOutput = new DataOutputStream(explicitOutputStream);
+        explicitHll.serialize(explicitOutput);
+        DataInputStream explicitInputStream = new DataInputStream(new ByteArrayInputStream(explicitOutputStream.toByteArray()));
+        Hll deserializedExplicitHll = new Hll();
+        deserializedExplicitHll.deserialize(explicitInputStream);
+        Assert.assertTrue(deserializedExplicitHll.getType() == HLL_DATA_EXPLICIT);
+
+        // test sparse
+        Hll sparseHll = new Hll();
+        for (int i = 0; i < HLL_SPARSE_THRESHOLD; i++) {
+            sparseHll.updateWithHash(i);
+        }
+        Assert.assertTrue(sparseHll.getType() == HLL_DATA_FULL);
+        // 2% error rate
+        Assert.assertTrue(sparseHll.estimateCardinality() > HLL_SPARSE_THRESHOLD * (1 - 0.02) &&
+                sparseHll.estimateCardinality() < HLL_SPARSE_THRESHOLD * (1 + 0.02));
+
+        ByteArrayOutputStream sparseOutputStream = new ByteArrayOutputStream();
+        DataOutput sparseOutput = new DataOutputStream(sparseOutputStream);
+        sparseHll.serialize(sparseOutput);
+        DataInputStream sparseInputStream = new DataInputStream(new ByteArrayInputStream(sparseOutputStream.toByteArray()));
+        Hll deserializedSparseHll = new Hll();
+        deserializedSparseHll.deserialize(sparseInputStream);
+        Assert.assertTrue(deserializedSparseHll.getType() == HLL_DATA_SPARSE);
+        Assert.assertTrue(sparseHll.estimateCardinality() == deserializedSparseHll.estimateCardinality());
+
+
+        // test full
+        Hll fullHll = new Hll();
+        for (int i = 1; i <= Short.MAX_VALUE; i++) {
+            fullHll.updateWithHash(i);
+        }
+        Assert.assertTrue(fullHll.getType() == HLL_DATA_FULL);
+        // the result 32748 is consistent with C++ 's implementation
+        Assert.assertTrue(fullHll.estimateCardinality() == 32748);
+        Assert.assertTrue(fullHll.estimateCardinality() > Short.MAX_VALUE * (1 - 0.02) &&
+                fullHll.estimateCardinality() < Short.MAX_VALUE * (1 + 0.02));
+
+        ByteArrayOutputStream fullHllOutputStream = new ByteArrayOutputStream();
+        DataOutput fullHllOutput = new DataOutputStream(fullHllOutputStream);
+        fullHll.serialize(fullHllOutput);
+        DataInputStream fullHllInputStream = new DataInputStream(new ByteArrayInputStream(fullHllOutputStream.toByteArray()));
+        Hll deserializedFullHll = new Hll();
+        deserializedFullHll.deserialize(fullHllInputStream);
+        Assert.assertTrue(deserializedFullHll.getType() == HLL_DATA_FULL);
+        Assert.assertTrue(deserializedFullHll.estimateCardinality() == fullHll.estimateCardinality());
+
+    }
+
+    // keep logic same with C++ version
+    // add additional compare logic with C++ version's estimateValue

Review comment:
       better to add comment in `be/test/olap/hll_test.cpp` to notice that the following test case should be consistent with java version in `fe/src/test/java/org/apache/doris/load/loadv2/HllTest.java`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] wangbo commented on pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
wangbo commented on pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320#issuecomment-640994595


   1 use little endian when serialize hll
   2 add some ut which keep same logic which be hll ut and value check
   @morningman plz review 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] wangbo commented on a change in pull request #3320: (#3319) support java version hyperloglog

Posted by GitBox <gi...@apache.org>.
wangbo commented on a change in pull request #3320:
URL: https://github.com/apache/incubator-doris/pull/3320#discussion_r441975600



##########
File path: fe/src/test/java/org/apache/doris/load/loadv2/HllTest.java
##########
@@ -0,0 +1,268 @@
+// 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.doris.load.loadv2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import static org.apache.doris.load.loadv2.Hll.*;
+
+public class HllTest {
+
+    @Test
+    public void testFindFirstNonZeroBitPosition() {
+        Assert.assertTrue(getLongTailZeroNum(0) == 0);
+        Assert.assertTrue(getLongTailZeroNum(1) == 0);
+        Assert.assertTrue(getLongTailZeroNum(1l << 30) == 30);
+        Assert.assertTrue(getLongTailZeroNum(1l << 62) == 62);
+    }
+
+    @Test
+    public void HllBasicTest() throws IOException {
+        // test empty
+        Hll emptyHll = new Hll();
+
+        Assert.assertTrue(emptyHll.getType() == HLL_DATA_EMPTY);
+        Assert.assertTrue(emptyHll.estimateCardinality() == 0);
+
+        ByteArrayOutputStream emptyOutputStream = new ByteArrayOutputStream();
+        DataOutput output = new DataOutputStream(emptyOutputStream);
+        emptyHll.serialize(output);
+        DataInputStream emptyInputStream = new DataInputStream(new ByteArrayInputStream(emptyOutputStream.toByteArray()));
+        Hll deserializedEmptyHll = new Hll();
+        deserializedEmptyHll.deserialize(emptyInputStream);
+        Assert.assertTrue(deserializedEmptyHll.getType() == HLL_DATA_EMPTY);
+
+        // test explicit
+        Hll explicitHll = new Hll();
+        for (int i = 0; i < HLL_EXPLICLIT_INT64_NUM; i++) {
+            explicitHll.updateWithHash(i);
+        }
+        Assert.assertTrue(explicitHll.getType() == HLL_DATA_EXPLICIT);
+        Assert.assertTrue(explicitHll.estimateCardinality() == HLL_EXPLICLIT_INT64_NUM);
+
+        ByteArrayOutputStream explicitOutputStream = new ByteArrayOutputStream();
+        DataOutput explicitOutput = new DataOutputStream(explicitOutputStream);
+        explicitHll.serialize(explicitOutput);
+        DataInputStream explicitInputStream = new DataInputStream(new ByteArrayInputStream(explicitOutputStream.toByteArray()));
+        Hll deserializedExplicitHll = new Hll();
+        deserializedExplicitHll.deserialize(explicitInputStream);
+        Assert.assertTrue(deserializedExplicitHll.getType() == HLL_DATA_EXPLICIT);
+
+        // test sparse
+        Hll sparseHll = new Hll();
+        for (int i = 0; i < HLL_SPARSE_THRESHOLD; i++) {
+            sparseHll.updateWithHash(i);
+        }
+        Assert.assertTrue(sparseHll.getType() == HLL_DATA_FULL);
+        // 2% error rate
+        Assert.assertTrue(sparseHll.estimateCardinality() > HLL_SPARSE_THRESHOLD * (1 - 0.02) &&
+                sparseHll.estimateCardinality() < HLL_SPARSE_THRESHOLD * (1 + 0.02));
+
+        ByteArrayOutputStream sparseOutputStream = new ByteArrayOutputStream();
+        DataOutput sparseOutput = new DataOutputStream(sparseOutputStream);
+        sparseHll.serialize(sparseOutput);
+        DataInputStream sparseInputStream = new DataInputStream(new ByteArrayInputStream(sparseOutputStream.toByteArray()));
+        Hll deserializedSparseHll = new Hll();
+        deserializedSparseHll.deserialize(sparseInputStream);
+        Assert.assertTrue(deserializedSparseHll.getType() == HLL_DATA_SPARSE);
+        Assert.assertTrue(sparseHll.estimateCardinality() == deserializedSparseHll.estimateCardinality());
+
+
+        // test full
+        Hll fullHll = new Hll();
+        for (int i = 1; i <= Short.MAX_VALUE; i++) {
+            fullHll.updateWithHash(i);
+        }
+        Assert.assertTrue(fullHll.getType() == HLL_DATA_FULL);
+        // the result 32748 is consistent with C++ 's implementation
+        Assert.assertTrue(fullHll.estimateCardinality() == 32748);
+        Assert.assertTrue(fullHll.estimateCardinality() > Short.MAX_VALUE * (1 - 0.02) &&
+                fullHll.estimateCardinality() < Short.MAX_VALUE * (1 + 0.02));
+
+        ByteArrayOutputStream fullHllOutputStream = new ByteArrayOutputStream();
+        DataOutput fullHllOutput = new DataOutputStream(fullHllOutputStream);
+        fullHll.serialize(fullHllOutput);
+        DataInputStream fullHllInputStream = new DataInputStream(new ByteArrayInputStream(fullHllOutputStream.toByteArray()));
+        Hll deserializedFullHll = new Hll();
+        deserializedFullHll.deserialize(fullHllInputStream);
+        Assert.assertTrue(deserializedFullHll.getType() == HLL_DATA_FULL);
+        Assert.assertTrue(deserializedFullHll.estimateCardinality() == fullHll.estimateCardinality());
+
+    }
+
+    // keep logic same with C++ version
+    // add additional compare logic with C++ version's estimateValue

Review comment:
       👌




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org