Skip to content

No data written when using WriteTableAsync using Clickhouse clickhouse/clickhouse-server:latest #77

Open
@aidanmorgan

Description

@aidanmorgan

I have an interesting bug when trying to bulk insert data into a table using the WriteTableAsync function. I've tried to provide a simple reproduction here:

Database Structure:

CREATE DATABASE IF NOT EXISTS issue77_db;

CREATE TABLE IF NOT EXISTS issue77_db.issue77_table (
    words String,
    time DateTime64(9)
)
ENGINE=MergeTree()
ORDER BY time;

Using the clickhouse/clickhouse-server:latest docker image the following insert works:

using Octonica.ClickHouseClient;

await using var conn = new ClickHouseConnection("Host=localhost");
conn.Open();

var cmd = conn.CreateCommand("INSERT INTO issue77_db.issue77_table(words, time) VALUES({words}, {time})");
cmd.Parameters.AddWithValue("words", "direct_insert");
cmd.Parameters.AddWithValue("time", DateTimeOffset.UtcNow);

var res = cmd.ExecuteNonQuery();
Console.WriteLine(res);

Running a bulk insert for this however does not work, doing a SELECT * against the table returns zero rows.:

using Octonica.ClickHouseClient;

var cancelToken = new CancellationTokenSource();

await using var conn = new ClickHouseConnection("Host=localhost");
await conn.OpenAsync();

var writer = await conn.CreateColumnWriterAsync("INSERT INTO issue77_db.issue77_table(words, time) VALUES", cancelToken.Token);

await writer.WriteTableAsync(new object[]
{
    new List<string>() {"aa", "bb", "cc", "dd"},
    new List<DateTimeOffset>()
    {
        DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(3)), 
        DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(2)),
        DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(1)), 
        DateTimeOffset.UtcNow
    }
}, 4, cancelToken.Token);

Checking the logs for the server, there seems to be a repeated error log printed:

<Information> TCPHandler: Client has dropped the connection, cancel the query.
<Information> executeQuery: Code: 394. DB::Exception: Query was cancelled or a client has unexpectedly dropped the connection. (QUERY_WAS_CANCELLED) (version 23.3.1.2823 (official build)) 

Switching to the yandex/clickhouse-server:latest image returns four rows.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions