You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by "KevinyhZou (via GitHub)" <gi...@apache.org> on 2026/07/20 02:00:04 UTC
[PR] [GLUTEN-12202][FLINK]Add support for compression in hive table sink [gluten]
KevinyhZou opened a new pull request, #12571:
URL: https://github.com/apache/gluten/pull/12571
<!--
Thank you for submitting a pull request! Here are some tips:
1. For first-time contributors, please read our contributing guide:
https://github.com/apache/gluten/blob/main/CONTRIBUTING.md
2. If necessary, create a GitHub issue for discussion beforehand to avoid duplicate work.
3. If the PR is specific to a single backend, include [VL] or [CH] in the PR title to indicate the
Velox or ClickHouse backend, respectively.
4. If the PR is not ready for review, please mark it as a draft.
-->
#12202
## What changes are proposed in this pull request?
<!--
Provide a clear and concise description of the changes introduced in this PR.
Ensure the PR description aligns with the code changes, especially after updates.
If applicable, include "Fixes #<GitHub_Issue_ID>" to automatically close the corresponding issue
when the PR is merged.
-->
## How was this patch tested?
<!--
Describe how the changes were tested, if applicable.
Include new tests to validate the functionality, if necessary.
For UI-related changes, attach screenshots to demonstrate the updates.
-->
## Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [GLUTEN-12572][FLINK]Add support for compression in hive table sink [gluten]
Posted by "lgbo-ustc (via GitHub)" <gi...@apache.org>.
lgbo-ustc commented on code in PR #12571:
URL: https://github.com/apache/gluten/pull/12571#discussion_r3629149523
##########
gluten-flink/planner/src/main/java/org/apache/gluten/velox/HiveSourceSinkFactory.java:
##########
@@ -96,4 +109,87 @@ private String resolveFormatFromHiveWriterFactory(Object hiveWriterFactory) {
ReflectUtils.getObjectField(factoryClass, hiveWriterFactory, "hiveOutputFormatClz");
return inferFormatFromClassName(outputFormatClz.getName());
}
+
+ private void addHiveCompressionParams(Object bucketsBuilder, Map<String, String> tableParams) {
+ Object hiveWriterFactory = getHiveWriterFactoryFromBucketsBuilder(bucketsBuilder);
+ if (hiveWriterFactory == null) {
+ return;
+ }
+ Properties tableProperties =
+ (Properties) ReflectUtils.tryGetObjectField(hiveWriterFactory, "tableProperties");
+ addNativeCompressionParamFromTableProperties(tableProperties, tableParams);
+ }
+
+ private Object getBucketsBuilder(OneInputStreamOperator<?, ?> fileWriterOperator) {
+ return ReflectUtils.getObjectField(
+ ABSTRACT_STREAMING_WRITER_CLASS, fileWriterOperator, "bucketsBuilder");
+ }
+
+ private Object getHiveWriterFactoryFromBucketsBuilder(Object bucketsBuilder) {
+ Object writerFactory = ReflectUtils.tryGetObjectField(bucketsBuilder, "writerFactory");
+ if (writerFactory == null
+ || !writerFactory.getClass().getName().contains("HiveBulkWriterFactory")) {
+ return null;
+ }
+ return ReflectUtils.getObjectField(writerFactory.getClass(), writerFactory, "factory");
+ }
+
+ static void addNativeCompressionParamFromTableProperties(
+ Properties tableProperties, Map<String, String> tableParams) {
+ if (!isParquetFormat(tableParams.get("format"))) {
+ tableParams.remove(COMPRESSION_KIND);
+ return;
+ }
+ if (tableProperties == null) {
+ return;
+ }
+
+ String compressionKind = resolveCompressionKind(tableProperties);
+ if (compressionKind != null) {
+ tableParams.put(COMPRESSION_KIND, compressionKind);
+ }
+ }
+
+ private static boolean isParquetFormat(String format) {
+ return format != null && "parquet".equalsIgnoreCase(format.trim());
+ }
+
+ private static String resolveCompressionKind(Properties tableProperties) {
+ for (String key : SUPPORTED_COMPRESSION_TABLE_KEYS) {
+ String compressionKind = normalizeCompressionKind(tableProperties.getProperty(key));
+ if (compressionKind != null) {
+ return compressionKind;
+ }
+ }
+ return null;
+ }
+
+ static String normalizeCompressionKind(String compression) {
Review Comment:
This normalization would be easier to read and maintain as a static map from lowercase input values to canonical native codec names. Then unsupported values naturally return null instead of being handled in a long switch. For example:
```java
private static final Map<String, String> SUPPORTED_COMPRESSION_KINDS =
Map.ofEntries(
Map.entry("snappy", "snappy"),
Map.entry("zstd", "zstd"),
Map.entry("zstandard", "zstd"),
Map.entry("lz4", "lz4"));
static String normalizeCompressionKind(String compression) {
if (compression == null) {
return null;
}
return SUPPORTED_COMPRESSION_KINDS.get(compression.trim().toLowerCase());
}
```
This also makes the supported codec set explicit and avoids accidentally passing unsupported native codecs later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [GLUTEN-12572][FLINK]Add support for compression in hive table sink [gluten]
Posted by "lgbo-ustc (via GitHub)" <gi...@apache.org>.
lgbo-ustc commented on PR #12571:
URL: https://github.com/apache/gluten/pull/12571#issuecomment-5018703280
Additional clean-code feedback, excluding the unrelated logging change already discussed separately:
1. HiveSourceSinkFactory.addCompressionParamsFromTableProperties is doing two different jobs: copying compression-like table properties and deriving the native sink.file.compression config. These have different responsibilities and different compatibility constraints. Please split the behavior or narrow this method to only produce the native config that is actually needed.
2. isCompressionProperty is too broad. Matching any key that contains compress or codec makes the planner pass through unrelated or future table properties by accident. A clearer and safer approach is to maintain an explicit allow-list of supported Hive/Flink compression keys.
3. normalizeCompressionKind is too permissive. It uses substring matching and returns unknown normalized values as-is, which lets planner generate configs that native may reject later. It would be cleaner to explicitly map supported values and return empty/null, fallback, or reject for unsupported codecs.
4. The Hive writer factory reflection path is duplicated with the existing format-resolution path. Both depend on bucketsBuilder -> writerFactory -> HiveBulkWriterFactory -> factory. Please consider sharing one small helper so Flink internal field-name changes do not need to be fixed in multiple places.
5. The new unit tests are focused on helper implementation details rather than behavior. The test using orc.compress also makes the expected output look valid even though native filesystem compression currently does not support ORC. Please add behavior-oriented coverage for supported Parquet codecs and unsupported format/codec cases, verifying fallback/no config/error behavior explicitly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [GLUTEN-12572][FLINK]Add support for compression in hive table sink [gluten]
Posted by "KevinyhZou (via GitHub)" <gi...@apache.org>.
KevinyhZou merged PR #12571:
URL: https://github.com/apache/gluten/pull/12571
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [GLUTEN-12572][FLINK]Add support for compression in hive table sink [gluten]
Posted by "lgbo-ustc (via GitHub)" <gi...@apache.org>.
lgbo-ustc commented on PR #12571:
URL: https://github.com/apache/gluten/pull/12571#issuecomment-5044231624
Clean-code suggestion: normalizeCompressionKind would be clearer as a static mapping table instead of a switch.
For example, keep a static map from lowercase input values to the canonical native codec name, then implement normalization as trim/lowercase + map lookup, returning null when the value is absent. This makes the supported codec set explicit, avoids a long switch, and makes it harder to accidentally pass through unsupported values later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org