DarkWanderer / ClickHouse.Client

.NET client for ClickHouse
MIT License
300 stars 58 forks source link

Inserting w/ `SETTINGS async_insert=1, wait_for_async_insert=1` and parameters throws an exception #297

Closed danifullview closed 1 year ago

danifullview commented 1 year ago

Hi,

When running:

var connection = new ClickHouseConnection(connectionUrl);
var cmd = connection.CreateCommand();
cmd.AddParameter("id", Guid.NewGuid());
cmd.AddParameter("ts", DateTime.UtcNow);
cmd.AddParameter("text", "*** Some Text Value - async ***");

cmd.CommandText = "INSERT INTO table VALUES ({id:UUID}, {ts:DateTime}, {text:String})";
cmd.ExecuteNonQuery();

it works as expected.

but when I do:

var connection = new ClickHouseConnection(connectionUrl);
var cmd = connection.CreateCommand();
cmd.AddParameter("id", Guid.NewGuid());
cmd.AddParameter("ts", DateTime.UtcNow);
cmd.AddParameter("text", "*** Some Text Value - async ***");

cmd.CommandText = "INSERT INTO table SETTINGS async_insert=1, wait_for_async_insert=1 VALUES ({id:UUID}, {ts:DateTime}, {text:String})";
cmd.ExecuteNonQuery();

I get this exception:

Code: 456. DB::Exception: Substitution `id` is not set: While executing WaitForAsyncInsert. (UNKNOWN_QUERY_PARAMETER) (version 23.3.1.30095 (official build))
DarkWanderer commented 1 year ago

Hi,

This is a quirk of behavior of ClickHouse itself: Without async_insert:

$ clickhouse-client --param_id 5 -q "INSERT INTO test.some_table VALUES ({id:Int32})"
$

With async_insert:

$ clickhouse-client --param_id 5 -q "INSERT INTO test.some_table SETTINGS async_insert=1 VALUES ({id:Int32})"
Received exception from server (version 23.3.2):
Code: 456. DB::Exception: Received from localhost:9000. DB::Exception: Substitution `id` is not set: While executing WaitForAsyncInsert. (UNKNOWN_QUERY_PARAMETER)
(query: INSERT INTO test.some_table SETTINGS async_insert=1 VALUES ({id:Int32}))
$

I.e. it looks like parameterized queries are not supported with async_insert

This feature looks very interesting for bulk insertion however, do you know which version it was introduced in?