This test is meant to cover that the HLL algorithm from the DataSketches library can be imported into Impala, builds without errors and the basic functionality is available to use. The below code is mostly a copy-paste from the example code found on the official DataSketches web page: https://datasketches.apache.org/docs/HLL/HllCppExample.html The purpose is to create 2 HLL sketches that have over
| 38 | // The purpose is to create 2 HLL sketches that have overlap in their data, serialize |
| 39 | // them, deserialize them and give a cardinality estimate combining the 2 sketches. |
| 40 | TEST(TestDataSketchesHll, UseDataSketchesInterface) { |
| 41 | const int lg_k = 11; |
| 42 | const auto type = datasketches::HLL_4; |
| 43 | std::stringstream sketch_stream1; |
| 44 | std::stringstream sketch_stream2; |
| 45 | // This section generates two sketches with some overlap and serializes them into files |
| 46 | { |
| 47 | // 100000 distinct keys |
| 48 | datasketches::hll_sketch sketch1(lg_k, type); |
| 49 | for (int key = 0; key < 100000; key++) sketch1.update(key); |
| 50 | sketch1.serialize_compact(sketch_stream1); |
| 51 | |
| 52 | // 100000 distinct keys where 50000 overlaps with sketch1 |
| 53 | datasketches::hll_sketch sketch2(lg_k, type); |
| 54 | for (int key = 50000; key < 150000; key++) sketch2.update(key); |
| 55 | sketch2.serialize_compact(sketch_stream2); |
| 56 | } |
| 57 | |
| 58 | // This section deserializes the sketches and produces union |
| 59 | { |
| 60 | datasketches::hll_sketch sketch1 = |
| 61 | datasketches::hll_sketch::deserialize(sketch_stream1); |
| 62 | datasketches::hll_sketch sketch2 = |
| 63 | datasketches::hll_sketch::deserialize(sketch_stream2); |
| 64 | |
| 65 | datasketches::hll_union union_sketch(lg_k); |
| 66 | union_sketch.update(sketch1); |
| 67 | union_sketch.update(sketch2); |
| 68 | datasketches::hll_sketch sketch = union_sketch.get_result(type); |
| 69 | |
| 70 | // These sketching algorithms are sensitive for the order of the inputs and may |
| 71 | // return different estimations withing the error bounds of the algorithm. However, |
| 72 | // the order of the inputs fed to the sketches is fix here so we get the same |
| 73 | // estimate every time we run this test. |
| 74 | EXPECT_EQ(152040, (int)sketch.get_estimate()); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // This test is meant to cover that the CPC algorithm from the DataSketches library can |
| 79 | // be imported into Impala, builds without errors and the basic functionality is |
nothing calls this directly
no test coverage detected