eerhardt commented on code in PR #35496:
URL: https://github.com/apache/arrow/pull/35496#discussion_r1193971809


##########
csharp/test/Apache.Arrow.Tests/NullArrayTests.cs:
##########
@@ -0,0 +1,162 @@
+// 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.Linq;
+using Xunit;
+
+namespace Apache.Arrow.Tests
+{
+    public class NullArrayTests
+    {
+        public class Builder
+        {
+            public class Append
+            {
+                [Theory]
+                [InlineData(1)]
+                [InlineData(3)]
+                public void IncrementsLength(int count)
+                {
+                    var builder = new NullArray.Builder();
+
+                    for (var i = 0; i < count; i++)
+                    {
+                        builder.AppendNull();
+                    }
+
+                    var array = builder.Build();
+
+                    Assert.Equal(count, array.Length);
+                }
+            }
+
+            public class Clear
+            {
+                [Fact]
+                public void ClearsArray()
+                {
+                    var array = new NullArray.Builder()
+                        .Resize(8)
+                        .AppendNull()
+                        .AppendNull()
+                        .Clear()
+                        .Build();
+
+                    Assert.Equal(0, array.Length);
+                }
+            }
+
+            public class Swap
+            {
+                [Fact]
+                public void SwapsExpectedBits()
+                {
+                    var array = new BooleanArray.Builder()

Review Comment:
   Are these really "NullArray tests"?



##########
csharp/test/Apache.Arrow.Tests/CDataInterfacePythonTests.cs:
##########
@@ -343,5 +419,297 @@ public unsafe void ExportSchema()
             // Since we allocated, we are responsible for freeing the pointer.
             CArrowSchema.Free(cSchema);
         }
+
+        [SkippableFact]
+        public unsafe void ImportArray()
+        {
+            CArrowArray* cArray = CArrowArray.Create();
+            CArrowSchema* cSchema = CArrowSchema.Create();
+
+            using (Py.GIL())
+            {
+                dynamic pa = Py.Import("pyarrow");
+                dynamic array = pa.array(new[] { "hello", "world", null, 
"foo", "bar" });
+
+                long arrayPtr = ((IntPtr)cArray).ToInt64();
+                long schemaPtr = ((IntPtr)cSchema).ToInt64();
+                array._export_to_c(arrayPtr, schemaPtr);
+            }
+
+            ArrowType type = CArrowSchemaImporter.ImportType(cSchema);
+            IArrowArray importedArray = 
CArrowArrayImporter.ImportArray(cArray, type);
+
+            Assert.Equal(5, importedArray.Length);

Review Comment:
   Is there more asserting we can do in these tests?



##########
csharp/src/Apache.Arrow/Ipc/ArrowStreamWriter.cs:
##########
@@ -156,6 +157,10 @@ public void Visit(DictionaryArray array)
                 _buffers.Add(CreateBuffer(array.IndicesBuffer));
             }
 
+            public void Visit(NullArray array)
+            {
+            }

Review Comment:
   Can we add a comment describing why this is empty?



##########
csharp/src/Apache.Arrow/C/NativeDelegate.cs:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.Runtime.InteropServices;
+
+namespace Apache.Arrow.C
+{
+    internal struct NativeDelegate<T>

Review Comment:
   ```suggestion
       internal readonly struct NativeDelegate<T>
   ```



##########
csharp/src/Apache.Arrow/C/CArrowArray.cs:
##########
@@ -0,0 +1,84 @@
+// 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.Runtime.InteropServices;
+
+namespace Apache.Arrow.C
+{
+    /// <summary>
+    /// An Arrow C Data Interface Schema, which represents the data in an 
exported array or record batch.
+    /// </summary>
+    /// <remarks>
+    /// This is used to export <see cref="RecordBatch"/> or <see 
cref="IArrowArray"/> to other languages. It matches
+    /// the layout of the ArrowArray struct described in 
https://github.com/apache/arrow/blob/main/cpp/src/arrow/c/abi.h.
+    /// </remarks>
+    [StructLayout(LayoutKind.Sequential)]
+    public unsafe struct CArrowArray
+    {
+        public long length;
+        public long null_count;
+        public long offset;
+        public long n_buffers;
+        public long n_children;
+        public byte** buffers;
+        public CArrowArray** children;
+        public CArrowArray* dictionary;
+        public delegate* unmanaged[Stdcall]<CArrowArray*, void> release;
+        public void* private_data;
+
+        /// <summary>
+        /// Allocate and zero-initialize an unmanaged pointer of this type.
+        /// </summary>
+        /// <remarks>
+        /// This pointer must later be freed by <see cref="Free"/>.
+        /// </remarks>
+        public static CArrowArray* Create()
+        {
+            var ptr = (CArrowArray*)Marshal.AllocHGlobal(sizeof(CArrowArray));
+
+            ptr->length = 0;
+            ptr->n_buffers = 0;
+            ptr->offset = 0;
+            ptr->buffers = null;
+            ptr->n_children = 0;
+            ptr->children = null;
+            ptr->dictionary = null;
+            ptr->null_count = 0;
+            ptr->release = null;
+            ptr->private_data = null;
+
+            return ptr;
+        }
+
+        /// <summary>
+        /// Free a pointer that was allocated in <see cref="Create"/>.
+        /// </summary>
+        /// <remarks>
+        /// Do not call this on a pointer that was allocated elsewhere.
+        /// </remarks>
+        public static void Free(CArrowArray* schema)

Review Comment:
   ```suggestion
           public static void Free(CArrowArray* array)
   ```



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