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 5a7ce9675 fix(csharp/src/Drivers/Apache): Improve handling of
authentication and server type enumeration parsing (#2574)
5a7ce9675 is described below
commit 5a7ce9675eec47149cf384cd55d42c7fbc646e2e
Author: Bruce Irschick <[email protected]>
AuthorDate: Mon Mar 3 15:58:22 2025 -0800
fix(csharp/src/Drivers/Apache): Improve handling of authentication and
server type enumeration parsing (#2574)
Improves idiomatic handling of authentication and server type
enumerations
Fixes #2569
---
csharp/src/Drivers/Apache/Hive2/HiveServer2AuthType.cs | 3 +--
.../Drivers/Apache/Hive2/HiveServer2HttpConnection.cs | 18 ++++++++++++------
.../Drivers/Apache/Hive2/HiveServer2TransportType.cs | 3 +--
csharp/src/Drivers/Apache/Impala/ImpalaAuthType.cs | 3 +--
.../src/Drivers/Apache/Impala/ImpalaHttpConnection.cs | 10 ++++++++--
csharp/src/Drivers/Apache/Impala/ImpalaServerType.cs | 3 +--
.../Drivers/Apache/Impala/ImpalaStandardConnection.cs | 10 ++++++++--
csharp/src/Drivers/Apache/Spark/SparkAuthType.cs | 3 +--
.../src/Drivers/Apache/Spark/SparkConnectionFactory.cs | 1 -
csharp/src/Drivers/Apache/Spark/SparkHttpConnection.cs | 10 ++++++++--
csharp/src/Drivers/Apache/Spark/SparkServerType.cs | 3 +--
.../Drivers/Apache/Spark/SparkStandardConnection.cs | 10 ++++++++--
12 files changed, 50 insertions(+), 27 deletions(-)
diff --git a/csharp/src/Drivers/Apache/Hive2/HiveServer2AuthType.cs
b/csharp/src/Drivers/Apache/Hive2/HiveServer2AuthType.cs
index 7a8f62005..fb32987cb 100644
--- a/csharp/src/Drivers/Apache/Hive2/HiveServer2AuthType.cs
+++ b/csharp/src/Drivers/Apache/Hive2/HiveServer2AuthType.cs
@@ -19,7 +19,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
{
internal enum HiveServer2AuthType
{
- Invalid = 0,
None,
UsernameOnly,
Basic,
@@ -46,7 +45,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
authTypeValue = HiveServer2AuthType.Basic;
return true;
default:
- authTypeValue = HiveServer2AuthType.Invalid;
+ authTypeValue = default;
return false;
}
}
diff --git a/csharp/src/Drivers/Apache/Hive2/HiveServer2HttpConnection.cs
b/csharp/src/Drivers/Apache/Hive2/HiveServer2HttpConnection.cs
index 441012b45..6c22ed9cc 100644
--- a/csharp/src/Drivers/Apache/Hive2/HiveServer2HttpConnection.cs
+++ b/csharp/src/Drivers/Apache/Hive2/HiveServer2HttpConnection.cs
@@ -65,7 +65,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(HiveServer2Parameters.AuthType, out string?
authType);
- bool isValidAuthType =
HiveServer2AuthTypeParser.TryParse(authType, out HiveServer2AuthType
authTypeValue);
+ if (!HiveServer2AuthTypeParser.TryParse(authType, out
HiveServer2AuthType authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(HiveServer2Parameters.AuthType, authType,
$"Unsupported {HiveServer2Parameters.AuthType} value.");
+ }
switch (authTypeValue)
{
case HiveServer2AuthType.Basic:
@@ -143,10 +146,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
}
internal override IArrowArrayStream NewReader<T>(T statement, Schema
schema) => new HiveServer2Reader(
- statement,
- schema,
- dataTypeConversion: statement.Connection.DataTypeConversion,
- enableBatchSizeStopCondition: false);
+ statement,
+ schema,
+ dataTypeConversion: statement.Connection.DataTypeConversion,
+ enableBatchSizeStopCondition: false);
protected override TTransport CreateTransport()
{
@@ -155,7 +158,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
Properties.TryGetValue(HiveServer2Parameters.Path, out string?
path);
Properties.TryGetValue(HiveServer2Parameters.Port, out string?
port);
Properties.TryGetValue(HiveServer2Parameters.AuthType, out string?
authType);
- bool isValidAuthType =
HiveServer2AuthTypeParser.TryParse(authType, out HiveServer2AuthType
authTypeValue);
+ if (!HiveServer2AuthTypeParser.TryParse(authType, out
HiveServer2AuthType authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(HiveServer2Parameters.AuthType, authType,
$"Unsupported {HiveServer2Parameters.AuthType} value.");
+ }
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(AdbcOptions.Uri, out string? uri);
diff --git a/csharp/src/Drivers/Apache/Hive2/HiveServer2TransportType.cs
b/csharp/src/Drivers/Apache/Hive2/HiveServer2TransportType.cs
index 6d95fefe3..b0c0ee83a 100644
--- a/csharp/src/Drivers/Apache/Hive2/HiveServer2TransportType.cs
+++ b/csharp/src/Drivers/Apache/Hive2/HiveServer2TransportType.cs
@@ -19,7 +19,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
{
internal enum HiveServer2TransportType
{
- Invalid = 0,
Http,
Empty = int.MaxValue,
}
@@ -40,7 +39,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
serverTypeValue = HiveServer2TransportType.Http;
return true;
default:
- serverTypeValue = HiveServer2TransportType.Invalid;
+ serverTypeValue = default;
return false;
}
}
diff --git a/csharp/src/Drivers/Apache/Impala/ImpalaAuthType.cs
b/csharp/src/Drivers/Apache/Impala/ImpalaAuthType.cs
index 656e5ad08..201942c9b 100644
--- a/csharp/src/Drivers/Apache/Impala/ImpalaAuthType.cs
+++ b/csharp/src/Drivers/Apache/Impala/ImpalaAuthType.cs
@@ -19,7 +19,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
{
internal enum ImpalaAuthType
{
- Invalid = 0,
None,
UsernameOnly,
Basic,
@@ -46,7 +45,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
authTypeValue = ImpalaAuthType.Basic;
return true;
default:
- authTypeValue = ImpalaAuthType.Invalid;
+ authTypeValue = default;
return false;
}
}
diff --git a/csharp/src/Drivers/Apache/Impala/ImpalaHttpConnection.cs
b/csharp/src/Drivers/Apache/Impala/ImpalaHttpConnection.cs
index 67a7aa3d7..f32cad011 100644
--- a/csharp/src/Drivers/Apache/Impala/ImpalaHttpConnection.cs
+++ b/csharp/src/Drivers/Apache/Impala/ImpalaHttpConnection.cs
@@ -49,7 +49,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(ImpalaParameters.AuthType, out string?
authType);
- bool isValidAuthType = ImpalaAuthTypeParser.TryParse(authType, out
ImpalaAuthType authTypeValue);
+ if (!ImpalaAuthTypeParser.TryParse(authType, out ImpalaAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(ImpalaParameters.AuthType, authType, $"Unsupported
{ImpalaParameters.AuthType} value.");
+ }
switch (authTypeValue)
{
case ImpalaAuthType.Basic:
@@ -130,7 +133,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
Properties.TryGetValue(ImpalaParameters.Path, out string? path);
Properties.TryGetValue(ImpalaParameters.Port, out string? port);
Properties.TryGetValue(ImpalaParameters.AuthType, out string?
authType);
- bool isValidAuthType = ImpalaAuthTypeParser.TryParse(authType, out
ImpalaAuthType authTypeValue);
+ if (!ImpalaAuthTypeParser.TryParse(authType, out ImpalaAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(ImpalaParameters.AuthType, authType, $"Unsupported
{ImpalaParameters.AuthType} value.");
+ }
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(AdbcOptions.Uri, out string? uri);
diff --git a/csharp/src/Drivers/Apache/Impala/ImpalaServerType.cs
b/csharp/src/Drivers/Apache/Impala/ImpalaServerType.cs
index 102bca599..294d2b39b 100644
--- a/csharp/src/Drivers/Apache/Impala/ImpalaServerType.cs
+++ b/csharp/src/Drivers/Apache/Impala/ImpalaServerType.cs
@@ -19,7 +19,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
{
internal enum ImpalaServerType
{
- Invalid = 0,
Http,
Standard,
Empty = int.MaxValue,
@@ -44,7 +43,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
serverTypeValue = ImpalaServerType.Standard;
return true;
default:
- serverTypeValue = ImpalaServerType.Invalid;
+ serverTypeValue = default;
return false;
}
}
diff --git a/csharp/src/Drivers/Apache/Impala/ImpalaStandardConnection.cs
b/csharp/src/Drivers/Apache/Impala/ImpalaStandardConnection.cs
index 01045618d..1c8cb78fd 100644
--- a/csharp/src/Drivers/Apache/Impala/ImpalaStandardConnection.cs
+++ b/csharp/src/Drivers/Apache/Impala/ImpalaStandardConnection.cs
@@ -40,7 +40,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(ImpalaParameters.AuthType, out string?
authType);
- bool isValidAuthType = ImpalaAuthTypeParser.TryParse(authType, out
ImpalaAuthType authTypeValue);
+ if (!ImpalaAuthTypeParser.TryParse(authType, out ImpalaAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(ImpalaParameters.AuthType, authType, $"Unsupported
{ImpalaParameters.AuthType} value.");
+ }
switch (authTypeValue)
{
case ImpalaAuthType.None:
@@ -120,7 +123,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Impala
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(ImpalaParameters.AuthType, out string?
authType);
- bool isValidAuthType = ImpalaAuthTypeParser.TryParse(authType, out
ImpalaAuthType authTypeValue);
+ if (!ImpalaAuthTypeParser.TryParse(authType, out ImpalaAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(ImpalaParameters.AuthType, authType, $"Unsupported
{ImpalaParameters.AuthType} value.");
+ }
TOpenSessionReq request = new
TOpenSessionReq(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7)
{
CanUseMultipleCatalogs = true,
diff --git a/csharp/src/Drivers/Apache/Spark/SparkAuthType.cs
b/csharp/src/Drivers/Apache/Spark/SparkAuthType.cs
index 83a78a788..f4f4441e2 100644
--- a/csharp/src/Drivers/Apache/Spark/SparkAuthType.cs
+++ b/csharp/src/Drivers/Apache/Spark/SparkAuthType.cs
@@ -19,7 +19,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
{
internal enum SparkAuthType
{
- Invalid = 0,
None,
UsernameOnly,
Basic,
@@ -50,7 +49,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
authTypeValue = SparkAuthType.Token;
return true;
default:
- authTypeValue = SparkAuthType.Invalid;
+ authTypeValue = default;
return false;
}
}
diff --git a/csharp/src/Drivers/Apache/Spark/SparkConnectionFactory.cs
b/csharp/src/Drivers/Apache/Spark/SparkConnectionFactory.cs
index 7440f95f7..4feaf4183 100644
--- a/csharp/src/Drivers/Apache/Spark/SparkConnectionFactory.cs
+++ b/csharp/src/Drivers/Apache/Spark/SparkConnectionFactory.cs
@@ -40,7 +40,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
// TODO: Re-enable when properly supported
//SparkServerType.Standard => new
SparkStandardConnection(properties),
_ => throw new ArgumentOutOfRangeException(nameof(properties),
$"Unsupported or unknown value '{type}' given for property
'{SparkParameters.Type}'. Supported types: {ServerTypeParser.SupportedList}"),
-
};
}
diff --git a/csharp/src/Drivers/Apache/Spark/SparkHttpConnection.cs
b/csharp/src/Drivers/Apache/Spark/SparkHttpConnection.cs
index 33701a8f9..75abb1196 100644
--- a/csharp/src/Drivers/Apache/Spark/SparkHttpConnection.cs
+++ b/csharp/src/Drivers/Apache/Spark/SparkHttpConnection.cs
@@ -51,7 +51,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(SparkParameters.AuthType, out string?
authType);
- bool isValidAuthType = SparkAuthTypeParser.TryParse(authType, out
SparkAuthType authTypeValue);
+ if (!SparkAuthTypeParser.TryParse(authType, out SparkAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(SparkParameters.AuthType, authType, $"Unsupported
{SparkParameters.AuthType} value.");
+ }
switch (authTypeValue)
{
case SparkAuthType.Token:
@@ -138,7 +141,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
Properties.TryGetValue(SparkParameters.Path, out string? path);
Properties.TryGetValue(SparkParameters.Port, out string? port);
Properties.TryGetValue(SparkParameters.AuthType, out string?
authType);
- bool isValidAuthType = SparkAuthTypeParser.TryParse(authType, out
SparkAuthType authTypeValue);
+ if (!SparkAuthTypeParser.TryParse(authType, out SparkAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(SparkParameters.AuthType, authType, $"Unsupported
{SparkParameters.AuthType} value.");
+ }
Properties.TryGetValue(SparkParameters.Token, out string? token);
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
diff --git a/csharp/src/Drivers/Apache/Spark/SparkServerType.cs
b/csharp/src/Drivers/Apache/Spark/SparkServerType.cs
index 351a2a0b9..8e3dfb28d 100644
--- a/csharp/src/Drivers/Apache/Spark/SparkServerType.cs
+++ b/csharp/src/Drivers/Apache/Spark/SparkServerType.cs
@@ -19,7 +19,6 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
{
internal enum SparkServerType
{
- Invalid = 0,
Http,
Databricks,
Standard,
@@ -48,7 +47,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
serverTypeValue = SparkServerType.Standard;
return true;
default:
- serverTypeValue = SparkServerType.Invalid;
+ serverTypeValue = default;
return false;
}
}
diff --git a/csharp/src/Drivers/Apache/Spark/SparkStandardConnection.cs
b/csharp/src/Drivers/Apache/Spark/SparkStandardConnection.cs
index b548ec448..2c28ea8e1 100644
--- a/csharp/src/Drivers/Apache/Spark/SparkStandardConnection.cs
+++ b/csharp/src/Drivers/Apache/Spark/SparkStandardConnection.cs
@@ -37,7 +37,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(SparkParameters.AuthType, out string?
authType);
- bool isValidAuthType = SparkAuthTypeParser.TryParse(authType, out
SparkAuthType authTypeValue);
+ if (!SparkAuthTypeParser.TryParse(authType, out SparkAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(SparkParameters.AuthType, authType, $"Unsupported
{SparkParameters.AuthType} value.");
+ }
switch (authTypeValue)
{
case SparkAuthType.None:
@@ -112,7 +115,10 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Spark
Properties.TryGetValue(AdbcOptions.Username, out string? username);
Properties.TryGetValue(AdbcOptions.Password, out string? password);
Properties.TryGetValue(SparkParameters.AuthType, out string?
authType);
- bool isValidAuthType = SparkAuthTypeParser.TryParse(authType, out
SparkAuthType authTypeValue);
+ if (!SparkAuthTypeParser.TryParse(authType, out SparkAuthType
authTypeValue))
+ {
+ throw new
ArgumentOutOfRangeException(SparkParameters.AuthType, authType, $"Unsupported
{SparkParameters.AuthType} value.");
+ }
TOpenSessionReq request = base.CreateSessionRequest();
switch (authTypeValue)
{