public void Visit(ListType type)
            {
                CheckData(type, 2);
                ArrowBuffer validityBuffer = ConcatenateValidityBuffer();
                ArrowBuffer offsetBuffer   = ConcatenateOffsetBuffer();
                ArrayData   child          = Concatenate(SelectChildren(0), _allocator);

                Result = new ArrayData(type, _totalLength, _totalNullCount, 0, new ArrowBuffer[] { validityBuffer, offsetBuffer }, new[] { child });
            }
            private void ConcatenateVariableBinaryArrayData(IArrowType type)
            {
                CheckData(type, 3);
                ArrowBuffer validityBuffer = ConcatenateValidityBuffer();
                ArrowBuffer offsetBuffer   = ConcatenateOffsetBuffer();
                ArrowBuffer valueBuffer    = ConcatenateVariableBinaryValueBuffer();

                Result = new ArrayData(type, _totalLength, _totalNullCount, 0, new ArrowBuffer[] { validityBuffer, offsetBuffer, valueBuffer });
            }
Exemple #3
0
            public TArray Build(MemoryAllocator allocator = default)
            {
                ValueOffsets.Append(Offset);

                var data = new ArrayData(DataType, ValueOffsets.Length - 1, 0, 0,
                                         new[] { ArrowBuffer.Empty, ValueOffsets.Build(allocator), ValueBuffer.Build(allocator) });

                return(Build(data));
            }
 public static void EnsureBufferCount(this ArrayData data, int count)
 {
     if (data.Buffers.Length != count)
     {
         // TODO: Use localizable string resource
         throw new ArgumentException(
                   $"Buffer count <{data.Buffers.Length}> must be at least <{count}>",
                   nameof(data.Buffers.Length));
     }
 }
 public static void EnsureDataType(this ArrayData data, ArrowTypeId id)
 {
     if (data.DataType.TypeId != id)
     {
         // TODO: Use localizable string resource
         throw new ArgumentException(
                   $"Specified array type <{data.DataType.TypeId}> does not match expected type(s) <{id}>",
                   nameof(data.DataType.TypeId));
     }
 }
            public void Visit(StructType type)
            {
                CheckData(type, 1);
                List <ArrayData> children = new List <ArrayData>(type.Fields.Count);

                for (int i = 0; i < type.Fields.Count; i++)
                {
                    children.Add(Concatenate(SelectChildren(i), _allocator));
                }

                Result = new ArrayData(type, _arrayDataList[0].Length, _arrayDataList[0].NullCount, 0, _arrayDataList[0].Buffers, children);
            }
Exemple #7
0
 public ArrayData(
     IArrowType dataType,
     int length, int nullCount = 0, int offset              = 0,
     ArrowBuffer[] buffers     = null, ArrayData[] children = null, ArrayData dictionary = null)
 {
     DataType   = dataType ?? NullType.Default;
     Length     = length;
     NullCount  = nullCount;
     Offset     = offset;
     Buffers    = buffers;
     Children   = children;
     Dictionary = dictionary;
 }
Exemple #8
0
 public ArrayData(
     IArrowType dataType,
     int length, int nullCount         = 0, int offset = 0,
     IEnumerable <ArrowBuffer> buffers = null, IEnumerable <ArrayData> children = null, ArrayData dictionary = null)
 {
     DataType   = dataType ?? NullType.Default;
     Length     = length;
     NullCount  = nullCount;
     Offset     = offset;
     Buffers    = buffers?.ToArray();
     Children   = children?.ToArray();
     Dictionary = dictionary;
 }
Exemple #9
0
            public TArray Build(MemoryAllocator allocator = default)
            {
                ValueOffsets.Append(Offset);

                ArrowBuffer validityBuffer = NullCount > 0
                                        ? ValidityBuffer.Build(allocator).ValueBuffer
                                        : ArrowBuffer.Empty;

                var data = new ArrayData(DataType, ValueOffsets.Length - 1, NullCount, 0,
                                         new[] { validityBuffer, ValueOffsets.Build(allocator), ValueBuffer.Build(allocator) });

                return(Build(data));
            }
Exemple #10
0
        public Array Slice(int offset, int length)
        {
            if (offset > Length)
            {
                throw new ArgumentException($"Offset {offset} cannot be greater than Length {Length} for Array.Slice");
            }

            length  = Math.Min(Data.Length - offset, length);
            offset += Data.Offset;

            ArrayData newData = Data.Slice(offset, length);

            return(ArrowArrayFactory.BuildArray(newData) as Array);
        }
Exemple #11
0
            /// <summary>
            /// Build an Arrow array from the appended contents so far.
            /// </summary>
            /// <param name="allocator">Optional memory allocator.</param>
            /// <returns>Returns an array of type <typeparamref name="TArray"/>.</returns>
            public TArray Build(MemoryAllocator allocator = default)
            {
                var bufs = new[]
                {
                    NullCount > 0 ? ValidityBuffer.Build(allocator) : ArrowBuffer.Empty,
                    ValueOffsets.Build(allocator),
                    ValueBuffer.Build(allocator),
                };
                var data = new ArrayData(
                    DataType,
                    length: Length,
                    NullCount,
                    offset: 0,
                    bufs);

                return(Build(data));
            }
Exemple #12
0
        public DictionaryArray(ArrayData data) : base(data)
        {
            data.EnsureBufferCount(2);
            data.EnsureDataType(ArrowTypeId.Dictionary);

            if (data.Dictionary == null)
            {
                throw new ArgumentException($"{nameof(data.Dictionary)} must not be null");
            }

            var dicType = (DictionaryType)data.DataType;

            data.Dictionary.EnsureDataType(dicType.ValueType.TypeId);

            var indicesData = new ArrayData(dicType.IndexType, data.Length, data.NullCount, data.Offset, data.Buffers, data.Children);

            Indices    = ArrowArrayFactory.BuildArray(indicesData);
            Dictionary = ArrowArrayFactory.BuildArray(data.Dictionary);
        }
Exemple #13
0
        public static void EnsureDataType(this ArrayData data, params ArrowTypeId[] ids)
        {
            var valid = true;

            foreach (var id in ids)
            {
                if (data.DataType.TypeId != id)
                {
                    valid = false;
                }
            }

            if (!valid)
            {
                // TODO: Use localizable string resource
                throw new ArgumentException(
                          $"Specified array type <{data.DataType.TypeId}> does not match expected type(s) <{string.Join(",", ids)}>",
                          nameof(data.DataType.TypeId));
            }
        }
 public DoubleArray(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Double);
 }
Exemple #15
0
 protected abstract TArray Build(ArrayData data);
Exemple #16
0
 public BinaryArray(ArrowTypeId typeId, ArrayData data)
     : base(data)
 {
     data.EnsureDataType(typeId);
     data.EnsureBufferCount(3);
 }
Exemple #17
0
 protected override BinaryArray Build(ArrayData data)
 {
     return(new BinaryArray(data));
 }
 public UInt16Array(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.UInt16);
 }
Exemple #19
0
 public Int8Array(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Int8);
 }
Exemple #20
0
 public FloatArray(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Float);
 }
Exemple #21
0
 public StringArray(ArrayData data)
     : base(ArrowTypeId.String, data)
 {
 }
Exemple #22
0
 private ListArray(ArrayData data, IArrowArray values) : base(data)
 {
     data.EnsureBufferCount(2);
     data.EnsureDataType(ArrowTypeId.List);
     Values = values;
 }
Exemple #23
0
 public TimestampArray(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Timestamp);
 }
Exemple #24
0
 public Time32Array(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Time32);
 }
Exemple #25
0
        public static IArrowArray BuildArray(ArrayData data)
        {
            switch (data.DataType.TypeId)
            {
            case ArrowTypeId.Boolean:
                return(new BooleanArray(data));

            case ArrowTypeId.UInt8:
                return(new UInt8Array(data));

            case ArrowTypeId.Int8:
                return(new Int8Array(data));

            case ArrowTypeId.UInt16:
                return(new UInt16Array(data));

            case ArrowTypeId.Int16:
                return(new Int16Array(data));

            case ArrowTypeId.UInt32:
                return(new UInt32Array(data));

            case ArrowTypeId.Int32:
                return(new Int32Array(data));

            case ArrowTypeId.UInt64:
                return(new UInt64Array(data));

            case ArrowTypeId.Int64:
                return(new Int64Array(data));

            case ArrowTypeId.Float:
                return(new FloatArray(data));

            case ArrowTypeId.Double:
                return(new DoubleArray(data));

            case ArrowTypeId.String:
                return(new StringArray(data));

            case ArrowTypeId.FixedSizedBinary:
                return(new FixedSizeBinaryArray(data));

            case ArrowTypeId.Binary:
                return(new BinaryArray(data));

            case ArrowTypeId.Timestamp:
                return(new TimestampArray(data));

            case ArrowTypeId.List:
                return(new ListArray(data));

            case ArrowTypeId.Struct:
                return(new StructArray(data));

            case ArrowTypeId.Union:
                return(new UnionArray(data));

            case ArrowTypeId.Date64:
                return(new Date64Array(data));

            case ArrowTypeId.Date32:
                return(new Date32Array(data));

            case ArrowTypeId.Time32:
                return(new Time32Array(data));

            case ArrowTypeId.Time64:
                return(new Time64Array(data));

            case ArrowTypeId.Decimal128:
                return(new Decimal128Array(data));

            case ArrowTypeId.Decimal256:
                return(new Decimal256Array(data));

            case ArrowTypeId.Dictionary:
                return(new DictionaryArray(data));

            case ArrowTypeId.HalfFloat:
            case ArrowTypeId.Interval:
            case ArrowTypeId.Map:
            default:
                throw new NotSupportedException($"An ArrowArray cannot be built for type {data.DataType.TypeId}.");
            }
        }
Exemple #26
0
 public Date64Array(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Date64);
 }
Exemple #27
0
 protected Array(ArrayData data)
 {
     Data = data ?? throw new ArgumentNullException(nameof(data));
 }
Exemple #28
0
 protected PrimitiveArray(ArrayData data)
     : base(data)
 {
     data.EnsureBufferCount(2);
 }
Exemple #29
0
 public BooleanArray(ArrayData data)
     : base(data)
 {
     data.EnsureDataType(ArrowTypeId.Boolean);
 }
Exemple #30
0
 public ListArray(ArrayData data)
     : this(data, ArrowArrayFactory.BuildArray(data.Children[0]))
 {
 }