This is an automated email from the ASF dual-hosted git repository.

curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 879ff324 test(csharp/test/Drivers/Snowflake): refactor snowflake test 
framework (#1323)
879ff324 is described below

commit 879ff324aac9f03c0e93145d87b92be27c5692bb
Author: Ruoxuan Wang <[email protected]>
AuthorDate: Tue Dec 5 21:02:39 2023 +0800

    test(csharp/test/Drivers/Snowflake): refactor snowflake test framework 
(#1323)
---
 csharp/test/Drivers/Snowflake/ClientTests.cs       | 68 ++++++++++-----------
 .../Snowflake/Resources/snowflakeconfig.json       | 21 +++++--
 .../Snowflake/SnowflakeTestConfiguration.cs        | 70 +++++++++++++++++-----
 .../Drivers/Snowflake/SnowflakeTestingUtils.cs     | 11 +++-
 4 files changed, 111 insertions(+), 59 deletions(-)

diff --git a/csharp/test/Drivers/Snowflake/ClientTests.cs 
b/csharp/test/Drivers/Snowflake/ClientTests.cs
index 77d12fb4..e8958650 100644
--- a/csharp/test/Drivers/Snowflake/ClientTests.cs
+++ b/csharp/test/Drivers/Snowflake/ClientTests.cs
@@ -39,7 +39,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
     {
         public ClientTests()
         {
-           
Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE));
+            
Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE));
         }
 
         /// <summary>
@@ -50,7 +50,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 string[] queries = 
SnowflakeTestingUtils.GetQueries(testConfiguration);
 
@@ -68,7 +68,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 adbcConnection.Open();
 
@@ -104,7 +104,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 Tests.ClientTests.CanClientGetSchema(adbcConnection, 
testConfiguration);
             }
@@ -119,7 +119,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 Tests.ClientTests.CanClientExecuteQuery(adbcConnection, 
testConfiguration);
             }
@@ -136,7 +136,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
             testConfiguration.Query = "SELECT * WHERE 0=1";
             testConfiguration.ExpectedResultsCount = 0;
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 Tests.ClientTests.CanClientExecuteQuery(adbcConnection, 
testConfiguration);
             }
@@ -151,7 +151,9 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
+            Skip.If(testConfiguration.Authentication.SnowflakeJwt is null, 
"JWT authentication is not configured");
+
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration, 
SnowflakeAuthentication.AuthJwt))
             {
                 Tests.ClientTests.CanClientExecuteQuery(adbcConnection, 
testConfiguration);
             }
@@ -166,7 +168,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 SampleDataBuilder sampleDataBuilder = 
SnowflakeData.GetSampleData();
 
@@ -179,7 +181,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         {
             SnowflakeTestConfiguration testConfiguration = 
Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);
 
-            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnection(testConfiguration))
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration))
             {
                 adbcConnection.Open();
 
@@ -218,7 +220,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
             }
         }
 
-        private Adbc.Client.AdbcConnection 
GetSnowflakeAdbcConnectionUsingConnectionString(SnowflakeTestConfiguration 
testConfiguration)
+        private Adbc.Client.AdbcConnection 
GetSnowflakeAdbcConnectionUsingConnectionString(SnowflakeTestConfiguration 
testConfiguration, string authType = null)
         {
             // see https://arrow.apache.org/adbc/0.5.1/driver/snowflake.html
 
@@ -228,22 +230,32 @@ namespace 
Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
             builder[SnowflakeParameters.HOST] = testConfiguration.Host;
             builder[SnowflakeParameters.DATABASE] = testConfiguration.Database;
             builder[SnowflakeParameters.USERNAME] = testConfiguration.User;
-            if 
(!string.IsNullOrEmpty(testConfiguration.AuthenticationTokenPath))
+            if (authType == SnowflakeAuthentication.AuthJwt)
             {
-                builder[SnowflakeParameters.AUTH_TYPE] = 
testConfiguration.AuthenticationType;
-                string privateKey = 
File.ReadAllText(testConfiguration.AuthenticationTokenPath);
-                if (testConfiguration.AuthenticationType.Equals("auth_jwt", 
StringComparison.OrdinalIgnoreCase))
+                string privateKey = 
testConfiguration.Authentication.SnowflakeJwt.PrivateKey;
+                builder[SnowflakeParameters.AUTH_TYPE] = 
SnowflakeAuthentication.AuthJwt;
+                builder[SnowflakeParameters.PKCS8_VALUE] = privateKey;
+                builder[SnowflakeParameters.USERNAME] = 
testConfiguration.Authentication.SnowflakeJwt.User;
+                if 
(!string.IsNullOrEmpty(testConfiguration.Authentication.SnowflakeJwt.PrivateKeyPassPhrase))
                 {
-                    builder[SnowflakeParameters.PKCS8_VALUE] = privateKey;
-                    if(!string.IsNullOrEmpty(testConfiguration.Pkcs8Passcode))
-                    {
-                        builder[SnowflakeParameters.PKCS8_PASS] = 
testConfiguration.Pkcs8Passcode;
-                    }
+                    builder[SnowflakeParameters.PKCS8_PASS] = 
testConfiguration.Authentication.SnowflakeJwt.PrivateKeyPassPhrase;
+                }
+            }
+            else if (authType == SnowflakeAuthentication.AuthOAuth)
+            {
+                builder[SnowflakeParameters.AUTH_TYPE] = 
SnowflakeAuthentication.AuthOAuth;
+                builder[SnowflakeParameters.AUTH_TOKEN] = 
testConfiguration.Authentication.OAuth.Token;
+                if (testConfiguration.Authentication.OAuth.User != null)
+                {
+                    builder[SnowflakeParameters.USERNAME] = 
testConfiguration.Authentication.OAuth.User;
                 }
             }
-            else
+            else if (string.IsNullOrEmpty(authType) || authType == 
SnowflakeAuthentication.AuthSnowflake)
             {
-                builder[SnowflakeParameters.PASSWORD] = 
testConfiguration.Password;
+                // if no auth type is specified, use the snowflake auth
+                builder[SnowflakeParameters.AUTH_TYPE] = 
SnowflakeAuthentication.AuthSnowflake;
+                builder[SnowflakeParameters.USERNAME] = 
testConfiguration.Authentication.Default.User;
+                builder[SnowflakeParameters.PASSWORD] = 
testConfiguration.Authentication.Default.Password;
             }
             AdbcDriver snowflakeDriver = 
SnowflakeTestingUtils.GetSnowflakeAdbcDriver(testConfiguration);
             return new Adbc.Client.AdbcConnection(builder.ConnectionString)
@@ -251,19 +263,5 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
                 AdbcDriver = snowflakeDriver
             };
         }
-        private Adbc.Client.AdbcConnection 
GetSnowflakeAdbcConnection(SnowflakeTestConfiguration testConfiguration)
-        {
-            Dictionary<string, string> parameters = new Dictionary<string, 
string>();
-
-            AdbcDriver snowflakeDriver = 
SnowflakeTestingUtils.GetSnowflakeAdbcDriver(testConfiguration, out parameters);
-
-            Adbc.Client.AdbcConnection adbcConnection = new 
Adbc.Client.AdbcConnection(
-                snowflakeDriver,
-                parameters: parameters,
-                options: new Dictionary<string, string>()
-            );
-
-            return adbcConnection;
-        }
     }
 }
diff --git a/csharp/test/Drivers/Snowflake/Resources/snowflakeconfig.json 
b/csharp/test/Drivers/Snowflake/Resources/snowflakeconfig.json
index d3b43581..dec0c492 100644
--- a/csharp/test/Drivers/Snowflake/Resources/snowflakeconfig.json
+++ b/csharp/test/Drivers/Snowflake/Resources/snowflakeconfig.json
@@ -4,19 +4,28 @@
     "account": "",
     "host": "",
     "database": "",
-    "user": "",
-    "password": "",
     "warehouse": "",
-    "authenticationType": "",
-    "authenticationTokenPath": "",
-    "pkcs8Passcode": "",
-    "useHighPrecision":  true,
+    "useHighPrecision": true,
     "metadata": {
         "catalog": "",
         "schema": "",
         "table": "",
         "expectedColumnCount": 0
     },
+    "authentication": {
+        "auth_oauth": {
+            "token": ""
+        },
+        "auth_jwt": {
+            "private_key_file": "",
+            "private_key_pwd": "",
+            "user": ""
+        },
+        "auth_snowflake": {
+            "user": "",
+            "password": ""
+        }
+    },
     "query": "",
     "expectedResults": 0
 }
diff --git a/csharp/test/Drivers/Snowflake/SnowflakeTestConfiguration.cs 
b/csharp/test/Drivers/Snowflake/SnowflakeTestConfiguration.cs
index 96bdcc22..b2f7b2ba 100644
--- a/csharp/test/Drivers/Snowflake/SnowflakeTestConfiguration.cs
+++ b/csharp/test/Drivers/Snowflake/SnowflakeTestConfiguration.cs
@@ -73,27 +73,65 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         public string Warehouse { get; set; }
 
         /// <summary>
-        /// The Snowflake authentication type.
+        /// The Snowflake use high precision
         /// </summary>
-        [JsonPropertyName("authenticationType")]
-        public string AuthenticationType { get; set; }
+        [JsonPropertyName("useHighPrecision")]
+        public bool UseHighPrecision { get; set; } = true;
 
         /// <summary>
-        /// The file location of the authentication token (if using).
+        /// The snowflake Authentication
         /// </summary>
-        [JsonPropertyName("authenticationTokenPath"), JsonIgnore(Condition = 
JsonIgnoreCondition.WhenWritingDefault)]
-        public string AuthenticationTokenPath { get; set; }
+        [JsonPropertyName("authentication")]
+        public SnowflakeAuthentication Authentication { get; set; }
 
-        /// <summary>
-        /// The passcode to use if the JWT token is encrypted.
-        /// </summary>
-        [JsonPropertyName("pkcs8Passcode"), JsonIgnore(Condition = 
JsonIgnoreCondition.WhenWritingDefault)]
-        public string Pkcs8Passcode { get; set; }
+    }
 
-        /// <summary>
-        /// The Snowflake authentication type.
-        /// </summary>
-        [JsonPropertyName("useHighPrecision")]
-        public bool UseHighPrecision { get; set; } = true;
+    public class SnowflakeAuthentication
+    {
+        public const string AuthOAuth = "auth_oauth";
+        public const string AuthJwt = "auth_jwt";
+        public const string AuthSnowflake = "auth_snowflake";
+
+        [JsonPropertyName(AuthOAuth)]
+        public OAuthAuthentication OAuth { get; set; }
+
+        [JsonPropertyName(AuthJwt)]
+        public JwtAuthentication SnowflakeJwt { get; set; }
+
+        [JsonPropertyName(AuthSnowflake)]
+        public DefaultAuthentication Default { get; set; }
+    }
+
+    public class OAuthAuthentication
+    {
+        [JsonPropertyName("token")]
+        public string Token { get; set; }
+
+        [JsonPropertyName("user")]
+        public string User { get; set; }
+    }
+
+    public class JwtAuthentication
+    {
+        [JsonPropertyName("private_key")]
+        public string PrivateKey { get; set; }
+
+        [JsonPropertyName("private_key_file")]
+        public string PrivateKeyFile { get; set; }
+
+        [JsonPropertyName("private_key_pwd")]
+        public string PrivateKeyPassPhrase{ get; set; }
+
+        [JsonPropertyName("user")]
+        public string User { get; set; }
+    }
+
+    public class DefaultAuthentication
+    {
+        [JsonPropertyName("user")]
+        public string User { get; set; }
+
+        [JsonPropertyName("password")]
+        public string Password { get; set; }
     }
 }
diff --git a/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs 
b/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs
index 18fcafb6..a6c63868 100644
--- a/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs
+++ b/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs
@@ -34,6 +34,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
         public const string PASSWORD = "password";
         public const string WAREHOUSE = "adbc.snowflake.sql.warehouse";
         public const string AUTH_TYPE = "adbc.snowflake.sql.auth_type";
+        public const string AUTH_TOKEN = 
"adbc.snowflake.sql.client_option.auth_token";
         public const string HOST = "adbc.snowflake.sql.uri.host";
         public const string PKCS8_VALUE = 
"adbc.snowflake.sql.client_option.jwt_private_key_pkcs8_value";
         public const string PKCS8_PASS = 
"adbc.snowflake.sql.client_option.jwt_private_key_pkcs8_password";
@@ -78,11 +79,17 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
                 { SnowflakeParameters.USERNAME, testConfiguration.User },
                 { SnowflakeParameters.PASSWORD, testConfiguration.Password },
                 { SnowflakeParameters.WAREHOUSE, testConfiguration.Warehouse },
-                { SnowflakeParameters.AUTH_TYPE, 
testConfiguration.AuthenticationType },
                 { SnowflakeParameters.USE_HIGH_PRECISION, 
testConfiguration.UseHighPrecision.ToString().ToLowerInvariant() }
             };
 
-            if (!string.IsNullOrWhiteSpace(testConfiguration.Host))
+            if(testConfiguration.Authentication.Default is not null)
+            {
+                parameters[SnowflakeParameters.AUTH_TYPE] = 
SnowflakeAuthentication.AuthSnowflake;
+                parameters[SnowflakeParameters.USERNAME] = 
testConfiguration.Authentication.Default.User;
+                parameters[SnowflakeParameters.PASSWORD] = 
testConfiguration.Authentication.Default.Password;
+            }
+
+            if(!string.IsNullOrWhiteSpace(testConfiguration.Host))
             {
                 parameters[SnowflakeParameters.HOST] = testConfiguration.Host;
             }

Reply via email to