Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: attempt to fix issues where loop will read past the end of a block #487

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
26 changes: 25 additions & 1 deletion src/Parquet.Test/Encodings/DeltaBinaryPackedEncodingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,35 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Parquet.Encodings;
using Parquet.Rows;
using Xunit;

namespace Parquet.Test.Encodings {
public class DeltaBinaryPackedEncodingTest {
public class DeltaBinaryPackedEncodingTest : TestBase {
[Fact]
public async Task TestDeltaBinaryPackedFile() {
Table t;
using(Stream stream = OpenTestFile("test-delta-binary-packed.parquet")) {
using(ParquetReader reader = await ParquetReader.CreateAsync(stream)) {
t = await reader.ReadAsTableAsync();
}
}

Assert.Equal("{'column1': 1000}", t[0].ToString());
Assert.Equal("{'column1': 1}", t[1].ToString());
Assert.Equal("{'column1': 2}", t[2].ToString());
Assert.Equal("{'column1': 3}", t[3].ToString());
Assert.Equal("{'column1': 4}", t[4].ToString());
Assert.Equal("{'column1': 5}", t[5].ToString());
Assert.Equal("{'column1': 6}", t[6].ToString());
Assert.Equal("{'column1': 7}", t[7].ToString());
Assert.Equal("{'column1': 8}", t[8].ToString());
Assert.Equal("{'column1': 9}", t[9].ToString());
Assert.Equal("{'column1': 10}", t[10].ToString());
}

[Fact]
public void EncodeAndDecodeInt32() {

Expand Down
Binary file not shown.
8 changes: 6 additions & 2 deletions src/Parquet/Encodings/DeltaBinaryPackedEncoder.Variations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ private static int DecodeInt(Span<byte> s, Span<int> dest, out int consumedBytes
if(bitWidth == 0) {
// there's not data for bitwidth 0
for(int i = 0; i < valuesPerMiniblock && destOffset < dest.Length; i++, read++) {
if(read >= totalValueCount)
break;
currentValue += minDelta;
dest[destOffset++] = currentValue;
}
Expand All @@ -150,7 +152,7 @@ private static int DecodeInt(Span<byte> s, Span<int> dest, out int consumedBytes
spos += bitWidth;
}

for(int i = 0; i < vbuf.Length && destOffset < dest.Length; i++, read++) {
for(int i = 0; i < vbuf.Length && destOffset < dest.Length && read < totalValueCount; i++, read++) {
currentValue += minDelta + vbuf[i];
dest[destOffset++] = currentValue;
}
Expand Down Expand Up @@ -297,6 +299,8 @@ private static int DecodeLong(Span<byte> s, Span<long> dest, out int consumedByt
if(bitWidth == 0) {
// there's not data for bitwidth 0
for(int i = 0; i < valuesPerMiniblock && destOffset < dest.Length; i++, read++) {
if(read >= totalValueCount)
break;
currentValue += minDelta;
dest[destOffset++] = currentValue;
}
Expand All @@ -308,7 +312,7 @@ private static int DecodeLong(Span<byte> s, Span<long> dest, out int consumedByt
spos += bitWidth;
}

for(int i = 0; i < vbuf.Length && destOffset < dest.Length; i++, read++) {
for(int i = 0; i < vbuf.Length && destOffset < dest.Length && read < totalValueCount; i++, read++) {
currentValue += minDelta + vbuf[i];
dest[destOffset++] = currentValue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Parquet/Encodings/DeltaBinaryPackedEncoder.Variations.tt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ namespace Parquet.Encodings {
if(bitWidth == 0) {
// there's not data for bitwidth 0
for(int i = 0; i < valuesPerMiniblock && destOffset < dest.Length; i++, read++) {
if(read >= totalValueCount)
break;
currentValue += minDelta;
dest[destOffset++] = currentValue;
}
Expand All @@ -159,7 +161,7 @@ namespace Parquet.Encodings {
spos += bitWidth;
}

for(int i = 0; i < vbuf.Length && destOffset < dest.Length; i++, read++) {
for(int i = 0; i < vbuf.Length && destOffset < dest.Length && read < totalValueCount; i++, read++) {
currentValue += minDelta + vbuf[i];
dest[destOffset++] = currentValue;
}
Expand Down
Loading