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

未关闭
#567 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
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 分钟
30 天内合并 PR
128

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dfa1/vortex-java 的其他 Issue

查看 dfa1/vortex-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。