Record Class CsvFileSourceConfig
- Record Components:
path- the file system path to the CSV file; must not be blankhasHeader-trueif the first row contains column namescolumns- the ordered column specifications; empty to infer themreferences- the declared column references; may be emptynames- 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
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 Summary
ConstructorsConstructorDescriptionCsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns) Creates a config with no declared references.CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references) Creates a config with declared references and no names-only list.CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references, List<String> names) Creates an instance of aCsvFileSourceConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncolumns()Returns the value of thecolumnsrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanReturns the value of thehasHeaderrecord component.booleanWhether the heading is inferred from the file when the script is analysed, rather than declared.names()Returns the value of thenamesrecord component.path()Returns the value of thepathrecord component.Returns the value of thereferencesrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
CsvFileSourceConfig
public CsvFileSourceConfig(String path, boolean hasHeader, List<ColumnSpec> columns, List<ColumnReference> references, List<String> names) Creates an instance of aCsvFileSourceConfigrecord class.- Parameters:
path- the value for thepathrecord componenthasHeader- the value for thehasHeaderrecord componentcolumns- the value for thecolumnsrecord componentreferences- the value for thereferencesrecord componentnames- the value for thenamesrecord 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
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:
truewhen no schema is declared
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
path
Returns the value of thepathrecord component.- Returns:
- the value of the
pathrecord component
-
hasHeader
public boolean hasHeader()Returns the value of thehasHeaderrecord component.- Returns:
- the value of the
hasHeaderrecord component
-
columns
Returns the value of thecolumnsrecord component.- Returns:
- the value of the
columnsrecord component
-
references
Returns the value of thereferencesrecord component.- Returns:
- the value of the
referencesrecord component
-
names
Returns the value of thenamesrecord component.- Returns:
- the value of the
namesrecord component
-