[jdbc-v1] asTempTable() external tables are loaded as RowBinary, whatever their format
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 70/100
Rechercherichtung
Lies ClickHouseStatementImpl.java etwa ab Zeile 311, wo der Inhalt der temporären externen Tabelle geschrieben wird, und vergleiche ihn mit der Formateinstellung von ClickHouseExternalTable und dem Standardwert der Anfrage in ClickHouseRequest.java etwa ab Zeile 95. Ergänze die Tests für externe Tabellen um TabSeparated, CSV und JSONEachRow neben dem bestehenden Fall RowBinary. Fertig ist die Arbeit, wenn temporäre Tabellen jedes Inhaltsformat korrekt laden, entsprechend dem Verhalten ohne asTempTable().
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
With the v1 JDBC driver, an external table that is built with asTempTable() and bound to {tt 'name'} is loaded as RowBinary, whatever the format of the table. The default format of ClickHouseExternalTable is TabSeparated, so a table with the default format fails. The same table without asTempTable() works. TabSeparated, CSV and JSONEachRow content all show the problem; only RowBinary content works (the only format that testQueryWithExternalTable uses with asTempTable()).
The result depends on the content:
- content that does not parse as
RowBinary: the query fails withCANNOT_READ_ALL_DATA; - content that parses as
RowBinary(for exampleUInt8orUInt32columns in TSV or CSV): the query returns wrong values, with no error.
Root cause: ClickHouseStatementImpl.java:311 writes the content with request.write().table(tableName).data(t.getContent()) and does not set t.getFormat(), so the INSERT gets the default input format of the request, RowBinary (ClickHouseRequest.java:95). The query log shows the statement that the driver sends: INSERT INTO `ext` FORMAT RowBinary. The fix is one format(...) call on that write.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related:
- #3438 (open): another external-table defect in the same
asTempTable()code (getStructure()).
Steps to reproduce
- Use the v1 driver (
-Dclickhouse.jdbc.v1=true). - Bind
ClickHouseExternalTable.builder().name("ext").columns("v UInt8").content(<"1\n2\n">).asTempTable().build()toSELECT * FROM {tt 'ext'}, with noformat(...)(TabSeparated). - Read the result:
[49, 10, 50, 10]. WithoutasTempTable():[1, 2].
Error Log or Exception StackTrace
ext v UInt64 -> [42]
ext v UInt8 -> [1, 2]
temp v UInt64 -> Code: 33. DB::Exception: Cannot read all data. Bytes read: 3. Bytes expected: 8: (at row 1)
temp v UInt8 -> [49, 10, 50, 10]
Expected Behaviour
The temporary table gets the rows of the content in the format of the table, as without asTempTable(). The server, for the same bytes in a temporary table ext (v UInt8):
$ printf '1\n2\n' | curl --data-binary @- '…/?session_id=s&query=INSERT+INTO+ext+FORMAT+TSV' # SELECT groupArray(v) FROM ext -> [1,2]
$ printf '1\n2\n' | curl --data-binary @- '…/?session_id=s&query=INSERT+INTO+ext+FORMAT+RowBinary' # SELECT groupArray(v) FROM ext -> [49,10,50,10]
Code Example
Reproduction program (Java, 35 lines)
import com.clickhouse.data.ClickHouseExternalTable;
import java.io.ByteArrayInputStream;
import java.sql.*;
import java.util.*;
public class TempTableFormat {
static void run(Connection conn, String column, String tsv, boolean temp) {
ClickHouseExternalTable.Builder b = ClickHouseExternalTable.builder().name("ext")
.columns(column).content(new ByteArrayInputStream(tsv.getBytes())); // format: TabSeparated (default)
if (temp) b.asTempTable();
try (PreparedStatement ps = conn.prepareStatement("SELECT * FROM {tt 'ext'}")) {
ps.setObject(1, b.build());
ResultSet rs = ps.executeQuery();
List<String> rows = new ArrayList<>();
while (rs.next()) rows.add(rs.getString(1));
System.out.println((temp ? "temp " : "ext ") + column + " -> " + rows);
} catch (SQLException e) {
System.out.println((temp ? "temp " : "ext ") + column + " -> " + e.getMessage().split("\n")[0]);
}
}
public static void main(String[] args) throws Exception {
System.setProperty("clickhouse.jdbc.v1", "true");
Properties p = new Properties();
p.setProperty("user", "default");
p.setProperty("password", System.getenv("CLICKHOUSE_PASSWORD"));
p.setProperty("compress", "false"); // see #3107
try (Connection conn = DriverManager.getConnection("jdbc:clickhouse://clickhouse:8123/default", p)) {
for (boolean temp : new boolean[] {false, true}) {
run(conn, "v UInt64", "42\n", temp);
run(conn, "v UInt8", "1\n2\n", temp);
}
}
}
}
Configuration
Client Configuration
System.setProperty("clickhouse.jdbc.v1", "true");
// JDBC properties: compress=false (#3107)
Environment
- Cloud
- Client version:
mainat 9934d2e88 (0.12.0-rc1-SNAPSHOT), v1 driver - Language version: OpenJDK 17.0.21
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.11.2.4
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none (the driver creates the temporary table)- Sample data for all these tables: in the program
Classification: impact: Data integrity · area: Queries (external temporary tables)
Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-go#2170. Verified against a live server.
- Vorherrschende Sprache
- Java
- Sterne
- 1.6k
- Forks
- 657
- Ø Merge
- 2 T. 6 Std.
- Gemergte PRs (30 T.)
- 36
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer antworten meist innerhalb von 1 Tag
-
tests
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc performance queries sql-parser
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer antworten meist innerhalb von 1 Tag
-
api-diagnostics bug client jdbc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3439 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug client jdbc legacy queries
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3438 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in ClickHouse/clickhouse-java
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
quelea-projection/Quelea#749 ·
Maintainer antworten meist innerhalb von 1 Tag
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
erkamyaman/rust-anything#963 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 76/100
-
Deferred
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Sanne/incus-spawn#2768 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
morluto/rea#15041 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag