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
5 changes: 5 additions & 0 deletions cpp/WriterProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,9 @@ extern "C"
{
TRYCATCH(*memory_pool = (*writer_properties)->memory_pool();)
}

PARQUETSHARP_EXPORT ExceptionInfo* WriterProperties_Store_Decimal_As_Integer(const std::shared_ptr<WriterProperties>* writer_properties, bool* store_decimal_as_integer)
{
TRYCATCH(*store_decimal_as_integer = (*writer_properties)->store_decimal_as_integer();)
}
}
10 changes: 10 additions & 0 deletions cpp/WriterPropertiesBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,14 @@ extern "C"
{
TRYCATCH(builder->memory_pool(pool);)
}

PARQUETSHARP_EXPORT ExceptionInfo* WriterPropertiesBuilder_Enable_Store_Decimal_As_Integer(WriterProperties::Builder* builder)
{
TRYCATCH(builder->enable_store_decimal_as_integer();)
}

PARQUETSHARP_EXPORT ExceptionInfo* WriterPropertiesBuilder_Disable_Store_Decimal_As_Integer(WriterProperties::Builder* builder)
{
TRYCATCH(builder->disable_store_decimal_as_integer();)
}
}
3 changes: 3 additions & 0 deletions csharp.test/TestWriterProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void TestDefaultProperties()
Assert.True(p.WritePageIndex);
Assert.False(p.PageChecksumEnabled);
Assert.That(p.MemoryPool.BackendName, Is.Not.Empty);
Assert.False(p.StoreDecimalAsInteger);
}

[Test]
Expand All @@ -46,6 +47,7 @@ public static void TestPropertiesBuilder()
.DisableWritePageIndex()
.EnablePageChecksum()
.MemoryPool(MemoryPool.SystemMemoryPool())
.EnableStoreDecimalAsInteger()
.Build();

Assert.AreEqual("Meeeee!!!", p.CreatedBy);
Expand All @@ -61,6 +63,7 @@ public static void TestPropertiesBuilder()
Assert.False(p.WritePageIndex);
Assert.True(p.PageChecksumEnabled);
Assert.AreEqual("system", p.MemoryPool.BackendName);
Assert.True(p.StoreDecimalAsInteger);
}

[Test]
Expand Down
3 changes: 3 additions & 0 deletions csharp/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ ParquetSharp.ReaderProperties.ThriftContainerSizeLimit.get -> int
ParquetSharp.ReaderProperties.SetThriftContainerSizeLimit(int size) -> void
ParquetSharp.ReaderProperties.FooterReadSize.get -> long
ParquetSharp.ReaderProperties.SetFooterReadSize(long size) -> void
ParquetSharp.WriterProperties.StoreDecimalAsInteger.get -> bool
ParquetSharp.WriterPropertiesBuilder.EnableStoreDecimalAsInteger() -> ParquetSharp.WriterPropertiesBuilder!
ParquetSharp.WriterPropertiesBuilder.DisableStoreDecimalAsInteger() -> ParquetSharp.WriterPropertiesBuilder!
8 changes: 8 additions & 0 deletions csharp/WriterProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public SortingColumn[] SortingColumns()
/// </summary>
public MemoryPool MemoryPool => new MemoryPool(ExceptionInfo.Return<IntPtr>(Handle, WriterProperties_Memory_Pool));

/// <summary>
/// Whether decimals with precision between 1 and 18 (inclusive) are stored as integers.
/// </summary>
public bool StoreDecimalAsInteger => ExceptionInfo.Return<bool>(Handle, WriterProperties_Store_Decimal_As_Integer);

internal readonly ParquetHandle Handle;

[DllImport(ParquetDll.Name)]
Expand Down Expand Up @@ -340,5 +345,8 @@ public SortingColumn[] SortingColumns()

[DllImport(ParquetDll.Name)]
private static extern IntPtr WriterProperties_Memory_Pool(IntPtr writerProperties, out IntPtr memoryPool);

[DllImport(ParquetDll.Name)]
private static extern IntPtr WriterProperties_Store_Decimal_As_Integer(IntPtr writerProperties, out bool storeDecimalAsInteger);
}
}
37 changes: 37 additions & 0 deletions csharp/WriterPropertiesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,37 @@ private void ApplyDefaults()
});
}

/// <summary>
/// Allow decimals with precision between 1 and 18 (inclusive) to be stored as integers.
/// By default, this is DISABLED and all decimal types annotate fixed_len_byte_array.
///
/// When enabled, the Parquet writer will use following physical types to store decimals:
/// - int32: for precision between 1 and 9.
/// - int64: for precision between 10 and 18.
/// - fixed_len_byte_array: for precision > 18.
///
/// As a consequence, decimal columns stored in integer types are more compact.
/// </summary>
public WriterPropertiesBuilder EnableStoreDecimalAsInteger()
{
ExceptionInfo.Check(WriterPropertiesBuilder_Enable_Store_Decimal_As_Integer(_handle.IntPtr));
GC.KeepAlive(_handle);
return this;
}

/// <summary>
/// Disable decimal logical type with precision between 1 and 18 (inclusive) to be stored
/// as integer physical type.
///
/// This is the default.
/// </summary>
public WriterPropertiesBuilder DisableStoreDecimalAsInteger()
{
ExceptionInfo.Check(WriterPropertiesBuilder_Disable_Store_Decimal_As_Integer(_handle.IntPtr));
GC.KeepAlive(_handle);
return this;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void OnDefaultProperty<T>(T? defaultPropertyValue, Action<T> setProperty)
where T : struct
Expand Down Expand Up @@ -766,6 +797,12 @@ private static void OnDefaultRefProperty<T>(T? defaultPropertyValue, Action<T> s
[DllImport(ParquetDll.Name)]
private static extern IntPtr WriterPropertiesBuilder_Memory_Pool(IntPtr builder, IntPtr memoryPool);

[DllImport(ParquetDll.Name)]
private static extern IntPtr WriterPropertiesBuilder_Enable_Store_Decimal_As_Integer(IntPtr builder);

[DllImport(ParquetDll.Name)]
private static extern IntPtr WriterPropertiesBuilder_Disable_Store_Decimal_As_Integer(IntPtr builder);

private readonly ParquetHandle _handle;
}
}