Repository navigation
Conversation
chernser
requested changes
Nov 30, 2026
chernser
left a comment
Contributor
There was a problem hiding this comment.
Much appreciate the contribution!
Most looks fine - I will review once more today.
Please fix tests failing on cluster - you should not set the table engine.
[ERROR] InsertTests.testInsertQuery:946 expected [2] but found [0]
[ERROR] InsertTests.testInsertQuery:946 expected [2] but found [0]
[ERROR] InsertTests.testInsertQuery:946 expected [2] but found [0]
[ERROR] InsertTests.testInsertQuery:946 expected [2] but found [0]
[ERROR] InsertTests.testInsertQuery:946 expected [2] but found [0]
Thanks!
…T statements
The insert methods could only build `INSERT INTO <table> [(columns)] FORMAT <format>`.
An application could not send a statement such as
`INSERT INTO t SELECT ... FROM input('...')` or `INSERT INTO FUNCTION ...`
with data from a stream.
Add three `insertQuery` overloads (DataStreamWriter, InputStream, and
DataStreamWriter with query parameters). The client sends the statement as
it is in the `query` URL parameter, as the other insert methods do. When a
format is given, the client appends a new line and `FORMAT <format>`; when
it is null, the statement must have its own FORMAT clause and the default
format of the client is not sent. The operation reports no target table to
metrics and spans.
The existing insert methods delegate to the same private `executeInsert`
and keep their behavior. The change is additive.
Relates to ClickHouse#2071
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cluster profile sets default_table_engine=ReplicatedMergeTree, and nginx sends each request to any of the three replicas. The tables with an explicit MergeTree engine were not replicated, so the read-back on another replica found no rows. Use the default engine, as the other insert tests do. The file() table function writes a file that is local to one server. Send all requests of that test to the same replica with the replica tag header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
den-crane
force-pushed
the
feature/insert-query
branch
from
November 30, 2026 17:10
4d54a8c to
4132776
Compare
Contributor
Author
|
Thanks! Fixed in 4132776: the tests no longer set the table engine, so the cluster's default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Client#insertQuery, which inserts data with anINSERTstatement that the application writes. Before, the insert methods could only makeINSERT INTO <table> [(columns)] FORMAT <format>. That is not enough for statements such as:Relates to #2071 (closed by #2289, which added only column lists; the
input()use case in the last comment of the issue was not covered).Closes #2726
API (additive)
A new method name is necessary:
insert(String, DataStreamWriter, ClickHouseFormat, InsertSettings)already exists with a table name as the first argument.Behavior
sqlas it is in thequeryURL parameter, as the other insert methods do. The request body has only the data. The client does not parse, validate, or escape the SQL.format != null: the client appends a new line andFORMAT <format>. The new line keeps the clause out of a--comment at the end of the SQL.format == null: the SQL must have its ownFORMATclause. The default format of the client is not sent (noX-ClickHouse-Formatheader), so it cannot conflict with the clause.queryParams: values for{name:Type}placeholders, sent asparam_<name>URL parameters with the same value formatting asClient#query.InsertSettings#appCompressedData(true, "gzip")(for example a.parquet.gzfile).tableNameisnull). The javadoc ofSpanRecorder,MetricsRecorder,SpanSupport, andMetricsSupportnow says thattableNamecan benull.Implementation
The retry/metrics/span/cancellation loop of
insert(tableName, columns, writer, format, settings)moved into a privateexecuteInsert(...). The existing method builds the same SQL as before and calls it. TheInputStreamwriter and the query-parameter formatting became private helpers, shared with the existing paths.Compatibility
Additive only. No existing signature or behavior changes.
Tests (
InsertTests, which also runs in the LZ4, ZSTD and HTTP-compression subclasses)testInsertQuery(data provider):INSERT ... SELECT ... FROM input(...) GROUP BY ...with the format appended by the client, aFORMATclause in the SQL, a trailing--comment, a{k:UInt64}query parameter, and theInputStreamoverload. Checks every column of every row.testInsertQueryCompressedParquet:test_sample.parquet.gz(from tests for ORC / Parquet #571, copied toclient-v2test resources) withappCompressedData(true, "gzip")and a transform inSELECT.testInsertQueryIntoTableFunction:INSERT INTO FUNCTION file('<uuid>.csv.gz', ...); checks the gzip magic bytes of the file and the rows read back. Skipped on Cloud.testInsertQueryIntoNullFunction:INSERT INTO FUNCTION null(...); checks the written rows.testInsertQueryServerError: duplicateFORMATclause gives aServerExceptionand no rows.testInsertQueryInvalidArguments: null/blank SQL, null writer, null settings giveIllegalArgumentException.Local run against ClickHouse 26.11: all
insertQuerytests pass in all four classes. The only failures in those classes,testInsertAndReadBackWithSecureConnection(LZ4/ZSTD), need the SSL setup of the Testcontainers environment and fail the same way without this change.Checklist
history/latest/2071.md)🤖 Generated with Claude Code
Note
Medium Risk
Additive API with refactored insert execution path; callers must not embed untrusted values in raw SQL, and null-format behavior depends on correct FORMAT handling in the statement.
Overview
Adds
Client#insertQueryso applications can run arbitraryINSERTSQL (e.g.INSERT ... SELECT ... FROM input(...)orINSERT INTO FUNCTION file(...)) with body data from anInputStreamorDataStreamWriter. The client sends the statement as-is; whenformatis set it appends\nFORMAT <format>; whenformatisnullthe SQL must already includeFORMATand the client clears the default format header so it cannot conflict.{name:Type}parameters use the samequeryParams/formatQueryParamspath asClient#query.Existing table/column
insertoverloads are unchanged in behavior: SQL building stays ininsert(...), while retry/metrics/span/cancellation logic is centralized in privateexecuteInsert, withinputStreamWritershared for stream-based inserts.Observability Javadoc now documents
tableNameasnullfor custom inserts (nodb.collection.name). Integration tests coverinput()aggregation, query params, pre-compressed parquet, table functions, validation, and duplicateFORMATerrors.Reviewed by Cursor Bugbot for commit 4132776. Bugbot is set up for automated code reviews on this repo. Configure here.