Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(csharp/src/Drivers/BigQuery): Fix failure when returning multiple table schemas from BigQuery #1336

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 15 additions & 43 deletions csharp/src/Drivers/BigQuery/BigQueryConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
public class BigQueryConnection : AdbcConnection
{
readonly IReadOnlyDictionary<string, string> properties;
BigQueryClient? client;

Check warning on line 41 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# ubuntu-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 41 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# windows-2019

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 41 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# macos-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
GoogleCredential? credential;

Check warning on line 42 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# ubuntu-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# windows-2019

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# macos-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

const string infoDriverName = "ADBC BigQuery Driver";
const string infoDriverVersion = "1.0.0";
Expand Down Expand Up @@ -221,7 +221,7 @@
new Int64Array.Builder().Build(),
new Int32Array.Builder().Build(),
new ListArray.Builder(StringType.Default).Build(),
CreateNestedListArray(new List<IArrowArray?>(){ entriesDataArray }, entryType)

Check warning on line 224 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# ubuntu-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 224 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# windows-2019

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 224 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# macos-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
};

DenseUnionArray infoValue = new DenseUnionArray(infoUnionType, arrayLength, childrenArrays, typeBuilder.Build(), offsetBuilder.Build(), nullCount);
Expand Down Expand Up @@ -258,7 +258,7 @@
string columnNamePattern)
{
StringArray.Builder catalogNameBuilder = new StringArray.Builder();
List<IArrowArray?> catalogDbSchemasValues = new List<IArrowArray?>();

Check warning on line 261 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# ubuntu-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 261 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# windows-2019

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 261 in csharp/src/Drivers/BigQuery/BigQueryConnection.cs

View workflow job for this annotation

GitHub Actions / C# macos-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
string catalogRegexp = PatternToRegEx(catalogPattern);
PagedEnumerable<ProjectList, CloudProject> catalogs = this.client.ListProjects();

Expand Down Expand Up @@ -988,47 +988,44 @@
IArrowTypeVisitor<ListType>,
IArrowTypeVisitor<FixedSizeListType>,
IArrowTypeVisitor<StructType>,
IArrowTypeVisitor<UnionType>,
IArrowTypeVisitor<MapType>
{
public ArrayData Result { get; private set; }

const int Length = 0;

public void Visit(BooleanType type)
{
Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty, ArrowBuffer.Empty });
Result = new BooleanArray.Builder().Build().Data;
}

public void Visit(FixedWidthType type)
{
Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty, ArrowBuffer.Empty });
Result = new ArrayData(type, 0, 0, 0, new[] { ArrowBuffer.Empty, ArrowBuffer.Empty });
}

public void Visit(BinaryType type)
{
Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty, ArrowBuffer.Empty, ArrowBuffer.Empty });
Result = new BinaryArray.Builder().Build().Data;
}

public void Visit(StringType type)
{
Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty, ArrowBuffer.Empty, ArrowBuffer.Empty });
Result = new StringArray.Builder().Build().Data;
}

public void Visit(ListType type)
{
type.ValueDataType.Accept(this);
ArrayData child = Result;

Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty, ArrowBuffer.Empty }, new[] { child });
Result = new ArrayData(type, 0, 0, 0, new[] { ArrowBuffer.Empty, MakeInt0Buffer() }, new[] { child });
}

public void Visit(FixedSizeListType type)
{
type.ValueDataType.Accept(this);
ArrayData child = Result;

Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty }, new[] { child });
Result = new ArrayData(type, 0, 0, 0, new[] { ArrowBuffer.Empty }, new[] { child });
}

public void Visit(StructType type)
Expand All @@ -1040,50 +1037,25 @@
children[i] = Result;
}

Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty }, children);
}

public void Visit(UnionType type)
{
int bufferCount = type.Mode switch
{
UnionMode.Sparse => 1,
UnionMode.Dense => 2,
_ => throw new InvalidOperationException($"Unknown UnionMode {type.Mode}"),
};

ArrayData[] children = new ArrayData[type.Fields.Count];
for (int i = 0; i < type.Fields.Count; i++)
{
type.Fields[i].DataType.Accept(this);
children[i] = Result;
}

ArrowBuffer[] buffers = new ArrowBuffer[bufferCount];
buffers[0] = ArrowBuffer.Empty;
if (bufferCount > 1)
{
buffers[1] = ArrowBuffer.Empty;
}

Result = new ArrayData(type, Length, Length, 0, buffers, children);
Result = new ArrayData(type, 0, 0, 0, new[] { ArrowBuffer.Empty }, children);
}

public void Visit(MapType type)
{
ArrayData[] children = new ArrayData[2];
type.KeyField.DataType.Accept(this);
children[0] = Result;
type.ValueField.DataType.Accept(this);
children[1] = Result;

Result = new ArrayData(type, Length, Length, 0, new[] { ArrowBuffer.Empty }, children);
Result = new MapArray.Builder(type).Build().Data;
}

public void Visit(IArrowType type)
{
throw new NotImplementedException($"EmptyArrayCreationVisitor for {type.Name} is not supported yet.");
}

private static ArrowBuffer MakeInt0Buffer()
{
ArrowBuffer.Builder<int> builder = new ArrowBuffer.Builder<int>();
builder.Append(0);
return builder.Build();
}
}
}
}
Loading