[client-v2, jdbc-v2] A Time value that is negative or 24 h or more is read as a time of day (-01:02:03 becomes 22:57:57)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- java
調査の方向性
Start with the named conversion paths in DataTypeConverter.java, AbstractBinaryFormatReader.java, and JdbcUtils.java, then inspect the jdbc-time-as-sql-time tests in tests/clickhouse-client/allowlist.txt and related issue #3419. Reproduce the negative and 24-hour-or-more cases with the supplied Java program. Done means affected reads return the full server value or report that it cannot be represented, and never silently return a different time; the issue leaves the conversion behavior for java.sql.Time and LocalTime to a maintainer decision.
索引モデルが issue の本文から書いたものです。
説明
Description
A ClickHouse Time or Time64 value can be from -999:59:59 to 999:59:59. client-v2 and jdbc-v2 read a value that is negative or 24 hours or more as its time of day, and report no error: -01:02:03 becomes 22:57:57, and 25:00:00 becomes 01:00:00. Values from 00:00:00 to 23:59:59 are correct.
These reads are affected:
- client-v2:
getStringandgetLocalTimeofGenericRecord(queryAll) and ofClickHouseBinaryFormatReader, alsogetStringof anArray(Time)value ([22:57:57]); - jdbc-v2:
ResultSet.getString,getObject(col)(the default mappingjava.sql.Time, which holds only the time of day: 82677000 ms for-01:02:03), andgetObject(col, LocalTime.class).
jdbc-v2 getTime(col) keeps the full value (-3723000 ms for -01:02:03). For Time64, getObject(col) also drops the fraction (01:00:00 for 25:00:00.5).
The same defect was reported for ch-go in https://github.com/ClickHouse/ch-go/issues/1249 and for clickhouse-odbc in https://github.com/ClickHouse/clickhouse-odbc/issues/643.
Steps to reproduce
- Start a ClickHouse server.
- Run the program in "Code Example" in a JVM with the time zone UTC, with the
clickhouse-jdbc-alljar andslf4j-apion the classpath.
Error Log or Exception StackTrace
toTime(-3723) server=-01:02:03 client-v2: getString=22:57:57 getLocalTime=22:57:57 reader.getString=22:57:57 reader.getLocalTime=22:57:57
toTime(90000) server=25:00:00 client-v2: getString=01:00:00 getLocalTime=01:00 reader.getString=01:00:00 reader.getLocalTime=01:00
toTime64('25:00:00.5', 1) server=25:00:00.5 client-v2: getString=01:00:00.5 getLocalTime=01:00:00.500 reader.getString=01:00:00.5 reader.getLocalTime=01:00:00.500
toTime(3723) server=01:02:03 client-v2: getString=01:02:03 getLocalTime=01:02:03 reader.getString=01:02:03 reader.getLocalTime=01:02:03
[toTime(-3723)] server=['-01:02:03'] client-v2: getString=[22:57:57]
toTime(-3723) server=-01:02:03 jdbc-v2: getString=22:57:57 getObject=22:57:57 (82677000 ms) getObject(LocalTime)=22:57:57 | getTime=-3723000 ms
toTime(90000) server=25:00:00 jdbc-v2: getString=01:00:00 getObject=01:00:00 (3600000 ms) getObject(LocalTime)=01:00 | getTime=90000000 ms
toTime64('25:00:00.5', 1) server=25:00:00.5 jdbc-v2: getString=01:00:00.5 getObject=01:00:00 (3600000 ms) getObject(LocalTime)=01:00:00.500 | getTime=90000500 ms
toTime(3723) server=01:02:03 jdbc-v2: getString=01:02:03 getObject=01:02:03 (3723000 ms) getObject(LocalTime)=01:02:03 | getTime=3723000 ms
[toTime(-3723)] server=['-01:02:03'] jdbc-v2: getString=[22:57:57]
Expected Behaviour
The value that the server gives (toString(t), the server= column above; curl with FORMAT TSV gives the same text): -01:02:03, 25:00:00, 25:00:00.5, ['-01:02:03']. getString must return this text. A LocalTime cannot hold these values, and a java.sql.Time made from a LocalTime cannot either: these reads must return the full value (as getTime(col) does), or throw an error that says that the value does not fit. They must not return a different time.
Root cause:
DataTypeConverter.timeToStringformats the value with the time-of-day patternHH:mm:ss(DataTypeConverter.java:156-168), andAbstractBinaryFormatReader.getStringconverts the value toLocalTimefirst (AbstractBinaryFormatReader.java:381).- client-v2
getLocalTimereturnsdt.toLocalTime()of the epoch-basedLocalDateTimethat the reader makes forTime(AbstractBinaryFormatReader.java:1015). - jdbc-v2
JdbcUtils.convertmakes thejava.sql.TimewithTime.valueOf(LocalTime.from(value))(JdbcUtils.java:426), and theLocalTimewithLocalTime.from(value)(JdbcUtils.java:416).
DataTypeUtils.durationToTimeString already writes the signed text. The fix needs a maintainer decision for the time-of-day types: return the full value in the java.sql.Time (as getTime does) and throw for LocalTime, or throw for both.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related:
- #3419 (open): a negative
Time64with a fraction is decoded wrong, in a different function. tests/clickhouse-client/allowlist.txt, groupjdbc-time-as-sql-time(from #3389): lists 43 jdbc-v2 core SQL tests for thegetObjectpart ("Issue: not filed yet").
Code Example
Reproduction program (Java, 49 lines)
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.client.api.query.QueryResponse;
import java.sql.*;
import java.time.LocalTime;
import java.util.Properties;
public class Repro {
static final String[] CASES = {"toTime(-3723)", "toTime(90000)", "toTime64('25:00:00.5', 1)", "toTime(3723)"};
public static void main(String[] args) throws Exception {
String pw = System.getenv("CLICKHOUSE_PASSWORD");
try (Client client = new Client.Builder().addEndpoint("http://clickhouse:8123")
.setUsername("default").setPassword(pw).build()) {
for (String c : CASES) {
String sql = "SELECT " + c + " AS t, toString(t) AS s";
GenericRecord r = client.queryAll(sql).get(0);
try (QueryResponse resp = client.query(sql).get();
ClickHouseBinaryFormatReader rd = client.newBinaryFormatReader(resp)) {
rd.next();
System.out.printf("%-26s server=%-11s client-v2: getString=%s getLocalTime=%s reader.getString=%s reader.getLocalTime=%s%n",
c, r.getString("s"), r.getString("t"), r.getLocalTime("t"), rd.getString("t"), rd.getLocalTime("t"));
}
}
GenericRecord a = client.queryAll("SELECT [toTime(-3723)] AS a, toString(a) AS s").get(0);
System.out.printf("%-26s server=%-11s client-v2: getString=%s%n", "[toTime(-3723)]", a.getString("s"), a.getString("a"));
}
Properties p = new Properties();
p.setProperty("user", "default");
p.setProperty("password", pw);
try (Connection cn = DriverManager.getConnection("jdbc:clickhouse://clickhouse:8123/default", p);
Statement st = cn.createStatement()) {
for (String c : CASES) {
try (ResultSet rs = st.executeQuery("SELECT " + c + " AS t, toString(t) AS s")) {
rs.next();
Time t = (Time) rs.getObject("t");
System.out.printf("%-26s server=%-11s jdbc-v2: getString=%s getObject=%s (%d ms) getObject(LocalTime)=%s | getTime=%d ms%n",
c, rs.getString("s"), rs.getString("t"), t, t.getTime(), rs.getObject("t", LocalTime.class),
rs.getTime("t").getTime());
}
}
try (ResultSet rs = st.executeQuery("SELECT [toTime(-3723)] AS a, toString(a) AS s")) {
rs.next();
System.out.printf("%-26s server=%-11s jdbc-v2: getString=%s%n", "[toTime(-3723)]", rs.getString("s"), rs.getString("a"));
}
}
}
}
Configuration
Client Configuration
new Client.Builder().addEndpoint("http://clickhouse:8123").setUsername("default").setPassword(...).build();
DriverManager.getConnection("jdbc:clickhouse://clickhouse:8123/default", props); // user, password
Environment
- Cloud
- Client version:
main(8480ca001): client-v2, and theclickhouse-jdbc-alljar (jdbc-v2) - Language version: Java 17.0.21
- OS: Linux
ClickHouse Server
- ClickHouse Server version: 26.11.2.4
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none- Sample data for all these tables: none
Classification: impact: Data integrity · area: Data types & formats (Time, Time64)
Found by automated analysis (Polyglot AI) while checking ch-go#1249 and clickhouse-odbc#643 against the other client repos. Verified against a live server.
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 657
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/clickhouse-java のほかの issue
-
api-diagnostics bug jdbc
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
ClickHouse/clickhouse-java#3464 ·
メンテナーはふだん 1 日以内に返信
-
tests
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-java#3452 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc performance queries sql-parser
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
ClickHouse/clickhouse-java#3451 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc legacy queries
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ClickHouse/clickhouse-java#3444 ·
メンテナーはふだん 1 日以内に返信
-
api-diagnostics bug client jdbc
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-java#3439 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ClickHouse/clickhouse-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
quelea-projection/Quelea#749 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
erkamyaman/rust-anything#963 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 76/100
-
Deferred
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Sanne/incus-spawn#2768 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
morluto/rea#15041 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信