Repository navigation
Description
Description
The v1 stack cannot read a TabSeparatedWithNames result (also TSVWithNamesAndTypes, TabSeparatedRawWithNames, CustomSeparatedWithNames) that has one column whose name starts with Code: . The server returns 200 OK and the row, but the client throws IllegalArgumentException: ClickHouse error: <column name> and returns no row.
Affected entry points (each tested with SELECT 1 AS `Code: 1` ):
- v1
ClickHouseClientwith one of these formats, with each HTTP connection provider (APACHE_HTTP_CLIENT,HTTP_URL_CONNECTION,HTTP_CLIENT); - the v1 JDBC driver (
clickhouse.jdbc.v1=true) with... FORMAT TSVWithNames: aSQLExceptioncaused by the sameIllegalArgumentException; - R2DBC
Connection.createBatch(), which reads every statement asTabSeparatedWithNamesAndTypes(ClickHouseBatch.java:16).
Not affected: two or more columns, a name that does not start with Code: , CSVWithNames, the default format RowBinaryWithNamesAndTypes, R2DBC createStatement(). client-v2 and jdbc-v2 do not use this reader.
Steps to reproduce
- Start a ClickHouse server (tested: 26.11.7.10).
- Run the program in "Code Example" with the v1 client on the class path.
- The query with two columns returns its row. The query with one column throws.
Error Log or Exception StackTrace
SELECT 1 AS `Code: 1`, 2 AS b -> [Code: 1] = 1
SELECT 1 AS `Code: 1` -> java.lang.IllegalArgumentException: ClickHouse error: Code: 1
Expected Behaviour
The client returns the column Code: 1 with the value 1, as the server sends it (200 OK, no X-ClickHouse-Exception-Code header):
$ curl -s -i 'http://localhost:8123/' --data-binary 'SELECT 1 AS `Code: 1` FORMAT TabSeparatedWithNames'
HTTP/1.1 200 OK
Content-Type: text/tab-separated-values; charset=UTF-8
X-ClickHouse-Format: TabSeparatedWithNames
...
Code: 1
1
Root cause: ClickHouseTabSeparatedProcessor.readColumns() reads a header line that starts with Code: and contains no tab as a server error (clickhouse-data/src/main/java/com/clickhouse/data/format/ClickHouseTabSeparatedProcessor.java:96). The header of a one-column result has no tab, so a valid column name matches.
The check also has a use: with send_progress_in_http_headers=1, the server can send 200 OK before an error. The HTTP_URL_CONNECTION and HTTP_CLIENT providers read X-ClickHouse-Exception-Code only for a status other than 200 (HttpUrlConnectionImpl.java:171, src/main/java11/.../HttpClientConnectionImpl.java:143), so for them this check is the only detection of such an error (tested: IllegalArgumentException: ClickHouse error: Code: 395. ...). The default Apache provider reads the header also on a 200 (ApacheHttpConnectionImpl.java:216) and throws ClickHouseException with code 395. A fix must keep the error detection of the two other providers.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Code Example
Reproduction program (Java, 30 lines)
import com.clickhouse.client.*;
import com.clickhouse.client.config.ClickHouseClientOption;
import com.clickhouse.data.*;
public class Repro {
public static void main(String[] args) throws Exception {
ClickHouseNode server = ClickHouseNode.builder()
.host(System.getenv().getOrDefault("CLICKHOUSE_HOST", "localhost"))
.port(ClickHouseProtocol.HTTP, 8123)
.credentials(ClickHouseCredentials.fromUserAndPassword("default",
System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "")))
.build();
String[] queries = { "SELECT 1 AS `Code: 1`, 2 AS b", "SELECT 1 AS `Code: 1`" };
try (ClickHouseClient client = ClickHouseClient.newInstance(ClickHouseProtocol.HTTP)) {
for (String sql : queries) {
try (ClickHouseResponse r = client.read(server)
.option(ClickHouseClientOption.COMPRESS, false) // see #3107 (server 26.9+)
.format(ClickHouseFormat.TabSeparatedWithNames)
.query(sql).executeAndWait()) {
for (ClickHouseRecord rec : r.records()) {
System.out.println(sql + " -> [" + r.getColumns().get(0).getColumnName() + "] = "
+ rec.getValue(0).asString());
}
} catch (Exception e) {
System.out.println(sql + " -> " + e);
}
}
}
}
}Configuration
Client Configuration
// v1 client defaults, except compress=false: on server 26.9+ every compressed v1 read fails (#3107)Environment
- Cloud
- Client version:
main0e607b9 (0.12.0-rc1-SNAPSHOT) - Language version: OpenJDK 17.0.21.1
- OS: Linux (Ubuntu 22.04)
ClickHouse Server
- ClickHouse Server version: 26.11.7.10
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none (the query reads no table)- Sample data for all these tables: none
Classification: impact: none · area: Data types & formats (TabSeparatedWithNames)
Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-go#2203. Verified against a live server.
Activity