Skip to content

Commit d430695

Browse files
committed
修复ClickHouseBulkCopy没传ColumnNames与未调用InitAsync可能导致Column names not initialized. Call InitAsync once to load column data
1 parent bcd1163 commit d430695

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Providers/FreeSql.Provider.ClickHouse/Curd/ClickHouseInsert.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,21 @@ async protected override Task<int> RawExecuteAffrowsAsync(CancellationToken canc
185185
before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, null, _params);
186186
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
187187
var data = ToDataTable();
188+
var columns = new string[_table.ColumnsByPosition.Length];
189+
for (var i = 0; i < columns.Length; i++)
190+
{
191+
columns[i] = _table.ColumnsByPosition[i].CsName;
192+
}
188193
using (var conn = await _orm.Ado.MasterPool.GetAsync())
189194
{
190195
using (var bulkCopyInterface = new ClickHouseBulkCopy(conn.Value as ClickHouseConnection)
191196
{
192197
DestinationTableName = data.TableName,
193-
BatchSize = _source.Count
198+
BatchSize = _source.Count,
199+
ColumnNames = columns,
194200
})
195201
{
202+
await bulkCopyInterface.InitAsync();
196203
await bulkCopyInterface.WriteToServerAsync(data, default);
197204
}
198205
}
@@ -201,7 +208,7 @@ async protected override Task<int> RawExecuteAffrowsAsync(CancellationToken canc
201208
catch (Exception ex)
202209
{
203210
exception = ex;
204-
throw ex;
211+
throw;
205212
}
206213
finally
207214
{

0 commit comments

Comments
 (0)