Skip to content

Commit

Permalink
SNOW-893834 after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dstempniak committed Oct 11, 2023
1 parent 913f0ec commit c803ab4
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 225 deletions.
201 changes: 72 additions & 129 deletions Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions Snowflake.Data.Tests/IntegrationTests/SFReusableChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class SFReusableChunkTest : SFBaseTest
[Test]
public void TestDelCharPr431()
{
using (IDbConnection conn = new SnowflakeDbConnectionWithResultFormat(ResultFormat.JSON))
using (IDbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString;
conn.Open();

SessionParameterAlterer.SetResultFormat(conn, ResultFormat.JSON);
CreateOrReplaceTable(conn, TableName, new []{"col STRING"});

IDbCommand cmd = conn.CreateCommand();
Expand Down Expand Up @@ -51,6 +52,7 @@ public void TestDelCharPr431()
}
Assert.AreEqual(largeTableRowCount, rowCount);

SessionParameterAlterer.RestoreResultFormat(conn);
// Reader's RecordsAffected should be available even if the connection is closed
conn.Close();
}
Expand All @@ -62,11 +64,12 @@ public void TestParseJson()
IChunkParserFactory previous = ChunkParserFactory.Instance;
ChunkParserFactory.Instance = new TestChunkParserFactory(1);

using (IDbConnection conn = new SnowflakeDbConnectionWithResultFormat(ResultFormat.JSON))
using (IDbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString;
conn.Open();

SessionParameterAlterer.SetResultFormat(conn, ResultFormat.JSON);
CreateOrReplaceTable(conn, TableName, new []{"src VARIANT"});

IDbCommand cmd = conn.CreateCommand();
Expand Down Expand Up @@ -110,6 +113,7 @@ select parse_json('{{
}
Assert.AreEqual(500, rowCount);

SessionParameterAlterer.RestoreResultFormat(conn);
// Reader's RecordsAffected should be available even if the connection is closed
conn.Close();
}
Expand All @@ -122,11 +126,12 @@ public void TestChunkRetry()
IChunkParserFactory previous = ChunkParserFactory.Instance;
ChunkParserFactory.Instance = new TestChunkParserFactory(6); // lower than default retry of 7

using (IDbConnection conn = new SnowflakeDbConnectionWithResultFormat(ResultFormat.JSON))
using (IDbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString;
conn.Open();

SessionParameterAlterer.SetResultFormat(conn, ResultFormat.JSON);
CreateOrReplaceTable(conn, TableName, new []{"col STRING"});

IDbCommand cmd = conn.CreateCommand();
Expand Down Expand Up @@ -157,6 +162,7 @@ public void TestChunkRetry()
}
Assert.AreEqual(largeTableRowCount, rowCount);

SessionParameterAlterer.RestoreResultFormat(conn);
// Reader's RecordsAffected should be available even if the connection is closed
conn.Close();
}
Expand Down
23 changes: 17 additions & 6 deletions Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Apache.Arrow.Types;
using NUnit.Framework;
using Snowflake.Data.Core;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.UnitTests
{
Expand Down Expand Up @@ -185,7 +186,7 @@ public void TestExtractCellReturnsNumber16()
[Test]
public void TestExtractCellReturnsNumber8()
{
var testValues = new sbyte[] { 0, 127, -120 };
var testValues = new sbyte[] { 0, 127, -128 };
var sfType = SFDataType.FIXED;

for (var scale = 0; scale <= 9; ++scale)
Expand Down Expand Up @@ -220,7 +221,7 @@ public void TestExtractCellReturnsText()
var testValues = new string[]
{
"",
"AAA $ BBB & CCC * (ZZZ) aaa zzz `~!@#$%^&*()_+-={}|[]\\;':\",./<>?"
TestDataGenarator.StringWithUnicode
};
var sfType = SFDataType.TEXT;
var scale = 0;
Expand All @@ -234,7 +235,7 @@ public void TestExtractCellReturnsArray()
var testValues = new string[]
{
"",
"AAA $ BBB & CCC * (ZZZ) aaa zzz `~!@#$%^&*()_+-={}|[]\\;':\",./<>?"
TestDataGenarator.StringWithUnicode
};
var sfType = SFDataType.ARRAY;
var scale = 0;
Expand Down Expand Up @@ -404,9 +405,19 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje
case SFDataType.ARRAY:
case SFDataType.VARIANT:
case SFDataType.OBJECT:
column = new StringArray.Builder()
.AppendRange(values as string[])
.Build();
switch (values)
{
case string[] arr:
column = new StringArray.Builder()
.AppendRange(arr)
.Build();
break;
case char[] arr:
column = new StringArray.Builder()
.AppendRange(arr.Select(ch => ch.ToString()))
.Build();
break;
}
break;

case SFDataType.BINARY:
Expand Down
71 changes: 39 additions & 32 deletions Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Apache.Arrow.Ipc;
using NUnit.Framework;
using Snowflake.Data.Core;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.UnitTests
{
Expand Down Expand Up @@ -146,18 +147,16 @@ public void TestGetNumber16()
[Test]
public void TestGetNumber8()
{
var testValues = new sbyte[] { 0, 127, -120 };
var testValues = new sbyte[] { 0, 127, -128 };

TestGetNumber(testValues);
}

private void TestGetNumber(IEnumerable testValues)
{
var sfType = SFDataType.FIXED;

for (var scale = 0; scale <= 9; ++scale)
{
PrepareTestCase(sfType, scale, testValues);
PrepareTestCase(SFDataType.FIXED, scale, testValues);

foreach (var testValue in testValues)
{
Expand Down Expand Up @@ -196,9 +195,8 @@ private void TestGetNumber(IEnumerable testValues)
public void TestGetBoolean()
{
var testValues = new bool[] { true, false };
var sfType = SFDataType.BOOLEAN;

PrepareTestCase(sfType, 0, testValues);
PrepareTestCase(SFDataType.BOOLEAN, 0, testValues);

foreach (var testValue in testValues)
{
Expand All @@ -212,9 +210,8 @@ public void TestGetBoolean()
public void TestGetReal()
{
var testValues = new double[] { 0, Double.MinValue, Double.MaxValue };
var sfType = SFDataType.REAL;

PrepareTestCase(sfType, 0, testValues);
PrepareTestCase(SFDataType.REAL, 0, testValues);

foreach (var testValue in testValues)
{
Expand All @@ -230,11 +227,10 @@ public void TestGetText()
var testValues = new string[]
{
"",
"AAA $ BBB & CCC * (ZZZ) aaa zzz `~!@#$%^&*()_+-={}|[]\\;':\",./<>?"
TestDataGenarator.StringWithUnicode
};
var sfType = SFDataType.TEXT;

PrepareTestCase(sfType, 0, testValues);
PrepareTestCase(SFDataType.TEXT, 0, testValues);

foreach (var testValue in testValues)
{
Expand All @@ -244,26 +240,43 @@ public void TestGetText()
}
}

[Test]
public void TestGetTextWithOneChar()
{
var testValues =
TestDataGenarator.AsciiCodes.ToCharArray()
.Append(TestDataGenarator.SnowflakeUnicode)
.ToArray();

PrepareTestCase(SFDataType.TEXT, 0, testValues);

foreach (var testValue in testValues)
{
_arrowResultSet.Next();
Assert.AreEqual(testValue, _arrowResultSet.GetChar(ColumnIndex));
}
}

[Test]
public void TestGetArray()
{
var testValues = new string[]
{
"",
"AAA $ BBB & CCC * (ZZZ) aaa zzz `~!@#$%^&*()_+-={}|[]\\;':\",./<>?"
TestDataGenarator.StringWithUnicode
};
var sfType = SFDataType.ARRAY;

PrepareTestCase(sfType, 0, testValues);
PrepareTestCase(SFDataType.ARRAY, 0, testValues);

foreach (var testValue in testValues)
{
_arrowResultSet.Next();
Assert.AreEqual(testValue, _arrowResultSet.GetValue(ColumnIndex));
char[] buffer = new char[100];
char[] buffer = new char[1000];
var len = _arrowResultSet.GetChars(ColumnIndex, 0, buffer, 0, buffer.Length);
Assert.AreEqual(testValue.Length, len);
Assert.AreEqual(testValue, new String(buffer, 0, (int)len));
var str = new String(buffer, 0, (int)len);
Assert.AreEqual(testValue, str);
Assert.AreEqual(testValue.Length, str.Length);
}
}

Expand All @@ -275,9 +288,8 @@ public void TestGetBinary()
new byte[] { },
new byte[] { 0, 19, 33, 200, 10, 13, 255 }
};
var sfType = SFDataType.BINARY;

PrepareTestCase(sfType, 0, testValues);
PrepareTestCase(SFDataType.BINARY, 0, testValues);
foreach (var testValue in testValues)
{
_arrowResultSet.Next();
Expand All @@ -299,9 +311,8 @@ public void TestGetDate()
DateTime.Parse("0001-01-01"),
DateTime.Parse("9999-12-31")
};
var sfType = SFDataType.DATE;

PrepareTestCase(sfType, 0, testValues);
PrepareTestCase(SFDataType.DATE, 0, testValues);

foreach (var testValue in testValues)
{
Expand All @@ -320,12 +331,11 @@ public void TestGetTime()
DateTime.Parse("0001-01-01 00:00:00.0000000"),
DateTime.Parse("9999-12-31 23:59:59.9999999")
};
var sfType = SFDataType.TIME;


for (var scale = 0; scale <= 7; ++scale)
{
var values = ArrowResultChunkTest.TruncateValues(testValues, scale);
PrepareTestCase(sfType, scale, values);
PrepareTestCase(SFDataType.TIME, scale, values);

foreach (var testValue in values)
{
Expand All @@ -348,12 +358,11 @@ public void TestGetTimestampTz()
DateTimeOffset.Parse("0001-01-01 00:00:00.0000000 +0000"),
DateTimeOffset.Parse("9999-12-31 23:59:59.9999999 +0000"),
};
var sfType = SFDataType.TIMESTAMP_TZ;


for (var scale = 0; scale <= 9; ++scale)
{
var values = ArrowResultChunkTest.TruncateValues(testValues, scale);
PrepareTestCase(sfType, scale, values);
PrepareTestCase(SFDataType.TIMESTAMP_TZ, scale, values);

foreach (var testValue in values)
{
Expand All @@ -372,12 +381,11 @@ public void TestGetTimestampLtz()
DateTimeOffset.Parse("0001-01-01 00:00:00.0000000 +0000").ToLocalTime(),
DateTimeOffset.Parse("9999-12-31 23:59:59.9999999 +0000").ToLocalTime(),
};
var sfType = SFDataType.TIMESTAMP_LTZ;

for (var scale = 0; scale <= 9; ++scale)
{
var values = ArrowResultChunkTest.TruncateValues(testValues, scale);
PrepareTestCase(sfType, scale, values);
PrepareTestCase(SFDataType.TIMESTAMP_LTZ, scale, values);

foreach (var testValue in values)
{
Expand All @@ -396,12 +404,11 @@ public void TestGetTimestampNtz()
DateTime.Parse("0001-01-01 00:00:00.0000000"),
DateTime.Parse("9999-12-31 23:59:59.9999999")
};
var sfType = SFDataType.TIMESTAMP_NTZ;


for (var scale = 0; scale <= 9; ++scale)
{
var values = ArrowResultChunkTest.TruncateValues(testValues, scale);
PrepareTestCase(sfType, scale, values);
PrepareTestCase(SFDataType.TIMESTAMP_NTZ, scale, values);

foreach (var testValue in values)
{
Expand Down
44 changes: 0 additions & 44 deletions Snowflake.Data.Tests/Util/SnowflakeDbConnectionWithResultFormat.cs

This file was deleted.

6 changes: 6 additions & 0 deletions Snowflake.Data.Tests/Util/TestDataGenarator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

using System;
using System.Linq;

namespace Snowflake.Data.Tests.Util
{
Expand All @@ -16,6 +17,11 @@ public class TestDataGenarator
private static string s_digitChars = "0" + s_nonZeroDigits;
private static string s_letterChars = s_lowercaseChars + s_uppercaseChars;
private static string s_alphanumericChars = s_letterChars + s_digitChars;

public static string AsciiCodes => new String(Enumerable.Range(0, 256).Select(ch => (char)ch).ToArray());
public static char SnowflakeUnicode => '\u2744';
public static string EmojiUnicode => "\uD83D\uDE00";
public static string StringWithUnicode => AsciiCodes + SnowflakeUnicode + EmojiUnicode;

public static bool NextBool()
{
Expand Down
Loading

0 comments on commit c803ab4

Please sign in to comment.