Record Class QueryEvent

java.lang.Object
java.lang.Record
com.darkcollective.relix.events.QueryEvent
Record Components:
stage - which part of the pipeline produced the event
code - a short identifier, e.g. "SEL-001", "JOIN", "PUSHDOWN"; never blank
description - a human-readable summary of what happened; never blank
target - the query/relation the event applies to, if known
metrics - the quantities observed with the event; EventMetrics.NONE when the producer measured nothing

public record QueryEvent(QueryEvent.Stage stage, String code, String description, Optional<String> target, EventMetrics metrics) extends Record
One observed decision in the query pipeline — a rule that fired in the optimizer, or a physical choice the planner made.

The event is deliberately neutral and display-oriented: it carries a QueryEvent.Stage, a short code, a human-readable description, and an optional target (the query or relation it applies to). It exposes none of the producer's internal types, so a single QueryEventListener can observe the optimizer and the planner as one uniform feed.

It also carries optional EventMetrics — the quantities the prose cannot express. A trace is read by a human, but a consumer that compares an estimate against what a run actually produced has to compute with the number rather than parse it back out of a sentence. Measurements live behind one optional component so that observing something new later adds a factory to EventMetrics rather than a component here, which a record in a published module cannot gain cheaply.

  • Constructor Details

    • QueryEvent

      public QueryEvent(QueryEvent.Stage stage, String code, String description, Optional<String> target, EventMetrics metrics)
      Creates an instance of a QueryEvent record class.
      Parameters:
      stage - the value for the stage record component
      code - the value for the code record component
      description - the value for the description record component
      target - the value for the target record component
      metrics - the value for the metrics record component
    • QueryEvent

      public QueryEvent(QueryEvent.Stage stage, String code, String description, Optional<String> target)
      As the canonical constructor, but measuring nothing — the shape for a producer that only describes what it did.
      Parameters:
      stage - the pipeline stage
      code - a short identifier; never blank
      description - a human-readable summary; never blank
      target - the query/relation the event applies to, if known
  • Method Details

    • of

      public static QueryEvent of(QueryEvent.Stage stage, String code, String description)
      Creates an event with no target.
      Parameters:
      stage - the pipeline stage
      code - the short identifier
      description - the human-readable summary
      Returns:
      a new event whose target() is empty
    • of

      public static QueryEvent of(QueryEvent.Stage stage, String code, String description, String target)
      Creates an event targeting a specific query/relation.
      Parameters:
      stage - the pipeline stage
      code - the short identifier
      description - the human-readable summary
      target - the query/relation name
      Returns:
      a new event with the given target
    • withTarget

      public QueryEvent withTarget(String target)
      Returns a copy of this event with target as its target — used by a consumer that knows the owning query an emitter could not.
      Parameters:
      target - the query/relation name; must not be null
      Returns:
      a copy carrying the given target
    • withMetrics

      public QueryEvent withMetrics(EventMetrics measured)
      Returns a copy of this event carrying measured.

      The wither shape matches withTarget(String), and for the same reason: a producer writes the description when it knows what it did, and attaches what it counted once it knows the number — which for a row count is only after the rows have been delivered.

      Parameters:
      measured - the quantities observed; must not be null
      Returns:
      a new event; this one is unchanged
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • stage

      public QueryEvent.Stage stage()
      Returns the value of the stage record component.
      Returns:
      the value of the stage record component
    • code

      public String code()
      Returns the value of the code record component.
      Returns:
      the value of the code record component
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • target

      public Optional<String> target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • metrics

      public EventMetrics metrics()
      Returns the value of the metrics record component.
      Returns:
      the value of the metrics record component