Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[JAVA] FlightSQL JDBC Driver PreparedStatement#setTimestamp() ignores connection timeStampPrecision

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

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
java
领域
databases

调研方向

首先跟踪 PreparedStatement#setTimestamp 以及针对 timestamptz 的 setTimestamp,直到 DateTimeUtils#sqlTimestampToUnixTimestamp(Timestamp, TimeZone),然后检查连接选项 timeStampPrecision 如何暴露给该路径。重现 issue 中的微秒和毫秒示例;如果确定了相关的测试位置,则添加或更新针对性的覆盖。对于每种配置的精度,服务器都收到正确的 epoch 值,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Type: bug

The FlightSQL JDBC driver always treats timestamps as milliseconds when sending them to the server, ignoring the connection setting timeStampPrecision (for example microseconds). As a result, when the connection precision is set to microseconds the driver truncates/offsets the timestamp and the value stored on the server is incorrect.

Expected behavior When the JDBC connection option timeStampPrecision is set (e.g. microseconds, milliseconds, nanoseconds), PreparedStatement#setTimestamp (and setTimestamp with timestamptz) should send timestamps with the configured precision so the server receives the correct epoch value.

Actual behavior The driver converts java.sql.Timestamp values to an epoch value assuming milliseconds. If the connection is configured for microseconds (or other precision) the conversion is incorrect and inserted timestamps are wrong.

String jdbcUrlFlight = "jdbc:arrow-flight-sql://localhost:9994?useEncryption=0";
try (Connection conn = DriverManager.getConnection(jdbcUrlFlight);
     PreparedStatement stmt = conn.prepareStatement("INSERT INTO ... VALUES (?, ?, ?, ?, ?)")) {

    for (RowData row : generatedData) {
        stmt.setDate(1, row.c_date());
        stmt.setTime(2, row.c_time());
        stmt.setTime(3, row.c_timetz());
        stmt.setTimestamp(4, row.c_timestamp());      // incorrect conversion happens here
        stmt.setTimestamp(5, row.c_timestamptz());   // and here
        stmt.addBatch();
    }
    stmt.executeBatch();
}

Example A — timestamp precision in microseconds (bug triggered)

  • Value I want to insert:

    • Timestamp object: "2024-11-03 12:45:09.869885001"
    • nanos = 869885001
    • fastTime = 1730634309000
  • DateTimeUtils#sqlTimestampToUnixTimestamp(Timestamp, TimeZone) returns: 1730637909869:

    • Interpreted as milliseconds, that is: 2024-11-03 12:45:09.869 (GMT)
  • Final value inserted into server: 1970-01-21 00:43:57.909869

    • Incorrect because the connection used microsecond precision but driver treated the value as milliseconds.

Example B — timestamp precision in milliseconds (works)

  • Value I want to insert:

    • "2023-11-29 09:47:32.659534860"
    • nanos = 659534860
    • fastTime = 1701247652000
  • Driver sends: 1701251252659 (interpreted as milliseconds)

  • Server receives: 2023-11-29 09:47:32.659 — correct when precision is milliseconds.

Environment

  • flight-sql-jdbc-driver-18.3.0.jar
  • Java: 17
  • Server FlightSQL implementation/version: 18.2
  • OS: Windows

Relevant code & suspected area

DateTimeUtils#sqlTimestampToUnixTimestamp(Timestamp, TimeZone) appears to be converting timestamps assuming millisecond precision.

public static long sqlTimestampToUnixTimestamp(Timestamp timestamp, TimeZone timeZone) {
        long time = timestamp.getTime();
        LocalDateTime dateTime = timestamp.toLocalDateTime();
        long unixTimestamp = dateTime.toEpochSecond(ZoneOffset.UTC) * 1000L + (long)dateTime.get(ChronoField.MILLI_OF_SECOND);
        if (timeZone != null) {
            unixTimestamp += (long)timeZone.getOffset(time);
        }

        unixTimestamp -= (long)DEFAULT_ZONE.getOffset(time);
        return unixTimestamp;
    }

The driver should respect the connection timeStampPrecision parameter, and correctlyreturn the exact epoch value (as a long) at the configured timestamp precision.

主要语言
Java
星标
95
派生
154
平均合并
2 天 10 小时
30 天内合并 PR
11

贡献指南

打开贡献指南

从这里开始

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

apache/arrow-java 的其他 Issue

查看 apache/arrow-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

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