westonpace commented on code in PR #34133:
URL: https://github.com/apache/arrow/pull/34133#discussion_r1138629019


##########
csharp/src/Apache.Arrow/C/CArrowSchema.cs:
##########
@@ -0,0 +1,124 @@
+// 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;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    /// <summary>
+    /// An Arrow C Data Interface Schema, which represents a type, field, or 
schema.
+    /// </summary>
+    /// <remarks>
+    /// This is used to export <see cref="ArrowType"/>, <see cref="Field"/>, or
+    /// <see cref="Schema"/> to other languages. It matches the layout of the
+    /// ArrowSchema struct described in 
https://github.com/apache/arrow/blob/main/cpp/src/arrow/c/abi.h.
+    /// </remarks>
+    [StructLayout(LayoutKind.Sequential)]
+    public unsafe struct CArrowSchema
+    {
+        public byte* format;
+        public byte* name;
+        public byte* metadata;
+        public long flags;
+        public long n_children;
+        public CArrowSchema** children;
+        public CArrowSchema* dictionary;
+        public delegate* unmanaged[Stdcall]<CArrowSchema*, 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 CArrowSchema* Create()
+        {
+            var ptr = 
(CArrowSchema*)Marshal.AllocHGlobal(sizeof(CArrowSchema));
+
+            ptr->format = null;
+            ptr->name = null;
+            ptr->metadata = null;
+            ptr->flags = 0;
+            ptr->n_children = 0;
+            ptr->children = null;
+            ptr->dictionary = null;
+            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(CArrowSchema* schema)
+        {
+            if (schema->release != null)
+            {
+                // Call release if not already called.
+                schema->release(schema);
+            }
+            Marshal.FreeHGlobal((IntPtr)schema);
+        }
+
+
+        /// <summary>
+        /// Whether this field is semantically nullable (regardless of whether 
it actually has null values)
+        /// </summary>
+        public const long ArrowFlagDictionaryOrdered = 1;
+        /// <summary>
+        /// For dictionary-encoded types, whether the ordering of dictionary 
indices is semantically meaningful.
+        /// </summary>
+        public const long ArrowFlagNullable = 2;

Review Comment:
   ```suggestion
           /// <summary>
           /// For dictionary-encoded types, whether the ordering of dictionary 
indices is semantically meaningful.
           /// </summary>
           public const long ArrowFlagDictionaryOrdered = 1;
           /// <summary>
           /// Whether this field is semantically nullable (regardless of 
whether it actually has null values)
           /// </summary>
           public const long ArrowFlagNullable = 2;
   ```
   Looks like these comments got swapped



##########
csharp/src/Apache.Arrow/C/CArrowSchemaImporter.cs:
##########
@@ -0,0 +1,301 @@
+// 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.IO;
+using System.Linq;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaImporter
+    {
+        /// <summary>
+        /// Import C pointer as an <see cref="ArrowType"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,

Review Comment:
   ```suggestion
           /// Typically, you will allocate an uninitialized CArrowSchema 
pointer,
   ```



##########
csharp/src/Apache.Arrow/C/CArrowSchemaExporter.cs:
##########
@@ -0,0 +1,265 @@
+// 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.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaExporter
+    {
+        /// <summary>
+        /// Export a type to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="datatype">The datatype to export</param>
+        /// <param name="schema">An allocated but uninitialized CArrowSchema 
pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(dataType, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);

Review Comment:
   Won't this trigger a call to `exportPtr->release`?  Is that safe given that 
you've already passed ownership during the `foreign_import_function`.



##########
csharp/src/Apache.Arrow/C/CArrowSchemaExporter.cs:
##########
@@ -0,0 +1,265 @@
+// 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.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaExporter
+    {
+        /// <summary>
+        /// Export a type to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="datatype">The datatype to export</param>
+        /// <param name="schema">An allocated but uninitialized CArrowSchema 
pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(dataType, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportType(IArrowType datatype, 
CArrowSchema* schema)
+        {
+            if (schema == null)
+            {
+                throw new ArgumentNullException("Cannot export schema to a 
null pointer.");
+            }
+            if (schema->release != null)
+            {
+                throw new ArgumentException("Cannot export schema to a struct 
that is already initialized.");
+            }
+
+            schema->format = StringUtil.ToCStringUtf8(GetFormat(datatype));
+            schema->name = null;
+            schema->metadata = null;
+            schema->flags = GetFlags(datatype);
+
+            schema->children = ConstructChildren(datatype, out var 
numChildren);
+            schema->n_children = numChildren;
+
+            schema->dictionary = ConstructDictionary(datatype);
+
+            schema->release = (delegate* unmanaged[Stdcall]<CArrowSchema*, 
void>)Marshal.GetFunctionPointerForDelegate(
+                ReleaseCArrowSchema);
+
+            schema->private_data = null;
+        }
+
+        /// <summary>
+        /// Export a field to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="field">The field to export</param>
+        /// <param name="schema">An allocated but uninitialized CArrowSchema 
pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(field, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportField(Field field, CArrowSchema* 
schema)
+        {
+            ExportType(field.DataType, schema);
+            schema->name = StringUtil.ToCStringUtf8(field.Name);
+            // TODO: field metadata
+            schema->metadata = null;
+            schema->flags = GetFlags(field.DataType, field.IsNullable);
+        }
+
+        /// <summary>
+        /// Export a schema to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="schema">The schema to export</param>
+        /// <param name="out_schema">An allocated but uninitialized 
CArrowSchema pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(schema, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportSchema(Schema schema, CArrowSchema* 
out_schema)
+        {
+            var structType = new StructType(schema.FieldsList);
+            // TODO: top-level metadata
+            ExportType(structType, out_schema);
+        }
+
+        private static char FormatTimeUnit(TimeUnit unit) => unit switch
+        {
+            TimeUnit.Second => 's',
+            TimeUnit.Millisecond => 'm',
+            TimeUnit.Microsecond => 'u',
+            TimeUnit.Nanosecond => 'n',
+            _ => throw new InvalidDataException($"Unsupported time unit for 
export: {unit}"),
+        };
+
+        private static string GetFormat(IArrowType datatype)
+        {
+            switch (datatype)
+            {
+                case NullType _: return "n";
+                case BooleanType _: return "b";
+                // Integers
+                case Int8Type _: return "c";
+                case UInt8Type _: return "C";
+                case Int16Type _: return "s";
+                case UInt16Type _: return "S";
+                case Int32Type _: return "i";
+                case UInt32Type _: return "I";
+                case Int64Type _: return "l";
+                case UInt64Type _: return "L";
+                // Floats
+                case HalfFloatType _: return "e";
+                case FloatType _: return "f";
+                case DoubleType _: return "g";
+                // Decimal
+                case Decimal128Type decimalType:
+                    return $"d:{decimalType.Precision},{decimalType.Scale}";
+                case Decimal256Type decimalType:
+                    return 
$"d:{decimalType.Precision},{decimalType.Scale},256";
+                // Binary
+                case BinaryType _: return "z";
+                case StringType _: return "u";
+                case FixedSizeBinaryType binaryType:
+                    return $"w:{binaryType.ByteWidth}";
+                // Date
+                case Date32Type _: return "tdD";
+                case Date64Type _: return "tdm";
+                // Time
+                case Time32Type timeType:
+                    return String.Format("tt{0}", 
FormatTimeUnit(timeType.Unit));
+                case Time64Type timeType:
+                    // Same prefix as Time32, but allowed time units are 
different.
+                    return String.Format("tt{0}", 
FormatTimeUnit(timeType.Unit));
+                // Timestamp
+                case TimestampType timestampType:
+                    return String.Format("ts{0}:{1}", 
FormatTimeUnit(timestampType.Unit), timestampType.Timezone);
+                // Nested
+                case ListType _: return "+l";
+                case StructType _: return "+s";
+                // Dictionary
+                case DictionaryType dictionaryType:
+                    return GetFormat(dictionaryType.IndexType);
+                default: throw new NotImplementedException($"Exporting 
{datatype.Name} not implemented");
+            };
+        }
+
+        private static long GetFlags(IArrowType datatype, bool nullable = true)
+        {
+            long flags = 0;
+
+            if (nullable)
+            {
+                flags |= CArrowSchema.ArrowFlagNullable;
+            }
+
+            if (datatype is DictionaryType dictionaryType)
+            {
+                if (dictionaryType.Ordered)
+                {
+                    flags |= CArrowSchema.ArrowFlagDictionaryOrdered;
+                }
+            }
+
+            // TODO: when we implement MapType, make sure to set the 
KEYS_SORTED flag.

Review Comment:
   Could you check if the type id is a map type and throw a "not supported" 
exception?  This way, when map type is eventually added, it won't silently do 
the wrong thing if we miss this spot.



##########
csharp/src/Apache.Arrow/C/CArrowSchemaImporter.cs:
##########
@@ -0,0 +1,301 @@
+// 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.IO;
+using System.Linq;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaImporter
+    {
+        /// <summary>
+        /// Import C pointer as an <see cref="ArrowType"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,
+        /// pass that to external function, and then use this method to import
+        /// the result.
+        /// 
+        /// <code>
+        /// CArrowSchema* importedPtr = CArrowSchema.Create();
+        /// foreign_export_function(importedPtr);
+        /// ArrowType importedType = 
CArrowSchemaImporter.ImportType(importedPtr);
+        /// CArrowSchema.Free(importedPtr);
+        /// </code>
+        /// </examples>
+        public static unsafe ArrowType ImportType(CArrowSchema* ptr)
+        {
+            using var importedType = new ImportedArrowSchema(ptr);
+            return importedType.GetAsType();
+        }
+
+        /// <summary>
+        /// Import C pointer as an <see cref="Field"/>.

Review Comment:
   ```suggestion
           /// Import C pointer as a <see cref="Field"/>.
   ```



##########
csharp/src/Apache.Arrow/C/CArrowSchemaExporter.cs:
##########
@@ -0,0 +1,265 @@
+// 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.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaExporter
+    {
+        /// <summary>
+        /// Export a type to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="datatype">The datatype to export</param>
+        /// <param name="schema">An allocated but uninitialized CArrowSchema 
pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(dataType, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportType(IArrowType datatype, 
CArrowSchema* schema)
+        {
+            if (schema == null)
+            {
+                throw new ArgumentNullException("Cannot export schema to a 
null pointer.");
+            }
+            if (schema->release != null)
+            {
+                throw new ArgumentException("Cannot export schema to a struct 
that is already initialized.");
+            }
+
+            schema->format = StringUtil.ToCStringUtf8(GetFormat(datatype));
+            schema->name = null;
+            schema->metadata = null;
+            schema->flags = GetFlags(datatype);
+
+            schema->children = ConstructChildren(datatype, out var 
numChildren);
+            schema->n_children = numChildren;
+
+            schema->dictionary = ConstructDictionary(datatype);
+
+            schema->release = (delegate* unmanaged[Stdcall]<CArrowSchema*, 
void>)Marshal.GetFunctionPointerForDelegate(
+                ReleaseCArrowSchema);
+
+            schema->private_data = null;
+        }
+
+        /// <summary>
+        /// Export a field to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="field">The field to export</param>
+        /// <param name="schema">An allocated but uninitialized CArrowSchema 
pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(field, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportField(Field field, CArrowSchema* 
schema)
+        {
+            ExportType(field.DataType, schema);
+            schema->name = StringUtil.ToCStringUtf8(field.Name);
+            // TODO: field metadata
+            schema->metadata = null;
+            schema->flags = GetFlags(field.DataType, field.IsNullable);
+        }
+
+        /// <summary>
+        /// Export a schema to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="schema">The schema to export</param>
+        /// <param name="out_schema">An allocated but uninitialized 
CArrowSchema pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(schema, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportSchema(Schema schema, CArrowSchema* 
out_schema)
+        {
+            var structType = new StructType(schema.FieldsList);
+            // TODO: top-level metadata
+            ExportType(structType, out_schema);
+        }
+
+        private static char FormatTimeUnit(TimeUnit unit) => unit switch
+        {
+            TimeUnit.Second => 's',
+            TimeUnit.Millisecond => 'm',
+            TimeUnit.Microsecond => 'u',
+            TimeUnit.Nanosecond => 'n',
+            _ => throw new InvalidDataException($"Unsupported time unit for 
export: {unit}"),
+        };
+
+        private static string GetFormat(IArrowType datatype)
+        {
+            switch (datatype)
+            {
+                case NullType _: return "n";
+                case BooleanType _: return "b";
+                // Integers
+                case Int8Type _: return "c";
+                case UInt8Type _: return "C";
+                case Int16Type _: return "s";
+                case UInt16Type _: return "S";
+                case Int32Type _: return "i";
+                case UInt32Type _: return "I";
+                case Int64Type _: return "l";
+                case UInt64Type _: return "L";
+                // Floats
+                case HalfFloatType _: return "e";
+                case FloatType _: return "f";
+                case DoubleType _: return "g";
+                // Decimal
+                case Decimal128Type decimalType:
+                    return $"d:{decimalType.Precision},{decimalType.Scale}";
+                case Decimal256Type decimalType:
+                    return 
$"d:{decimalType.Precision},{decimalType.Scale},256";
+                // Binary
+                case BinaryType _: return "z";
+                case StringType _: return "u";
+                case FixedSizeBinaryType binaryType:
+                    return $"w:{binaryType.ByteWidth}";
+                // Date
+                case Date32Type _: return "tdD";
+                case Date64Type _: return "tdm";
+                // Time
+                case Time32Type timeType:
+                    return String.Format("tt{0}", 
FormatTimeUnit(timeType.Unit));
+                case Time64Type timeType:
+                    // Same prefix as Time32, but allowed time units are 
different.
+                    return String.Format("tt{0}", 
FormatTimeUnit(timeType.Unit));
+                // Timestamp
+                case TimestampType timestampType:
+                    return String.Format("ts{0}:{1}", 
FormatTimeUnit(timestampType.Unit), timestampType.Timezone);
+                // Nested
+                case ListType _: return "+l";
+                case StructType _: return "+s";
+                // Dictionary
+                case DictionaryType dictionaryType:
+                    return GetFormat(dictionaryType.IndexType);
+                default: throw new NotImplementedException($"Exporting 
{datatype.Name} not implemented");
+            };
+        }
+
+        private static long GetFlags(IArrowType datatype, bool nullable = true)
+        {
+            long flags = 0;
+
+            if (nullable)
+            {
+                flags |= CArrowSchema.ArrowFlagNullable;
+            }
+
+            if (datatype is DictionaryType dictionaryType)
+            {
+                if (dictionaryType.Ordered)
+                {
+                    flags |= CArrowSchema.ArrowFlagDictionaryOrdered;
+                }
+            }
+
+            // TODO: when we implement MapType, make sure to set the 
KEYS_SORTED flag.
+            return flags;
+        }
+
+        private static unsafe CArrowSchema** ConstructChildren(IArrowType 
datatype, out long numChildren)
+        {
+            if (datatype is NestedType nestedType)
+            {
+                IReadOnlyList<Field> fields = nestedType.Fields;
+                int numFields = fields.Count;
+                numChildren = numFields;

Review Comment:
   Is there a chance that `numChildren` could be 0?  Does `AllocHGlobal` return 
`IntPtr.Zero` in that case?
   
   Maybe more of a concern on import but I seem to recall a zero-field union 
being a useless, but technically possible, data type.



##########
csharp/src/Apache.Arrow/C/CArrowSchemaImporter.cs:
##########
@@ -0,0 +1,301 @@
+// 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.IO;
+using System.Linq;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaImporter
+    {
+        /// <summary>
+        /// Import C pointer as an <see cref="ArrowType"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,
+        /// pass that to external function, and then use this method to import
+        /// the result.
+        /// 
+        /// <code>
+        /// CArrowSchema* importedPtr = CArrowSchema.Create();
+        /// foreign_export_function(importedPtr);
+        /// ArrowType importedType = 
CArrowSchemaImporter.ImportType(importedPtr);
+        /// CArrowSchema.Free(importedPtr);
+        /// </code>
+        /// </examples>
+        public static unsafe ArrowType ImportType(CArrowSchema* ptr)
+        {
+            using var importedType = new ImportedArrowSchema(ptr);
+            return importedType.GetAsType();
+        }
+
+        /// <summary>
+        /// Import C pointer as an <see cref="Field"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,

Review Comment:
   ```suggestion
           /// Typically, you will allocate an uninitialized CArrowSchema 
pointer,
   ```



##########
csharp/src/Apache.Arrow/C/CArrowSchemaImporter.cs:
##########
@@ -0,0 +1,301 @@
+// 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.IO;
+using System.Linq;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaImporter
+    {
+        /// <summary>
+        /// Import C pointer as an <see cref="ArrowType"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,
+        /// pass that to external function, and then use this method to import
+        /// the result.
+        /// 
+        /// <code>
+        /// CArrowSchema* importedPtr = CArrowSchema.Create();
+        /// foreign_export_function(importedPtr);
+        /// ArrowType importedType = 
CArrowSchemaImporter.ImportType(importedPtr);
+        /// CArrowSchema.Free(importedPtr);
+        /// </code>
+        /// </examples>
+        public static unsafe ArrowType ImportType(CArrowSchema* ptr)
+        {
+            using var importedType = new ImportedArrowSchema(ptr);
+            return importedType.GetAsType();
+        }
+
+        /// <summary>
+        /// Import C pointer as an <see cref="Field"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,
+        /// pass that to external function, and then use this method to import
+        /// the result.
+        /// 
+        /// <code>
+        /// CArrowSchema* importedPtr = CArrowSchema.Create();
+        /// foreign_export_function(importedPtr);
+        /// Field importedField = 
CArrowSchemaImporter.ImportField(importedPtr);
+        /// CArrowSchema.Free(importedPtr);
+        /// </code>
+        /// </examples>
+        public static unsafe Field ImportField(CArrowSchema* ptr)
+        {
+            using var importedField = new ImportedArrowSchema(ptr);
+            return importedField.GetAsField();
+        }
+
+        /// <summary>
+        /// Import C pointer as an <see cref="Schema"/>.

Review Comment:
   ```suggestion
           /// Import C pointer as a <see cref="Schema"/>.
   ```



##########
csharp/src/Apache.Arrow/C/CArrowSchemaImporter.cs:
##########
@@ -0,0 +1,301 @@
+// 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.IO;
+using System.Linq;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaImporter
+    {
+        /// <summary>
+        /// Import C pointer as an <see cref="ArrowType"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,
+        /// pass that to external function, and then use this method to import
+        /// the result.
+        /// 
+        /// <code>
+        /// CArrowSchema* importedPtr = CArrowSchema.Create();
+        /// foreign_export_function(importedPtr);
+        /// ArrowType importedType = 
CArrowSchemaImporter.ImportType(importedPtr);
+        /// CArrowSchema.Free(importedPtr);
+        /// </code>
+        /// </examples>
+        public static unsafe ArrowType ImportType(CArrowSchema* ptr)
+        {
+            using var importedType = new ImportedArrowSchema(ptr);
+            return importedType.GetAsType();
+        }
+
+        /// <summary>
+        /// Import C pointer as an <see cref="Field"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,
+        /// pass that to external function, and then use this method to import
+        /// the result.
+        /// 
+        /// <code>
+        /// CArrowSchema* importedPtr = CArrowSchema.Create();
+        /// foreign_export_function(importedPtr);
+        /// Field importedField = 
CArrowSchemaImporter.ImportField(importedPtr);
+        /// CArrowSchema.Free(importedPtr);
+        /// </code>
+        /// </examples>
+        public static unsafe Field ImportField(CArrowSchema* ptr)
+        {
+            using var importedField = new ImportedArrowSchema(ptr);
+            return importedField.GetAsField();
+        }
+
+        /// <summary>
+        /// Import C pointer as an <see cref="Schema"/>.
+        /// </summary>
+        /// <remarks>
+        /// This will call the release callback on the passed struct, even if
+        /// this function fails.
+        /// </remarks>
+        /// <examples>
+        /// Typically, you will allocate a uninitialized CArrowSchema pointer,

Review Comment:
   ```suggestion
           /// Typically, you will allocate an uninitialized CArrowSchema 
pointer,
   ```



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