<@U0A71G31CDV> we have an iceberg table that has a...
# questions-and-troubleshooting
c
@Rocky we have an iceberg table that has a varbinary apache datasketches HLL column. Can we aggregate that in an external catalog MV?
r
Short answer: probably yes for building the MV, but there are two things the docs don't confirm, so test before committing. What's documented • StarRocks has the DataSketches HLL family:
ds_hll_accumulate
(builds a VARBINARY sketch),
ds_hll_combine
(aggregate function that merges VARBINARY sketches), and
ds_hll_estimate
(BIGINT from a sketch). So aggregating a VARBINARY sketch column is a supported SQL pattern in general. • Async MVs on external Iceberg catalogs are supported (non-partitioned v3.0+, partition-level features v3.1.4/v3.2+), and the listed supported data types for Iceberg MVs include
BINARY
under String. External-catalog MVs only support manual or fixed-interval async refresh — no automatic refresh on base-table change. What is not documented / needs verification 1. Sketch format compatibility. The
ds_hll_combine
docs describe its input as "a VARBINARY column containing serialized HyperLogLog sketches created by `ds_hll_accumulate`". They don't state that sketches serialized by the upstream Apache DataSketches library (e.g. Spark's
HllSketch.toCompactByteArray()
, typically HLL_4/lgK varies) are accepted. My expectation is that it works because both are DataSketches-serialized sketches, but I can't confirm that from the docs — check
log_k
and target type (HLL_4/HLL_6/HLL_8) consistency too. 2. VARBINARY in MV storage. Note the general limit that VARBINARY isn't supported in Aggregate-type tables and can't be a GROUP BY / partition / bucketing column. So your MV's GROUP BY keys must be ordinary columns and the sketch must land as a value column. Suggested validation path
Copy code
sql
-- 1. Sanity-check the sketch format directly on the catalog table first
SELECT ds_hll_estimate(sketch_col) FROM iceberg_catalog.db.tbl;

-- 2. If that returns a plausible number, the MV should be able to store ds_hll_combine(sketch_col)
CREATE MATERIALIZED VIEW mv_hll
DISTRIBUTED BY HASH(dt)
REFRESH ASYNC EVERY (INTERVAL 1 HOUR)
AS SELECT dt, ds_hll_combine(sketch_col) AS sketch FROM iceberg_catalog.db.tbl GROUP BY dt;
One more caveat: query rewrite for external-catalog MVs is documented for the classic aggregate functions (
hll_union
,
bitmap_union
,
percentile_union
, etc.) and, from v3.4, generic aggregate states like
ds_hll_count_distinct_union(ds_hll_count_distinct_state(x))
. I did not find documentation that
ds_hll_combine
participates in MV query rewrite, so don't assume a plain query will be transparently rewritten to this MV — you may need to query the MV directly (or use
force_external_table_query_rewrite
and verify with EXPLAIN). If format compatibility turns out to be the blocker, ask in the StarRocks community Slack (or file an issue on the StarRocks GitHub repo) — that's a detail worth a maintainer's confirmation rather than a guess. References • using_starrocks/async_mv/feature-support-asynchronous-materialized-views.md • using_starrocks/async_mv/use_cases/query_rewrite_with_materialized_views.md • using_starrocks/Materialized_view-single_table.md