Record Class ColumnDefinition

java.lang.Object
java.lang.Record
com.darkcollective.relix.symbol.ColumnDefinition
Record Components:
name - the column name; must not be blank
type - the type of values in this column (scalar or nested); must not be null
provenance - the column's source-relation origin, or null if unknown

public record ColumnDefinition(String name, Type type, ColumnProvenance provenance) extends Record
A single column in a relation schema — its name, Type, and optional source-relation ColumnProvenance.

The type may be a ScalarType (the flat, all-scalar case) or a nested StructType/ArrayType — relix is an NF² (non-first- normal-form) algebra in which the classic flat relational model is the special case where every column is scalar. A column whose nested shape is unknown (schema-on-read) is typed ScalarType.ANY.

Column names are case-preserved (the declared form is stored as-is), but all schema-level lookups via Schema.column(String) are case-insensitive.

The optional provenance() records which relation the column came from and under what name, so that a relation-qualified reference (rooms.name) resolves precisely above a join even when the physical column has been renamed to disambiguate a collision. Provenance is metadata: it deliberately does not participate in equals(Object)/hashCode(), so two columns with the same name and type remain equal (and Schema equality — relied upon for union-compatibility, deduplication, and set operations — is unchanged) whether or not they carry provenance.

  • Constructor Details

    • ColumnDefinition

      public ColumnDefinition(String name, Type type, ColumnProvenance provenance)
      Creates an instance of a ColumnDefinition record class.
      Parameters:
      name - the value for the name record component
      type - the value for the type record component
      provenance - the value for the provenance record component
    • ColumnDefinition

      public ColumnDefinition(String name, Type type)
      Convenience constructor for a column with no known provenance — the common case (declared source schemas, projections of computed expressions, and most call sites).
      Parameters:
      name - the column name; must not be blank
      type - the column type; must not be null
  • Method Details

    • withProvenance

      public ColumnDefinition withProvenance(ColumnProvenance provenance)
      Returns a copy of this column with the given provenance.
      Parameters:
      provenance - the source-relation origin; may be null to clear it
      Returns:
      a column identical to this one but carrying provenance
    • withName

      public ColumnDefinition withName(String newName)
      Returns a copy of this column with a different physical name, preserving the type and provenance. Used when a join renames a colliding right-side column (physical name_r) while keeping its (relation, name) origin.
      Parameters:
      newName - the replacement physical name; must not be blank
      Returns:
      a column identical to this one but named newName
    • matchesQualified

      public boolean matchesQualified(String qualifier, String columnName)
      Whether this column's provenance matches the relation-qualified reference qualifier.columnName (case-insensitive). Always false when the column carries no provenance.
      Parameters:
      qualifier - the relation qualifier
      columnName - the column name within that relation
      Returns:
      true if this column originates from qualifier under the name columnName
    • equals

      public boolean equals(Object o)

      Equality is over name and type only — provenance() is excluded (see the class Javadoc).

      Specified by:
      equals in class Record
    • hashCode

      public int hashCode()
      — over name and type only (provenance excluded).
      Specified by:
      hashCode in class Record
    • 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
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • type

      public Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • provenance

      public ColumnProvenance provenance()
      Returns the value of the provenance record component.
      Returns:
      the value of the provenance record component