Octonica / ClickHouseClient

ClickHouse .NET Core driver
Apache License 2.0
140 stars 23 forks source link

Asynchronous Inserts (async_insert) #72

Closed xxramm16916 closed 1 year ago

xxramm16916 commented 1 year ago
    Hi. I'm sorry for asking the question here.

    I have same function:
    `
    await using var connection = new ClickHouseConnection(_connectionStringBuilder);
    await connection.OpenAsync(cancellationToken);

    await using ClickHouseColumnWriter writer = await connection
        .CreateColumnWriterAsync("INSERT INTO db.testtable(num, id, str) VALUES", cancellationToken);

    await writer.WriteTableAsync(definition.Data, definition.Count, cancellationToken);
    `

     I would like to throw request settings. INSERT INTO db.testtable(num, id, str) VALUES (...); settings insert_distributed_sync = 1;

     Is it possible to do this? Is it possible to set these settings for the connection?

     So, I need something like this documentation https://clickhouse.com/docs/en/cloud/bestpractices/asynchronous-inserts
victor-sushko commented 1 year ago

Hi!

You can execute the command SET setting=value. This command sets the value of the property for the connection.

    await using var connection = new ClickHouseConnection(_connectionStringBuilder);
    await connection.OpenAsync(cancellationToken);

    var cmd = connection.CreateCommand();
    cmd.CommandText = "SET insert_distributed_sync = 1";
    await cmd.ExecuteNonQueryAsync(cancellationToken);

    await using ClickHouseColumnWriter writer = await connection
        .CreateColumnWriterAsync("INSERT INTO db.testtable(num, id, str) VALUES", cancellationToken);

    await writer.WriteTableAsync(definition.Data, definition.Count, cancellationToken);
xxramm16916 commented 1 year ago

thank you)