[JAVA] FlightSQL JDBC Driver PreparedStatement#setTimestamp() ignores connection timeStampPrecision
まだ誰も着手していません。
評価
調査の方向性
まず、timestamptz に対する PreparedStatement#setTimestamp と setTimestamp を DateTimeUtils#sqlTimestampToUnixTimestamp(Timestamp, TimeZone) まで追跡し、次に接続オプション timeStampPrecision がその経路にどのように公開されているかを調べます。issue のマイクロ秒およびミリ秒の例を再現し、該当するテスト場所が特定できた場合は、対象を絞ったカバレッジを追加または更新します。設定された各精度に対してサーバーが正しい epoch 値を受信すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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時間
- マージ済み PR(30日)
- 11
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/arrow-java のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
apache/arrow-java#1261 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/arrow-java#1236 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/arrow-java#1230 ·
-
Type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
apache/arrow-java#1205 ·
-
Type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/arrow-java#1196 · コメント 1 件 ·
apache/arrow-java の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 オープンbug frontend maui-pilot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
objectionary/eo-graphs#74 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100