From 2e8efd1c27a6d175592cc138e4472e073ed9a9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Hofman?= Date: Fri, 16 Feb 2024 10:47:51 +0100 Subject: [PATCH] SNOW-950923 review fixes and improved docs on GET/PUT execution failures --- README.md | 23 ++++++++++++++----- .../IntegrationTests/SFPutGetTest.cs | 3 +-- .../UnitTests/SFFileTransferAgentTests.cs | 1 - 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e10ad5caf..5a9a833a0 100644 --- a/README.md +++ b/README.md @@ -685,11 +685,11 @@ using (IDbConnection conn = new SnowflakeDbConnection()) { try { - conn.ConnectionString = ""; + conn.ConnectionString = ""; conn.Open(); var cmd = (SnowflakeDbCommand)conn.CreateCommand(); // cast allows get QueryId from the command - cmd.CommandText = $"PUT file://some_data.csv @my_schema.my_stage AUTO_COMPRESS=TRUE"; + cmd.CommandText = "PUT file://some_data.csv @my_schema.my_stage AUTO_COMPRESS=TRUE"; var reader = cmd.ExecuteReader(); Assert.IsTrue(reader.read()); // on success Assert.DoesNotThrow(() => Guid.Parse(cmd.GetQueryId())); @@ -698,10 +698,15 @@ using (IDbConnection conn = new SnowflakeDbConnection()) { Assert.DoesNotThrow(() => Guid.Parse(e.QueryId)); // when failed Assert.That(e.InnerException.GetType(), Is.EqualTo(typeof(FileNotFoundException))); - + } + catch (Exception e) + { + // for instance on a query execution if a connection was not opened } ``` -In case of a failure a SnowflakeDbException will be thrown with the affected QueryId. +In case of a failure an exception will be thrown. +If it was after the query got executed this exception will be a SnowflakeDbException containing affected QueryId. +In case of the initial phase of execution QueryId might not be provided. Inner exception (if applicable) will provide some details on the failure cause and it will be for example: FileNotFoundException, DirectoryNotFoundException. @@ -715,11 +720,11 @@ To use the command in a driver similar code can be executed in a client app: ```cs try { - conn.ConnectionString = ""; + conn.ConnectionString = ""; conn.Open(); var cmd = (SnowflakeDbCommand)conn.CreateCommand(); // cast allows get QueryId from the command - cmd.CommandText = $"GET @my_schema.my_stage/stage_file.csv file://local_file.csv AUTO_COMPRESS=TRUE"; + cmd.CommandText = "GET @my_schema.my_stage/stage_file.csv file://local_file.csv AUTO_COMPRESS=TRUE"; var reader = cmd.ExecuteReader(); Assert.IsTrue(reader.read()); // if succeeded Assert.DoesNotThrow(() => Guid.Parse(cmd.GetQueryId())); @@ -728,9 +733,15 @@ To use the command in a driver similar code can be executed in a client app: { Assert.DoesNotThrow(() => Guid.Parse(e.QueryId)); // on failure } + catch (Exception e) + { + // some other failure has occurred before query got started + } ``` In case of a failure a SnowflakeDbException will be thrown or DBDataReader will return a False response. In any case QueryId should be available from the exception or command property. +Similarly to PUT command in some rare cases QueryID might not be possible to provide and a generic Exception +can be thrown. Close the Connection -------------------- diff --git a/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs b/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs index 309a11316..8898f573a 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs @@ -7,7 +7,6 @@ using System.Data.Common; using System.IO.Compression; using System.Text; -using Castle.Components.DictionaryAdapter; using Snowflake.Data.Tests.Util; namespace Snowflake.Data.Tests.IntegrationTests @@ -533,7 +532,7 @@ string PutFile( String additionalAttribute = "", ResultStatus expectedStatus = ResultStatus.UPLOADED) { - String queryId; + string queryId; using (var command = conn.CreateCommand()) { // Prepare PUT query diff --git a/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs b/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs index 4f984bba5..4e7c2041e 100644 --- a/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs +++ b/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs @@ -2,7 +2,6 @@ * Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. */ -using Amazon.S3.Transfer; using Snowflake.Data.Client; using Snowflake.Data.Tests.Util;