java.lang.Object
com.darkcollective.relix.connectors.std.internal.CsvDataSourceConnector
All Implemented Interfaces:
DataSourceConnector, AutoCloseable

public final class CsvDataSourceConnector extends Object implements DataSourceConnector
A 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 a BigDecimal; throws EvaluationException if the cell is not a valid number.
  • STRING — returned verbatim (no trimming).
  • ANY — attempted as NUMBER first; falls back to STRING.
  • 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 Details

    • CsvDataSourceConnector

      public CsvDataSourceConnector(SemanticModel model, Path baseDir)
      Creates a connector for the given semantic model and base directory.
      Parameters:
      model - the fully-validated semantic model whose sources map provides CSV path and schema configuration; must not be null
      baseDir - the directory used to resolve relative CSV paths; must not be null
  • Method Details

    • open

      public Stream<Row> open(String relationName, Schema schema)
      Opens a stream of rows for the named CSV-backed relation.
      Specified by:
      open in interface DataSourceConnector
      Parameters:
      relationName - the canonical (lower-cased) relation name
      schema - 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 type
      UncheckedIOException - if an I/O error occurs while reading the file