VOOZH about

URL: https://www.nuget.org/packages/SharpJuice.ClickHouse/

⇱ NuGet Gallery | SharpJuice.ClickHouse 1.0.7




SharpJuice.ClickHouse 1.0.7

dotnet add package SharpJuice.ClickHouse --version 1.0.7
 
 
NuGet\Install-Package SharpJuice.ClickHouse -Version 1.0.7
 
 
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="SharpJuice.ClickHouse" Version="1.0.7" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpJuice.ClickHouse" Version="1.0.7" />
 
Directory.Packages.props
<PackageReference Include="SharpJuice.ClickHouse" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpJuice.ClickHouse --version 1.0.7
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SharpJuice.ClickHouse, 1.0.7"
 
 
#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.
#:package SharpJuice.ClickHouse@1.0.7
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SharpJuice.ClickHouse&version=1.0.7
 
Install as a Cake Addin
#tool nuget:?package=SharpJuice.ClickHouse&version=1.0.7
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Writing .Net objects to ClickHouse

👁 NuGet

Octonica.ClickHouseClient extension for easily writing objects to ClickHouse using bulk insert and ArrayPool for high performance and low memory allocation.

Registration

 ClickHouseConnectionSettings connectionSettings = ...;

 services.AddSingleton<IClickHouseConnectionFactory>(new ClickHouseConnectionFactory(connectionSettings));
 services.AddSingleton<ITableWriterBuilder, TableWriterBuilder>();	
 services.AddSingleton<ClickHouseRepository>();	

Flat object

 public sealed class ClickHouseRepository 
 {
 private readonly ITableWriter<Order> _tableWriter;
 
 public ClickHouseRepository(ITableWriterBuilder tableWriterBuilder)
 {
 _tableWriter = tableWriterBuilder
 .For<Order>("table_name")
 .AddColumn("order_id", a => a.OrderId)
 .AddColumn("user_id", a => a.UserId)
 .AddColumn("created_at", a => a.CreatedAt) 
		.Build();
 }

 public async Task Add(IReadOnlyCollection<Order> orders, CancellationToken token)
 {
	 ...
 await _tableWriter.Insert(orders, token);
	 ...
 }
 }

Nested objects

 public sealed class ClickHouseRepository 
 {
 private readonly ITableWriter<Order> _tableWriter;
 
 public ClickHouseRepository(ITableWriterBuilder tableWriterBuilder)
 {
 _tableWriter = tableWriterBuilder
 .For<Order>("table_name")
 .AddColumn("order_id", a => a.OrderId)
 .AddColumn("date", a => a.Date)
 .AddNestedColumn("item", x => x.Items, c => c
 .AddColumn("id", x => x.Id)
 .AddColumn("quantity", x => x.Quantity)
 .AddColumn("name", x => x.Name)
 .AddColumn("price", x => x.Price))
 .AddNestedColumn(x => x.Discounts, c => c
 .AddColumn("discount.id", x => x.Id)
 .AddColumn("discount.name", x => x.Name)
 .AddColumn("discount.value", x => x.Value)) 
 .Build(); 
 }

 public async Task Add(IReadOnlyCollection<Order> orders, CancellationToken token)
 {
	 ...
 await _tableWriter.Insert(orders, token);
	 ...
 }
 }

Array join (only one ArrayJoin per writer)

 public sealed class ClickHouseRepository 
 {
 private readonly ITableWriter<Order> _tableWriter;
 
 public ClickHouseRepository(ITableWriterBuilder tableWriterBuilder)
 {
 _tableWriter = tableWriterBuilder
 .For<Order>("table_name")
 .AddColumn("order_id", a => a.OrderId)
 .AddColumn("date", a => a.Date)
 .ArrayJoin(a => a.Items, c => c
 .AddColumn("item_id", x => x.Id)
 .AddColumn("item_quantity", x => x.Quantity)
 .AddColumn("item_name", x => x.Name)
 .AddColumn("item_price", x => x.Price))
		 .Build();
 }

 public async Task Add(IReadOnlyCollection<Order> orders, CancellationToken token)
 {
	 ...
 await _tableWriter.Insert(orders, token);
	 ...
 }
 }

Performance and memory allocation benchmark (.net 8)

Benchmark source code

Method ObjectsCount Mean Error StdDev Gen0 Gen1 Gen2 Allocated
NestedObject_Writer 1000 71.87 ms 1.425 ms 2.176 ms - - - 1148.29 KB
FlatObject_Writer 1000 73.33 ms 1.159 ms 1.028 ms 375.0000 250.0000 - 2837.81 KB
ClickhouseClient_ColumnWriter 1000 78.63 ms 1.631 ms 4.731 ms 428.5714 142.8571 - 2948.86 KB
NestedObject_Writer 100 101.91 ms 1.629 ms 1.523 ms - - - 205 KB
ClickhouseClient_ColumnWriter 100 102.99 ms 2.008 ms 2.749 ms - - - 368.33 KB
FlatObject_Writer 100 103.24 ms 2.025 ms 2.633 ms - - - 358.71 KB
NestedObject_Writer 10000 281.58 ms 10.143 ms 29.102 ms 1000.0000 - - 9140.61 KB
ClickhouseClient_ColumnWriter 10000 284.90 ms 9.745 ms 27.325 ms 4000.0000 1000.0000 - 27643.59 KB
FlatObject_Writer 10000 302.62 ms 13.242 ms 38.836 ms 4000.0000 1000.0000 - 26020.02 KB
NestedObject_Writer 30000 712.17 ms 23.182 ms 67.622 ms 2000.0000 1000.0000 - 14370.6 KB
ClickhouseClient_ColumnWriter 30000 775.75 ms 22.886 ms 66.396 ms 11000.0000 5000.0000 2000.0000 69326.91 KB
FlatObject_Writer 30000 781.20 ms 24.974 ms 72.057 ms 10000.0000 3000.0000 - 65002.87 KB

Thanks to @deniskuzmin and @LegaNoga

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 1,094 5/10/2024
1.0.6 223 3/21/2024
1.0.5 219 3/12/2024
1.0.4 230 2/14/2024
1.0.3 222 2/11/2024
1.0.2 200 2/9/2024
1.0.1 220 2/7/2024
1.0.0 229 1/25/2024