Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-1332: Avoid NegativeArraySizeException when using searchArgument #1340

Closed
wants to merge 3 commits into from

Conversation

cxzl25
Copy link
Contributor

@cxzl25 cxzl25 commented Dec 17, 2022

What changes were proposed in this pull request?

searchArgument takes effect only when rowIndexStride is greater than 0.

Why are the changes needed?

When orc.row.index.stride is set to a negative number, using searchArgument will throw NegativeArraySizeException.

Caused by: java.lang.NegativeArraySizeException
	at org.apache.orc.impl.RecordReaderImpl$SargApplier.pickRowGroups(RecordReaderImpl.java:1164)
	at org.apache.orc.impl.RecordReaderImpl.pickRowGroups(RecordReaderImpl.java:1273)
	at org.apache.orc.impl.RecordReaderImpl.readStripe(RecordReaderImpl.java:1293)
	at org.apache.orc.impl.RecordReaderImpl.advanceStripe(RecordReaderImpl.java:1345)
	at org.apache.orc.impl.RecordReaderImpl.advanceToNextRow(RecordReaderImpl.java:1388)
	at org.apache.orc.impl.RecordReaderImpl.<init>(RecordReaderImpl.java:367)

How was this patch tested?

add UT

@github-actions github-actions bot added the JAVA label Dec 17, 2022
@@ -237,7 +237,7 @@ protected RecordReaderImpl(ReaderImpl fileReader,
this.fileIncluded = evolution.getFileIncluded();
SearchArgument sarg = options.getSearchArgument();
boolean[] rowIndexCols = new boolean[evolution.getFileIncluded().length];
if (sarg != null && rowIndexStride != 0) {
if (sarg != null && rowIndexStride > 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.rowIndexStride = opts.getRowIndexStride();
this.buildIndex = opts.isBuildIndex() && (rowIndexStride > 0);

@deshanxiao
Copy link
Contributor

deshanxiao commented Dec 19, 2022

Thank you @cxzl25. This is a good fix. The main problem is the the inconsistency of reading and writing implementation.

@deshanxiao
Copy link
Contributor

CC @dongjoon-hyun @guiyanakuang

@guiyanakuang
Copy link
Member

Thank you for making a PR.

I think it would be better to also make the writer reset the negative rowIndexStride to 0. This provides a wider range of compatibility. Allowing a negative rowIndexStride to be written to the file footer, then older versions of the ORC reader will still not be read correctly.

Copy link
Member

@guiyanakuang guiyanakuang left a comment

Choose a reason for hiding this comment

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

+1 LGTM

Copy link
Member

@williamhyun williamhyun left a comment

Choose a reason for hiding this comment

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

+1 LGTM

williamhyun pushed a commit that referenced this pull request Dec 26, 2022
### What changes were proposed in this pull request?
searchArgument takes effect only when rowIndexStride is greater than 0.

### Why are the changes needed?
When `orc.row.index.stride` is set to a negative number, using searchArgument will throw NegativeArraySizeException.

```java
Caused by: java.lang.NegativeArraySizeException
	at org.apache.orc.impl.RecordReaderImpl$SargApplier.pickRowGroups(RecordReaderImpl.java:1164)
	at org.apache.orc.impl.RecordReaderImpl.pickRowGroups(RecordReaderImpl.java:1273)
	at org.apache.orc.impl.RecordReaderImpl.readStripe(RecordReaderImpl.java:1293)
	at org.apache.orc.impl.RecordReaderImpl.advanceStripe(RecordReaderImpl.java:1345)
	at org.apache.orc.impl.RecordReaderImpl.advanceToNextRow(RecordReaderImpl.java:1388)
	at org.apache.orc.impl.RecordReaderImpl.<init>(RecordReaderImpl.java:367)
```

### How was this patch tested?
add UT

Closes #1340 from cxzl25/ORC-1332.

Authored-by: sychen <sychen@ctrip.com>
Signed-off-by: William Hyun <william@apache.org>
(cherry picked from commit ae84ad0)
Signed-off-by: William Hyun <william@apache.org>
@dongjoon-hyun dongjoon-hyun added this to the 1.8.2 milestone Dec 27, 2022
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, late LGTM.

dongjoon-hyun pushed a commit that referenced this pull request Jan 6, 2023
### What changes were proposed in this pull request?
searchArgument takes effect only when rowIndexStride is greater than 0.

### Why are the changes needed?
When `orc.row.index.stride` is set to a negative number, using searchArgument will throw NegativeArraySizeException.

```java
Caused by: java.lang.NegativeArraySizeException
	at org.apache.orc.impl.RecordReaderImpl$SargApplier.pickRowGroups(RecordReaderImpl.java:1164)
	at org.apache.orc.impl.RecordReaderImpl.pickRowGroups(RecordReaderImpl.java:1273)
	at org.apache.orc.impl.RecordReaderImpl.readStripe(RecordReaderImpl.java:1293)
	at org.apache.orc.impl.RecordReaderImpl.advanceStripe(RecordReaderImpl.java:1345)
	at org.apache.orc.impl.RecordReaderImpl.advanceToNextRow(RecordReaderImpl.java:1388)
	at org.apache.orc.impl.RecordReaderImpl.<init>(RecordReaderImpl.java:367)
```

### How was this patch tested?
add UT

Closes #1340 from cxzl25/ORC-1332.

Authored-by: sychen <sychen@ctrip.com>
Signed-off-by: William Hyun <william@apache.org>
(cherry picked from commit ae84ad0)
Signed-off-by: William Hyun <william@apache.org>
(cherry picked from commit 38aef73)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@dongjoon-hyun
Copy link
Member

I backported this to branch-1.7 too.

@dongjoon-hyun dongjoon-hyun modified the milestones: 1.8.2, 1.7.8 Jan 6, 2023
cxzl25 added a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
### What changes were proposed in this pull request?
searchArgument takes effect only when rowIndexStride is greater than 0.

### Why are the changes needed?
When `orc.row.index.stride` is set to a negative number, using searchArgument will throw NegativeArraySizeException.

```java
Caused by: java.lang.NegativeArraySizeException
	at org.apache.orc.impl.RecordReaderImpl$SargApplier.pickRowGroups(RecordReaderImpl.java:1164)
	at org.apache.orc.impl.RecordReaderImpl.pickRowGroups(RecordReaderImpl.java:1273)
	at org.apache.orc.impl.RecordReaderImpl.readStripe(RecordReaderImpl.java:1293)
	at org.apache.orc.impl.RecordReaderImpl.advanceStripe(RecordReaderImpl.java:1345)
	at org.apache.orc.impl.RecordReaderImpl.advanceToNextRow(RecordReaderImpl.java:1388)
	at org.apache.orc.impl.RecordReaderImpl.<init>(RecordReaderImpl.java:367)
```

### How was this patch tested?
add UT

Closes apache#1340 from cxzl25/ORC-1332.

Authored-by: sychen <sychen@ctrip.com>
Signed-off-by: William Hyun <william@apache.org>
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.

None yet

5 participants