| 1542 | |
| 1543 | template<typename T> |
| 1544 | void AggregateFunctions::PcsaUpdate(FunctionContext* c, const T& input, StringVal* dst) { |
| 1545 | DCHECK_EQ(dst->len, PC_INTERMEDIATE_BYTES); |
| 1546 | if (input.is_null) return; |
| 1547 | |
| 1548 | // Core of the algorithm. This is a direct translation of the code in the paper. |
| 1549 | // Please see the paper for details. Using stochastic averaging, we only need to |
| 1550 | // the hash value once for each row. |
| 1551 | uint32_t hash_value = AnyValUtil::Hash(input, *c->GetArgType(0), 0); |
| 1552 | uint32_t row_index = hash_value % NUM_PC_BITMAPS; |
| 1553 | |
| 1554 | // We want the zero-based position of the least significant 1-bit in binary |
| 1555 | // representation of hash_value. BitUtil::CountTrailingZeros(x,y) does exactly this |
| 1556 | // because it returns the number of trailing 0-bits in x (or y if x is zero). |
| 1557 | const int bit_index = |
| 1558 | BitUtil::CountTrailingZeros(hash_value / NUM_PC_BITMAPS, PC_BITMAP_LENGTH - 1); |
| 1559 | |
| 1560 | // Set bitmap[row_index, bit_index] to 1 |
| 1561 | SetDistinctEstimateBit(dst->ptr, row_index, bit_index); |
| 1562 | } |
| 1563 | |
| 1564 | string DistinctEstimateBitMapToString(uint8_t* v) { |
| 1565 | stringstream debugstr; |
nothing calls this directly
no test coverage detected