HashidaTKS commented on a change in pull request #10990:
URL: https://github.com/apache/arrow/pull/10990#discussion_r715027097



##########
File path: csharp/test/Apache.Arrow.Tests/ArrowArrayConcatenatorTests.cs
##########
@@ -0,0 +1,383 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Apache.Arrow.Types;
+using Xunit;
+
+namespace Apache.Arrow.Tests
+{
+    public class ArrowArrayConcatenatorTests
+    {
+        [Fact]
+        public void TestStandardCases()
+        {
+            foreach ((List<IArrowArray> testTargetArrayList, IArrowArray 
expectedArray) in GenerateTestData())
+            {
+                IArrowArray actualArray = 
ArrowArrayConcatenator.Concatenate(testTargetArrayList);
+                ArrowReaderVerifier.CompareArrays(expectedArray, actualArray);
+            }
+        }
+
+        [Fact]
+        public void TestNullOrEmpty()
+        {
+            Assert.Null(ArrowArrayConcatenator.Concatenate(null));
+            Assert.Null(ArrowArrayConcatenator.Concatenate(new 
List<IArrowArray>()));
+        }
+
+        [Fact]
+        public void TestSingleElement()
+        {
+            Int32Array array = new 
Int32Array.Builder().Append(1).Append(2).Build();
+            IArrowArray actualArray = ArrowArrayConcatenator.Concatenate(new 
[] { array });
+            ArrowReaderVerifier.CompareArrays(array, actualArray);
+        }
+
+        private static IEnumerable<Tuple<List<IArrowArray>, IArrowArray>> 
GenerateTestData()
+        {
+            var targetTypes = new List<IArrowType>() {
+                    BooleanType.Default,
+                    Int8Type.Default,
+                    Int16Type.Default,
+                    Int32Type.Default,
+                    Int64Type.Default,
+                    UInt8Type.Default,
+                    UInt16Type.Default,
+                    UInt32Type.Default,
+                    UInt64Type.Default,
+                    FloatType.Default,
+                    DoubleType.Default,
+                    BinaryType.Default,
+                    StringType.Default,
+                    Date32Type.Default,
+                    Date64Type.Default,
+                    TimestampType.Default,
+                    new Decimal128Type(14, 10),
+                    new Decimal256Type(14,10),
+                    new ListType(Int64Type.Default),
+                    new StructType(new List<Field>{
+                        new 
Field.Builder().Name("Strings").DataType(StringType.Default).Nullable(true).Build(),
+                        new 
Field.Builder().Name("Ints").DataType(Int32Type.Default).Nullable(true).Build()
+                    }),
+                };
+
+            foreach (IArrowType type in targetTypes)
+            {
+                var creator = new TestDataGenerator();
+                type.Accept(creator);
+                yield return Tuple.Create(creator.TestTargetArrayList, 
creator.ExpectedArray);
+            }
+        }
+
+        private class TestDataGenerator :
+            IArrowTypeVisitor<BooleanType>,
+            IArrowTypeVisitor<Int8Type>,
+            IArrowTypeVisitor<Int16Type>,
+            IArrowTypeVisitor<Int32Type>,
+            IArrowTypeVisitor<Int64Type>,
+            IArrowTypeVisitor<UInt8Type>,
+            IArrowTypeVisitor<UInt16Type>,
+            IArrowTypeVisitor<UInt32Type>,
+            IArrowTypeVisitor<UInt64Type>,
+            IArrowTypeVisitor<FloatType>,
+            IArrowTypeVisitor<DoubleType>,
+            IArrowTypeVisitor<BinaryType>,
+            IArrowTypeVisitor<StringType>,
+            IArrowTypeVisitor<Decimal128Type>,
+            IArrowTypeVisitor<Decimal256Type>,
+            IArrowTypeVisitor<Date32Type>,
+            IArrowTypeVisitor<Date64Type>,
+            IArrowTypeVisitor<TimestampType>,
+            IArrowTypeVisitor<ListType>,
+            IArrowTypeVisitor<StructType>
+        {
+
+            private List<List<int?>> _baseData;
+
+            private int _baseDataListCount;
+
+            private int _baseDataTotalElementCount;
+
+            public List<IArrowArray> TestTargetArrayList { get; }
+            public IArrowArray ExpectedArray { get; private set; }
+
+            public TestDataGenerator()
+            {
+                _baseData = new List<List<int?>> {
+                    new List<int?> { 1, 2, 3 },
+                    new List<int?> { 100, 101, null },
+                    new List<int?> { 11, null, 12 },
+                };
+
+                _baseDataListCount = _baseData.Count;
+                _baseDataTotalElementCount = _baseData.Sum(_ => _.Count);
+                TestTargetArrayList = new 
List<IArrowArray>(_baseDataListCount);
+            }
+
+            public void Visit(BooleanType type) => GenerateTestData<bool, 
BooleanArray, BooleanArray.Builder>(type, x => x % 2 == 0);
+            public void Visit(Int8Type type) => GenerateTestData<sbyte, 
Int8Array, Int8Array.Builder>(type, x => (sbyte)x);
+            public void Visit(Int16Type type) => GenerateTestData<short, 
Int16Array, Int16Array.Builder>(type, x => (short)x);
+            public void Visit(Int32Type type) => GenerateTestData<int, 
Int32Array, Int32Array.Builder>(type, x => x);
+            public void Visit(Int64Type type) => GenerateTestData<long, 
Int64Array, Int64Array.Builder>(type, x => x);
+            public void Visit(UInt8Type type) => GenerateTestData<byte, 
UInt8Array, UInt8Array.Builder>(type, x => (byte)x);
+            public void Visit(UInt16Type type) => GenerateTestData<ushort, 
UInt16Array, UInt16Array.Builder>(type, x => (ushort)x);
+            public void Visit(UInt32Type type) => GenerateTestData<uint, 
UInt32Array, UInt32Array.Builder>(type, x => (uint)x);
+            public void Visit(UInt64Type type) => GenerateTestData<ulong, 
UInt64Array, UInt64Array.Builder>(type, x => (ulong)x);
+            public void Visit(FloatType type) => GenerateTestData<float, 
FloatArray, FloatArray.Builder>(type, x => x);
+            public void Visit(DoubleType type) => GenerateTestData<double, 
DoubleArray, DoubleArray.Builder>(type, x => x);
+            public void Visit(Date32Type type) => GenerateTestData<DateTime, 
Date32Array, Date32Array.Builder>(type, x => DateTime.MinValue.AddDays(x));
+            public void Visit(Date64Type type) => GenerateTestData<DateTime, 
Date64Array, Date64Array.Builder>(type, x => DateTime.MinValue.AddDays(x));

Review comment:
       The `TestData` class is dependent on `Length` and unable to generate 
flexible data for now.
   For example, when a type is `Int32Type`, it can not create data starts with 
a non-zero value like `[3,4,5]`.
   On the other hand, we need to create that kind of data for testing array 
concatenation.
   E.g. an expected concatenated array is `[0,1,2,3,4,5,6,7,null]` and base 
arrays are `[0,1,2]`, `[3,4,5]`, `[6.7.null]`.
   
   In order to reuse the `TestData` class, we need to modify it to be able to 
handle arbitrary data, but it might have a considerable impact.
   For the above reasons, I didn't reuse(modify) it.
   
   I think it is better to modify the `TestData` class and use it in 
`ArrowArrayConcatenatorTests` in future.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to