apache / apache/arrow-adbc

bug(csharp/src/Drivers/Apache): Apache drivers don't throw an error if the port is missing

Open
#3,389 0 comments 0 reactions 0 assignees View on GitHub
Type: bug
Dominant language
C#
Stars
627
Forks
217
Avg merge
17h
Merged PRs (30d)
57

Description

### What happened?

There is a bug in the Apache drivers where the `ValidateConnection` method doesn't throw an error if the port is missing or unspecified

Example port validation logic

```
// Validate port range
Properties.TryGetValue(SparkParameters.Port, out string? port);
if (int.TryParse(port, out int portNumber) && (portNumber <= IPEndPoint.MinPort || portNumber > IPEndPoint.MaxPort))
throw new ArgumentOutOfRangeException(
nameof(Properties),
port,
$"Parameter '{SparkParameters.Port}' value is not in the valid range of 1 .. {IPEndPoint.MaxPort}.");
```
The above logic ends up parsing a missing or null port value as a zero port number and doesn't throw an error

The logic should instead be modified to something like:

```
// Validate port range
Properties.TryGetValue(SparkParameters.Port, out string? port);
if (string.IsNullOrWhiteSpace(port))
{
throw new ArgumentException(
$"Required parameter '{SparkParameters.Port}' is missing. Please provide a port number for the data source.",
nameof(Properties));
}
if (int.TryParse(port, out int portNumber) && (portNumber <= IPEndPoint.MinPort || portNumber > IPEndPoint.MaxPort))
{
throw new ArgumentOutOfRangeException(
nameof(Properties),
port,
$"Parameter '{SparkParameters.Port}' value is not in the valid range of 1 .. {IPEndPoint.MaxPort}.");
}
```
This needs to be fixed for Spark, Hive, and Impala.

### Stack Trace

_No response_

### How can we reproduce the bug?

The issue can be reproduced by not specifying a port value in the config for the Apache driver.

### Environment/Setup

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.