eerhardt commented on a change in pull request #11931:
URL: https://github.com/apache/arrow/pull/11931#discussion_r773312342



##########
File path: csharp/src/Apache.Arrow/Column.cs
##########
@@ -62,7 +62,16 @@ 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)
+                {
+                    return false;
+                }
+
+                var dataTypeComparer = new 
ArrayDataTypeComparer(Field.DataType);

Review comment:
       This can be lifted out of the `for` loop - there is no need to create a 
new one every time through the loop.

##########
File path: csharp/src/Apache.Arrow/Arrays/ArrayDataTypeComparer.cs
##########
@@ -0,0 +1,170 @@
+// 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 Apache.Arrow.Types;
+
+namespace Apache.Arrow
+{
+    internal sealed class ArrayDataTypeComparer :
+        IArrowTypeVisitor<TimestampType>,
+        IArrowTypeVisitor<Date32Type>,
+        IArrowTypeVisitor<Date64Type>,
+        IArrowTypeVisitor<Time32Type>,
+        IArrowTypeVisitor<Time64Type>,
+        IArrowTypeVisitor<FixedSizeBinaryType>,
+        IArrowTypeVisitor<ListType>,
+        IArrowTypeVisitor<StructType>
+    {
+        private readonly IArrowType _expectedType;
+        private bool _dataTypeMatch;
+
+        public ArrayDataTypeComparer(IArrowType expectedType)
+        {
+            _expectedType = expectedType;
+        }
+
+        public bool DataTypeMatch => _dataTypeMatch;
+
+        public void Visit(TimestampType actualType)
+        {
+            var expectedType = _expectedType as TimestampType;
+
+            if (expectedType == null) return;
+
+            if (expectedType.Timezone == actualType.Timezone && 
expectedType.Unit == actualType.Unit)
+            {
+                _dataTypeMatch = true;
+            }

Review comment:
       I think this pattern is easier to read:
   
   ```suggestion
               if (_expectedType is TimestampType expectedType
                   && expectedType.Timezone == actualType.Timezone
                   && expectedType.Unit == actualType.Unit)
               {
                   _dataTypeMatch = true;
               }
   ```




-- 
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