Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +457,25 @@ public T? this[long rowIndex]
return null;
}
int arrayIndex = GetArrayContainingRowIndex(rowIndex);
rowIndex = rowIndex - arrayIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;
return Buffers[arrayIndex][(int)rowIndex];
var bufferOffset = (int)(rowIndex % ReadOnlyDataFrameBuffer<T>.MaxCapacity);
return Buffers[arrayIndex][bufferOffset];
}
set
{
int arrayIndex = GetArrayContainingRowIndex(rowIndex);
rowIndex = rowIndex - arrayIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;
var bufferOffset = (int)(rowIndex % ReadOnlyDataFrameBuffer<T>.MaxCapacity);

Buffers.GetOrCreateMutable(arrayIndex);
NullBitMapBuffers.GetOrCreateMutable(arrayIndex);

if (value.HasValue)
{
Buffers[arrayIndex][(int)rowIndex] = value.Value;
Buffers[arrayIndex][bufferOffset] = value.Value;
SetValidityBit(rowIndex, true);
}
else
{
Buffers[arrayIndex][(int)rowIndex] = default;
Buffers[arrayIndex][bufferOffset] = default;
SetValidityBit(rowIndex, false);
}
}
Expand Down
19 changes: 17 additions & 2 deletions test/Microsoft.Data.Analysis.Tests/BufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@
using System.Text;
using Apache.Arrow;
using Microsoft.ML.TestFramework.Attributes;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Microsoft.Data.Analysis.Tests
{
public class BufferTests
{
[X64Fact("32-bit doesn't allow to allocate more than 2 Gb")]
public void TestGetterAndSetterForColumnsGreaterThanMaxCapacity()
{
const int MaxCapacityInBytes = 2147483591;

var length = MaxCapacityInBytes + 5;
var column = new PrimitiveDataFrameColumn<byte>("LargeColumn", length);
var index = length - 1;
column[index] = 33;

Assert.Equal((byte)33, column[index]);
Assert.Null(column[index % MaxCapacityInBytes]);
}

[Fact]
public void TestNullCounts()
{
Expand Down Expand Up @@ -446,15 +461,15 @@ public void TestArrowStringColumnClone()
Assert.Null(clone[i]);
}

[X64Fact("32-bit dosn't allow to allocate more than 2 Gb")]
[X64Fact("32-bit doesn't allow to allocate more than 2 Gb")]
public void TestAppend_SizeMoreThanMaxBufferCapacity()
{
//Check appending value, than can increase buffer size over MaxCapacity (default strategy is to double buffer capacity)
PrimitiveDataFrameColumn<byte> intColumn = new PrimitiveDataFrameColumn<byte>("Byte1", int.MaxValue / 2 - 1);
intColumn.Append(10);
}

[X64Fact("32-bit dosn't allow to allocate more than 2 Gb")]
[X64Fact("32-bit doesn't allow to allocate more than 2 Gb")]
public void TestAppendMany_SizeMoreThanMaxBufferCapacity()
{
const int MaxCapacityInBytes = 2147483591;
Expand Down