client-v2: an Instant written to Time64(3) stores 999:59:59.000, and negative BigInteger/Instant Time64 values fail
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 657
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 36
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc performance queries sql-parser
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc legacy queries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
api-diagnostics bug client jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3439 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ClickHouse/clickhouse-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
quelea-projection/Quelea#749 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
erkamyaman/rust-anything#963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
-
Deferred
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Sanne/incus-spawn#2768 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
morluto/rea#15041 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày