| 68 | } |
| 69 | |
| 70 | IMPALA_UDF_EXPORT |
| 71 | void HllUpdate(FunctionContext* ctx, const IntVal& src, StringVal* dst) { |
| 72 | if (src.is_null) return; |
| 73 | assert(dst != NULL); |
| 74 | assert(!dst->is_null); |
| 75 | assert(dst->len == pow(2, HLL_PRECISION)); |
| 76 | uint64_t hash_value = Hash(src); |
| 77 | // Use the lower bits to index into the number of streams and then find the first 1 bit |
| 78 | // after the index bits. |
| 79 | int idx = hash_value % dst->len; |
| 80 | const uint64_t hash_top_bits = hash_value >> HLL_PRECISION; |
| 81 | uint8_t first_one_bit = |
| 82 | 1 + ((hash_top_bits != 0) ? __builtin_ctzll(hash_top_bits) : |
| 83 | (sizeof(hash_value) * CHAR_BIT - HLL_PRECISION)); |
| 84 | dst->ptr[idx] = ::max(dst->ptr[idx], first_one_bit); |
| 85 | } |
| 86 | |
| 87 | IMPALA_UDF_EXPORT |
| 88 | void HllMerge(FunctionContext* ctx, const StringVal& src, StringVal* dst) { |
no test coverage detected