| 3159 | } |
| 3160 | |
| 3161 | void AggregateFunctions::SampledNdvMerge(FunctionContext* ctx, const StringVal& src, |
| 3162 | StringVal* dst) { |
| 3163 | SampledNdvState* src_state = reinterpret_cast<SampledNdvState*>(src.ptr); |
| 3164 | SampledNdvState* dst_state = reinterpret_cast<SampledNdvState*>(dst->ptr); |
| 3165 | for (int i = 0; i < SampledNdvState::NUM_HLL_BUCKETS; ++i) { |
| 3166 | StringVal src_hll = StringVal(src_state->buckets[i].hll, DEFAULT_HLL_LEN); |
| 3167 | StringVal dst_hll = StringVal(dst_state->buckets[i].hll, DEFAULT_HLL_LEN); |
| 3168 | HllMerge(ctx, src_hll, &dst_hll); |
| 3169 | dst_state->buckets[i].row_count += src_state->buckets[i].row_count; |
| 3170 | } |
| 3171 | // Total count. Not really needed after Update() but kept for sanity checking. |
| 3172 | dst_state->total_row_count += src_state->total_row_count; |
| 3173 | // Propagate sampling percent to Finalize(). |
| 3174 | dst_state->sample_perc = src_state->sample_perc; |
| 3175 | } |
| 3176 | |
| 3177 | BigIntVal AggregateFunctions::SampledNdvFinalize(FunctionContext* ctx, |
| 3178 | const StringVal& src) { |