Skip to content

Commit

Permalink
SNOW-1640968 Reset -> Clear, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dstempniak committed Oct 9, 2024
1 parent 37bdea4 commit c7bf0ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
27 changes: 27 additions & 0 deletions Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SFReusableChunk> PrepareChunkAsync(string stringData, int colCount, int rowCount)
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/BaseResultChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions Snowflake.Data/Core/SFReusableChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit c7bf0ef

Please sign in to comment.