From ea372ab6068e497db33255bfc9766eb555edd5d1 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-hx Date: Fri, 6 Oct 2023 17:34:44 -0700 Subject: [PATCH] adding missed fix for HTAP parameter removal --- .../IntegrationTests/SFDbDataReaderIT.cs | 22 +++++++++++++++++++ .../UnitTests/SFSessionTest.cs | 6 +++++ Snowflake.Data/Core/ArrowResultSet.cs | 2 +- Snowflake.Data/Core/SFResultSet.cs | 2 +- Snowflake.Data/Core/SFResultSetMetaData.cs | 18 ++++----------- Snowflake.Data/Core/Session/SFSession.cs | 19 ++++++++++++++-- .../Core/Session/SFSessionParameter.cs | 2 ++ 7 files changed, 53 insertions(+), 18 deletions(-) diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs index 158abc7f0..936508446 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs @@ -174,6 +174,28 @@ public void TestGetDate(string inputTimeStr) testGetDateAndOrTime(inputTimeStr, null, SFDataType.DATE); } + [Test] + public void TestDateOutputFormat() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + IDbCommand cmd = conn.CreateCommand(); + cmd.CommandText = "alter session set DATE_OUTPUT_FORMAT='MM/DD/YYYY'"; + cmd.ExecuteNonQuery(); + + cmd.CommandText = $"select TO_DATE('2013-05-17')"; + IDataReader reader = cmd.ExecuteReader(); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual("05/17/2013", reader.GetString(0)); + + reader.Close(); + conn.Close(); + } + } [Test] [TestCase(null, null)] diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionTest.cs index 51635d662..b9530b83b 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionTest.cs @@ -34,6 +34,12 @@ public void TestUpdateDatabaseAndSchema() Assert.AreEqual(databaseName, sfSession.database); Assert.AreEqual(schemaName, sfSession.schema); + + // when database or schema name is missing in the response, + // the cached value should keep unchanged + sfSession.UpdateDatabaseAndSchema(null, null); + Assert.AreEqual(databaseName, sfSession.database); + Assert.AreEqual(schemaName, sfSession.schema); } [Test] diff --git a/Snowflake.Data/Core/ArrowResultSet.cs b/Snowflake.Data/Core/ArrowResultSet.cs index 5c3103320..6bc0112c3 100755 --- a/Snowflake.Data/Core/ArrowResultSet.cs +++ b/Snowflake.Data/Core/ArrowResultSet.cs @@ -45,7 +45,7 @@ public ArrowResultSet(QueryExecResponseData responseData, SFStatement sfStatemen responseData.rowSet = null; - sfResultSetMetaData = new SFResultSetMetaData(responseData); + sfResultSetMetaData = new SFResultSetMetaData(responseData, this.sfStatement.SfSession); isClosed = false; diff --git a/Snowflake.Data/Core/SFResultSet.cs b/Snowflake.Data/Core/SFResultSet.cs index 2e20453ba..1f36a5cd2 100755 --- a/Snowflake.Data/Core/SFResultSet.cs +++ b/Snowflake.Data/Core/SFResultSet.cs @@ -39,7 +39,7 @@ public SFResultSet(QueryExecResponseData responseData, SFStatement sfStatement, _currentChunk = new SFResultChunk(responseData.rowSet); responseData.rowSet = null; - sfResultSetMetaData = new SFResultSetMetaData(responseData); + sfResultSetMetaData = new SFResultSetMetaData(responseData, this.sfStatement.SfSession); isClosed = false; diff --git a/Snowflake.Data/Core/SFResultSetMetaData.cs b/Snowflake.Data/Core/SFResultSetMetaData.cs index 1045109f4..c4c46f973 100755 --- a/Snowflake.Data/Core/SFResultSetMetaData.cs +++ b/Snowflake.Data/Core/SFResultSetMetaData.cs @@ -37,25 +37,15 @@ class SFResultSetMetaData /// private Dictionary columnNameToIndexCache = new Dictionary(); - internal SFResultSetMetaData(QueryExecResponseData queryExecResponseData) + internal SFResultSetMetaData(QueryExecResponseData queryExecResponseData, SFSession session) { rowTypes = queryExecResponseData.rowType; columnCount = rowTypes.Count; statementType = findStatementTypeById(queryExecResponseData.statementTypeId); columnTypes = InitColumnTypes(); - - foreach (NameValueParameter parameter in queryExecResponseData.parameters) - { - switch(parameter.name) - { - case "DATE_OUTPUT_FORMAT": - dateOutputFormat = parameter.value; - break; - case "TIME_OUTPUT_FORMAT": - timeOutputFormat = parameter.value; - break; - } - } + + dateOutputFormat = session.ParameterMap[SFSessionParameter.DATE_OUTPUT_FORMAT].ToString(); + timeOutputFormat = session.ParameterMap[SFSessionParameter.TIME_OUTPUT_FORMAT].ToString(); } internal SFResultSetMetaData(PutGetResponseData putGetResponseData) diff --git a/Snowflake.Data/Core/Session/SFSession.cs b/Snowflake.Data/Core/Session/SFSession.cs index 6d91aa094..5e78db2a9 100755 --- a/Snowflake.Data/Core/Session/SFSession.cs +++ b/Snowflake.Data/Core/Session/SFSession.cs @@ -380,6 +380,13 @@ internal SFRestRequest BuildTimeoutRestRequest(Uri uri, Object body) internal void UpdateSessionParameterMap(List parameterList) { logger.Debug("Update parameter map"); + // with HTAP parameter removal parameters might not returned + // query response + if (parameterList is null) + { + return; + } + foreach (NameValueParameter parameter in parameterList) { if (Enum.TryParse(parameter.name, out SFSessionParameter parameterName)) @@ -432,8 +439,16 @@ internal RequestQueryContext GetQueryContextRequest() internal void UpdateDatabaseAndSchema(string databaseName, string schemaName) { - this.database = databaseName; - this.schema = schemaName; + // with HTAP session metadata removal database/schema + // might be not returened in query result + if (databaseName != null) + { + this.database = databaseName; + } + if (schemaName != null) + { + this.schema = schemaName; + } } internal void startHeartBeatForThisSession() diff --git a/Snowflake.Data/Core/Session/SFSessionParameter.cs b/Snowflake.Data/Core/Session/SFSessionParameter.cs index 4212f5b35..97fdcec23 100755 --- a/Snowflake.Data/Core/Session/SFSessionParameter.cs +++ b/Snowflake.Data/Core/Session/SFSessionParameter.cs @@ -12,5 +12,7 @@ internal enum SFSessionParameter CLIENT_STAGE_ARRAY_BINDING_THRESHOLD, CLIENT_SESSION_KEEP_ALIVE, QUERY_CONTEXT_CACHE_SIZE, + DATE_OUTPUT_FORMAT, + TIME_OUTPUT_FORMAT, } }