Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1640968 chunk downloader fix #1022

Merged
merged 10 commits into from
Oct 9, 2024
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
25 changes: 17 additions & 8 deletions Snowflake.Data/Core/BaseResultChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace Snowflake.Data.Core
public abstract class BaseResultChunk : IResultChunk
{
internal abstract ResultFormat ResultFormat { get; }

public int RowCount { get; protected set; }

public int ColumnCount { get; protected set; }

public int ChunkIndex { get; protected set; }

internal int CompressedSize;

internal int UncompressedSize;

internal string Url { get; set; }

internal string[,] RowSet { get; set; }

public int GetRowCount() => RowCount;

public int GetChunkIndex() => ChunkIndex;
Expand All @@ -32,11 +32,11 @@ public abstract class BaseResultChunk : IResultChunk
public abstract UTF8Buffer ExtractCell(int rowIndex, int columnIndex);

public abstract UTF8Buffer ExtractCell(int columnIndex);

internal abstract bool Next();

internal abstract bool Rewind();

internal virtual void Reset(ExecResponseChunk chunkInfo, int chunkIndex)
{
RowCount = chunkInfo.rowCount;
Expand All @@ -46,6 +46,15 @@ internal virtual void Reset(ExecResponseChunk chunkInfo, int chunkIndex)
UncompressedSize = chunkInfo.uncompressedSize;
}

internal virtual void Clear()
{
RowCount = 0;
Url = null;
ChunkIndex = 0;
CompressedSize = 0;
UncompressedSize = 0;
}

internal virtual void ResetForRetry()
{
}
Expand Down
Loading
Loading