From 82e39c4010245f35f2d126ae212cbd8fff94d652 Mon Sep 17 00:00:00 2001 From: hutiefang76 <137664623+hutiefang76@users.noreply.github.com> Date: Wed, 9 Sep 2026 04:45:04 +0800 Subject: [PATCH] fix(client-v2): report LZ4 byte counts Fixes #3108 --- CHANGELOG.md | 2 ++ .../internal/ClickHouseLZ4InputStream.java | 2 +- .../ClickHouseLZ4InputStreamTest.java | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 client-v2/src/test/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStreamTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eff8d530..098f1a172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -137,6 +137,8 @@ ### Bug Fixes +- **[client-v2]** Fixed truncated LZ4 stream errors reporting literal `{0}` and `{1}` placeholders instead of the + number of bytes read and expected. (https://github.com/ClickHouse/clickhouse-java/issues/3108) - **[jdbc-v2]** Fixed `DatabaseMetaData#getTables` reporting `TABLE_TYPE = TABLE` for a table with the `BigQuery` engine (present in `system.table_engines` since ClickHouse `26.8`). The engine was missing from the engine-to-table-type mapping, so it fell back to the default `TABLE`, and `getTables(..., types = {"REMOTE TABLE"})` diff --git a/client-v2/src/main/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStream.java b/client-v2/src/main/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStream.java index 8550fb6c2..980b06cf9 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStream.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStream.java @@ -83,7 +83,7 @@ private boolean readFully(byte[] b, int off, int len) throws IOException { if (n == 0) { return false; } - throw new IOException(ClickHouseUtils.format("Incomplete read: {0} of {1}", n, len)); + throw new IOException(ClickHouseUtils.format("Incomplete read: %s of %s", n, len)); } n += count; } diff --git a/client-v2/src/test/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStreamTest.java b/client-v2/src/test/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStreamTest.java new file mode 100644 index 000000000..e6ab846e5 --- /dev/null +++ b/client-v2/src/test/java/com/clickhouse/client/api/internal/ClickHouseLZ4InputStreamTest.java @@ -0,0 +1,25 @@ +package com.clickhouse.client.api.internal; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import net.jpountz.lz4.LZ4Factory; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ClickHouseLZ4InputStreamTest { + + @Test + public void reportsActualByteCountsForTruncatedHeader() { + byte[] truncatedHeader = new byte[10]; + ClickHouseLZ4InputStream input = new ClickHouseLZ4InputStream( + new ByteArrayInputStream(truncatedHeader), + LZ4Factory.fastestJavaInstance().fastDecompressor(), + 8192); + + IOException exception = Assert.expectThrows(IOException.class, + () -> input.read(new byte[1], 0, 1)); + + Assert.assertEquals(exception.getMessage(), "Incomplete read: 10 of 25"); + } +}