Record Class RenameNode

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.RenameNode
Record Components:
relationName - the new relation name; empty for a column-only rename, and when present must not be blank
attributes - positional new attribute names (arity-checked); empty unless this is the positional form
pairs - old → new column renames; empty unless this is the pair form
input - the source relation; must not be null
location - the source location of this node; never null
All Implemented Interfaces:
RelNode

public record RenameNode(Optional<String> relationName, List<String> attributes, List<RenameNode.RenamePair> pairs, RelNode input, SourceLocation location) extends Record implements RelNode
Rename (ρ) — renames a relation and optionally reassigns its attribute names.

Three column-naming forms, distinguished at parse time:

  • relation-only — ρ E (Employees): rename the relation label, leave every column untouched. Both attributes() and pairs() are empty.
  • positional — ρ E (id, name) (Employees): rename the columns positionally; the list must match the input arity exactly. Carried in attributes().
  • pairs — ρ E (name → room_name, id → room_id) (Employees): rename only the listed columns (old → new); unlisted columns pass through unchanged. Carried in pairs(). This is the textbook ρ_{a→b}(R) form.

The positional and pair forms are mutually exclusive — a single rename may not mix bare names and old → new pairs.

The new relation name is optional: ρ (name → room_name) (Employees) renames columns without re-anchoring the relation label, so surviving columns keep their existing origin qualifier. When present, the relation name re-anchors every output column's provenance to it (this is what makes a self-join distinguishable).

  • Constructor Details

    • RenameNode

      public RenameNode(Optional<String> relationName, List<String> attributes, List<RenameNode.RenamePair> pairs, RelNode input, SourceLocation location)
      Creates an instance of a RenameNode record class.
      Parameters:
      relationName - the value for the relationName record component
      attributes - the value for the attributes record component
      pairs - the value for the pairs record component
      input - the value for the input record component
      location - the value for the location record component
    • RenameNode

      public RenameNode(String relationName, List<String> attributes, RelNode input, SourceLocation location)
      Convenience constructor for the relation-and-positional-columns form (a new relation name plus a possibly-empty positional attribute list). Preserves the original (String, List, RelNode, SourceLocation) signature so existing call sites are unchanged.
    • RenameNode

      public RenameNode(String relationName, List<String> attributes, RelNode input)
      Convenience constructor for tests; uses SourceLocation.UNKNOWN.
  • Method Details

    • renamesColumns

      public boolean renamesColumns()
      True iff this rename reassigns any column names (positional or pair form).
    • withInput

      public RenameNode withInput(RelNode newInput)
      Returns a copy of this node over newInput, preserving all rename metadata.
    • accept

      public <R> R accept(RelNodeVisitor<R> visitor)
      Specified by:
      accept in interface RelNode
    • 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.
    • relationName

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

      public List<String> attributes()
      Returns the value of the attributes record component.
      Returns:
      the value of the attributes record component
    • pairs

      public List<RenameNode.RenamePair> pairs()
      Returns the value of the pairs record component.
      Returns:
      the value of the pairs record component
    • input

      public RelNode input()
      Returns the value of the input record component.
      Returns:
      the value of the input record component
    • location

      public SourceLocation location()
      Returns the value of the location record component.
      Specified by:
      location in interface RelNode
      Returns:
      the value of the location record component