danmoseley commented on code in PR #36134:
URL: https://github.com/apache/arrow/pull/36134#discussion_r1393599083
##########
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:
nit, .NET Standard 2.0/2.1 do not have an EOL, they define a standard, not a
runtime or product. All future .NET's including .NET 6, 7, and 8 are expected
to support .NET Standard 2.1. It's true that .NET Standard is getting
increasingly less useful as .NET evolves while .NET Framework is static.
you probably know this -- just suggesting this comment ought to say ".NET 5
and lower are EOL"
--
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]