From c7bf0eff3f617951556354ee1d73f817d9ae7751 Mon Sep 17 00:00:00 2001 From: Dariusz Stempniak Date: Wed, 9 Oct 2024 11:11:14 +0200 Subject: [PATCH] SNOW-1640968 Reset -> Clear, added tests --- .../UnitTests/SFReusableChunkTest.cs | 27 +++++++++++++++++++ Snowflake.Data/Core/BaseResultChunk.cs | 2 +- Snowflake.Data/Core/SFReusableChunk.cs | 17 ++++++------ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs b/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs index 6f021994b..25627dcaf 100755 --- a/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs @@ -219,6 +219,33 @@ public void TestResetClearsChunkData() Assert.AreEqual(0, chunk.ChunkIndex); Assert.AreEqual(chunkInfo.url, chunk.Url); Assert.AreEqual(chunkInfo.rowCount, chunk.RowCount); + Assert.AreEqual(chunkInfo.uncompressedSize, chunk.UncompressedSize); + Assert.Greater(chunk.data.blockCount, 0); + Assert.Greater(chunk.data.metaBlockCount, 0); + } + + [Test] + public void TestClearRemovesAllChunkData() + { + const int RowCount = 3; + string data = "[ [\"1\"], [\"2\"], [\"3\"] ]"; + var chunk = PrepareChunkAsync(data, 1, RowCount).Result; + + ExecResponseChunk chunkInfo = new ExecResponseChunk() + { + url = "new_url", + uncompressedSize = 100, + rowCount = 200 + }; + + chunk.Clear(); + + Assert.AreEqual(0, chunk.ChunkIndex); + Assert.AreEqual(null, chunk.Url); + Assert.AreEqual(0, chunk.RowCount); + Assert.AreEqual(0, chunk.UncompressedSize); + Assert.AreEqual(0, chunk.data.blockCount); + Assert.AreEqual(0, chunk.data.metaBlockCount); } private async Task PrepareChunkAsync(string stringData, int colCount, int rowCount) diff --git a/Snowflake.Data/Core/BaseResultChunk.cs b/Snowflake.Data/Core/BaseResultChunk.cs index d43f86dbf..b3b764210 100755 --- a/Snowflake.Data/Core/BaseResultChunk.cs +++ b/Snowflake.Data/Core/BaseResultChunk.cs @@ -46,7 +46,7 @@ internal virtual void Reset(ExecResponseChunk chunkInfo, int chunkIndex) UncompressedSize = chunkInfo.uncompressedSize; } - internal virtual void Reset() + internal virtual void Clear() { RowCount = 0; Url = null; diff --git a/Snowflake.Data/Core/SFReusableChunk.cs b/Snowflake.Data/Core/SFReusableChunk.cs index 0e6f7595d..4db8ec0d7 100755 --- a/Snowflake.Data/Core/SFReusableChunk.cs +++ b/Snowflake.Data/Core/SFReusableChunk.cs @@ -12,7 +12,7 @@ class SFReusableChunk : BaseResultChunk { internal override ResultFormat ResultFormat => ResultFormat.JSON; - private readonly BlockResultData data; + internal readonly BlockResultData data; private int _currentRowIndex = -1; @@ -29,11 +29,11 @@ internal override void Reset(ExecResponseChunk chunkInfo, int chunkIndex) data.Reset(RowCount, ColumnCount, chunkInfo.uncompressedSize); } - internal override void Reset() + internal override void Clear() { - base.Reset(); + base.Clear(); _currentRowIndex = -1; - data.Reset(); + data.Clear(); } internal override void ResetForRetry() @@ -76,14 +76,15 @@ internal override bool Rewind() return _currentRowIndex >= 0; } - private class BlockResultData + internal class BlockResultData { private static readonly int NULL_VALUE = -100; - private int blockCount; + internal int blockCount; private static int blockLengthBits = 23; private static int blockLength = 1 << blockLengthBits; - int metaBlockCount; + + internal int metaBlockCount; private static int metaBlockLengthBits = 15; private static int metaBlockLength = 1 << metaBlockLengthBits; @@ -109,7 +110,7 @@ internal void Reset(int rowCount, int colCount, int uncompressedSize) this.metaBlockCount = getMetaBlock(rowCount * colCount - 1) + 1; } - internal void Reset() + internal void Clear() { savedRowCount = 0; savedColCount = 0;