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

Feature request: add API for 2 step group writting #484

Open
i-sinister opened this issue Feb 29, 2024 · 0 comments
Open

Feature request: add API for 2 step group writting #484

i-sinister opened this issue Feb 29, 2024 · 0 comments

Comments

@i-sinister
Copy link

Issue description

I have to save a large dataset with many groups each having 20M rows and currently it takes too much time. I think it would improve overall speed if appending a group would be 'pipelined' by separating into 2 steps:

  1. preparing data to write
  2. appending to the file

Current parquet-dotnet implementation already uses 2 separate memory streams while saving content of the column (DataColumnWriter.WriteColumnAsync):

  1. copy data from column array into memory stream
  2. copy memory stream into byte array and compress into another byte array
  3. append compressed byte array to the parquet "file"

Whole process could be 'pipelined':

  1. application starts a thread that prepares serialized compressed data and metadata for columns
  2. application starts another thread that appends prepared column data to the parquet file:

Something like (BlockingCollection is an overkill here ofcourse):

using (var extendedGroupWriter = parquetWriter.CreateExtendedGroupWriter(...))
{
  var queue = new BlockingCollection();
  var prepareTask = Task.Factory.StartNew(
    () =>
    {
       foreach (var partition in GetLargePartitionedDataSet())
       {
         var preparedgroup = extendedGroupWriter
           .StartGroupPreparation()
           // serializing and compressing data for field1
           .Append(field1, partition.Select(...))
          // serializing and compressing data for field2
           .Append(field2, partition.Select(...))
          // serializing and compressing data for field3
           .Append(field3, partition.Select(...))
           .PrepareGroupData();
         queue.Add(preparedGroup);
       }
       queue.CompleteAdding();
    });
  var writeTask = Task.Factory.StartNew(
    () =>
    {
      while (!queue.IsCompleted)
      {
	  using var preparedGroup = queue.Take(cancellationToken);
          parquetWriter.WritePreparedGroup(preparedGroup);
      }
    });
  await writeTask;
}

Or serialization and compression could be separate steps and compression could be done directly into the target stead, without using extra memory stream.

These same approach could be used on the column level:

  1. first thread prepares data for the column
  2. second thread appends column data as soon as it is ready
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

No branches or pull requests

1 participant