Skip to content

feat(jdbc): JdbcExporter, matching the CSV and Parquet exporters #567

Open

Description

@dfa1

vortex-jdbc only has JdbcImporter/JdbcImportOptions; csv and parquet each have an importer and an exporter. Add JdbcExporter + JdbcExportOptions for symmetry: read a Vortex file and move its rows into a table in a JDBC database over a caller-supplied Connection.

API sketch

JdbcExportOptions opts = JdbcExportOptions.defaults()
        .withBatchSize(5_000)
        .withBinder(JdbcBinder.standard()
                .with(DType.Extension.class, (ps, i, value) -> ps.setObject(i, value)));

JdbcExporter.export(vortexPath, connection, "ohlc", opts);
  • Options are a final class with a private constructor, defaults() and withXxx copies, as everywhere else. The target table is a required argument of export, not an option (confirm that CsvExporter/ParquetExporter take their target the same way).
  • Binder (callback): a small functional interface that sets one value on a PreparedStatement. JdbcBinder.standard() covers primitives, strings, decimals, booleans and dates. A user overrides only the types their database needs special handling for (Postgres arrays, setObject for timestamps).
  • DDL helper, not automatic: a DType to SQL type function plus createTableSql(name, dtype) returns a CREATE TABLE string. The exporter never creates or alters a table on its own; creation is opt-in.

Behavior

  • Appends to an existing table with INSERT INTO t (cols...) VALUES (?, ...) through a PreparedStatement. Nulls follow the validity mask.
  • One transaction for the whole export: remember the connection's auto-commit setting, setAutoCommit(false), addBatch() per row, executeBatch() every batchSize rows, commit() at the end, rollback() and rethrow on failure, and restore auto-commit in a finally. The connection belongs to the caller. A failed export leaves nothing behind.
  • ProgressListener, as in the other exporters.

Open design questions

  • Reverse type mapping DType to SQL type (the inverse of SqlTypeToDType); it varies by database.
  • Create-if-missing vs truncate vs fail-if-exists: all opt-in, append is the default.
  • A withCommitEvery(n) option for very large exports, if a long-lived transaction proves a problem. Not in the first cut.

Not needed for the jdbc:vortex: driver work (#566). No demand yet, so this waits until someone needs it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions