public static object? ValueAt()

in csharp/src/Apache.Arrow.Adbc/Extensions/IArrowArrayExtensions.cs [62:171]


        public static object? ValueAt(this IArrowArray arrowArray, int index, StructResultType resultType = StructResultType.JsonString)
        {
            if (arrowArray == null) throw new ArgumentNullException(nameof(arrowArray));
            if (index < 0) throw new ArgumentOutOfRangeException(nameof(index));

            if (arrowArray.IsNull(index))
                return null;

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

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

            return null;
        }