Skip to content

Commit

Permalink
debug not working test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko committed Jun 7, 2024
1 parent ac82397 commit 2d723b1
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions Snowflake.Data.Tests/IntegrationTests/SFBindTestIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
namespace Snowflake.Data.Tests.IntegrationTests
{

[TestFixture]
[TestFixture]
class SFBindTestIT : SFBaseTest
{
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SFBindTestIT>();

[Test]
public void TestArrayBind()
{

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

CreateOrReplaceTable(conn, TableName, new []
{
"cola INTEGER",
Expand Down Expand Up @@ -208,7 +208,7 @@ public void TestBindValue()
{
dbConnection.ConnectionString = ConnectionString;
dbConnection.Open();

CreateOrReplaceTable(dbConnection, TableName, new[]
{
"intData NUMBER",
Expand All @@ -222,7 +222,7 @@ public void TestBindValue()
"dateTimeData DATETIME",
"dateTimeWithTimeZone TIMESTAMP_TZ"
});

foreach (DbType type in Enum.GetValues(typeof(DbType)))
{
bool isTypeSupported = true;
Expand Down Expand Up @@ -299,7 +299,7 @@ public void TestBindValue()
param.Value = Encoding.UTF8.GetBytes("BinaryData");
break;
default:
// Not supported
// Not supported
colName = "stringData";
isTypeSupported = false;
break;
Expand Down Expand Up @@ -381,7 +381,7 @@ public void TestBindValueWithSFDataType()
"unsupportedType VARCHAR"
};
}

s_logger.Warn($"Trying to create a table: {TableName} with columns: {columns} !!!");
CreateOrReplaceTable(dbConnection, TableName, columns);

using (IDbCommand command = dbConnection.CreateCommand())
Expand Down Expand Up @@ -437,7 +437,7 @@ public void TestBindValueWithSFDataType()
Assert.AreEqual(1, rowsInserted);
}
// DB rejects query if param type is VARIANT, OBJECT or ARRAY
else if (!type.Equals(SFDataType.VARIANT) &&
else if (!type.Equals(SFDataType.VARIANT) &&
!type.Equals(SFDataType.OBJECT) &&
!type.Equals(SFDataType.ARRAY))
{
Expand Down Expand Up @@ -492,7 +492,7 @@ public void TestParameterCollection()
p2.ParameterName = "2";
p1.DbType = DbType.Int16;
p2.Value = 2;


var p3 = cmd.CreateParameter();
p2.ParameterName = "2";
Expand All @@ -507,7 +507,7 @@ public void TestParameterCollection()
((SnowflakeDbParameterCollection)cmd.Parameters).AddRange(parameters);
Assert.Throws<NotImplementedException>(
() => { cmd.Parameters.CopyTo(parameters, 5); });

Assert.AreEqual(3, cmd.Parameters.Count);
Assert.IsTrue(cmd.Parameters.Contains(p2));
Assert.IsTrue(cmd.Parameters.Contains("2"));
Expand All @@ -518,7 +518,7 @@ public void TestParameterCollection()
Assert.AreEqual(2, cmd.Parameters.Count);
Assert.AreSame(p1, cmd.Parameters[0]);

cmd.Parameters.RemoveAt(0);
cmd.Parameters.RemoveAt(0);
Assert.AreSame(p3, cmd.Parameters[0]);

cmd.Parameters.Clear();
Expand All @@ -536,15 +536,15 @@ public void TestPutArrayBind()
{
conn.ConnectionString = ConnectionString;
conn.Open();

CreateOrReplaceTable(conn, TableName, new []
{
"cola INTEGER",
"colb STRING",
"colc DATE",
"cold TIME",
"cole TIMESTAMP_NTZ",
"colf TIMESTAMP_TZ"
"colf TIMESTAMP_TZ"
});

using (IDbCommand cmd = conn.CreateCommand())
Expand Down Expand Up @@ -579,7 +579,7 @@ public void TestPutArrayBind()
p2.DbType = DbType.String;
p2.Value = arrstring.ToArray();
cmd.Parameters.Add(p2);

DateTime date1 = DateTime.ParseExact("2000-01-01 00:00:00.0000000", "yyyy-MM-dd HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
DateTime date2 = DateTime.ParseExact("2020-05-11 23:59:59.9999999", "yyyy-MM-dd HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
DateTime date3 = DateTime.ParseExact("2021-07-22 23:59:59.9999999", "yyyy-MM-dd HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -645,7 +645,7 @@ public void TestPutArrayBind()
p6.DbType = DbType.DateTimeOffset;
p6.Value = arrTz.ToArray();
cmd.Parameters.Add(p6);

var count = cmd.ExecuteNonQuery();
Assert.AreEqual(total * 3, count);

Expand All @@ -657,18 +657,18 @@ public void TestPutArrayBind()
conn.Close();
}
}

[Test]
public void TestPutArrayBindWorkDespiteOtTypeNameHandlingAuto()
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings {
TypeNameHandling = TypeNameHandling.Auto
};

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

CreateOrReplaceTable(conn, TableName, new []
{
"cola REAL",
Expand All @@ -682,7 +682,7 @@ public void TestPutArrayBindWorkDespiteOtTypeNameHandlingAuto()
cmd.CommandText = insertCommand;

var total = 250;

List<double> arrdouble = new List<double>();
List<string> arrstring = new List<string>();
List<int> arrint = new List<int>();
Expand All @@ -691,11 +691,11 @@ public void TestPutArrayBindWorkDespiteOtTypeNameHandlingAuto()
arrdouble.Add(i * 10 + 1);
arrdouble.Add(i * 10 + 2);
arrdouble.Add(i * 10 + 3);

arrstring.Add("stra"+i);
arrstring.Add("strb"+i);
arrstring.Add("strc"+i);

arrint.Add(i * 10 + 1);
arrint.Add(i * 10 + 2);
arrint.Add(i * 10 + 3);
Expand All @@ -705,13 +705,13 @@ public void TestPutArrayBindWorkDespiteOtTypeNameHandlingAuto()
p1.DbType = DbType.Double;
p1.Value = arrdouble.ToArray();
cmd.Parameters.Add(p1);

var p2 = cmd.CreateParameter();
p2.ParameterName = "2";
p2.DbType = DbType.String;
p2.Value = arrstring.ToArray();
cmd.Parameters.Add(p2);

var p3 = cmd.CreateParameter();
p3.ParameterName = "3";
p3.DbType = DbType.Int32;
Expand All @@ -737,7 +737,7 @@ public void TestPutArrayIntegerBind()
{
conn.ConnectionString = ConnectionString;
conn.Open();

CreateOrReplaceTable(conn, TableName, new []
{
"cola INTEGER"
Expand Down Expand Up @@ -835,7 +835,7 @@ public void TestExplicitDbTypeAssignmentForArrayValue()
conn.Close();
}
}

private const string FormatYmd = "yyyy/MM/dd";
private const string FormatHms = "HH\\:mm\\:ss";
private const string FormatHmsf = "HH\\:mm\\:ss\\.fff";
Expand Down Expand Up @@ -869,7 +869,7 @@ public void TestExplicitDbTypeAssignmentForArrayValue()
[TestCase(ResultFormat.ARROW, SFTableType.Hybrid, SFDataType.TIMESTAMP_NTZ, 6, DbType.DateTime, FormatYmdHms, null)]
[TestCase(ResultFormat.ARROW, SFTableType.Hybrid, SFDataType.TIMESTAMP_TZ, 6, DbType.DateTimeOffset, FormatYmdHmsZ, null)]
[TestCase(ResultFormat.ARROW, SFTableType.Hybrid, SFDataType.TIMESTAMP_LTZ, 6, DbType.DateTimeOffset, FormatYmdHmsZ, null)]
// ICEBERG Tables; require env variables: ICEBERG_EXTERNAL_VOLUME, ICEBERG_CATALOG, ICEBERG_BASE_LOCATION.
// ICEBERG Tables; require env variables: ICEBERG_EXTERNAL_VOLUME, ICEBERG_CATALOG, ICEBERG_BASE_LOCATION.
[TestCase(ResultFormat.JSON, SFTableType.Iceberg, SFDataType.DATE, null, DbType.Date, FormatYmd, null)]
[TestCase(ResultFormat.JSON, SFTableType.Iceberg, SFDataType.TIME, null, DbType.Time, FormatHms, null)]
[TestCase(ResultFormat.JSON, SFTableType.Iceberg, SFDataType.TIME, 6, DbType.Time, FormatHmsf, null)]
Expand Down Expand Up @@ -897,7 +897,7 @@ public void TestDateTimeBinding(ResultFormat resultFormat, SFTableType tableType
var smallBatchRowCount = 2;
var bigBatchRowCount = bindingThreshold / 2;
s_logger.Info(testCase);

using (IDbConnection conn = new SnowflakeDbConnection(ConnectionString))
{
conn.Open();
Expand All @@ -906,13 +906,13 @@ public void TestDateTimeBinding(ResultFormat resultFormat, SFTableType tableType
if (!timeZone.IsNullOrEmpty()) // Driver ignores this setting and relies on local environment timezone
conn.ExecuteNonQuery($"alter session set TIMEZONE = '{timeZone}'");

CreateOrReplaceTable(conn,
TableName,
tableType.TableDDLCreationPrefix(),
CreateOrReplaceTable(conn,
TableName,
tableType.TableDDLCreationPrefix(),
new[] {
"id number(10,0) not null primary key", // necessary only for HYBRID tables
$"ts {columnWithPrecision}"
},
$"ts {columnWithPrecision}"
},
tableType.TableDDLCreationFlags());

// Act+Assert
Expand All @@ -938,7 +938,7 @@ public void TestDateTimeBinding(ResultFormat resultFormat, SFTableType tableType
Assert.AreEqual(1+smallBatchRowCount+bigBatchRowCount, row);
}
}

private void InsertSingleRecord(IDbConnection conn, string sqlInsert, DbType binding, int identifier, ExpectedTimestampWrapper ts)
{
using (var insert = conn.CreateCommand(sqlInsert))
Expand All @@ -958,7 +958,7 @@ private void InsertSingleRecord(IDbConnection conn, string sqlInsert, DbType bin
// Act
s_logger.Info(sqlInsert);
var rowsAffected = insert.ExecuteNonQuery();

// Assert
Assert.AreEqual(1, rowsAffected);
Assert.IsNull(((SnowflakeDbCommand)insert).GetBindStage());
Expand All @@ -980,11 +980,11 @@ private void InsertMultipleRecords(IDbConnection conn, string sqlInsert, DbType
{
insert.Add("2", binding, Enumerable.Repeat(ts.GetDateTime(), rowsCount).ToArray());
}

// Act
s_logger.Debug(sqlInsert);
var rowsAffected = insert.ExecuteNonQuery();

// Assert
Assert.AreEqual(rowsCount, rowsAffected);
if (shouldUseBinding)
Expand All @@ -993,11 +993,11 @@ private void InsertMultipleRecords(IDbConnection conn, string sqlInsert, DbType
Assert.IsNull(((SnowflakeDbCommand)insert).GetBindStage());
}
}
private static string ColumnTypeWithPrecision(SFDataType columnType, Int32? columnPrecision)

private static string ColumnTypeWithPrecision(SFDataType columnType, Int32? columnPrecision)
=> columnPrecision != null ? $"{columnType}({columnPrecision})" : $"{columnType}";
}

class ExpectedTimestampWrapper
{
private readonly SFDataType _columnType;
Expand Down Expand Up @@ -1051,7 +1051,7 @@ internal void AssertEqual(object actual, string comparisonFormat, string faultMe
internal DateTime GetDateTime() => _expectedDateTime ?? throw new Exception($"Column {_columnType} is not matching the expected value type {typeof(DateTime)}");

internal DateTimeOffset GetDateTimeOffset() => _expectedDateTimeOffset ?? throw new Exception($"Column {_columnType} is not matching the expected value type {typeof(DateTime)}");

internal static bool IsOffsetType(SFDataType type) => type == SFDataType.TIMESTAMP_LTZ || type == SFDataType.TIMESTAMP_TZ;
}
}

0 comments on commit 2d723b1

Please sign in to comment.