Read Primitives — Approximate Distinct Count
Read Primitives benchmark · all Read Primitives queries
HLL distinct count on a high-cardinality key (sketch on Polars/PySpark/DataFusion; exact on Pandas/Modin/cuDF/Dask)
Representative SQL
Rendered for DataFusion with default parameters.
SELECT APPROX_DISTINCT(o_custkey) AS unique_customersFROM ordersWHERE o_orderdate >= CAST('1995-01-01' AS DATE)Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def approx_count_distinct_simple_expression_impl(ctx: DataFrameContext) -> Any: orders = ctx.get_table("orders") col = ctx.col lit = ctx.lit
return orders.filter(col("o_orderdate") >= lit(date(1995, 1, 1))).select( col("o_custkey").approx_n_unique().alias("unique_customers") )Get the exact query for your run
The blocks above are representative. To get the precise statement a specific platform runs at a specific scale, substitute your own values:
from benchbox import ReadPrimitives
bench = ReadPrimitives(scale_factor=0.01) # your scale factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['approx_count_distinct_simple'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'approx_count_distinct_simple', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py