Record Class CsvFileSourceConfig

java.lang.Object
java.lang.Record
com.darkcollective.relix.lang.ast.source.CsvFileSourceConfig
Record Components:
path - the file system path to the CSV file; must not be blank
hasHeader - true if the first row contains column names
columns - the ordered column specifications; empty to infer them
references - the declared column references; may be empty
names - the columns' names, in file order, their types to be inferred; empty to take them from the schema or the header row
All Implemented Interfaces:
SourceConfig

public record CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references, List<String> names) extends Record implements SourceConfig
Configuration for a local CSV file source.

Example:

   source Products from csv("./products.csv") {
       schema: {
           id:    NUMBER,
           name:  STRING,
           price: NUMBER
       }
   };
 

When hasHeader() is true the first row of the file is treated as a header row and matched against the schema column names. When false columns are matched positionally.

The schema may be left out, and is then inferred when the script is analysed, from the start of the file: each column's name from the header row, its type the narrowest its values read as. names() names the columns instead — for a file with no header row, or one whose header names are unusable — and the types are still inferred; a source that gives names reads its columns by position, skipping a header row if it has one. A source declares a schema or names, not both.

An optional references: block declares foreign-key style relationships from this source's columns to other relations.

  • Constructor Details

    • CsvFileSourceConfig

      public CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references, List<String> names)
      Creates an instance of a CsvFileSourceConfig record class.
      Parameters:
      path - the value for the path record component
      hasHeader - the value for the hasHeader record component
      columns - the value for the columns record component
      references - the value for the references record component
      names - the value for the names record component
    • CsvFileSourceConfig

      public CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references)
      Creates a config with declared references and no names-only list.
    • CsvFileSourceConfig

      public CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns)
      Creates a config with no declared references.
  • Method Details

    • infersSchema

      public boolean infersSchema()
      Whether the heading is inferred from the file when the script is analysed, rather than declared.
      Returns:
      true when no schema is declared
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • path

      public String path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component
    • hasHeader

      public boolean hasHeader()
      Returns the value of the hasHeader record component.
      Returns:
      the value of the hasHeader record component
    • columns

      public List<ColumnSpec> columns()
      Returns the value of the columns record component.
      Returns:
      the value of the columns record component
    • references

      public List<ColumnReference> references()
      Returns the value of the references record component.
      Returns:
      the value of the references record component
    • names

      public List<String> names()
      Returns the value of the names record component.
      Returns:
      the value of the names record component