Skip to content

Commit

Permalink
SNOW-950923 revert repackaging exception when non-put/get command are…
Browse files Browse the repository at this point in the history
… executed
  • Loading branch information
sfc-gh-mhofman committed Feb 19, 2024
1 parent 9ed5361 commit 1a7d139
Showing 1 changed file with 83 additions and 58 deletions.
141 changes: 83 additions & 58 deletions Snowflake.Data/Core/SFStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,71 +343,47 @@ internal SFBaseResultSet Execute(int timeout, string sql, Dictionary<string, Bin
{
// Trim the sql query and check if this is a PUT/GET command
string trimmedSql = TrimSql(sql);

try
{
if (IsPutOrGetCommand(trimmedSql))
{
isPutGetQuery = true;
PutGetExecResponse response =
ExecuteHelper<PutGetExecResponse, PutGetResponseData>(
timeout,
sql,
bindings,
describeOnly);
return ExecuteSqlWithPutGet(timeout, trimmedSql, bindings, describeOnly);
}

logger.Debug("PUT/GET queryId: " + (response.data != null ? response.data.queryId : "Unknown"));
return ExecuteSqlOtherThanPutGet(timeout, trimmedSql, bindings, describeOnly);
}
finally
{
CleanUpCancellationTokenSources();
ClearQueryRequestId();
}
}

SFFileTransferAgent fileTransferAgent =
new SFFileTransferAgent(trimmedSql, SfSession, response.data, CancellationToken.None);
internal SFBaseResultSet ExecuteSqlWithPutGet(int timeout, string sql, Dictionary<string, BindingDTO> bindings, bool describeOnly)
{
try
{
isPutGetQuery = true;
PutGetExecResponse response =
ExecuteHelper<PutGetExecResponse, PutGetResponseData>(
timeout,
sql,
bindings,
describeOnly);

// Start the file transfer
fileTransferAgent.execute();
logger.Debug("PUT/GET queryId: " + (response.data != null ? response.data.queryId : "Unknown"));

if (response.data != null)
_lastQueryId = response.data.queryId;
SFFileTransferAgent fileTransferAgent =
new SFFileTransferAgent(sql, SfSession, response.data, CancellationToken.None);

// Get the results of the upload/download
return fileTransferAgent.result();
}
else
{
int arrayBindingThreshold = 0;
if (SfSession.ParameterMap.ContainsKey(SFSessionParameter.CLIENT_STAGE_ARRAY_BINDING_THRESHOLD))
{
String val = (String)SfSession.ParameterMap[SFSessionParameter.CLIENT_STAGE_ARRAY_BINDING_THRESHOLD];
arrayBindingThreshold = Int32.Parse(val);
}

int numBinding = GetBindingCount(bindings);

if (0 < arrayBindingThreshold
&& arrayBindingThreshold <= numBinding
&& !describeOnly)
{
try
{
AssignQueryRequestId();
SFBindUploader uploader = new SFBindUploader(SfSession, _requestId);
uploader.Upload(bindings);
_bindStage = uploader.getStagePath();
ClearQueryRequestId();
}
catch (Exception e)
{
logger.Warn("Exception encountered trying to upload binds to stage. Attaching binds in payload instead. {0}", e);
}
}
// Start the file transfer
fileTransferAgent.execute();

QueryExecResponse response =
ExecuteHelper<QueryExecResponse, QueryExecResponseData>(
timeout,
sql,
bindings,
describeOnly);
if (response.data != null)
_lastQueryId = response.data.queryId;

return BuildResultSet(response, CancellationToken.None);
}
// Get the results of the upload/download
return fileTransferAgent.result();
}
catch (SnowflakeDbException ex)
{
Expand All @@ -420,13 +396,62 @@ internal SFBaseResultSet Execute(int timeout, string sql, Dictionary<string, Bin
logger.Error("Query execution failed.", ex);
throw new SnowflakeDbException(ex, SFError.INTERNAL_ERROR);

Check warning on line 397 in Snowflake.Data/Core/SFStatement.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/SFStatement.cs#L394-L397

Added lines #L394 - L397 were not covered by tests
}
finally
}

internal SFBaseResultSet ExecuteSqlOtherThanPutGet(int timeout, string sql, Dictionary<string, BindingDTO> bindings, bool describeOnly)
{
try
{
CleanUpCancellationTokenSources();
ClearQueryRequestId();
int arrayBindingThreshold = 0;
if (SfSession.ParameterMap.ContainsKey(SFSessionParameter.CLIENT_STAGE_ARRAY_BINDING_THRESHOLD))
{
String val =
(String)SfSession.ParameterMap[SFSessionParameter.CLIENT_STAGE_ARRAY_BINDING_THRESHOLD];
arrayBindingThreshold = Int32.Parse(val);
}

int numBinding = GetBindingCount(bindings);

if (0 < arrayBindingThreshold
&& arrayBindingThreshold <= numBinding
&& !describeOnly)
{
try
{
AssignQueryRequestId();
SFBindUploader uploader = new SFBindUploader(SfSession, _requestId);
uploader.Upload(bindings);
_bindStage = uploader.getStagePath();
ClearQueryRequestId();
}
catch (Exception e)
{
logger.Warn(
"Exception encountered trying to upload binds to stage. Attaching binds in payload instead. {0}",
e);

Check warning on line 431 in Snowflake.Data/Core/SFStatement.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/SFStatement.cs#L427-L431

Added lines #L427 - L431 were not covered by tests
}
}

QueryExecResponse response =
ExecuteHelper<QueryExecResponse, QueryExecResponseData>(
timeout,
sql,
bindings,
describeOnly);

return BuildResultSet(response, CancellationToken.None);
}
catch (Exception ex)
{
logger.Error("Query execution failed.", ex);
if (ex is SnowflakeDbException snowflakeDbException)
{
_lastQueryId = snowflakeDbException.QueryId ?? _lastQueryId;
}
throw;
}
}

internal async Task<SFBaseResultSet> GetResultWithIdAsync(string resultId, CancellationToken cancellationToken)
{
var req = BuildResultRequestWithId(resultId);
Expand Down

0 comments on commit 1a7d139

Please sign in to comment.