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

Write RowGroup total size and compressed size #580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justinas-marozas
Copy link

I noticed that the row group total size in the file I wrote was suspiciously small compared to the column sizes and found that the ParquetRowGroupWriter sums up compressed column sizes to write the total byte size. Changing TotalByteSize to count TotalUncompressedSizes fixed it.

I have decided to also write TotalCompressedSize for good measure.

Test Code

using System.IO.Compression;
using Parquet;
using Parquet.Data;
using Parquet.Schema;

var rand = new Random(123456);
List<DateTime> dates = Enumerable.Range(1, 5).Select(x => new DateTime(2024, 12, x)).ToList();
List<string> ids = ["123", "234", "345", "456", "567", "678", "789", "890"];
List<int> values = Enumerable.Range(0, 1000).Select(x => rand.Next(1000)).ToList();

var schema = new ParquetSchema(
    new DataField<DateTime>("timestamp", nullable: false),
    new DataField<string>("id", nullable: false),
    new DataField<int>("value", nullable: false));

var timestampColumn = new DataColumn(
    schema.DataFields.First(f => f.Name == "timestamp"),
    Enumerable.Range(0, 100_000).Select(_ => dates[rand.Next(dates.Count)]).ToArray());
var idColumn = new DataColumn(
    schema.DataFields.First(f => f.Name == "id"),
    Enumerable.Range(0, 100_000).Select(_ => ids[rand.Next(ids.Count)]).ToArray());
var valuesColumn = new DataColumn(
    schema.DataFields.First(f => f.Name == "value"),
    Enumerable.Range(0, 100_000).Select(_ => values[rand.Next(values.Count)]).ToArray());

using var stream = File.Create("test.parquet");
using ParquetWriter writer = await ParquetWriter.CreateAsync(schema, stream);

writer.CompressionMethod = CompressionMethod.Zstd;
writer.CompressionLevel = CompressionLevel.Optimal;

using ParquetRowGroupWriter groupWriter = writer.CreateRowGroup();

await groupWriter.WriteColumnAsync(timestampColumn);
await groupWriter.WriteColumnAsync(idColumn);
await groupWriter.WriteColumnAsync(valuesColumn);

Before

image

After

image

@aloneguid aloneguid added this to the 5.0.3 milestone Dec 17, 2024
Copy link
Owner

@aloneguid aloneguid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really good, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants