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-1796: [C++] fix return wrong result if lack of hasnull #2055

Closed
wants to merge 4 commits into from

Conversation

shuai-xu
Copy link
Contributor

What changes were proposed in this pull request?

This pr fix the bug that if the column statistics in a orc file is not fully written, and lack of hasnull field, user may get a wrong result using c++ to read it.
For example, a file struct<string col1, string col2>, has 10 lines, col1 all has value, col2 all is null. the column 1's stat written by trino may be
numberOfValues: 10
stringStatistics {
minimum: "10"
maximum: "100"
sum: 565
}. col2's stat is numberOfValues: 0. They all have no hasnull field. When we want to get where col2 is null, we will get nothing.

Why are the changes needed?

User may get a wrong result with this bug.

How was this patch tested?

Add unit tests.

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

No

@github-actions github-actions bot added the CPP label Oct 25, 2024
@wgtmac
Copy link
Member

wgtmac commented Oct 27, 2024

Thanks for the fix! It makes sense to me. Please make the CI happy.

BTW, has Trino fixed this issue on its writer side?

@shuai-xu
Copy link
Contributor Author

Thanks for the fix! It makes sense to me. Please make the CI happy.

BTW, has Trino fixed this issue on its writer side?

The ci is fixed, it seems need approval to rerun. We are trying to fix it on Trino.

@wgtmac
Copy link
Member

wgtmac commented Oct 28, 2024

Please fix the format check. Thanks!

@shuai-xu
Copy link
Contributor Author

Please fix the format check. Thanks!

Done, CI passed.

Copy link
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

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, LGTM.

@dongjoon-hyun
Copy link
Member

What is the target version for this fix, @shuai-xu and @wgtmac ?

@wgtmac
Copy link
Member

wgtmac commented Oct 29, 2024

I think we can backport this to 1.9 and 1.8?

@wgtmac wgtmac closed this in e492bef Oct 29, 2024
wgtmac pushed a commit that referenced this pull request Oct 29, 2024
### What changes were proposed in this pull request?
This pr fix the bug that if the column statistics in a orc file is not fully written, and lack of hasnull field, user may get a wrong result using c++ to read it.
For example, a file struct<string col1, string col2>, has 10 lines, col1 all has value, col2 all is null. the column 1's stat written by trino may be
numberOfValues: 10
stringStatistics {
  minimum: "10"
  maximum: "100"
  sum: 565
}. col2's stat is  numberOfValues: 0. They all have no hasnull field. When we want to get where col2 is null, we will get nothing.

### Why are the changes needed?
User may get a wrong result with this bug.

### How was this patch tested?
Add unit tests.

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

Closes #2055 from shuai-xu/2054.

Authored-by: shuai-xu <xushuai@bigo.sg>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
(cherry picked from commit e492bef)
Signed-off-by: Gang Wu <ustcwg@gmail.com>
@wgtmac
Copy link
Member

wgtmac commented Oct 29, 2024

I just merged it and backported it to branch-2.0. The backport to branch-1.9 failed due to our code style change since 2.0.

@dongjoon-hyun
Copy link
Member

+1 for backporting decision. Thank you!

@dongjoon-hyun dongjoon-hyun added this to the 2.0.3 milestone Oct 29, 2024
@dongjoon-hyun
Copy link
Member

Ur, @wgtmac and @shuai-xu , the JIRA ID looks wrong to me. Where this ID comes from?

@wgtmac
Copy link
Member

wgtmac commented Oct 29, 2024

Sorry that I didn't check the JIRA id in title. :(

@shuai-xu
Copy link
Contributor Author

@dongjoon-hyun sorry, I open the issue on github #2054, need I open one on jira?

@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Oct 31, 2024

Since we didn't make any releases or tags yet, it's recoverable if we do reset those branches, master and branch-2.0. Although it could affect the downstream, do you mind resetting them, @wgtmac and @shuai-xu ?

@dongjoon-hyun
Copy link
Member

BTW, I also missed this. So, you don't need to feel sorry about this. We can recover this in a correct way.

@wgtmac wgtmac changed the title ORC-2054: [C++] fix return wrong result if lack of hasnull ORC-1796: [C++] fix return wrong result if lack of hasnull Oct 31, 2024
wgtmac pushed a commit that referenced this pull request Oct 31, 2024
This pr fix the bug that if the column statistics in a orc file is not fully written, and lack of hasnull field, user may get a wrong result using c++ to read it.
For example, a file struct<string col1, string col2>, has 10 lines, col1 all has value, col2 all is null. the column 1's stat written by trino may be
numberOfValues: 10
stringStatistics {
  minimum: "10"
  maximum: "100"
  sum: 565
}. col2's stat is  numberOfValues: 0. They all have no hasnull field. When we want to get where col2 is null, we will get nothing.

User may get a wrong result with this bug.

Add unit tests.

No

Closes #2055 from shuai-xu/2054.

Authored-by: shuai-xu <xushuai@bigo.sg>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
wgtmac pushed a commit that referenced this pull request Oct 31, 2024
This pr fix the bug that if the column statistics in a orc file is not fully written, and lack of hasnull field, user may get a wrong result using c++ to read it.
For example, a file struct<string col1, string col2>, has 10 lines, col1 all has value, col2 all is null. the column 1's stat written by trino may be
numberOfValues: 10
stringStatistics {
  minimum: "10"
  maximum: "100"
  sum: 565
}. col2's stat is  numberOfValues: 0. They all have no hasnull field. When we want to get where col2 is null, we will get nothing.

User may get a wrong result with this bug.

Add unit tests.

No

Closes #2055 from shuai-xu/2054.

Authored-by: shuai-xu <xushuai@bigo.sg>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
(cherry picked from commit e492bef)
Signed-off-by: Gang Wu <ustcwg@gmail.com>
@wgtmac
Copy link
Member

wgtmac commented Oct 31, 2024

I have created https://issues.apache.org/jira/browse/ORC-1796 and fix the commits in both main and branch-2.0 branches.

kou pushed a commit to apache/arrow that referenced this pull request Nov 17, 2024
### Rationale for this change

This PR aims to upgrade ORC to 2.0.3 to bring the following bug fixes.
- https://orc.apache.org/news/2024/08/15/ORC-2.0.2/
  - apache/orc#1963
  - apache/orc#1997
  - apache/orc#1981
- https://orc.apache.org/news/2024/11/14/ORC-2.0.3/
  - apache/orc#2055

### What changes are included in this PR?

To use the latest bug fixed version.

### Are these changes tested?

This should pass the CIs.

### Are there any user-facing changes?

No.
* GitHub Issue: #44744

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
dongjoon-hyun pushed a commit that referenced this pull request Dec 12, 2024
### What changes were proposed in this pull request?
close: #2079
relate pr: #2055
Introduce fallback logic in the C++ reader to set hasNull to true when the field is missing, similar to the Java implementation.
The Java implementation includes the following logic:
```java
if (stats.hasHasNull()) {
    hasNull = stats.getHasNull();
} else {
    hasNull = true;
}
```
In contrast, the C++ implementation directly uses the has_null value without any fallback logic:
```c++
ColumnStatisticsImpl::ColumnStatisticsImpl(const proto::ColumnStatistics& pb) {
    stats_.setNumberOfValues(pb.number_of_values());
    stats_.setHasNull(pb.has_null());
}
```
### Why are the changes needed?
We encountered an issue with the C++ implementation of the ORC reader when handling ORC files written with version 0.12. Specifically, files written in this version do not include the hasNull field in the column statistics metadata. While the Java implementation of the ORC reader handles this gracefully by defaulting hasNull to true when the field is absent, the C++ implementation does not handle this scenario correctly.
**This issue prevents predicates like IS NULL from being pushed down to the ORC reader!!! As a result, all rows in the file are filtered out, leading to incorrect query results :(**
### How was this patch tested?
I have tested this using [Doris](https://github.com/apache/doris) external pipeline:
apache/doris#45104
apache/doris-thirdparty#259

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

Closes #2082 from suxiaogang223/fix_has_null.

Authored-by: Socrates <suxiaogang223@icloud.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
suxiaogang223 added a commit to suxiaogang223/orc that referenced this pull request Dec 16, 2024
close: apache#2079
relate pr: apache#2055
Introduce fallback logic in the C++ reader to set hasNull to true when the field is missing, similar to the Java implementation.
The Java implementation includes the following logic:
```java
if (stats.hasHasNull()) {
    hasNull = stats.getHasNull();
} else {
    hasNull = true;
}
```
In contrast, the C++ implementation directly uses the has_null value without any fallback logic:
```c++
ColumnStatisticsImpl::ColumnStatisticsImpl(const proto::ColumnStatistics& pb) {
    stats_.setNumberOfValues(pb.number_of_values());
    stats_.setHasNull(pb.has_null());
}
```
We encountered an issue with the C++ implementation of the ORC reader when handling ORC files written with version 0.12. Specifically, files written in this version do not include the hasNull field in the column statistics metadata. While the Java implementation of the ORC reader handles this gracefully by defaulting hasNull to true when the field is absent, the C++ implementation does not handle this scenario correctly.
**This issue prevents predicates like IS NULL from being pushed down to the ORC reader!!! As a result, all rows in the file are filtered out, leading to incorrect query results :(**
I have tested this using [Doris](https://github.com/apache/doris) external pipeline:
apache/doris#45104
apache/doris-thirdparty#259
No

Closes apache#2082 from suxiaogang223/fix_has_null.

Authored-by: Socrates <suxiaogang223@icloud.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun pushed a commit that referenced this pull request Dec 20, 2024
close: #2079
relate pr: #2055
Introduce fallback logic in the C++ reader to set hasNull to true when the field is missing, similar to the Java implementation. The Java implementation includes the following logic:
```java
if (stats.hasHasNull()) {
    hasNull = stats.getHasNull();
} else {
    hasNull = true;
}
```
In contrast, the C++ implementation directly uses the has_null value without any fallback logic:
```c++
ColumnStatisticsImpl::ColumnStatisticsImpl(const proto::ColumnStatistics& pb) {
    stats_.setNumberOfValues(pb.number_of_values());
    stats_.setHasNull(pb.has_null());
}
```
We encountered an issue with the C++ implementation of the ORC reader when handling ORC files written with version 0.12. Specifically, files written in this version do not include the hasNull field in the column statistics metadata. While the Java implementation of the ORC reader handles this gracefully by defaulting hasNull to true when the field is absent, the C++ implementation does not handle this scenario correctly. **This issue prevents predicates like IS NULL from being pushed down to the ORC reader!!! As a result, all rows in the file are filtered out, leading to incorrect query results :(** I have tested this using [Doris](https://github.com/apache/doris) external pipeline: apache/doris#45104
apache/doris-thirdparty#259 No

Closes #2082 from suxiaogang223/fix_has_null.

Authored-by: Socrates <suxiaogang223icloud.com>

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

### Why are the changes needed?

### How was this patch tested?

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

Closes #2086 from suxiaogang223/cherry_pick_fix_has_null.

Authored-by: Socrates <suxiaogang223@icloud.com>
Signed-off-by: Dongjoon Hyun <dongjoon@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.

3 participants