Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1729244_large_timestaps
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dstempniak authored Oct 14, 2024
2 parents fd737a1 + 1394f53 commit 78e4b5c
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 71 deletions.
Binary file modified .github/workflows/parameters/parameters_AWS.json.gpg
Binary file not shown.
3 changes: 2 additions & 1 deletion .github/workflows/parameters/parameters_AZURE.json.gpg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
� V���&|���@US��ҹ�'j��M�*,#঍�Q^���s(Q��Z��Nl��,3�x���GZ�&�����L] �64+@2-�E����F�ȇ����#~����m�JQti)��k���f/g�B����Xd6�6��=fdM�R�%� ��*�?�����d������G~���'u�8��Px��(B�ib��D4"g�V�� ;��mU�+� %��6UPJuw �H'�9�v�㰅WB} 9�� ���A�"{ é�g)��� �Ysa�
� P�&�V�X����S}jV�;�0�����D��ssx(G���� 0�n�P�UŴ‰Ob�p�w3cH��i�6�W�<ᄑ�U�^�K1x���TbiAmvu2��.+ʝ���.��f*����\��V�RY/ti����}�?!�@�E���r��}�c,..p��f���k��Ny�������I�[��;K�?d�iv�x&8X%NW+,���[�>3���`������� ��H���s��cFI���
}�v�ź�m�l��c�����"A���4��
Expand Down
Binary file modified .github/workflows/parameters/parameters_GCP.json.gpg
Binary file not shown.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ Snowflake data types and their .NET types is covered in: [Data Types and Data Fo
How execute a query, use query bindings, run queries synchronously and asynchronously:
[Running Queries and Reading Results](doc/QueryingData.md)

## Structured types

Using structured types: [Structured types](doc/StructuredTypes.md)

## Vector type

Using vector type: [Vector type](doc/VectorType.md)

## Stage Files

Using stage files within PUT/GET commands:
Expand Down
32 changes: 16 additions & 16 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.GetStucturedArray<string>(0);
var array = reader.GetArray<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.GetStucturedArray<Identity>(0);
var array = reader.GetArray<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.GetStucturedArray<string[]>(0);
var array = reader.GetArray<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.GetStucturedArray<Dictionary<string, string>>(0);
var array = reader.GetArray<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.GetStucturedArray<string>(0);
var array = reader.GetArray<string>(0);

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

// act
var array = reader.GetStucturedArray<int>(0);
var array = reader.GetArray<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.GetStucturedArray<long>(0);
var array = reader.GetArray<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.GetStucturedArray<float>(0);
var array = reader.GetArray<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.GetStucturedArray<double>(0);
var array = reader.GetArray<double>(0);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// assert
SnowflakeDbExceptionAssert.HasErrorCode(thrown, SFError.STRUCTURED_TYPE_READ_DETAILED_ERROR);
Expand Down
27 changes: 0 additions & 27 deletions Snowflake.Data.Tests/IntegrationTests/VectorTypesIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Snowflake.Data.Client;
using System.Data.Common;
using Snowflake.Data.Core;
using Snowflake.Data.Tests.Util;
using System;

namespace Snowflake.Data.Tests.IntegrationTests
Expand Down Expand Up @@ -345,32 +344,6 @@ public void TestThrowExceptionForInvalidIdentifierForFloatVector()
}
}

[Test]
public void TestThrowExceptionForInvalidVectorType()
{
using (DbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString;
conn.Open();
AlterSessionSettings(conn);

using (DbCommand command = conn.CreateCommand())
{
command.CommandText = "SELECT ARRAY_CONSTRUCT(1.1)::ARRAY(DOUBLE)";
var reader = (SnowflakeDbDataReader)command.ExecuteReader();
Assert.IsTrue(reader.Read());

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

// assert
SnowflakeDbExceptionAssert.HasErrorCode(thrown, SFError.STRUCTURED_TYPE_READ_DETAILED_ERROR);
Assert.That(thrown.Message, Does.Contain("Failed to read structured type when getting an array"));
Assert.That(thrown.Message, Does.Contain("Method GetArray<System.Double> can be used only for vector types"));
}
}
}

private void AlterSessionSettings(DbConnection conn)
{
using (var command = conn.CreateCommand())
Expand Down
33 changes: 6 additions & 27 deletions Snowflake.Data/Client/SnowflakeDbDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public override int GetValues(object[] values)
return count;
}

internal T GetObject<T>(int ordinal)
public T GetObject<T>(int ordinal)
where T : class, new()
{
try
Expand Down Expand Up @@ -282,9 +282,11 @@ public T[] GetArray<T>(int ordinal)
{
var rowType = resultSet.sfResultSetMetaData.rowTypes[ordinal];
var fields = rowType.fields;
if (fields == null || fields.Count == 0 || !JsonToStructuredTypeConverter.IsVectorType(rowType.type))
var isArrayOrVector = JsonToStructuredTypeConverter.IsArrayType(rowType.type) ||
JsonToStructuredTypeConverter.IsVectorType(rowType.type);
if (fields == null || fields.Count == 0 || !isArrayOrVector)
{
throw new StructuredTypesReadingException($"Method GetArray<{typeof(T)}> can be used only for vector types");
throw new StructuredTypesReadingException($"Method GetArray<{typeof(T)}> can be used only for structured array or vector types");
}

var stringValue = GetString(ordinal);
Expand All @@ -299,30 +301,7 @@ public T[] GetArray<T>(int ordinal)
}
}

internal T[] GetStucturedArray<T>(int ordinal)
{
try
{
var rowType = resultSet.sfResultSetMetaData.rowTypes[ordinal];
var fields = rowType.fields;
if (fields == null || fields.Count == 0 || !JsonToStructuredTypeConverter.IsArrayType(rowType.type))
{
throw new StructuredTypesReadingException($"Method GetArray<{typeof(T)}> can be used only for structured array");
}

var stringValue = GetString(ordinal);
var json = stringValue == null ? null : JArray.Parse(stringValue);
return JsonToStructuredTypeConverter.ConvertArray<T>(fields, json);
}
catch (Exception e)
{
if (e is SnowflakeDbException)
throw;
throw StructuredTypesReadingHandler.ToSnowflakeDbException(e, "when getting an array");
}
}

internal Dictionary<TKey, TValue> GetMap<TKey, TValue>(int ordinal)
public Dictionary<TKey, TValue> GetMap<TKey, TValue>(int ordinal)
{
try
{
Expand Down
Loading

0 comments on commit 78e4b5c

Please sign in to comment.