Skip to content

Commit

Permalink
Add a test of using data chunks in query tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmosegaard committed Sep 17, 2023
1 parent 8c3e096 commit cc0e188
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion DuckDB.NET.Test/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,27 @@ public void QueryTest()
var columnCount = NativeMethods.Query.DuckDBColumnCount(ref queryResult);
columnCount.Should().Be(2);

// Using Data Chunks API
var chunkCount = NativeMethods.Types.DuckDBResultChunkCount(queryResult);
chunkCount.Should().Be(1);

using var chunk = NativeMethods.Types.DuckDBResultGetChunk(queryResult, 0);
var columnCountInChunk = NativeMethods.DataChunks.DuckDBDataChunkGetColumnCount(chunk);
columnCountInChunk.Should().Be(2);
var chunkRowCount = NativeMethods.DataChunks.DuckDBDataChunkGetSize(chunk);
chunkRowCount.Should().Be(3);

var columnA = NativeMethods.DataChunks.DuckDBDataChunkGetVector(chunk, 0);
using var columnALogicalType = NativeMethods.DataChunks.DuckDBVectorGetColumnType(columnA);
var columnAType = NativeMethods.LogicalType.DuckDBGetTypeId(columnALogicalType);
columnAType.Should().Be(DuckDBType.DuckdbTypeInteger);

var columnB = NativeMethods.DataChunks.DuckDBDataChunkGetVector(chunk, 1);
using var columnBLogicalType = NativeMethods.DataChunks.DuckDBVectorGetColumnType(columnB);
var columnBType = NativeMethods.LogicalType.DuckDBGetTypeId(columnBLogicalType);
columnBType.Should().Be(DuckDBType.DuckdbTypeBoolean);

NativeMethods.Query.DuckDBDestroyResult(ref queryResult);
}
}
}
}

0 comments on commit cc0e188

Please sign in to comment.