我需要将 HLL 草图从 ApacheBeam 保存到 BigQuery。
我找到了一些用于 Apache-Beam 的扩展库:
但我找不到将草图本身保存到 BigQuery 的方法。以后可以通过一段时间滑动将其与合并功能和其他功能一起使用:请参阅此链接
我的代码:
.apply("hll-count", Combine.perKey(ApproximateDistinct.ApproximateDistinctFn
.create(StringUtf8Coder.of())))
.apply("reify-windows", Reify.windows())
.apply("to-table-row", ParDo.of(new DoFn< ValueInSingleWindow<KV<GroupByData,HyperLogLogPlus>>, TableRow>() {
@ProcessElement
public void processElement(ProcessContext processContext) {
ValueInSingleWindow<KV<GroupByData,HyperLogLogPlus>> windowed = processContext.element();
KV<GroupByData, HyperLogLogPlus> keyData = windowed.getValue();
GroupByData key = keyData.getKey();
HyperLogLogPlus hyperLogLogPlus = keyData.getValue();
if (key != null) {
TableRow tableRow = new TableRow();
tableRow.set("country_code",key.countryCode);
tableRow.set("event", key.event);
tableRow.set("profile", key.profile);
tableRow.set("occurrences", hyperLogLogPlus.cardinality());
我刚刚找到了如何做,hyperLogLogPlus.cardinality()
但是如何编写缓冲区本身,以便我以后可以在 BiGQuery 中运行它的合并功能。
使用hyperLogLogPlus.getBytes
也不适用于合并。