You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "adamreeve (via GitHub)" <gi...@apache.org> on 2024/07/16 04:52:12 UTC

[PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

adamreeve opened a new pull request, #43269:
URL: https://github.com/apache/arrow/pull/43269

   ### Rationale for this change
   
   See #43266
   
   ### What changes are included in this PR?
   
   * Add new Array subtypes: LargeBinaryArray, LargeStringArray and LargeListArray
   * Support round-tripping these array types via the IPC format
   * Support round-tripping these array types via the C Data Interface
   * Improve error messages when importing arrays that are too large via IPC or C Data Interface
   * Enable integration tests for the new types 
   * Update documentation
   
   ### Are these changes tested?
   
   Yes, I've added some basic tests specifically for the new array types, and added these to the test data generator so they're covered by the existing tests for round tripping using IPC and C Data Interface.
   
   ### Are there any user-facing changes?
   
   Yes, this is a new user facing feature.
   
   ### Implementation notes
   
   * I haven't added builders for these new array types. Given they're added to help with interoperability with other libraries, I wouldn't expect .NET users to build arrays of these types as they provide no other benefit over the non-large types until we have proper large memory support. But I'm happy to add this if it would be useful.
   * The new array types share a lot of logic with the non-large types. I considered trying to consolidate this logic by adding a new `BinaryArrayBase<TOffset>` class for example, but I think this would require generic math support to work nicely, and would still complicate the code quite a bit and add extra virtual method call overhead. So I think it's fine to keep these new Array subtypes independent from the non-large types.
   * I haven't included support for materializing a LargeStringArray (see #41048). I'm not sure whether there would be a use for this, but it could be added later if needed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #43269:
URL: https://github.com/apache/arrow/pull/43269#discussion_r1682050604


##########
csharp/src/Apache.Arrow/Arrays/LargeBinaryArray.cs:
##########
@@ -0,0 +1,156 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using Apache.Arrow.Types;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace Apache.Arrow;
+
+public class LargeBinaryArray : Array, IReadOnlyList<byte[]>, ICollection<byte[]>
+{
+    public LargeBinaryArray(ArrayData data)
+        : base(data)
+    {
+        data.EnsureDataType(ArrowTypeId.LargeBinary);
+        data.EnsureBufferCount(3);
+    }
+
+    public LargeBinaryArray(ArrowTypeId typeId, ArrayData data)
+        : base(data)
+    {
+        data.EnsureDataType(typeId);
+        data.EnsureBufferCount(3);
+    }
+
+    public LargeBinaryArray(IArrowType dataType, int length,
+        ArrowBuffer valueOffsetsBuffer,
+        ArrowBuffer dataBuffer,
+        ArrowBuffer nullBitmapBuffer,
+        int nullCount = 0, int offset = 0)
+    : this(new ArrayData(dataType, length, nullCount, offset,
+        new[] { nullBitmapBuffer, valueOffsetsBuffer, dataBuffer }))
+    { }
+
+    public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor);
+
+    public ArrowBuffer ValueOffsetsBuffer => Data.Buffers[1];
+
+    public ArrowBuffer ValueBuffer => Data.Buffers[2];
+
+    public ReadOnlySpan<long> ValueOffsets => ValueOffsetsBuffer.Span.CastTo<long>().Slice(Offset, Length + 1);
+
+    public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();

Review Comment:
   I have to admit that I like the consistency of having the same members on both classes, but I also wonder at the value (ha ha) of exposing this at all. Someone who needs to get at the underlying buffer can already access ValueBuffer, and this span doesn't have any clear uses.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on code in PR #43269:
URL: https://github.com/apache/arrow/pull/43269#discussion_r1678770560


##########
csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:
##########
@@ -132,7 +132,13 @@ protected ReadResult ReadMessage()
 
                 Flatbuf.Message message = Flatbuf.Message.GetRootAsMessage(CreateByteBuffer(messageBuff));
 
-                int bodyLength = checked((int)message.BodyLength);
+                if (message.BodyLength > int.MaxValue)

Review Comment:
   I don't think there's a need for more specific checks when importing individual arrays as this should cover all scenarios.
   
   I also tested reading data from Flight but that actually fails on the C++ server side with an error that > 2 GB record batches are not supported (see [FlightPayload::Validate](https://github.com/apache/arrow/blob/21238a7f5ebb224410d84ecf32dbe3556cab363a/cpp/src/arrow/flight/types.cc#L207)).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on code in PR #43269:
URL: https://github.com/apache/arrow/pull/43269#discussion_r1682071209


##########
csharp/src/Apache.Arrow/Arrays/LargeBinaryArray.cs:
##########
@@ -0,0 +1,156 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using Apache.Arrow.Types;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace Apache.Arrow;
+
+public class LargeBinaryArray : Array, IReadOnlyList<byte[]>, ICollection<byte[]>
+{
+    public LargeBinaryArray(ArrayData data)
+        : base(data)
+    {
+        data.EnsureDataType(ArrowTypeId.LargeBinary);
+        data.EnsureBufferCount(3);
+    }
+
+    public LargeBinaryArray(ArrowTypeId typeId, ArrayData data)
+        : base(data)
+    {
+        data.EnsureDataType(typeId);
+        data.EnsureBufferCount(3);
+    }
+
+    public LargeBinaryArray(IArrowType dataType, int length,
+        ArrowBuffer valueOffsetsBuffer,
+        ArrowBuffer dataBuffer,
+        ArrowBuffer nullBitmapBuffer,
+        int nullCount = 0, int offset = 0)
+    : this(new ArrayData(dataType, length, nullCount, offset,
+        new[] { nullBitmapBuffer, valueOffsetsBuffer, dataBuffer }))
+    { }
+
+    public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor);
+
+    public ArrowBuffer ValueOffsetsBuffer => Data.Buffers[1];
+
+    public ArrowBuffer ValueBuffer => Data.Buffers[2];
+
+    public ReadOnlySpan<long> ValueOffsets => ValueOffsetsBuffer.Span.CastTo<long>().Slice(Offset, Length + 1);
+
+    public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();

Review Comment:
   Good point, not adding this member solves the backwards compatibility problem nicely, and I don't see a great need for it either. I'll remove this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on code in PR #43269:
URL: https://github.com/apache/arrow/pull/43269#discussion_r1678762644


##########
csharp/src/Apache.Arrow/Arrays/LargeBinaryArray.cs:
##########
@@ -0,0 +1,156 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using Apache.Arrow.Types;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace Apache.Arrow;
+
+public class LargeBinaryArray : Array, IReadOnlyList<byte[]>, ICollection<byte[]>
+{
+    public LargeBinaryArray(ArrayData data)
+        : base(data)
+    {
+        data.EnsureDataType(ArrowTypeId.LargeBinary);
+        data.EnsureBufferCount(3);
+    }
+
+    public LargeBinaryArray(ArrowTypeId typeId, ArrayData data)
+        : base(data)
+    {
+        data.EnsureDataType(typeId);
+        data.EnsureBufferCount(3);
+    }
+
+    public LargeBinaryArray(IArrowType dataType, int length,
+        ArrowBuffer valueOffsetsBuffer,
+        ArrowBuffer dataBuffer,
+        ArrowBuffer nullBitmapBuffer,
+        int nullCount = 0, int offset = 0)
+    : this(new ArrayData(dataType, length, nullCount, offset,
+        new[] { nullBitmapBuffer, valueOffsetsBuffer, dataBuffer }))
+    { }
+
+    public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor);
+
+    public ArrowBuffer ValueOffsetsBuffer => Data.Buffers[1];
+
+    public ArrowBuffer ValueBuffer => Data.Buffers[2];
+
+    public ReadOnlySpan<long> ValueOffsets => ValueOffsetsBuffer.Span.CastTo<long>().Slice(Offset, Length + 1);
+
+    public ReadOnlySpan<byte> Values => ValueBuffer.Span.CastTo<byte>();

Review Comment:
   I'm not sure if we want to consider naming this something different like `SmallValues` to help with backwards compatibility when we eventually have something like a `LargeReadOnlySpan<T>` type.
   
   This problem isn't specific to these new array types though. For `PrimitiveArray` for example we'll probably also want to introduce a new "Large" version of the `Values` ReadOnlySpan, so for consistency I think it's fine to keep calling this `Values`. Then we can later add something named like `LargeValues` to all applicable array types.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on PR #43269:
URL: https://github.com/apache/arrow/pull/43269#issuecomment-2231841928

   Yeah as Curt says this is about compatibility with other libraries, but otherwise these don't currently provide any other benefit if you're only using .NET, and you'll get errors if you try to import anything that's too large.
   
   I'm happy to revert the documentation changes if you think they're misleading? Or maybe update the wording to add that this is only to help with interoperability?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #43269:
URL: https://github.com/apache/arrow/pull/43269#issuecomment-2238082643

   After merging your PR, Conbench analyzed the 0 benchmarking runs that have been run so far on merge-commit 299ad7086928c555f3e861c20327276d1c4f2557.
   
   None of the specified runs were found on the Conbench server.
   
   The [full Conbench report](https://github.com/apache/arrow/runs/27647833906) has more details.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on code in PR #43269:
URL: https://github.com/apache/arrow/pull/43269#discussion_r1678770560


##########
csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:
##########
@@ -132,7 +132,13 @@ protected ReadResult ReadMessage()
 
                 Flatbuf.Message message = Flatbuf.Message.GetRootAsMessage(CreateByteBuffer(messageBuff));
 
-                int bodyLength = checked((int)message.BodyLength);
+                if (message.BodyLength > int.MaxValue)

Review Comment:
   I don't think there's a need for more specific checks when importing individual arrays as this should cover all scenarios.
   
   There's also an `ArrowMemoryReaderImplementation` but that needs to be constructed with a `ReadOnlyMemory<byte>` so is already limited to 2 GiB.
   
   I tested reading data from Flight which uses a `RecordBatchReaderImplementation`, but that actually fails on the C++ server side with an error that > 2 GiB record batches are not supported (see [FlightPayload::Validate](https://github.com/apache/arrow/blob/21238a7f5ebb224410d84ecf32dbe3556cab363a/cpp/src/arrow/flight/types.cc#L207)), and I'm not sure whether any other languages do support > 2 GiB batches over Flight.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on PR #43269:
URL: https://github.com/apache/arrow/pull/43269#issuecomment-2234923766

   OK thanks, I've updated the status documentation so it isn't so misleading now


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on PR #43269:
URL: https://github.com/apache/arrow/pull/43269#issuecomment-2230691230

   @raulcd The primary motivation is integration with Polars, which apparently doesn't support the non-Large versions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #43269:
URL: https://github.com/apache/arrow/pull/43269#issuecomment-2232791195

   > Or maybe update the wording to add that this is only to help with interoperability?
   
   Thanks, that makes sense with the context. I see the value of supporting it now. I think we could try to improve the wording as suggested as it might be misleading for users who might potentially have issues with interoperability when using large formats from other systems/languages if those don't fit the current limitations.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43266: [C#] Add LargeBinary, LargeString and LargeList array types [arrow]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher merged PR #43269:
URL: https://github.com/apache/arrow/pull/43269


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org