client-v2: an Instant written to Time64(3) stores 999:59:59.000, and negative BigInteger/Instant Time64 values fail
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Start in serializeTime64 in SerializerUtils.java (around line 845). It does not receive the column scale, so Instant values are always converted to nanoseconds, and BigInteger and Instant values go through BinaryStreamUtils.writeUnsignedInt64, which rejects negative values. Run the 44-line reproduction in the issue against a local server: done means Time64(3) Instant stores 01:02:03.456, negative BigInteger and Instant values store -01:02:03.456, and the Long results stay unchanged.
由索引模型根據 Issue 內容生成。
描述
Description
When client-v2 inserts a java.time.Instant into a Time64(p) column with p < 9, the server stores a different value, and the client reports no error. 01:02:03.456 written to a Time64(3) column is read back as 999:59:59.000. A Time64(9) column stores the correct value. RowBinaryFormatWriter.setValue and POJO inserts (Client.insert(table, List), also into Nullable(Time64(3))) give the same result.
A negative Time64 value fails with IllegalArgumentException when it is a BigInteger or an Instant, for every scale. The same value as a Long is stored correctly.
Root cause:
SerializerUtils.serializeTime64(SerializerUtils.java:845) does not get the column, so it converts anInstantto nanoseconds (scale 9) for every column scale (:851).- It writes
BigIntegerandInstantvalues withBinaryStreamUtils.writeUnsignedInt64(OutputStream, BigInteger), which accepts only 0 to 2^64-1 (BinaryStreamUtils.java:862), butTime64is signed.
The fix is in serializeTime64 only. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: #3417 (open): the jdbc-v2 writer fails for LocalTime in the same function.
Steps to reproduce
- Create the table
t (id Int32, t Time64(3), tail Int32). - Insert one row with
RowBinaryFormatWriterandsetValue("t", Instant.ofEpochSecond(3723, 456_000_000))(01:02:03.456). - Run
SELECT toString(t) FROM t.
Error Log or Exception StackTrace
Time64(3) Instant 1970-01-01T01:02:03.456Z stored 999:59:59.000
Time64(9) Instant 1970-01-01T01:02:03.456Z stored 01:02:03.456000000
Time64(3) BigInteger -3723456 FAIL java.lang.IllegalArgumentException: BigInteger(-3723456) should be between 0 and 18446744073709551615 inclusive of both values
Time64(9) Instant 1969-12-31T22:57:56.544Z FAIL java.lang.IllegalArgumentException: BigInteger(-3723456000000) should be between 0 and 18446744073709551615 inclusive of both values
Time64(3) Long -3723456 stored -01:02:03.456
For the first row, SELECT toDecimal64(t, 3) FROM t returns 3723456000.000: the client wrote 3723456000000 ticks instead of 3723456.
Expected Behaviour
The client stores the value that the server gives for the same time:
SELECT toString(toTime64('01:02:03.456', 3)) -- 01:02:03.456
SELECT toString(toTime64('-01:02:03.456', 3)) -- -01:02:03.456
In RowBinary, the server writes toTime64('01:02:03.456', 3) as the Int64 3723456 and toTime64('-01:02:03.456', 3) as -3723456. So the first row must store 01:02:03.456, and the two negative rows must store -01:02:03.456 (-01:02:03.456000000 for Time64(9)), as the Long row does.
Code Example
Reproduction program (Java, 44 lines)
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.data_formats.RowBinaryFormatWriter;
import com.clickhouse.client.api.insert.InsertSettings;
import com.clickhouse.client.api.metadata.TableSchema;
import com.clickhouse.data.ClickHouseFormat;
import java.math.BigInteger;
import java.time.Instant;
public class Repro {
static Client client;
static void run(String type, Object value) {
String result;
try {
client.execute("CREATE OR REPLACE TABLE t (id Int32, t " + type + ", tail Int32) ENGINE = Memory").get().close();
TableSchema schema = client.getTableSchema("t");
client.insert("t", out -> {
RowBinaryFormatWriter w = new RowBinaryFormatWriter(out, schema, ClickHouseFormat.RowBinary);
w.setValue("id", 1);
w.setValue("t", value);
w.setValue("tail", 7);
w.commitRow();
}, ClickHouseFormat.RowBinary, new InsertSettings()).get().close();
result = "stored " + client.queryAll("SELECT toString(t) AS s FROM t").get(0).getString("s");
} catch (Exception e) {
Throwable c = e;
while (c.getCause() != null) c = c.getCause();
result = "FAIL " + c;
}
System.out.printf("%-9s %-11s %-25s %s%n", type, value.getClass().getSimpleName(), value, result);
}
public static void main(String[] args) throws Exception {
client = new Client.Builder().addEndpoint("http://clickhouse:8123").setUsername("default")
.setPassword(System.getenv("CLICKHOUSE_PASSWORD"))
.serverSetting("enable_time_time64_type", "1").build();
run("Time64(3)", Instant.ofEpochSecond(3723, 456_000_000)); // 01:02:03.456
run("Time64(9)", Instant.ofEpochSecond(3723, 456_000_000));
run("Time64(3)", BigInteger.valueOf(-3723456)); // -01:02:03.456
run("Time64(9)", Instant.ofEpochSecond(-3724, 544_000_000)); // -01:02:03.456
run("Time64(3)", -3723456L);
client.close();
}
}
Configuration
Client Configuration
In the program (enable_time_time64_type=1).
Environment
- Cloud
- Client version: client-v2
0.12.0-rc1-SNAPSHOT,mainat 051a7ecfd - Language version: Java 17.0.21
- OS: Linux
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
- ClickHouse Server non-default settings, if any:
enable_time_time64_type=1 CREATE TABLEstatements for tables involved: in the program- Sample data for all these tables: in the program
Classification: impact: Data integrity · area: Data types & formats (Time64)
Found by automated analysis (Polyglot AI) while working on #3417. Verified against a live server.
- 主要語言
- Java
- 星號
- 1.6k
- 分支
- 657
- 平均合併
- 2 天 6 小時
- 30 天內合併 PR
- 36
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 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
維護者通常 1 天內回覆