Пример #1
0
 public TBuilder AppendNull()
 {
     ValueOffsets.Append(Offset);
     ValidityBuffer.Append(false);
     NullCount++;
     return(Instance);
 }
Пример #2
0
 public TBuilder Resize(int length)
 {
     ValueOffsets.Resize(length + 1);
     ValueBuffer.Resize(length);
     ValidityBuffer.Resize(length + 1);
     return(Instance);
 }
Пример #3
0
 public TBuilder Append(byte value)
 {
     ValueOffsets.Append(Offset);
     ValueBuffer.Append(value);
     Offset++;
     return(Instance);
 }
Пример #4
0
 public TBuilder Append(ReadOnlySpan <byte> span)
 {
     ValueOffsets.Append(Offset);
     ValueBuffer.Append(span);
     Offset += span.Length;
     return(Instance);
 }
Пример #5
0
 public TBuilder Clear()
 {
     ValueOffsets.Clear();
     ValueBuffer.Clear();
     ValidityBuffer.Clear();
     return(Instance);
 }
Пример #6
0
 public TBuilder Reserve(int capacity)
 {
     ValueOffsets.Reserve(capacity + 1);
     ValueBuffer.Reserve(capacity);
     ValidityBuffer.Reserve(capacity + 1);
     return(Instance);
 }
Пример #7
0
            private void AppendStringToBuffer(string s)
            {
                var span = Encoding.GetBytes(s);

                ValueOffsets.Append(Offset);
                ValueBuffer.Append(span);
                Offset += span.Length;
            }
Пример #8
0
 public TBuilder Resize(int length)
 {
     // TODO: [ARROW-9366] Resize the value buffer to a safe length based on offsets, not `length`.
     ValueOffsets.Resize(length + 1);
     ValueBuffer.Resize(length);
     ValidityBuffer.Resize(length + 1);
     return(Instance);
 }
Пример #9
0
 public TBuilder Reserve(int capacity)
 {
     // TODO: [ARROW-9366] Reserve capacity in the value buffer in a more sensible way.
     ValueOffsets.Reserve(capacity + 1);
     ValueBuffer.Reserve(capacity);
     ValidityBuffer.Reserve(capacity + 1);
     return(Instance);
 }
Пример #10
0
 /// <summary>
 /// Append a single null value to the array.
 /// </summary>
 /// <returns>Returns the builder (for fluent-style composition).</returns>
 public TBuilder AppendNull()
 {
     // Do not add to the value buffer in the case of a null.
     // Note that we do not need to increment the offset as a result.
     ValidityBuffer.Append(false);
     ValueOffsets.Append(Offset);
     return(Instance);
 }
Пример #11
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));
            }
Пример #12
0
            public TBuilder AppendRange(IEnumerable <byte> values)
            {
                var len = ValueBuffer.Length;

                ValueOffsets.Append(Offset);
                ValueBuffer.AppendRange(values);
                Offset += ValueBuffer.Length - len;
                return(Instance);
            }
Пример #13
0
            /// <summary>
            /// Clear all contents appended so far.
            /// </summary>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public TBuilder Clear()
            {
                ValueOffsets.Clear();
                ValueBuffer.Clear();
                ValidityBuffer.Clear();

                // Always write the first offset before anything has been written.
                Offset = 0;
                ValueOffsets.Append(Offset);
                return(Instance);
            }
Пример #14
0
            public TBuilder AppendRange(IEnumerable <byte[]> values)
            {
                foreach (var arr in values)
                {
                    var len = ValueBuffer.Length;
                    ValueOffsets.Append(Offset);
                    ValueBuffer.Append(arr);
                    Offset += ValueBuffer.Length - len;
                }

                return(Instance);
            }
Пример #15
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));
            }
Пример #16
0
            public TBuilder AppendRange(IEnumerable <byte> values)
            {
                if (values == null)
                {
                    return(AppendNull());
                }
                int len = ValueBuffer.Length;

                ValueBuffer.AppendRange(values);
                int valOffset = ValueBuffer.Length - len;

                ValueOffsets.Append(Offset);
                Offset += valOffset;
                ValidityBuffer.Append(true);
                return(Instance);
            }
Пример #17
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));
            }
Пример #18
0
            public TBuilder AppendRange(IEnumerable <byte[]> values)
            {
                foreach (byte[] arr in values)
                {
                    if (arr == null)
                    {
                        AppendNull();
                        continue;
                    }
                    int len = ValueBuffer.Length;
                    ValueOffsets.Append(Offset);
                    ValueBuffer.Append(arr);
                    ValidityBuffer.Append(true);
                    Offset += ValueBuffer.Length - len;
                }

                return(Instance);
            }
Пример #19
0
            /// <summary>
            /// Append a value, consisting of an enumerable collection of bytes, to the array.
            /// </summary>
            /// <remarks>
            /// Note that this method appends a single value, which may consist of arbitrarily many bytes.  If multiple
            /// values are to be added, use the <see cref="AppendRange(IEnumerable{byte})"/> method instead.
            /// </remarks>
            /// <param name="value">Enumerable collection of bytes to add.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public TBuilder Append(IEnumerable <byte> value)
            {
                if (value == null)
                {
                    return(AppendNull());
                }

                // Note: by looking at the length of the value buffer before and after, we avoid having to iterate
                // through the enumerable multiple times to get both length and contents.
                int priorLength = ValueBuffer.Length;

                ValueBuffer.AppendRange(value);
                int valueLength = ValueBuffer.Length - priorLength;

                Offset += valueLength;
                ValidityBuffer.Append(true);
                ValueOffsets.Append(Offset);
                return(Instance);
            }
Пример #20
0
 public StringDictionaryArray Build(MemoryAllocator allocator)
 {
     ValueOffsets.Append(Offset);
     return(new StringDictionaryArray(IndicesBuffer.Length, Entries.Count, NullBitmap.Build(allocator), IndicesBuffer.Build(allocator),
                                      ValueBuffer.Build(allocator), ValueOffsets.Build(allocator), NullCount));
 }