Skip to content

Commit

Permalink
Add test for double nested table insert (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer committed Apr 17, 2024
1 parent 6a14b69 commit eadd631
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions ClickHouse.Client.Tests/BulkCopyTests.cs
Expand Up @@ -292,7 +292,7 @@ public async Task ShouldExecuteWithDBNullArrays()
var targetTable = $"test.bulk_dbnull_array";

await connection.ExecuteStatementAsync($"TRUNCATE TABLE IF EXISTS {targetTable}");
await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (stringValue Array(String), intValue Array(Int32)) ENGINE TinyLog");
await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (stringValue Array(String), intValue Array(Int32)) ENGINE Memory");

using var bulkCopy = new ClickHouseBulkCopy(connection)
{
Expand All @@ -315,7 +315,7 @@ public async Task ShouldInsertNestedTable()
var targetTable = "test.bulk_nested";

await connection.ExecuteStatementAsync($"TRUNCATE TABLE IF EXISTS {targetTable}");
await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (`_id` UUID, `Comments` Nested(Id Nullable(String), Comment Nullable(String))) ENGINE TinyLog");
await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (`_id` UUID, `Comments` Nested(Id Nullable(String), Comment Nullable(String))) ENGINE Memory");

using var bulkCopy = new ClickHouseBulkCopy(connection)
{
Expand All @@ -324,7 +324,42 @@ public async Task ShouldInsertNestedTable()

await bulkCopy.InitAsync();

await bulkCopy.WriteToServerAsync(new List<object[]>() { new object[] { Guid.NewGuid(), new ITuple[] {("1", "Comment1"),("2","Comment2"),("3","Comment3")}} });
await bulkCopy.WriteToServerAsync(new List<object[]>() { new object[] { Guid.NewGuid(), new ITuple[] { ("1", "Comment1"), ("2", "Comment2"), ("3", "Comment3") } } });

using var reader = await connection.ExecuteReaderAsync($"SELECT * from {targetTable}");
Assert.AreEqual(1, bulkCopy.RowsWritten);
Assert.AreEqual(1, await connection.ExecuteScalarAsync($"SELECT count() FROM {targetTable}"));
}

[Test]
public async Task ShouldInsertDoubleNestedTable()
{
var targetTable = "test.bulk_double_nested";

await connection.ExecuteStatementAsync($"TRUNCATE TABLE IF EXISTS {targetTable}");
await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (Id Int64, Threads Nested(Id Int64, Comments Nested(Id Int64, Text String))) ENGINE Memory");

using var bulkCopy = new ClickHouseBulkCopy(connection)
{
DestinationTableName = targetTable,
};

await bulkCopy.InitAsync();

var comments = new[]
{
Tuple.Create(1, "Comment 1"),
Tuple.Create(2, "Comment 2"),
Tuple.Create(3, "Comment 3"),
};
var threads = new[]
{
Tuple.Create(1, comments),
Tuple.Create(2, comments),
Tuple.Create(3, comments),
};

await bulkCopy.WriteToServerAsync([[1, threads]]);

using var reader = await connection.ExecuteReaderAsync($"SELECT * from {targetTable}");
Assert.AreEqual(1, bulkCopy.RowsWritten);
Expand Down

0 comments on commit eadd631

Please sign in to comment.