Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-933246: adding missed fix for HTAP parameter removal #787

Merged
5 commits merged into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ 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();

// set format back to default to avoid impact other test cases
cmd.CommandText = "alter session set DATE_OUTPUT_FORMAT='YYYY-MM-DD'";
sfc-gh-pfus marked this conversation as resolved.
Show resolved Hide resolved
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))
sfc-gh-pfus marked this conversation as resolved.
Show resolved Hide resolved
sfc-gh-pfus marked this conversation as resolved.
Show resolved Hide resolved
{
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 (databaseName != null)
sfc-gh-mhofman marked this conversation as resolved.
Show resolved Hide resolved
{
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,
}
}
Loading