ClickHouse.Ado 1.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ClickHouse.Ado --version 1.2.1
NuGet\Install-Package ClickHouse.Ado -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ClickHouse.Ado" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ClickHouse.Ado --version 1.2.1
#r "nuget: ClickHouse.Ado, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ClickHouse.Ado as a Cake Addin
#addin nuget:?package=ClickHouse.Ado&version=1.2.1

// Install ClickHouse.Ado as a Cake Tool
#tool nuget:?package=ClickHouse.Ado&version=1.2.1

ClickHouse.ADO

.NET driver for Yandex ClickHouse. This driver implements native ClickHouse protocol, shamelessly ripped out of original ClickHouse sources. In some ways it does not comply to ADO.NET rules however this is intentional.

А ещё есть описание по-русски, см. ниже.

Important usage notes

No multiple queries

ClickHouse engine does not support parsing multiple queries per on IDbCommand.Execute* roundtrip. Please split your queries into separately executed commands.

Always use NextResult

Although you may think that NextResult would not be used due to aforementioned lack of multiple query support that's completely wrong! You must always use NextResult as ClickHouse protocol and engine may and will return multiple resultsets per query and sometime result schemas may differ (definetly in regard to field ordering if query doesn't explicitly specify it).

Hidden bulk-insert functionality

If you read ClickHouse documentation it stongly advices you to insert records in bulk (1000+ per request). This driver can do bulk inserts. To do so you have to use special insert syntax:

INSERT INTO some_table (col1, col2, col3) VALUES @bulk

And after that you must add parameted named bulk with its Value castable to IEnumerable each item of it must be IEnumerable too. Empty lists are not allowed. Alternatively you may pass IBulkInsertEnumerable implementation as a bulk's value to speed up processing and use less memory inside clickhouse driver. This may be used conviniently with the following syntax:

CREATE TABLE test (date Date, time DateTime, str String, int UInt16) ENGINE=MergeTree(date,(time,str,int), 8192)
class MyPersistableObject:IEnumerable{
	public string MyStringField;
	public DateTime MyDateField;
	public int MyIntField;

	//Count and order of returns must match column order in SQL INSERT
	public IEnumerator GetEnumerator(){
		yield return MyDateField;
		yield return MyDateField;
		yield return MyStringField;
		yield return (ushort)MyIntField;
	}
}

//... somewhere elsewhere ...
var list=new List<MyPersistableObject>();

// fill the list to insert
list.Add(new MyPersistableObject());

var command=connection.CreateCommand();
command.CommandText="INSERT INTO test (date,time,str,int) VALUES @bulk";
command.Parameters.Add(new ClickHouseParameter{
	ParameterName="bulk",
	Value=list
});
command.ExecuteNonQuery();

Extending and deriving

If you've fixed some bugs or wrote some useful addition to this driver, please, do pull request them back here.

If you need some functionality or found a bug but unable to implement/fix it, please file a ticket here, on GitHub.

ClickHouse.ADO по-русски

.NET драйвер для Yandex ClickHouse. В отличие от официального JDBC клиента этот драйвер не является обёрткой поверх ClickHouse HTTP, а реализует нативный протокол. Протокол (и части его реализации) нагло выдраны из исходников самого ClickHouse. В некоторых случаях этот драйвер ведёт себя не так, как обычные ADO.NET драйверы, это сделано намеренно и связано со спецификой ClickHouse.

Прочти это перед использованием

Нет поддержки нескольких запросов

Движок ClickHouse не умеет обрабатывать несколько SQL запросов за один вызов IDbCommand.Execute*. Запросы надо разбивать на отдельные команды.

Всегда используй NextResult

В связи с вышесказаным может показаться что NextResult не нужен, но это совершенно не так. Использование NextResult обязательно, поскольку протокол и движок ClickHouse может и будет возвращать несколько наборов данных на один запрос, и, хуже того, схемы этих наборов могут различаться (по крайней мере может быть перепутан порядок полей, если запрос не имеет явного указания порядка).

Секретная функция групповой вставки

В документации ClickHouse указано, что вставлять данные лучше пачками 100+ записей. Для этого предусмотрен специальный синтаксис:

INSERT INTO some_table (col1, col2, col3) VALUES @bulk

Для этой команды надо задать параметр bulk со значением Value приводимым к IEnumerable, каждый из элементов которого, в свою очередь, тоже должен быть IEnumerable. Кроме того, в качестве значения параметра bulk передать объект реализующий IBulkInsertEnumerable - это уменьшит использование памяти и процессора внутри драйвера clickhouse. Это удобно при использовании такого синтаксиса:

CREATE TABLE test (date Date, time DateTime, str String, int UInt16) ENGINE=MergeTree(date,(time,str,int), 8192)
class MyPersistableObject:IEnumerable{
	public string MyStringField;
	public DateTime MyDateField;
	public int MyIntField;

	//Количество и порядок return должны соответствовать количеству и порядку полей в SQL INSERT
	public IEnumerator GetEnumerator(){
		yield return MyDateField;
		yield return MyDateField;
		yield return MyStringField;
		yield return (ushort)MyIntField;
	}
}

//... где-то ещё ...
var list=new List<MyPersistableObject>();

// заполнение списка вставляемых объектов
list.Add(new MyPersistableObject());

var command=connection.CreateCommand();
command.CommandText="INSERT INTO test (date,time,str,int) VALUES @bulk";
command.Parameters.Add(new ClickHouseParameter{
	ParameterName="bulk",
	Value=list
});
command.ExecuteNonQuery();

Расширение и наследование

Если вы исправили баг или реализовали какую-то фичу, пожалуйста, сделайте pull request в этот репозиторий.

Если вам не хватает какой-то функции или вы нашли баг, который не можете исправить, напишите тикет здесь, на GitHub.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.5 is compatible.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on ClickHouse.Ado:

Package Downloads
ClickHouse.Net

Provides abstractions and helpers for ClickHouse.Ado.

CJENetworkLogger

.NET-based framework for building client-server applications

Dapper.Contrib.BulkInsert

Dapper bulk insert with Dapper.

CloudYxt.ClickHouse

云享通.Net Corec基于ClickHouse.Ado驱动建立常规数据操作库。

ClickHouse.Ado.Client

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on ClickHouse.Ado:

Repository Stars
masastack/MASA.Framework
.NET next-generation microservice development framework, which provides cloud native best practices based on Dapr.
Version Downloads Last updated
2.0.3 3,104 3/22/2024
2.0.2.2 16,665 11/7/2023
2.0.2.1 177 11/2/2023
2.0.2 686 10/25/2023
2.0.2-preview 1,878 10/11/2023
2.0.1-preview 849 10/10/2023
2.0.0-preview 78 10/10/2023
1.5.6-no-polling-on-tls 83 3/22/2024
1.5.5 61,912 6/2/2023
1.5.5-no-polling-on-tls 1,930 10/10/2023
1.5.4 62,576 3/2/2023
1.5.3 34,939 10/5/2022
1.5.2 3,109 9/27/2022
1.5.1 158,939 4/21/2022
1.4.3 5,764 4/5/2022
1.4.2 52,766 1/21/2022
1.4.0 128,052 8/9/2021
1.3.1 87,563 3/11/2021
1.2.6 52,713 10/27/2020
1.2.5 3,493 10/19/2020
1.2.4 9,105 9/16/2020
1.2.3 3,367 8/31/2020
1.2.2 2,151 8/25/2020
1.2.1 12,549 4/13/2020
1.2.0-preview-02 535 3/19/2020
1.2.0-preview-01 368 3/19/2020
1.1.21 21,361 2/4/2020
1.1.20 62,671 9/30/2019
1.1.19 1,718 9/23/2019
1.1.17 32,555 6/5/2019
1.1.16 705 5/30/2019
1.1.15 33,903 5/23/2019
1.1.13 16,185 1/28/2019
1.1.9 93,858 7/9/2018
1.1.7 1,077 7/5/2018
1.1.6 2,223 5/12/2018
1.1.5 21,464 11/27/2017
1.1.4 1,077 11/7/2017
1.1.3 1,020 11/3/2017
1.1.2 3,742 8/28/2017
1.1.1 1,433 6/21/2017
1.1.0 1,113 6/21/2017
1.0.2 1,140 6/2/2017
1.0.1 1,105 5/29/2017
1.0.0 1,404 4/26/2017