max_simple_state
max_simple_state calculates a partial max and returns a directly readable scalar wrapped as SimpleAggregateFunction. Ordinary max can combine those partial values again.
Unlike a full AggregateFunction state, the scalar does not need _merge or finalize_aggregation before it can be read.
Prepare two batches
sql
CREATE TABLE readings(batch UInt8, value Int64);
INSERT INTO readings VALUES (1, 10), (1, 20), (2, 90);
CREATE TABLE partials(batch UInt8, result SimpleAggregateFunction(max, Int64));
INSERT INTO partials
SELECT batch, max_simple_state(value)
FROM readings
GROUP BY batch;Read partial results
sql
SELECT batch, result
FROM partials
ORDER BY batch
FORMAT csv;text
1,20
2,90Combine the scalars
sql
SELECT max(result)
FROM partials
FORMAT csv;text
90The table does not combine rows automatically when values are inserted. Use an explicit aggregate query. See SimpleAggregateFunction for the supported inner types and functions.