Class CsvDataSourceConnector
- All Implemented Interfaces:
DataSourceConnector,AutoCloseable
DataSourceConnector that reads data from local CSV files.
The connector looks up each relation in the semantic model's
SemanticModel.sources() map to obtain the CsvFileSourceConfig,
then opens the file at the configured path resolved against the supplied base
directory.
Column mapping
When CsvFileSourceConfig.hasHeader() is true, the first
CSV row is read as column names and matched case-insensitively against the
schema declared in the source config. When false, columns are
matched positionally (CSV column 0 → schema column 0, etc.).
Type coercion
Each cell string is coerced to the declared schema type:
NUMBER— parsed as aBigDecimal; throwsEvaluationExceptionif the cell is not a valid number.STRING— returned verbatim (no trimming).ANY— attempted asNUMBERfirst; falls back toSTRING.BOOLEAN—"true"/"1"→true;"false"/"0"→false(case-insensitive).
Empty cells always become NullValue.INSTANCE regardless of type.
CSV format
Fields follow RFC 4180: a field enclosed in "…" may contain
commas and newlines; "" within a quoted field represents a literal
". Blank data lines are silently skipped. A UTF-8 BOM at the
start of the file is stripped.
Resource management
This connector reads the entire file eagerly into memory; the returned stream holds no open file handle, so closing the stream is a no-op.
Usage
SemanticResult result = analyzer.analyze(stream);
CsvDataSourceConnector csv = new CsvDataSourceConnector(
result.model().orElseThrow(), Path.of("data/"));
List<QueryResult> results = executor.execute(result, csv);
-
Constructor Summary
ConstructorsConstructorDescriptionCsvDataSourceConnector(SemanticModel model, Path baseDir) Creates a connector for the given semantic model and base directory. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.darkcollective.relix.processor.internal.DataSourceConnector
close, openQuery, openQuery
-
Constructor Details
-
CsvDataSourceConnector
Creates a connector for the given semantic model and base directory.- Parameters:
model- the fully-validated semantic model whosesourcesmap provides CSV path and schema configuration; must not be nullbaseDir- the directory used to resolve relative CSV paths; must not be null
-
-
Method Details
-
open
Opens a stream of rows for the named CSV-backed relation.- Specified by:
openin interfaceDataSourceConnector- Parameters:
relationName- the canonical (lower-cased) relation nameschema- the expected output schema- Returns:
- a stream of rows materialised from the CSV file; no open file handle is retained after this method returns
- Throws:
EvaluationException- if no CSV source declaration exists for the relation, the file cannot be found, or a cell cannot be coerced to its declared typeUncheckedIOException- if an I/O error occurs while reading the file
-