mirror of https://github.com/apache/druid.git
test fold permutations with various maxOverflow / offsets
This commit is contained in:
parent
cc40a3394d
commit
d96d82252d
|
@ -19,16 +19,23 @@
|
|||
|
||||
package io.druid.query.aggregation.hyperloglog;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
|
@ -810,6 +817,59 @@ public class HyperLogLogCollectorTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFoldOrder() throws Exception
|
||||
{
|
||||
final List<String> objects = Lists.newArrayList(
|
||||
"AQcH/xYEMXOjRTVSQ1NXVENEM1RTUlVTRDI1aEVnhkOjNUaCI2MkU2VVhVNkNyVTa4NEYkS0kjZYU1RDdEYzUjglNTUzVFM0NkU3ZFUjOVJCdlU0N2QjRDRUV1MyZjNmVDOUM2RVVFRzhnUzVXY1R1RHUnNziURUdmREM0VjVEQmU0aEInZYNzNZNVRFgzVFNolSJHNIQ3QklEZlNSNoNTJXpDk1dFWjJGNYNiQzQkZFNEYzc1NVhSczM2NmJDZlc3JJRCpVNiRlNEI3dmU1ZGI0Q1RCMhNFZEJDZDYyNFOCM3U0VmRlVlNIRVQ4VVw1djNDVURHVSaFU0VEY0U1JFNIVCYlVEJWM2NWU0eURDOjQ6YyNTYkZjNUVjR1ZDdnVkMzVHZFpjMzlmNEFHM0dHJlRYTHSEQjVZVVZkVVIzIjg2SUU0NSM0VFNDNCdGVlQkhBNENCVTZGZ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ullable
|
||||
@Override
|
||||
public HyperLogLogCollector apply(
|
||||
@Nullable String s
|
||||
)
|
||||
{
|
||||
return HyperLogLogCollector.makeCollector(
|
||||
ByteBuffer.wrap(Base64.decodeBase64(s))
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Collection<List<HyperLogLogCollector>> permutations = Collections2.permutations(collectors);
|
||||
Collection<List<HyperLogLogCollector>> selectPermutations = Lists.<List<HyperLogLogCollector>>newArrayList(
|
||||
Iterables.get(
|
||||
permutations,
|
||||
3
|
||||
)
|
||||
);
|
||||
|
||||
selectPermutations = permutations;
|
||||
|
||||
// ArrayList<List<HyperLogLogCollector>> selectPermutations = Lists.<List<HyperLogLogCollector>>newArrayList(
|
||||
// Iterables.get(
|
||||
// permutations,
|
||||
// 1
|
||||
// )
|
||||
// );
|
||||
|
||||
for(List<HyperLogLogCollector> permutation : selectPermutations) {
|
||||
HyperLogLogCollector collector = HyperLogLogCollector.makeLatestCollector();
|
||||
|
||||
for (HyperLogLogCollector foldee : permutation) {
|
||||
collector.fold(foldee);
|
||||
}
|
||||
System.err.println(collector.estimateCardinality());
|
||||
}
|
||||
}
|
||||
|
||||
// Provides a nice printout of error rates as a function of cardinality
|
||||
@Ignore @Test
|
||||
public void showErrorRate() throws Exception
|
||||
|
|
Loading…
Reference in New Issue