Record Class IndexedRelation

java.lang.Object
java.lang.Record
com.darkcollective.relix.processor.exec.IndexedRelation
Record Components:
schema - the schema shared by all rows in every group; never null
groups - a map from group-key (list of values, one per grouping attribute) to the rows that belong to that group; stored as an unmodifiable view; never null
All Implemented Interfaces:
MaterializedRelation

public record IndexedRelation(Schema schema, SequencedMap<List<Value>,List<Row>> groups) extends Record implements MaterializedRelation
A materialised relation whose rows are partitioned into groups by a composite key — the Relation type in the IBM flat-collection taxonomy (Key, Element Equality, Unordered, Multiple).

Groups are stored in insertion order (LinkedHashMap) so that output row ordering is stable and deterministic across executions.

This is the primary build structure for:

  • Aggregation (γ) — rows are grouped by the grouping attributes; each group is then reduced to a single aggregate output row.
  • Hash joins (future tasks) — the smaller input is indexed on the join key; the probe side performs key lookups via group(List).
  • Constructor Details

    • IndexedRelation

      public IndexedRelation(Schema schema, SequencedMap<List<Value>,List<Row>> groups)
      Creates an instance of a IndexedRelation record class.
      Parameters:
      schema - the value for the schema record component
      groups - the value for the groups record component
  • Method Details

    • build

      public static IndexedRelation build(Schema schema, Stream<Row> rows, Function<Row,List<Value>> keyExtractor)
      Builds an IndexedRelation by partitioning rows on the given key extractor. Insertion order of the first-seen key is preserved.
      Parameters:
      schema - the row schema
      rows - the rows to index; consumed once
      keyExtractor - a function from row to composite key
    • group

      public List<Row> group(List<Value> key)
      Returns the rows belonging to the given group key, or an empty list if no such group exists.
    • groupCount

      public int groupCount()
      Returns the number of distinct groups.
    • stream

      public Stream<Row> stream()
      Returns a lazy stream over all rows in this relation. The stream may be consumed exactly once.

      Iterates groups in insertion order, yielding all rows from each group before moving to the next.

      Specified by:
      stream in interface MaterializedRelation
    • 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.
    • schema

      public Schema schema()
      Returns the value of the schema record component.
      Specified by:
      schema in interface MaterializedRelation
      Returns:
      the value of the schema record component
    • groups

      public SequencedMap<List<Value>,List<Row>> groups()
      Returns the value of the groups record component.
      Returns:
      the value of the groups record component