From 0d89741771a69ed5ea4ce34a224c26dfca09f26d Mon Sep 17 00:00:00 2001 From: davidhcoe <13318837+davidhcoe@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:31:16 -0400 Subject: [PATCH] GH-37651: [C#] expose ArrowArrayConcatenator.Concatenate (#37652) ### Rationale for this change New C# drivers need the ability to concatenate arrays, particularly for metadata calls. ### What changes are included in this PR? Converts a previously internal class and method to a public class and method. ### Are these changes tested? No substantive product changes were made. All tests still pass. ### Are there any user-facing changes? It exposes previously hidden functionality. Resolves https://github.com/apache/arrow/issues/37651 * Closes: #37651 Lead-authored-by: David Coe Co-authored-by: davidhcoe <13318837+davidhcoe@users.noreply.github.com> Signed-off-by: David Li --- .../Arrays/ArrowArrayConcatenator.cs | 4 ++-- .../ArrowArrayConcatenatorTests.cs | 19 ++++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/csharp/src/Apache.Arrow/Arrays/ArrowArrayConcatenator.cs b/csharp/src/Apache.Arrow/Arrays/ArrowArrayConcatenator.cs index cc151210aec6b..ac8252211eae4 100644 --- a/csharp/src/Apache.Arrow/Arrays/ArrowArrayConcatenator.cs +++ b/csharp/src/Apache.Arrow/Arrays/ArrowArrayConcatenator.cs @@ -18,9 +18,9 @@ namespace Apache.Arrow { - static class ArrowArrayConcatenator + public static class ArrowArrayConcatenator { - internal static IArrowArray Concatenate(IReadOnlyList arrowArrayList , MemoryAllocator allocator = default) + public static IArrowArray Concatenate(IReadOnlyList arrowArrayList , MemoryAllocator allocator = default) { if(arrowArrayList == null || arrowArrayList.Count == 0) { diff --git a/csharp/test/Apache.Arrow.Tests/ArrowArrayConcatenatorTests.cs b/csharp/test/Apache.Arrow.Tests/ArrowArrayConcatenatorTests.cs index f1dcbb5d37b8f..6f4c17a959981 100644 --- a/csharp/test/Apache.Arrow.Tests/ArrowArrayConcatenatorTests.cs +++ b/csharp/test/Apache.Arrow.Tests/ArrowArrayConcatenatorTests.cs @@ -30,7 +30,7 @@ public void TestStandardCases() { foreach ((List testTargetArrayList, IArrowArray expectedArray) in GenerateTestData()) { - IArrowArray actualArray = ArrowArrayConcatenatorReflector.InvokeConcatenate(testTargetArrayList); + IArrowArray actualArray = ArrowArrayConcatenator.Concatenate(testTargetArrayList); ArrowReaderVerifier.CompareArrays(expectedArray, actualArray); } } @@ -38,15 +38,15 @@ public void TestStandardCases() [Fact] public void TestNullOrEmpty() { - Assert.Null(ArrowArrayConcatenatorReflector.InvokeConcatenate(null)); - Assert.Null(ArrowArrayConcatenatorReflector.InvokeConcatenate(new List())); + Assert.Null(ArrowArrayConcatenator.Concatenate(null)); + Assert.Null(ArrowArrayConcatenator.Concatenate(new List())); } [Fact] public void TestSingleElement() { Int32Array array = new Int32Array.Builder().Append(1).Append(2).Build(); - IArrowArray actualArray = ArrowArrayConcatenatorReflector.InvokeConcatenate(new[] { array }); + IArrowArray actualArray = ArrowArrayConcatenator.Concatenate(new[] { array }); ArrowReaderVerifier.CompareArrays(array, actualArray); } @@ -107,17 +107,6 @@ private static IEnumerable, IArrowArray>> GenerateTestDa } } - private static class ArrowArrayConcatenatorReflector - { - private static readonly MethodInfo s_concatenateInfo = typeof(ArrayData).Assembly.GetType("Apache.Arrow.ArrowArrayConcatenator") - .GetMethod("Concatenate", BindingFlags.Static | BindingFlags.NonPublic); - - internal static IArrowArray InvokeConcatenate(IReadOnlyList arrowArrayList, MemoryAllocator allocator = default) - { - return s_concatenateInfo.Invoke(null, new object[] { arrowArrayList, allocator }) as IArrowArray; - } - } - private class TestDataGenerator : IArrowTypeVisitor, IArrowTypeVisitor,