apache / apache/parquet-java

Configure the encoding used by ValueWriters

Đang mở
#1,989 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Component: Parquet Priority: Major Type: enhancement
Ngôn ngữ chính
Java
Star
3.1k
Fork
1.6k
Merge trung bình
3 ngày 12 giờ
Pull request đã merge (30 ngày)
33

Mô tả

This was supposed to be tackled by jira: https://issues.apache.org/jira/browse/PARQUET-601 but that ended up being just the work done to refactor the ValuesWriter factory code out of ParquetProperties. As that is now merged, it would be nice to revisit the original purpose - being able to configure which type of ValuesWriters to be used for writing out columns.

Background: Parquet is currently structured to choose the appropriate value writer based on the type of the column as well as the Parquet version. Value writers are responsible for writing out values with the appropriate encoding. As an example, for Boolean data types, we use BooleanPlainValuesWriter (v1.0) or RunLengthBitPackingHybridValuesWriter (v2.0). Code to do this is in the [DefaultV1ValuesWriterFactory](https://github.com/apache/parquet-mr/blob/master/parquet-column/src/main/java/org/apache/parquet/column/values/factory/DefaultV1ValuesWriterFactory.java#L31) and the [DefaultV2ValuesWriterFactory](https://github.com/apache/parquet-mr/blob/master/parquet-column/src/main/java/org/apache/parquet/column/values/factory/DefaultV2ValuesWriterFactory.java#L35).

Would be nice to support being able to override the encodings in some way.
That allows users to experiment with various encoding strategies manually as well as enables them to override the hardcoded defaults if they don't suit their use case.

Couple of options I can think of:

Specifying encoding by type (or column):
```Java
parquet.writer.encoding-override. = "encoding1[,encoding2]"
As an example:
"parquet.writer.encoding-override.int32" = "plain"
```
Chooses Plain encoding and hence the PlainValuesWriter.

When a primary + fallback need to be specified, we can do the following:
```Java
"parquet.writer.encoding-override.binary" = "rle_dictionary,delta_byte_array"
```

Chooses RLE_DICTIONARY encoding as the initial encoding and DELTA_BYTE_ARRAY encoding as the fallback and hence creates a FallbackWriter(PlainBinaryDictionaryValuesWriter, DeltaByteArrayWriter).
In such cases we can mandate that the first encoding listed must allow for Fallbacks by implementing [RequiresFallback](https://github.com/apache/parquet-mr/blob/master/parquet-column/src/main/java/org/apache/parquet/column/values/RequiresFallback.java#L31).

Another option suggested by @isnotinvain, was to allow overriding of the ValuesWriterFactory using reflection:
```Java
parquet.writer.factory-override = "org.apache.parquet.hadoop.MyValuesWriterFactory"
```

This creates a factory, MyValuesWriterFactory which is then invoked for every ColumnDescriptor to get a ValueWriter. This provides the flexibility to the user to implement a ValuesWriterFactory that can read configuration for per type / column encoding overrides. Can also be used to plug-in a more sophisticated approach where we choose the appropriate encoding based on the data being seen. A concern raised by @rdblue regarding this approach was that ValuesWriters are supposed to be internal classes in Parquet. So we shouldn't be allowing users to configure the ValuesWriter factories via config.

cc @julienledem / @rdblue / @isnotinvain for you thoughts / other ideas. We could also explore other ideas based on any other potential use cases.

**Reporter**: [Piyush Narang](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=pnarang) / @piyushnarang

**Note**: *This issue was originally created as [PARQUET-682](https://issues.apache.org/jira/browse/PARQUET-682). Please see the [migration documentation](https://issues.apache.org/jira/browse/PARQUET-2502) for further details.*

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu bằng cách đọc DefaultV1ValuesWriterFactory.java và DefaultV2ValuesWriterFactory.java, sau đó kiểm tra ValuesWriterFactory và RequiresFallback. Issue này đưa ra nhiều thiết kế cấu hình chưa được giải quyết, vì vậy trước tiên hãy xác định cách tiếp cận nào được chấp nhận. Công việc được xem là hoàn tất khi người dùng có thể ghi đè các encoding hoặc factory của value-writer như đã chỉ định và hành vi liên quan được bao phủ bởi các bài kiểm thử.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
data-engineering
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.