Skip to content

Commit

Permalink
adding missed fix for HTAP parameter removal
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-hx committed Oct 7, 2023
1 parent 6feb3cb commit ea372ab
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
22 changes: 22 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions Snowflake.Data.Tests/UnitTests/SFSessionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/ArrowResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/SFResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 4 additions & 14 deletions Snowflake.Data/Core/SFResultSetMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,15 @@ class SFResultSetMetaData
/// </summary>
private Dictionary<string, int> columnNameToIndexCache = new Dictionary<string, int>();

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)
Expand Down
19 changes: 17 additions & 2 deletions Snowflake.Data/Core/Session/SFSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ internal SFRestRequest BuildTimeoutRestRequest(Uri uri, Object body)
internal void UpdateSessionParameterMap(List<NameValueParameter> 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))
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions Snowflake.Data/Core/Session/SFSessionParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit ea372ab

Please sign in to comment.