Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
b01982b
Init new Buffer builder for byte and bits
Platob Apr 24, 2023
bad3aa8
BufferBuilder : growth capacity
Platob Apr 24, 2023
d3590b8
BufferBuilder : fix Build byte size
Platob Apr 24, 2023
03f8bc7
test : compile
Platob Apr 24, 2023
c3fc3c2
BufferBuilder : Append byteindex
Platob Apr 24, 2023
265bd8a
fix AppendByte
Platob Apr 24, 2023
1f3fc2a
BufferBuilder : full raw byte control
Platob Apr 24, 2023
2052934
BufferBuilder : force bit overhead commit on Build
Platob Apr 24, 2023
01f9c09
test : Append byte and bit
Platob Apr 24, 2023
111b641
BufferBuilder : append structs
Platob Apr 24, 2023
6e958b1
code : clean
Platob Apr 24, 2023
66dd5a1
BufferBuilder : fix bit set
Platob Apr 24, 2023
4e8c2c2
Array Builder
Platob Apr 25, 2023
caca140
set ValueArrayBuilder with appenders
Platob Apr 25, 2023
c69c643
Append Value validity mask
Platob Apr 25, 2023
c445f4b
ValueArrayBuilder append null
Platob Apr 25, 2023
bc9dd95
ArrayBuilder : Add typed value builder
Platob Apr 25, 2023
861d3f3
ArrayBuilder : Append arrow array data
Platob Apr 25, 2023
3685865
ArrayBuilder : fix append remaining bits
Platob Apr 25, 2023
3fd8697
ArrayBuilder : Memory reserve
Platob Apr 26, 2023
af06e32
ValueBuffer : dynamic Length get
Platob Apr 26, 2023
6884b3b
ValueBufferBuilder : ValueLength fix add BitOverhead length
Platob Apr 26, 2023
bfccd0f
ValueBufferBuilder : real ByteLength
Platob Apr 26, 2023
46e1daa
code : clean
Platob Apr 26, 2023
c48a33d
VariableValueArrayBuilder : create
Platob Apr 26, 2023
8e94268
VariableValueArrayBuilder : set CurrentOffset on bulk append
Platob Apr 26, 2023
0a8908a
VariableValueArrayBuilder : bulk append values
Platob Apr 26, 2023
0ed0b74
BufferBuilder : pow 2 growth
Platob Apr 26, 2023
262ac91
code : clean
Platob Apr 27, 2023
76a9d86
VariableValueArrayBuilder : dyn CurrentOffset
Platob Apr 27, 2023
01bcd62
VariableValueArrayBuilder : fix AppendValues
Platob Apr 27, 2023
8f9b477
VariableValueArrayBuilder : IEnumerable to ICollection
Platob Apr 27, 2023
201f51c
ValueArrayBuilder : bulk insert validity mask
Platob Apr 29, 2023
010e7b2
fix mask validity append
Platob Apr 29, 2023
4a04d4c
ValueArrayBuilder : append nulls
Platob Apr 29, 2023
a401f39
ArrayBuilder : pass allocator in build
Platob Apr 29, 2023
273b8cb
AppendNull fix isValid
Platob Apr 29, 2023
8385137
add unit tests for lambda array builders
Platob Apr 29, 2023
8234292
add global scalar
Platob Apr 29, 2023
fb6b81e
BinaryBuilder : unit tests
Platob Apr 29, 2023
efe9e7d
code : clean
Platob Apr 29, 2023
544878e
rm useless reserve
Platob Apr 29, 2023
45267c9
code : clean
Platob Apr 29, 2023
99150c7
code : clean
Platob Apr 29, 2023
97dc2d8
code : clean
Platob Apr 30, 2023
b0eba4f
AppendBytes : stackalloc bytes to bits
Platob Apr 30, 2023
b80b11a
add StructArrayBuilder
Platob Apr 30, 2023
9888c7b
add List array builder
Platob Apr 30, 2023
63cb44e
code : clean
Platob Apr 30, 2023
5616dd6
code : clean
Platob Apr 30, 2023
5086af1
code : clean EnsureAdditionalBytes bit buffer append
Platob Apr 30, 2023
7c04e24
code rm bits stackalloc
Platob Apr 30, 2023
6fd0505
add time array builders
Platob May 1, 2023
fba7f9a
add fixed size array builder
Platob May 1, 2023
f32af8c
code : clean
Platob May 1, 2023
2490432
add DateType array builder
Platob May 1, 2023
7f9cbbf
code : clean
Platob May 1, 2023
65cee1e
code : clean
Platob May 1, 2023
0357e1a
code : clean
Platob May 1, 2023
74166b8
code : clean
Platob May 1, 2023
8026622
code : clean
Platob May 1, 2023
7add5da
pull request comment adjustments
Platob May 6, 2023
7a40d16
code : Field builder type internal accessor
Platob May 6, 2023
b2629a0
code : string type DefaultEncoding UTF8
Platob May 6, 2023
61b437e
doc : add method hints
Platob May 6, 2023
8b4031f
code : buffer builder fix AppendBits
Platob May 6, 2023
55534b5
code : buffer builder AppendBits fix
Platob May 6, 2023
d38f889
code : optim validity array builder
Platob May 6, 2023
2f6eb77
code : fix list array builder offset
Platob May 6, 2023
2199888
code : append empty bits / bytes
Platob May 6, 2023
97161e0
code : add dynamic string struct append
Platob May 6, 2023
10e5997
code : struct builder IRecord
Platob May 7, 2023
b53a179
doc : error handling AppendValues
Platob May 7, 2023
7967549
code : add dot net reflection append
Platob May 7, 2023
0e7dac9
feat : add struct scalar append
Platob May 8, 2023
62e5ecf
feat : add primitive dotnet append
Platob May 8, 2023
55dd656
feat : custom to array
Platob May 8, 2023
75e6d30
code : clean
Platob May 9, 2023
f3e6434
clean imports
Platob May 9, 2023
ff37f47
code : clean
Platob May 9, 2023
e0eb6fb
feat : add struct scalar basic
Platob May 9, 2023
919879d
feat : add primitive scalars
Platob May 10, 2023
fddc369
code : clean
Platob May 10, 2023
bfa9887
feat : add decimal scalar
Platob May 10, 2023
e85e7ca
feat : ArrayBuilder append decimal
Platob May 10, 2023
e58ebf2
test : scalar integer
Platob May 10, 2023
31fb1c6
test : more numeric tests
Platob May 10, 2023
1e47747
fix : ValueBufferBuilder decimal bit size
Platob May 10, 2023
0c903c8
fix : default ValueBufferBuilder bit width
Platob May 10, 2023
43cc9b0
feat : add list, bin, string scalar get
Platob May 10, 2023
f1708d9
code : celan
Platob May 10, 2023
d7c09d9
feat : append list scalar
Platob May 10, 2023
25168d6
code : clean
Platob May 10, 2023
47c4606
fix : append array with offset
Platob May 10, 2023
a8762c0
code : clean
Platob May 10, 2023
d8ee2fb
code : clean
Platob May 10, 2023
c382fda
code : clean
Platob May 11, 2023
b684419
fix : append array true bit byte size buffer
Platob May 11, 2023
9badc55
code : clean
Platob May 11, 2023
9f9a6c0
feat : add generic get scalar
Platob May 11, 2023
6a1b94d
feat : get string scalar
Platob May 11, 2023
f640860
code : clean
Platob May 11, 2023
aba32e1
code : clean
Platob May 11, 2023
74c7768
code : rm try catch copy to fixed byte size
Platob May 11, 2023
5168800
feat : add nullable scalar
Platob May 11, 2023
77240fd
code : append nulls clean
Platob May 12, 2023
3c06556
code : nullable scalar type
Platob May 12, 2023
e958d17
code : clean
Platob May 12, 2023
61d6ab9
test : append sliced array
Platob May 12, 2023
227ac97
feat : async build + struct to batch
Platob May 12, 2023
6e28e76
test : Build async batch
Platob May 12, 2023
f14585a
feat : struct append scalar matching
Platob May 12, 2023
1d0db25
feat : get string from scalar
Platob May 12, 2023
3ac6ac7
doc : GetString
Platob May 12, 2023
785f2fc
fix : offset, bit + tests
Platob May 12, 2023
ce58ac3
test : boolean array append
Platob May 12, 2023
c26eb4f
code : clean
Platob May 13, 2023
5fb30ab
code : TypedBufferBuilder like cpp
Platob May 13, 2023
48170ba
code : clean
Platob May 14, 2023
25edf44
code : clean
Platob May 14, 2023
1a2cefc
feat : array append repeat
Platob May 14, 2023
2551acb
code : clean
Platob May 14, 2023
ac1acc5
code : scalar raw struct instead of byte buffer
Platob May 14, 2023
c1264af
feat : append repeat bytes
Platob May 14, 2023
0b1c3ab
feat : AppendBytes check bit offset
Platob May 14, 2023
f9d03c6
code : clean
Platob May 14, 2023
fa5bdb6
feat : scalar implicit cast
Platob May 14, 2023
c4fd25e
feat : implicit binary
Platob May 14, 2023
31f35d1
feat : get scalar + doc
Platob May 14, 2023
1bb8bac
fix : GetNullableScalar
Platob May 14, 2023
a57f22c
code : AppendScalar IDotNetStruct
Platob May 14, 2023
c2f9c74
feat : rm abstract check append scalar for sub types
Platob May 14, 2023
bfb49d2
code : is null
Platob May 14, 2023
e516ee7
feat : stackalloc temp
Platob May 14, 2023
95b2ef1
feat : append repeated string optim
Platob May 14, 2023
45f67d1
feat : buffer append empty bytes
Platob May 14, 2023
d81d76b
feat : string array bulk append
Platob May 15, 2023
2b9da70
code : clean
Platob May 15, 2023
d747ec2
cdoe : clean
Platob May 15, 2023
9650dc5
code : clean
Platob May 15, 2023
4f15e31
code : local var Memory.Span
Platob May 15, 2023
35aa0ad
doc : clean
Platob May 15, 2023
0eb64cf
code : clean
Platob May 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions csharp/src/Apache.Arrow/Arrays/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using System;
using System.Runtime.CompilerServices;
using Apache.Arrow.Arrays;
using Apache.Arrow.Builder;

namespace Apache.Arrow
{
Expand All @@ -40,6 +42,16 @@ public virtual void Accept(IArrowArrayVisitor visitor)
Accept(this, visitor);
}

TArray IArrowArray.As<TArray>() => As<TArray>();
TArray As<TArray>() where TArray : IArrowArray
{
if (this is not TArray casted)
{
throw new InvalidOperationException($"Cannot cast {this} as {typeof(TArray)}");
}
return casted;
}

public bool IsValid(int index) =>
NullCount == 0 || NullBitmapBuffer.IsEmpty || BitUtility.GetBit(NullBitmapBuffer.Span, index + Offset);

Expand All @@ -60,20 +72,54 @@ internal static void Accept<T>(T array, IArrowArrayVisitor visitor)
}
}

public Array Slice(int offset, int length)
public IArrowArray 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;
offset += Offset;

ArrayData newData = Data.Slice(offset, length);
return ArrowArrayFactory.BuildArray(newData) as Array;
return ArrayBuilderFactory.MakeArray(newData);
}

/// <summary>
/// Get non nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="IScalar"/></returns>
public virtual IScalar GetScalar(int index)
{
switch (Data.DataType.TypeId)
{
case Types.ArrowTypeId.Binary:
return As<BinaryArray>().GetScalar(index);
case Types.ArrowTypeId.FixedSizedBinary:
return As<FixedSizeBinaryArray>().GetScalar(index);
case Types.ArrowTypeId.String:
return As<StringArray>().GetScalar(index);
case Types.ArrowTypeId.List:
return As<ListArray>().GetScalar(index);
case Types.ArrowTypeId.Struct:
return As<StructArray>().GetScalar(index);
default:
throw new NotSupportedException($"Cannot get scalar from array of type {Data.DataType}");
}
}

/// <summary>
/// Get nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="INullableScalar"/></returns>
public INullableScalar GetNullableScalar(int index)
=> IsValid(index) ?
new NullableScalar(Data.DataType, true, GetScalar(index)) :
new NullableScalar(Data.DataType, false, null);

public void Dispose()
{
Dispose(true);
Expand All @@ -88,4 +134,4 @@ protected virtual void Dispose(bool disposing)
}
}
}
}
}
3 changes: 1 addition & 2 deletions csharp/src/Apache.Arrow/Arrays/ArrayData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class ArrayData : IDisposable

public readonly IArrowType DataType;
public readonly int Length;
public readonly int NullCount;
public int NullCount { get; internal set; }
public readonly int Offset;
public readonly ArrowBuffer[] Buffers;
public readonly ArrayData[] Children;
Expand Down Expand Up @@ -77,7 +77,6 @@ public ArrayData(
Children = children;
Dictionary = dictionary;
}

public void Dispose()
{
if (Buffers != null)
Expand Down
19 changes: 18 additions & 1 deletion csharp/src/Apache.Arrow/Arrays/BinaryArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,25 @@ public ReadOnlySpan<byte> GetBytes(int index)
return ReadOnlySpan<byte>.Empty;
}

return ValueBuffer.Span.Slice(ValueOffsets[index], GetValueLength(index));
return GetScalar(index).AsBytes();
}

// Arrow Scalar
public override IScalar GetScalar(int index) => GetScalar(index);

/// <summary>
/// Get non nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="BinaryScalar"/></returns>
public BinaryScalar GetScalar(int index, bool valid = true)
{
bool isValid = IsValid(index);
ReadOnlySpan<int> offsets = ValueOffsets;
int start = offsets[index];
int length = isValid ? offsets[index + 1] - start : 0;

return new(ValueBuffer.Slice(start, length));
}
}
}
17 changes: 17 additions & 0 deletions csharp/src/Apache.Arrow/Arrays/FixedSizeBinaryArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Apache.Arrow.Arrays
{
public class FixedSizeBinaryArray : Array
{
public FixedSizeBinaryType DataType => Data.DataType as FixedSizeBinaryType;

public FixedSizeBinaryArray(ArrayData data)
: base(data)
{
Expand Down Expand Up @@ -70,6 +72,21 @@ public ReadOnlySpan<byte> GetBytes(int index)
return ValueBuffer.Span.Slice(index * size, size);
}

// Arrow Scalar
public override IScalar GetScalar(int index) => GetScalar(index);

/// <summary>
/// Get non nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="FixedSizeBinaryScalar"/></returns>
public FixedSizeBinaryScalar GetScalar(int index, bool valid = true)
{
FixedSizeBinaryType type = DataType;
int size = type.BitWidth * 8;
return new(type, ValueBuffer.Slice(index * size, size));
}

public abstract class BuilderBase<TArray, TBuilder> : IArrowArrayBuilder<byte[], TArray, TBuilder>
where TArray : IArrowArray
where TBuilder : class, IArrowArrayBuilder<byte[], TArray, TBuilder>
Expand Down
19 changes: 19 additions & 0 deletions csharp/src/Apache.Arrow/Arrays/ListArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

using System;
using Apache.Arrow.Builder;
using Apache.Arrow.Memory;
using Apache.Arrow.Types;

Expand Down Expand Up @@ -196,5 +197,23 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}

// Arrow Scalar
public override IScalar GetScalar(int index) => GetScalar(index);

/// <summary>
/// Get non nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="ListScalar"/></returns>
public ListScalar GetScalar(int index, bool valid = true)
{
bool isValid = IsValid(index);
ReadOnlySpan<int> offsets = ValueOffsets;
int start = offsets[index];
int length = isValid ? offsets[index + 1] - start : 0;

return new(Data.DataType as ListType, Values.Slice(start, length), isValid);
}
}
}
41 changes: 22 additions & 19 deletions csharp/src/Apache.Arrow/Arrays/StringArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Apache.Arrow.Types;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Apache.Arrow.Types;

namespace Apache.Arrow
{
public class StringArray: BinaryArray
{
public static readonly Encoding DefaultEncoding = Encoding.UTF8;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway you can mark this with deprecated and run it through a deprecation cycle? Given this is a public member it's possible that others are relying on this.

public static readonly Encoding DefaultEncoding = StringType.DefaultEncoding;

public new class Builder : BuilderBase<StringArray, Builder>
{
Expand Down Expand Up @@ -70,26 +69,30 @@ public StringArray(int length,

public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor);

/// <summary>
/// Converts the underlying byte data to a string using the specified encoding.
/// </summary>
/// <param name="encoding">The encoding used to decode the byte data.</param>
/// <returns>String representation of the decoded byte data.</returns>
public string GetString(int index, Encoding encoding = default)
{
encoding = encoding ?? DefaultEncoding;
=> IsValid(index) ? encoding is null ? GetScalar(index).DotNet : GetScalar(index).GetString(encoding) : null;

ReadOnlySpan<byte> bytes = GetBytes(index);
// Arrow Scalar
public override IScalar GetScalar(int index) => GetScalar(index);

if (bytes == default)
{
return null;
}
if (bytes.Length == 0)
{
return string.Empty;
}
/// <summary>
/// Get non nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="StringScalar"/></returns>
public new StringScalar GetScalar(int index, bool valid = true)
{
bool isValid = IsValid(index);
ReadOnlySpan<int> offsets = ValueOffsets;
int start = offsets[index];
int length = isValid ? offsets[index + 1] - start : 0;

unsafe
{
fixed (byte* data = &MemoryMarshal.GetReference(bytes))
return encoding.GetString(data, bytes.Length);
}
return new(ValueBuffer.Slice(start, length));
}
}
}
19 changes: 19 additions & 0 deletions csharp/src/Apache.Arrow/Arrays/StructArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

using Apache.Arrow.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -55,5 +56,23 @@ private IReadOnlyList<IArrowArray> InitializeFields()
}
return result;
}

// Arrow Scalar
public override IScalar GetScalar(int index) => GetScalar(index);

/// <summary>
/// Get non nullable arrow scalar from array at index
/// </summary>
/// <param name="index">value index</param>
/// <returns><see cref="StructScalar"/></returns>
public StructScalar GetScalar(int index, bool valid = true)
{
var values = new IScalar[Fields.Count];

for (int i = 0; i < values.Length; i++)
values[i] = Fields[i].GetScalar(index);

return new(Data.DataType as StructType, values, IsValid(index));
}
}
}
25 changes: 22 additions & 3 deletions csharp/src/Apache.Arrow/ArrowBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace Apache.Arrow
{
// See https://arrow.apache.org/docs/cpp/api/memory.html#_CPPv4N5arrow6BufferE

public readonly partial struct ArrowBuffer : IEquatable<ArrowBuffer>, IDisposable
{
private readonly IMemoryOwner<byte> _memoryOwner;
Expand Down Expand Up @@ -53,13 +55,13 @@ internal ArrowBuffer(IMemoryOwner<byte> memoryOwner)
public ReadOnlySpan<byte> Span
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Memory.Span;
get => AsBytes();
}

public ArrowBuffer Clone(MemoryAllocator allocator = default)
{
return new Builder<byte>(Span.Length)
.Append(Span)
return new Builder.BufferBuilder(Span.Length)
.AppendBytes(Span)
.Build(allocator);
}

Expand All @@ -72,5 +74,22 @@ public void Dispose()
{
_memoryOwner?.Dispose();
}

/// <summary>
/// Forms a slice out of the given memory, beginning at 'start', of given length
/// </summary>
/// <param name="start">The index at which to begin this slice.</param>
/// <param name="length">The desired length for the slice (exclusive).</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown when the specified <paramref name="start"/> or end index is not in range (&lt;0 or &gt;Length).
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArrowBuffer Slice(int start, int length) => new(Memory.Slice(start, length));

/// <summary>
/// Returns a byte span from the memory.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe ReadOnlySpan<byte> AsBytes() => new((byte*)Memory.Pin().Pointer, Length);
}
}
Loading