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

public final class JsonFileDataSourceConnector extends Object implements DataSourceConnector
A DataSourceConnector that reads rows from a local JSON file as open (schema-on-read) documents — the first native nested-data source.

The connector looks up each relation in the semantic model's SemanticModel.sources() map to obtain its JsonFileSourceConfig, reads the file at the configured path (resolved against the supplied base directory), parses it via JsonValues, and yields one DocumentRow per record object.

Record extraction

Where the records live in the parsed document depends on JsonFileSourceConfig.records():

  • present — the path (e.g. "data.items") is navigated null-propagatingly into the document; the value found there must be a JSON array, and each element becomes a row.
  • absent — the top-level value is the record source: an array yields one row per element; a single object yields a single row.

Each record element must be a JSON object (StructValue); a non-object element raises an EvaluationException (a document row must be a struct).

Schema

JSON sources are open: the schema argument to open(java.lang.String, com.darkcollective.relix.symbol.Schema) is ignored, and every row reports Schema.open() via its DocumentRow. Columns are resolved by path at query time.

Resource management

The file is read eagerly into memory; the returned stream holds no open file handle, so closing it is a no-op.

  • Constructor Details

    • JsonFileDataSourceConnector

      public JsonFileDataSourceConnector(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 JSON path configuration; must not be null
      baseDir - the directory used to resolve relative JSON paths; must not be null
  • Method Details

    • open

      public Stream<Row> open(String relationName, Schema schema)
      Opens a stream of document rows for the named JSON-backed relation.
      Specified by:
      open in interface DataSourceConnector
      Parameters:
      relationName - the canonical (lower-cased) relation name
      schema - ignored — JSON sources are open / schema-on-read
      Returns:
      a stream of DocumentRows, one per record object
      Throws:
      EvaluationException - if no JSON source declaration exists for the relation, the records path does not resolve to an array, or a record element is not an object
      UncheckedIOException - if the file cannot be read