Skip to content

Commit

Permalink
Merge pull request #84 from G-Research/RowCompressFix
Browse files Browse the repository at this point in the history
Fixed compression argument being ignored by ParquetRowWriter.
  • Loading branch information
GPSnoopy authored Nov 28, 2019
2 parents 424eec4 + aaf3066 commit 958bd3a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
22 changes: 22 additions & 0 deletions csharp.test/TestRowOrientedParquetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ public static void TestWriterDoubleDispose()
}
}

[Test]
public static void TestCompressionArgument([Values(Compression.Uncompressed, Compression.Brotli)] Compression compression)
{
using (var buffer = new ResizableBuffer())
{
using (var outputStream = new BufferOutputStream(buffer))
using (var writer = ParquetFile.CreateRowWriter<(int, float)>(outputStream, compression: compression))
{
writer.WriteRows(new[] {(42, 3.14f)});
}

using (var inputStream = new BufferReader(buffer))
using (var reader = new ParquetFileReader(inputStream))
using (var group = reader.RowGroup(0))
{
Assert.AreEqual(2, group.MetaData.NumColumns);
Assert.AreEqual(compression, group.MetaData.GetColumnChunkMetaData(0).Compression);
Assert.AreEqual(compression, group.MetaData.GetColumnChunkMetaData(1).Compression);
}
}
}

private static void TestRoundtrip<TTuple>(TTuple[] rows)
{
using (var buffer = new ResizableBuffer())
Expand Down
2 changes: 1 addition & 1 deletion csharp/ParquetSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NoWarn>1591;</NoWarn>
<Version>2.0.2-beta3</Version>
<Version>2.0.2-beta4</Version>
<Company>G-Research</Company>
<Authors>G-Research</Authors>
<Product>ParquetSharp</Product>
Expand Down
4 changes: 2 additions & 2 deletions csharp/RowOriented/ParquetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static ParquetRowWriter<TTuple> CreateRowWriter<TTuple>(
IReadOnlyDictionary<string, string> keyValueMetadata = null)
{
var (columns, writeDelegate) = GetOrCreateWriteDelegate<TTuple>(columnNames);
return new ParquetRowWriter<TTuple>(path, columns, writeDelegate);
return new ParquetRowWriter<TTuple>(path, columns, compression, keyValueMetadata, writeDelegate);
}

/// <summary>
Expand All @@ -58,7 +58,7 @@ public static ParquetRowWriter<TTuple> CreateRowWriter<TTuple>(
IReadOnlyDictionary<string, string> keyValueMetadata = null)
{
var (columns, writeDelegate) = GetOrCreateWriteDelegate<TTuple>(columnNames);
return new ParquetRowWriter<TTuple>(outputStream, columns, writeDelegate);
return new ParquetRowWriter<TTuple>(outputStream, columns, compression, keyValueMetadata, writeDelegate);
}

private static ParquetRowReader<TTuple>.ReadAction GetOrCreateReadDelegate<TTuple>()
Expand Down
18 changes: 14 additions & 4 deletions csharp/RowOriented/ParquetRowWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ public sealed class ParquetRowWriter<TTuple> : IDisposable
{
internal delegate void WriteAction(ParquetRowWriter<TTuple> parquetRowWriter, TTuple[] rows, int length);

internal ParquetRowWriter(string path, Column[] columns, WriteAction writeAction)
: this(new ParquetFileWriter(path, columns), writeAction)
internal ParquetRowWriter(
string path,
Column[] columns,
Compression compression,
IReadOnlyDictionary<string, string> keyValueMetadata,
WriteAction writeAction)
: this(new ParquetFileWriter(path, columns, compression, keyValueMetadata), writeAction)
{
}

internal ParquetRowWriter(OutputStream outputStream, Column[] columns, WriteAction writeAction)
: this(new ParquetFileWriter(outputStream, columns), writeAction)
internal ParquetRowWriter(
OutputStream outputStream,
Column[] columns,
Compression compression,
IReadOnlyDictionary<string, string> keyValueMetadata,
WriteAction writeAction)
: this(new ParquetFileWriter(outputStream, columns, compression, keyValueMetadata), writeAction)
{
}

Expand Down

0 comments on commit 958bd3a

Please sign in to comment.