Skip to content

Commit

Permalink
SNOW-933246: adding missed fix for HTAP parameter removal (#787)
Browse files Browse the repository at this point in the history
### Description
sdk issue 693
Some cases for HTAP metadata/parameter removal was missed in September
release. Fix them and add test case as well.

### Checklist
- [x] Code compiles correctly
- [x] Code is formatted according to [Coding
Conventions](../CodingConventions.md)
- [x] Created tests which fail without the change (if possible)
- [x] All tests passing (`dotnet test`)
- [ ] Extended the README / documentation, if necessary
- [x] Provide JIRA issue id (if possible) or GitHub issue id in PR name
  • Loading branch information
Harry Xi authored Oct 12, 2023
1 parent 127343f commit 8c2feaa
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 16 deletions.
32 changes: 32 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,38 @@ 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();

try
{
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();
}
finally
{
// set format back to default to avoid impact other test cases
cmd.CommandText = "alter session set DATE_OUTPUT_FORMAT='YYYY-MM-DD'";
cmd.ExecuteNonQuery();
}

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
20 changes: 8 additions & 12 deletions Snowflake.Data/Core/SFResultSetMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ 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)

if (session.ParameterMap.ContainsKey(SFSessionParameter.DATE_OUTPUT_FORMAT))
{
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();
}
if (session.ParameterMap.ContainsKey(SFSessionParameter.TIME_OUTPUT_FORMAT))
{
timeOutputFormat = session.ParameterMap[SFSessionParameter.TIME_OUTPUT_FORMAT].ToString();
}
}

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 (!String.IsNullOrEmpty(databaseName))
{
this.database = databaseName;
}
if (!String.IsNullOrEmpty(schemaName))
{
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 8c2feaa

Please sign in to comment.