Skip to content

Commit

Permalink
Add BulkCopy test for inserting million rows #475 (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer authored May 14, 2024
1 parent 5b21825 commit b939d00
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ClickHouse.Client.Tests/BulkCopyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,38 @@ public async Task ShouldInsertDoubleNestedTable()
Assert.AreEqual(1, await connection.ExecuteScalarAsync($"SELECT count() FROM {targetTable}"));
}

[Test]
[TestCase(0.01)]
[TestCase(0.25)]
[TestCase(0.50)]
[TestCase(0.75)]
[TestCase(0.99)]
public async Task ShouldThrowExceptionOnInnerException(double fraction)
{
const int setSize = 3000000;
int dbNullIndex = (int)(setSize * fraction);

var targetTable = "test." + SanitizeTableName($"bulk_million_inserts");


var data = Enumerable.Repeat(new object[] { 1 }, setSize).ToArray();
data[dbNullIndex][0] = DBNull.Value;

//await connection.ExecuteStatementAsync($"TRUNCATE TABLE IF EXISTS {targetTable}");
await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (value Int16) ENGINE Null");

using var bulkCopy = new ClickHouseBulkCopy(connection)
{
DestinationTableName = targetTable,
MaxDegreeOfParallelism = 2,
BatchSize = 1000
};

await bulkCopy.InitAsync();

Assert.ThrowsAsync<ClickHouseBulkCopySerializationException>(async () => await bulkCopy.WriteToServerAsync(data, CancellationToken.None));
}

private static string SanitizeTableName(string input)
{
var builder = new StringBuilder();
Expand All @@ -377,3 +409,4 @@ private static string SanitizeTableName(string input)
return builder.ToString();
}
}

0 comments on commit b939d00

Please sign in to comment.