QueryEvent's text cannot say.
An event's description is prose for a human reading a trace. A consumer that
wants to compute with what a run observed — comparing an estimate against the
cardinality actually produced, or totalling the work a stage did — needs the quantity
itself, not a sentence containing it.
Why this is a class and not a record
It exists so that measuring something new later does not change QueryEvent
again, and that only works if adding a measurement does not break this type
either. A record cannot deliver that: its canonical constructor is part of its public
API and cannot be made less accessible than the record itself, so a second component
would change a signature callers may already use. A final class with a private
constructor can — every construction goes through a named factory or wither, so a new
measurement is a new method and never a changed signature.
Instances are immutable and compare by value; every wither returns a new one.
Not being a record has a cost worth knowing about: equals, hashCode,
toString and isEmpty() are hand-written, and each one enumerates the
measurements — so a new measurement is four edits, three of which fail silently if
forgotten. EventMetricsTest enumerates the fields reflectively and checks all
four against each one, so the omission fails the build instead.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EventMetricsMeasures nothing — the shape an event carries when no quantity was observed. -
Method Summary
Modifier and TypeMethodDescriptionduration()How long the observed step took, when it was timed.static EventMetricsMetrics recording elapsed time.booleaninthashCode()booleanisEmpty()Whether any measurement was recorded.static EventMetricsMetrics recording both — the shape every step that counts rows as it runs produces, since it knows the count and the elapsed time at the same moment.rows()The number of rows the observed step delivered, when it counted them.static EventMetricsrows(long rows) Metrics recording a row count.toString()withDuration(Duration elapsed) Returns a copy also recordingelapsed.withRows(long rowCount) Returns a copy also recordingrowCount.
-
Field Details
-
NONE
Measures nothing — the shape an event carries when no quantity was observed.
-
-
Method Details
-
rows
Metrics recording a row count.- Parameters:
rows- the number of rows delivered; must not be negative- Returns:
- metrics carrying
rows
-
duration
Metrics recording elapsed time.- Parameters:
elapsed- how long the observed step took; must not be null or negative- Returns:
- metrics carrying
elapsed
-
of
Metrics recording both — the shape every step that counts rows as it runs produces, since it knows the count and the elapsed time at the same moment.- Parameters:
rows- the number of rows delivered; must not be negativeelapsed- how long the observed step took; must not be null or negative- Returns:
- metrics carrying both quantities
-
rows
The number of rows the observed step delivered, when it counted them.Empty and zero are different answers: a query that returned nothing measured
0, while an event that counted nothing at all measures neither.- Returns:
- the row count, or empty when nothing was counted
-
duration
How long the observed step took, when it was timed.Wall clock, and therefore a number for a human diagnosing a slow query rather than one a test asserts on: it varies with the machine, the cache and whatever else the host is doing. What each producer claims to have timed differs and is documented where it is emitted — a scan reports the time it spent producing rows, excluding the work its consumer did with them, while a query's
ROWSevent reports the run's own elapsed time from first pull to last.- Returns:
- the elapsed time, or empty when nothing was timed
-
withRows
Returns a copy also recordingrowCount.- Parameters:
rowCount- the number of rows delivered; must not be negative- Returns:
- a new instance; this one is unchanged
-
withDuration
Returns a copy also recordingelapsed.- Parameters:
elapsed- how long the observed step took; must not be null or negative- Returns:
- a new instance; this one is unchanged
-
isEmpty
public boolean isEmpty()Whether any measurement was recorded.- Returns:
truewhen nothing was measured
-
equals
-
hashCode
public int hashCode() -
toString
-