jeremyosterhoudt commented on code in PR #36134:
URL: https://github.com/apache/arrow/pull/36134#discussion_r1394868597


##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -258,8 +259,77 @@ public TBuilder Swap(int i, int j)
 
             public TBuilder Set(int index, byte value)
             {
-                // TODO: Implement
+                ValueBuffer.Span[index] = value;
+                return Instance;
+            }
+
+            public TBuilder SetNull(int offset)
+            {
+                int index = ValueOffsets.Span[offset];
+                int length = GetOffsetValueLength(offset);
+
+                for (int i = 0; i < length; i++)
+                {
+                    ValueBuffer.Span[index + i] = 0;
+                }
+
+                ValidityBuffer.Set(offset, false);
+
+                return Instance;
+            }
+
+            public TBuilder Set(int offset, ReadOnlySpan<byte> values)
+            {
+#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
+                byte[] newValues = values.ToArray();
+                int index = ValueOffsets.Span[offset];
+                int existingValueLength = GetOffsetValueLength(offset);
+                int newValueLength = newValues.Length;
+
+                // Resize and shift the value and offset buffers
+                if (existingValueLength != newValueLength)
+                {
+                    int indexShift = newValueLength - existingValueLength;
+
+                    if (offset != ValueOffsets.Length)
+                    {
+                        //Shift the existing values after our change in size
+                        var afterValues = ValueBuffer.Span[(index + 
existingValueLength)..];
+                        ValueBuffer.Resize(ValueBuffer.Length + indexShift + 
1);
+                        afterValues.CopyTo(ValueBuffer.Span[(index + 
newValueLength)..]);
+                    }
+                    else
+                    {
+                        ValueBuffer.Resize(ValueBuffer.Length + indexShift + 
1);
+                    }
+
+                    //Update out offset indexes
+                    for (int i = offset + 1; i < ValueOffsets.Length; i++)
+                    {
+                        ValueOffsets.Span[i] += indexShift;
+                    }
+                }
+
+                for (int i = 0; i < newValues.Length; i++)
+                {
+                    Set(i + index, newValues[i]);
+                }
+
+                ValidityBuffer.Set(offset, true);
+
+                return Instance;
+#else
+                //There is not a clean way to shift the bytes with Span.CopyTo 
which was added in .NetStandard 2.1/.NET5
+                //Given .NetStandard past EOL, keep existing functionality the 
same for those users.

Review Comment:
   Great point!  I've updated the comment to reflect that the feature is only 
available to users running NetStandard 2.1/NET 5 and higher.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to