Skip to content

Commit

Permalink
fix(csharp/src/Drivers/BigQuery): return null on GetValue exception (#…
Browse files Browse the repository at this point in the history
…1562)

In a query such as `SELECT * FROM
bigquery-public-data.fhir_synthea.explanation_of_benefit`, a number of
items return null inside of the StructArray result. An exception is
thrown from the underlying Arrow calls because we hit a scenario where
Length and index are both 0, so an `ArgumentOutOfRangeException` is
thrown per
https://github.com/apache/arrow/blob/280bc112b23976d2f17c07c638bb62702ac89e8a/csharp/src/Apache.Arrow/Arrays/BinaryArray.cs#L356.

---------

Co-authored-by: David Coe <coedavid@umich.edu>
  • Loading branch information
davidhcoe and David Coe authored Feb 22, 2024
1 parent 6c06ae2 commit fa8498f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion csharp/src/Drivers/BigQuery/BigQueryConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ internal void Open()
if (!this.properties.TryGetValue(BigQueryParameters.ProjectId, out projectId))
throw new ArgumentException($"The {BigQueryParameters.ProjectId} parameter is not present");

if (this.properties.TryGetValue(BigQueryParameters.AuthenticationType, out authenticationType))
if (this.properties.TryGetValue(BigQueryParameters.AuthenticationType, out string? newAuthenticationType))
{
if (!string.IsNullOrEmpty(newAuthenticationType))
authenticationType = newAuthenticationType;

if (!authenticationType.Equals(BigQueryConstants.UserAuthenticationType, StringComparison.OrdinalIgnoreCase) &&
!authenticationType.Equals(BigQueryConstants.ServiceAccountAuthenticationType, StringComparison.OrdinalIgnoreCase))
{
Expand Down
3 changes: 3 additions & 0 deletions csharp/src/Drivers/BigQuery/BigQueryStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ private string SerializeToJson(StructArray structArray, int index)

private Dictionary<String, object> ParseStructArray(StructArray structArray, int index)
{
if (structArray.IsNull(index))
return null;

Check warning on line 237 in csharp/src/Drivers/BigQuery/BigQueryStatement.cs

View workflow job for this annotation

GitHub Actions / C# ubuntu-latest

Possible null reference return.

Check warning on line 237 in csharp/src/Drivers/BigQuery/BigQueryStatement.cs

View workflow job for this annotation

GitHub Actions / C# ubuntu-latest

Possible null reference return.

Check warning on line 237 in csharp/src/Drivers/BigQuery/BigQueryStatement.cs

View workflow job for this annotation

GitHub Actions / C# macos-latest

Possible null reference return.

Check warning on line 237 in csharp/src/Drivers/BigQuery/BigQueryStatement.cs

View workflow job for this annotation

GitHub Actions / C# macos-latest

Possible null reference return.

Check warning on line 237 in csharp/src/Drivers/BigQuery/BigQueryStatement.cs

View workflow job for this annotation

GitHub Actions / C# windows-2019

Possible null reference return.

Check warning on line 237 in csharp/src/Drivers/BigQuery/BigQueryStatement.cs

View workflow job for this annotation

GitHub Actions / C# windows-2019

Possible null reference return.

Dictionary<String, object> jsonDictionary = new Dictionary<String, object>();
StructType structType = (StructType)structArray.Data.DataType;
for (int i = 0; i < structArray.Data.Children.Length; i++)
Expand Down

0 comments on commit fa8498f

Please sign in to comment.