HashidaTKS commented on a change in pull request #11931: URL: https://github.com/apache/arrow/pull/11931#discussion_r770772397
########## File path: csharp/src/Apache.Arrow/Arrays/ArrayDataTypeComparer.cs ########## @@ -0,0 +1,76 @@ +// 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 Apache.Arrow.Types; + +namespace Apache.Arrow +{ + static class ArrayDataTypeComparer + { + internal static bool Compare(IArrowType expectedType, IArrowType actualType) + { + if (expectedType.TypeId != actualType.TypeId) + { + return false; + } + + if (actualType.TypeId == ArrowTypeId.FixedSizedBinary) + { + var expectedFixedSizeBinaryType = (FixedSizeBinaryType)expectedType; + var actualFixedSizeBinaryType = (FixedSizeBinaryType)actualType; + + if (expectedFixedSizeBinaryType.ByteWidth != actualFixedSizeBinaryType.ByteWidth) + { + return false; + } + + return true; + } + + if (actualType.TypeId == ArrowTypeId.List) + { + var expectedListType = (ListType)expectedType; + var actualListType = (ListType)actualType; + + CompareNested(expectedListType, actualListType); + } + + if (actualType.TypeId == ArrowTypeId.Struct) + { + var expectedStructType = (StructType)expectedType; + var actualStructType = (StructType)actualType; + + CompareNested(expectedStructType, actualStructType); + } + + return true; + } + + private static bool CompareNested(NestedType expectedType, NestedType actualType) + { + if (expectedType.Fields.Count != actualType.Fields.Count) + { + return false; + } + + for (int i = 0; i < expectedType.Fields.Count; i++) + { + Compare(expectedType.Fields[i].DataType, actualType.Fields[i].DataType); Review comment: Don't we need to compare not only `Filed.DataType` but also other `Field` members? (Maybe a new `FieldComparer` for the product projects is needed.) ########## File path: csharp/src/Apache.Arrow/Column.cs ########## @@ -62,7 +62,7 @@ private bool ValidateArrayDataTypes() { for (int i = 0; i < Data.ArrayCount; i++) { - if (Data.Array(i).Data.DataType != Field.DataType) + if (Data.Array(i).Data.DataType.TypeId != Field.DataType.TypeId) Review comment: Ah, my comment was not good. * `ArrayDataTypeComparer` need to support `TimestampType`, `Date32Type`, `Date64Type`, `Time32Type`, `Time64Type`, `FixedSizeBinaryType`. `ListType` and `StructType` like `Apache.Arrow.Tests.ArrayTypeComparer.cs`. * How about using Visitor Pattern for `ArrayDataTypeComparer`? * https://github.com/apache/arrow/blob/master/csharp/README.md#implementation * > Uses Acyclic Visitor Pattern for array types and arrays to facilitate serialization, record batch traversal, and format growth. ########## File path: csharp/test/Apache.Arrow.Tests/ArrowFileReaderTests.cs ########## @@ -155,5 +157,19 @@ public async Task TestReadMultipleRecordBatchAsync() ArrowReaderVerifier.CompareBatches(originalBatch1, readBatch3); } } + + [Fact] + public void TestRecordBatchBasics() + { + RecordBatch recordBatch = TestData.CreateSampleRecordBatch(length: 1); + Assert.Throws<ArgumentOutOfRangeException>(() => new RecordBatch(recordBatch.Schema, recordBatch.Arrays, -1)); + + var col1 = recordBatch.Column(0); + var col2 = recordBatch.Column("list0"); + ArrowReaderVerifier.CompareArrays(col1, col2); + + recordBatch.Dispose(); Review comment: The `using` statement ensures that `Dispose()` is called, but for increasing the coverage, I think either is fine. -- 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]
