Skip to content

Commit c6cc733

Browse files
committed
Initialize writers only once
1 parent bae8291 commit c6cc733

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

DuckDB.NET.Data/DuckDBAppender.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ internal unsafe DuckDBAppender(Native.DuckDBAppender appender, string qualifiedT
3939
}
4040

4141
dataChunk = NativeMethods.DataChunks.DuckDBCreateDataChunk(logicalTypeHandles, columnCount);
42+
43+
for (long index = 0; index < vectorWriters.LongLength; index++)
44+
{
45+
var vector = NativeMethods.DataChunks.DuckDBDataChunkGetVector(dataChunk, index);
46+
47+
vectorWriters[index] = VectorDataWriterFactory.CreateWriter(vector, logicalTypes[index]);
48+
}
4249
}
4350

4451
public DuckDBAppenderRow CreateRow()
@@ -48,11 +55,10 @@ public DuckDBAppenderRow CreateRow()
4855
throw new InvalidOperationException("Appender is already closed");
4956
}
5057

51-
if (rowCount % DuckDBVectorSize == 0)
58+
if (rowCount == DuckDBVectorSize)
5259
{
5360
AppendDataChunk();
5461

55-
InitVectorWriters();
5662
rowCount = 0;
5763
}
5864

@@ -95,16 +101,6 @@ public void Dispose()
95101
}
96102
}
97103

98-
private unsafe void InitVectorWriters()
99-
{
100-
for (long index = 0; index < vectorWriters.LongLength; index++)
101-
{
102-
var vector = NativeMethods.DataChunks.DuckDBDataChunkGetVector(dataChunk, index);
103-
104-
vectorWriters[index] = VectorDataWriterFactory.CreateWriter(vector, logicalTypes[index]);
105-
}
106-
}
107-
108104
private void AppendDataChunk()
109105
{
110106
NativeMethods.DataChunks.DuckDBDataChunkSetSize(dataChunk, rowCount);

DuckDB.NET.Test/DuckDBManagedAppenderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void GuidValues()
197197
Command.CommandText = "CREATE TABLE managedAppenderGuids(a UUID);";
198198
Command.ExecuteNonQuery();
199199

200-
var guids = GetRandomList<Guid?>(faker => faker.Random.Guid());
200+
var guids = GetRandomList<Guid?>(faker => faker.Random.Guid(), 5000);
201201
guids.Add(null);
202202

203203
using (var appender = Connection.CreateAppender("managedAppenderGuids"))

0 commit comments

Comments
 (0)