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

オープン
#567 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, sql
領域
database

調査の方向性

Start by comparing the existing JdbcImporter and JdbcImportOptions with the CSV and Parquet exporter APIs to locate the JDBC module’s conventions. Then review the import type mapping and exporter progress listener patterns before defining the export API and binder behavior. Done means exporting rows into a caller-provided table in batches with validity-aware nulls, transaction rollback on failure, restored auto-commit, and opt-in DDL support.

索引モデルが issue の本文から書いたものです。

説明

enhancement

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.

主要言語
Java
スター
3
フォーク
2
平均マージ
9時間 47分
マージ済み PR(30日)
128

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dfa1/vortex-java のほかの issue

dfa1/vortex-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。