Skip to content

Commit

Permalink
SNOW-1342958: Add vector type support (#1002)
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof Nozderko <[email protected]>
  • Loading branch information
sfc-gh-ext-simba-lf and sfc-gh-knozderko authored Oct 3, 2024
1 parent 77410c7 commit 717a804
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/IntegrationTests/SFBindTestIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void TestBindValueWithSFDataType()
dbConnection.Open();
foreach (SFDataType type in Enum.GetValues(typeof(SFDataType)))
{
if (!type.Equals(SFDataType.None) && !type.Equals(SFDataType.MAP))
if (!type.Equals(SFDataType.None) && !type.Equals(SFDataType.MAP) && !type.Equals(SFDataType.VECTOR))
{
bool isTypeSupported = true;
string[] columns;
Expand Down
55 changes: 40 additions & 15 deletions Snowflake.Data.Tests/IntegrationTests/StructuredArraysIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void TestSelectArray()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<string>(0);
var array = reader.GetStucturedArray<string>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -54,7 +54,7 @@ public void TestSelectArrayOfObjects()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<Identity>(0);
var array = reader.GetStucturedArray<Identity>(0);

// assert
Assert.AreEqual(2, array.Length);
Expand All @@ -79,7 +79,7 @@ public void TestSelectArrayOfArrays()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<string[]>(0);
var array = reader.GetStucturedArray<string[]>(0);

// assert
Assert.AreEqual(2, array.Length);
Expand All @@ -104,7 +104,7 @@ public void TestSelectArrayOfMap()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<Dictionary<string, string>>(0);
var array = reader.GetStucturedArray<Dictionary<string, string>>(0);

// assert
Assert.AreEqual(1, array.Length);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void TestSelectSemiStructuredTypesInArray(string valueSfString, string ex
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<string>(0);
var array = reader.GetStucturedArray<string>(0);

// assert
Assert.NotNull(array);
Expand All @@ -159,7 +159,7 @@ public void TestSelectArrayOfIntegers()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<int>(0);
var array = reader.GetStucturedArray<int>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -184,7 +184,7 @@ public void TestSelectArrayOfLong()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<long>(0);
var array = reader.GetStucturedArray<long>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -209,7 +209,7 @@ public void TestSelectArrayOfFloats()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<float>(0);
var array = reader.GetStucturedArray<float>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -234,7 +234,7 @@ public void TestSelectArrayOfDoubles()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<double>(0);
var array = reader.GetStucturedArray<double>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -243,6 +243,31 @@ public void TestSelectArrayOfDoubles()
}
}

[Test]
public void TestSelectArrayOfDoublesWithExponentNotation()
{
// arrange
using (var connection = new SnowflakeDbConnection(ConnectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
EnableStructuredTypes(connection);
var arrayOfDoubles = "ARRAY_CONSTRUCT(1.0e100, 1.0e-100)::ARRAY(DOUBLE)";
command.CommandText = $"SELECT {arrayOfDoubles}";
var reader = (SnowflakeDbDataReader) command.ExecuteReader();
Assert.IsTrue(reader.Read());

// act
var array = reader.GetStucturedArray<double>(0);

// assert
Assert.AreEqual(2, array.Length);
CollectionAssert.AreEqual(new[] { 1.0e100d, 1.0e-100d }, array);
}
}
}

[Test]
public void TestSelectStringArrayWithNulls()
{
Expand All @@ -259,7 +284,7 @@ public void TestSelectStringArrayWithNulls()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<string>(0);
var array = reader.GetStucturedArray<string>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -284,7 +309,7 @@ public void TestSelectIntArrayWithNulls()
Assert.IsTrue(reader.Read());

// act
var array = reader.GetArray<int?>(0);
var array = reader.GetStucturedArray<int?>(0);

// assert
Assert.AreEqual(3, array.Length);
Expand All @@ -309,7 +334,7 @@ public void TestSelectNullArray()
Assert.IsTrue(reader.Read());

// act
var nullArray = reader.GetArray<string>(0);
var nullArray = reader.GetStucturedArray<string>(0);

// assert
Assert.IsNull(nullArray);
Expand All @@ -333,7 +358,7 @@ public void TestThrowExceptionForInvalidArray()
Assert.IsTrue(reader.Read());

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => reader.GetArray<string>(0));
var thrown = Assert.Throws<SnowflakeDbException>(() => reader.GetStucturedArray<string>(0));

// assert
SnowflakeDbExceptionAssert.HasErrorCode(thrown, SFError.STRUCTURED_TYPE_READ_DETAILED_ERROR);
Expand All @@ -359,7 +384,7 @@ public void TestThrowExceptionForInvalidArrayElement()
Assert.IsTrue(reader.Read());

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => reader.GetArray<Guid>(0));
var thrown = Assert.Throws<SnowflakeDbException>(() => reader.GetStucturedArray<Guid>(0));

// assert
SnowflakeDbExceptionAssert.HasErrorCode(thrown, SFError.STRUCTURED_TYPE_READ_ERROR);
Expand All @@ -386,7 +411,7 @@ public void TestThrowExceptionForNextedInvalidElement()
Assert.IsTrue(reader.Read());

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => reader.GetArray<AnnotatedClassForConstructorConstruction>(0));
var thrown = Assert.Throws<SnowflakeDbException>(() => reader.GetStucturedArray<AnnotatedClassForConstructorConstruction>(0));

// assert
SnowflakeDbExceptionAssert.HasErrorCode(thrown, SFError.STRUCTURED_TYPE_READ_DETAILED_ERROR);
Expand Down
Loading

0 comments on commit 717a804

Please sign in to comment.