Skip to content

Conversation

@dongjoon-hyun
Copy link
Member

@dongjoon-hyun dongjoon-hyun commented Jun 30, 2025

What changes were proposed in this pull request?

This PR aims to fix PhysicalFsWriter to change tempOptions directly.

Why are the changes needed?

In the following code path, tempOptions is supposed to be updated and used. However, codec.getDefaultOptions() instanceof ZstdCodec.ZstdOptions options code is currently updating the return value of codec.getDefaultOptions() via a variable options.

CompressionCodec.Options tempOptions = codec.getDefaultOptions();
if (codec instanceof ZstdCodec &&
codec.getDefaultOptions() instanceof ZstdCodec.ZstdOptions options) {
OrcFile.ZstdCompressOptions zstdCompressOptions = opts.getZstdCompressOptions();
if (zstdCompressOptions != null) {
options.setLevel(zstdCompressOptions.getCompressionZstdLevel());
options.setWindowLog(zstdCompressOptions.getCompressionZstdWindowLog());
}
}
compress.withCodec(codec, tempOptions);

Technically, ZstdCodec.getDefaultOptions() returns the final static variable. This AS-IS code is trying to change this static object which leads unintended side-effects. We should avoid this code pattern.

private static final ZstdOptions DEFAULT_OPTIONS =
new ZstdOptions(3, 0);
@Override
public Options getDefaultOptions() {
return DEFAULT_OPTIONS;
}

How was this patch tested?

Pass the CIs with a newly added test case.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the JAVA label Jun 30, 2025
@Override
public Options getDefaultOptions() {
return DEFAULT_OPTIONS;
return DEFAULT_OPTIONS.copy();
Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, this PR makes this return a copied one to make it sure.

@dongjoon-hyun dongjoon-hyun changed the title ORC-1942: Fix PhysicalFsWriter to change tempOptions directly ORC-1942: Fix PhysicalFsWriter not to change ZstdCodec's default option Jun 30, 2025
@dongjoon-hyun
Copy link
Member Author

cc @cxzl25

dongjoon-hyun added a commit that referenced this pull request Jun 30, 2025
…option

### What changes were proposed in this pull request?

This PR aims to fix `PhysicalFsWriter` to change `tempOptions` directly.

### Why are the changes needed?

In the following code path, `tempOptions` is supposed to be updated and used. However, `codec.getDefaultOptions() instanceof ZstdCodec.ZstdOptions options` code is currently updating the return value of `codec.getDefaultOptions()` via a variable `options`.

https://github.com/apache/orc/blob/d3843bc043bea97bdd81a0f8e1fab3329efc7308/java/core/src/java/org/apache/orc/impl/PhysicalFsWriter.java#L118-L127

Technically, `ZstdCodec.getDefaultOptions()` returns the final static variable. This AS-IS code is trying to change this static object which leads unintended side-effects. We should avoid this code pattern.

https://github.com/apache/orc/blob/d3843bc043bea97bdd81a0f8e1fab3329efc7308/java/core/src/java/org/apache/orc/impl/ZstdCodec.java#L150-L156

### How was this patch tested?

Pass the CIs with a newly added test case.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #2304 from dongjoon-hyun/ORC-1942.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 3c63bf7)
Signed-off-by: Dongjoon Hyun <[email protected]>
dongjoon-hyun added a commit that referenced this pull request Jun 30, 2025
…option

### What changes were proposed in this pull request?

This PR aims to fix `PhysicalFsWriter` to change `tempOptions` directly.

### Why are the changes needed?

In the following code path, `tempOptions` is supposed to be updated and used. However, `codec.getDefaultOptions() instanceof ZstdCodec.ZstdOptions options` code is currently updating the return value of `codec.getDefaultOptions()` via a variable `options`.

https://github.com/apache/orc/blob/d3843bc043bea97bdd81a0f8e1fab3329efc7308/java/core/src/java/org/apache/orc/impl/PhysicalFsWriter.java#L118-L127

Technically, `ZstdCodec.getDefaultOptions()` returns the final static variable. This AS-IS code is trying to change this static object which leads unintended side-effects. We should avoid this code pattern.

https://github.com/apache/orc/blob/d3843bc043bea97bdd81a0f8e1fab3329efc7308/java/core/src/java/org/apache/orc/impl/ZstdCodec.java#L150-L156

### How was this patch tested?

Pass the CIs with a newly added test case.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #2304 from dongjoon-hyun/ORC-1942.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 3c63bf7)
Signed-off-by: Dongjoon Hyun <[email protected]>
@dongjoon-hyun
Copy link
Member Author

Merged to main/2.1/2.0.

Copy link
Contributor

@cxzl25 cxzl25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late LGTM. Thank you @dongjoon-hyun

@dongjoon-hyun
Copy link
Member Author

Thank you for reviewing, @cxzl25 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants