From 163bc03664fc6c0a855364b96dd9374b097373cb Mon Sep 17 00:00:00 2001 From: Curt Hagenlocher Date: Thu, 30 Nov 2023 16:21:21 -0800 Subject: [PATCH] fix(csharp/src/Drivers/BigQuery): Fix failure when returning multiple table schemas from BigQuery (#1336) Closes #1329 --- .../Drivers/BigQuery/BigQueryConnection.cs | 58 +++++-------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs index ff3c852f56..dea7c9caaa 100644 --- a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs +++ b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs @@ -988,31 +988,28 @@ private class EmptyArrayCreationVisitor : IArrowTypeVisitor, IArrowTypeVisitor, IArrowTypeVisitor, - IArrowTypeVisitor, IArrowTypeVisitor { 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) @@ -1020,7 +1017,7 @@ 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) @@ -1028,7 +1025,7 @@ 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) @@ -1040,50 +1037,25 @@ public void Visit(StructType type) 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 builder = new ArrowBuffer.Builder(); + builder.Append(0); + return builder.Build(); + } } } }