Skip to content

Commit

Permalink
Changed according to comments, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Jan 2, 2024
1 parent 6f84c1b commit 0499a4e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
31 changes: 27 additions & 4 deletions Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Apache.Arrow;
using Apache.Arrow.Types;
Expand Down Expand Up @@ -156,10 +157,32 @@ public void TestUnusedExtractCellThrowsNotSupportedException()
[Test]
public void TestExtractCellReturnsNull()
{
var chunk = new ArrowResultChunk(RecordBatchWithNullValue);
chunk.Next();

Assert.AreEqual(DBNull.Value, chunk.ExtractCell(0, SFDataType.FIXED, 0));
var cases = new Dictionary<ArrowResultChunk, SFDataType>
{
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Int8", false, col => col.Int8(array => array.AppendNull())).Build()), SFDataType.FIXED },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Int16", false, col => col.Int16(array => array.AppendNull())).Build()), SFDataType.FIXED },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Int32", false, col => col.Int32(array => array.AppendNull())).Build()), SFDataType.FIXED },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Int64", false, col => col.Int64(array => array.AppendNull())).Build()), SFDataType.FIXED },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Decimal128", false, col => col.Decimal128(new Decimal128Type(0, 0), array => array.AppendNull())).Build()), SFDataType.FIXED },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Boolean", false, col => col.Boolean(array => array.AppendNull())).Build()), SFDataType.BOOLEAN },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Real", false, col => col.Double(array => array.AppendNull())).Build()), SFDataType.REAL },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Text", false, col => col.String(array => array.AppendNull())).Build()), SFDataType.TEXT },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Array", false, col => col.String(array => array.AppendNull())).Build()), SFDataType.ARRAY },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Variant", false, col => col.String(array => array.AppendNull())).Build()), SFDataType.VARIANT },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Object", false, col => col.String(array => array.AppendNull())).Build()), SFDataType.OBJECT },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Binary", false, col => col.Binary(array => array.AppendNull())).Build()), SFDataType.BINARY },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Date", false, col => col.Date32(array => array.AppendNull())).Build()), SFDataType.DATE },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Time", false, col => col.Int32(array => array.AppendNull())).Build()), SFDataType.TIME },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Timestamp_TZ", false, col => col.Int32(array => array.AppendNull())).Build()), SFDataType.TIMESTAMP_TZ },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Timestamp_LTZ", false, col => col.Int32(array => array.AppendNull())).Build()), SFDataType.TIMESTAMP_LTZ },
{ new ArrowResultChunk(new RecordBatch.Builder().Append("Col_Timestamp_NTZ", false, col => col.Int32(array => array.AppendNull())).Build()), SFDataType.TIMESTAMP_NTZ },
};

foreach (var (chunk, type) in cases)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'KeyValuePair<ArrowResultChunk, SFDataType>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair<ArrowResultChunk, SFDataType>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair<ArrowResultChunk, SFDataType>', with 2 out parameters and a void return type.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'chunk'.

Check failure on line 181 in Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

Cannot infer the type of implicitly-typed deconstruction variable 'type'.
{
chunk.Next();
Assert.AreEqual(DBNull.Value, chunk.ExtractCell(0, type, 0), $"Expected DBNull.Value for SFDataType: {type}");
}
}

[Test]
Expand Down
37 changes: 21 additions & 16 deletions Snowflake.Data/Core/ArrowResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,35 @@ public ArrowResultSet(QueryExecResponseData responseData, SFStatement sfStatemen

queryId = responseData.queryId;

if (responseData.rowsetBase64.Length > 0)
ReadChunk(responseData);
}
catch(Exception ex)

Check warning on line 50 in Snowflake.Data/Core/ArrowResultSet.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/ArrowResultSet.cs#L50

Added line #L50 was not covered by tests
{
s_logger.Error("Result set error queryId="+responseData.queryId, ex);
throw;
}
}

private void ReadChunk(QueryExecResponseData responseData)
{
if (responseData.rowsetBase64.Length > 0)
{
using (var stream = new MemoryStream(Convert.FromBase64String(responseData.rowsetBase64)))
{
using (var stream = new MemoryStream(Convert.FromBase64String(responseData.rowsetBase64)))
using (var reader = new ArrowStreamReader(stream))
{
using (var reader = new ArrowStreamReader(stream))
var recordBatch = reader.ReadNextRecordBatch();
_currentChunk = new ArrowResultChunk(recordBatch);
while ((recordBatch = reader.ReadNextRecordBatch()) != null)
{
var recordBatch = reader.ReadNextRecordBatch();
_currentChunk = new ArrowResultChunk(recordBatch);
while ((recordBatch = reader.ReadNextRecordBatch()) != null)
{
((ArrowResultChunk)_currentChunk).AddRecordBatch(recordBatch);
}
((ArrowResultChunk)_currentChunk).AddRecordBatch(recordBatch);
}

Check warning on line 70 in Snowflake.Data/Core/ArrowResultSet.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/ArrowResultSet.cs#L68-L70

Added lines #L68 - L70 were not covered by tests
}
}
else
{
_currentChunk = new ArrowResultChunk(columnCount);
}
}
catch(Exception ex)
else
{
s_logger.Error("Result set error queryId="+responseData.queryId, ex);
throw;
_currentChunk = new ArrowResultChunk(columnCount);
}
}

Expand Down
2 changes: 0 additions & 2 deletions Snowflake.Data/Core/BaseResultChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ internal virtual void Reset(ExecResponseChunk chunkInfo, int chunkIndex)
RowCount = chunkInfo.rowCount;
Url = chunkInfo.url;
ChunkIndex = chunkIndex;

CompressedSize = chunkInfo.compressedSize;
UncompressedSize = chunkInfo.uncompressedSize;

}

internal virtual void ResetForRetry()
Expand Down

0 comments on commit 0499a4e

Please sign in to comment.