public static Func GetValueConverter()

in csharp/src/Apache.Arrow.Adbc/Extensions/IArrowArrayExtensions.cs [196:307]


        public static Func<IArrowArray, int, object?> GetValueConverter(this IArrowType arrayType, StructResultType resultType)
        {
            if (arrayType == null) throw new ArgumentNullException(nameof(arrayType));

            switch (arrayType.TypeId)
            {
                case ArrowTypeId.Null:
                    return (array, index) => null;
                case ArrowTypeId.Boolean:
                    return (array, index) => ((BooleanArray)array).GetValue(index);
                case ArrowTypeId.Date32:
                    return (array, index) => ((Date32Array)array).GetDateTime(index);
                case ArrowTypeId.Date64:
                    return (array, index) => ((Date64Array)array).GetDateTime(index);
                case ArrowTypeId.Decimal32:
                    return (array, index) => ((Decimal32Array)array).GetDecimal(index);
                case ArrowTypeId.Decimal64:
                    return (array, index) => ((Decimal64Array)array).GetDecimal(index);
                case ArrowTypeId.Decimal128:
                    return (array, index) => ((Decimal128Array)array).GetSqlDecimal(index);
                case ArrowTypeId.Decimal256:
                    return (array, index) => ((Decimal256Array)array).GetString(index);
                case ArrowTypeId.Double:
                    return (array, index) => ((DoubleArray)array).GetValue(index);
                case ArrowTypeId.Float:
                    return (array, index) => ((FloatArray)array).GetValue(index);
#if NET5_0_OR_GREATER
                case ArrowTypeId.HalfFloat:
                    return (array, index) => ((HalfFloatArray)array).GetValue(index);
#endif
                case ArrowTypeId.Int8:
                    return (array, index) => ((Int8Array)array).GetValue(index);
                case ArrowTypeId.Int16:
                    return (array, index) => ((Int16Array)array).GetValue(index);
                case ArrowTypeId.Int32:
                    return (array, index) => ((Int32Array)array).GetValue(index);
                case ArrowTypeId.Int64:
                    return (array, index) => ((Int64Array)array).GetValue(index);
                case ArrowTypeId.String:
                    return (array, index) => array.Data.DataType.TypeId == ArrowTypeId.Decimal256 ?
                        ((Decimal256Array)array).GetString(index) :
                        ((StringArray)array).GetString(index);
#if NET6_0_OR_GREATER
                case ArrowTypeId.Time32:
                    return (array, index) => ((Time32Array)array).GetTime(index);
                case ArrowTypeId.Time64:
                    return (array, index) => ((Time64Array)array).GetTime(index);
#else
                case ArrowTypeId.Time32:
                    Time32Type time32Type = (Time32Type)arrayType;
                    switch (time32Type.Unit)
                    {
                        case TimeUnit.Second:
                            return (array, index) => array.IsNull(index) ? null : TimeSpan.FromSeconds(((Time32Array)array).GetValue(index)!.Value);
                        case TimeUnit.Millisecond:
                            return (array, index) => array.IsNull(index) ? null : TimeSpan.FromMilliseconds(((Time32Array)array).GetValue(index)!.Value);
                        default:
                            throw new InvalidDataException("Unsupported time unit for Time32Type");
                    }
                case ArrowTypeId.Time64:
                    Time64Type time64Type = (Time64Type)arrayType;
                    switch (time64Type.Unit)
                    {
                        case TimeUnit.Microsecond:
                            return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetValue(index)!.Value * 10);
                        case TimeUnit.Nanosecond:
                            return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetValue(index)!.Value / 100);
                        default:
                            throw new InvalidDataException("Unsupported time unit for Time64Type");
                    }
#endif
                case ArrowTypeId.Timestamp:
                    return (array, index) => ((TimestampArray)array).GetTimestamp(index);
                case ArrowTypeId.UInt8:
                    return (array, index) => ((UInt8Array)array).GetValue(index);
                case ArrowTypeId.UInt16:
                    return (array, index) => ((UInt16Array)array).GetValue(index);
                case ArrowTypeId.UInt32:
                    return (array, index) => ((UInt32Array)array).GetValue(index);
                case ArrowTypeId.UInt64:
                    return (array, index) => ((UInt64Array)array).GetValue(index);
                case ArrowTypeId.Interval:
                    IntervalType intervalType = (IntervalType)arrayType;
                    switch (intervalType.Unit)
                    {
                        case IntervalUnit.DayTime:
                            return (array, index) => ((DayTimeIntervalArray)array).GetValue(index);
                        case IntervalUnit.MonthDayNanosecond:
                            return (array, index) => ((MonthDayNanosecondIntervalArray)array).GetValue(index);
                        case IntervalUnit.YearMonth:
                            return (array, index) => ((YearMonthIntervalArray)array).GetValue(index);
                        default:
                            throw new NotSupportedException($"Unsupported interval unit: {intervalType.Unit}");
                    }
                case ArrowTypeId.Binary:
                    return (array, index) => array.IsNull(index) ? null : ((BinaryArray)array).GetBytes(index).ToArray();
                case ArrowTypeId.List:
                    return (array, index) => ((ListArray)array).GetSlicedValues(index);
                case ArrowTypeId.Struct:
                    return resultType == StructResultType.JsonString ?
                        (array, index) => SerializeToJson((StructArray)array, index) :
                        (array, index) => ParseStructArray((StructArray)array, index);

                    // not covered:
                    // -- map array
                    // -- dictionary array
                    // -- fixed size binary
                    // -- union array
            }

            throw new NotSupportedException($"Unsupported ArrowTypeId: {arrayType.TypeId}");
        }