Skip to content

PARQUET-2327: get min/max column statistics by isset flag - #36814

Closed
rip-nsk wants to merge 1 commit into
apache:mainfrom
rip-nsk:PARQUET-2327
Closed

rip-nsk wants to merge 1 commit into
apache:mainfrom
rip-nsk:PARQUET-2327

Conversation

@rip-nsk

@rip-nsk rip-nsk commented Jul 21, 2023

Copy link
Copy Markdown
Contributor

Rationale for this change

min/max statistics can be stored in column chunk metadata in min/max or min_value/max_value fields.
current behavior for selecting a specific pair depends on the sort order, which may contradict to isset flag.

What changes are included in this PR?

Trivial change to get min/max column statistics by isset flag

Are these changes tested?

tested on customers data.

Are there any user-facing changes?

no

@rip-nsk
rip-nsk requested a review from wgtmac as a code owner July 21, 2023 17:31
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

⚠️ Ticket has no components in JIRA, make sure you assign one.

@github-actions

Copy link
Copy Markdown

⚠️ Ticket has not been started in JIRA, please click 'Start Progress'.

// If ColumnOrder is defined, return max_value and min_value
if (descr->column_order().get_order() == ColumnOrder::TYPE_DEFINED_ORDER) {
// Return max_value and min_value if defined
if (metadata.statistics.__isset.max_value || metadata.statistics.__isset.min_value) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think ColumnOrder checking can be removed here. If a writer does not set ColumnOrder but writes both min/max and min_value/max_value, we should still get stats from min/max as per the specs.

@mapleFU mapleFU left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to the standard [1]. If we don't know the column-order, the max-value and min-value cannot be used. So the origin code here is ok.

However, I guess current impl is a bit weired, if it's column-order is unknown, it seek from min and max. Should we just return min-max not set. I guess the origin code is for compatible with legacy min and max. Can @pitrou confirm that?

In Java Parquet-mr and arrow-rs, if column-order is undefined, the behavior seems similiar. Rust think that it would be a SIGNED order[2], and parquet-mr[3] thinks it would be better to discard the min_value and max_value statistics

[1] https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift#L219
[2] https://github.com/apache/arrow-rs/blob/master/parquet/src/basic.rs#L450
[3] apache/parquet-java@c6764c4#diff-1afc9f89a782ddd4e7cd17546ca048954091627d7a31597ab88892eb2a7a76ab

@mapleFU

mapleFU commented Jul 22, 2023 •

Copy link
Copy Markdown
Member

By the way, do we discard the min-max when order is not SINGED @wgtmac ? Seems if order is not SIGNED, using min-max is a bit dangerous
I think we didn't handle this, maybe I should port some code from parquet-mr?

@rip-nsk

rip-nsk commented Jul 22, 2023

Copy link
Copy Markdown
Contributor Author

I have customers file set (table, writer id - "parquet-mr compatible Photon version 0.2")
where min/max_value are set for string column with undefined order - current implementation ignores them.
In general, for row group filtering (using range predicate by min/max) sort order does not matter,
only the correct min/max values are needed.

@mapleFU

mapleFU commented Jul 23, 2023

Copy link
Copy Markdown
Member

In general, for row group filtering (using range predicate by min/max) sort order does not matter,
only the correct min/max values are needed.

Hmmm, for example, if you're using int32 and uint32, the encoded bytes might be the same, but the handling method would be different. As for string, it might has different collations. So just compare the binary usally doesn't get the right result. As the spec saying [1] "without column_orders, the meaning of the min_value and max_value fields in the Statistics object and the ColumnIndex object is undefined". So I guess this code can not checking.

I think you can confirm with Photon contributor, and as for solving it, you can prune using thrift Statistics.

[1] https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift#L1049

@pitrou

pitrou commented Jul 24, 2023

Copy link
Copy Markdown
Member

I agree with @wgtmac and @mapleFU . The original code looks correct to me and the proposed change does not conform to the spec.

@rip-nsk

rip-nsk commented Jul 25, 2023 •

Copy link
Copy Markdown
Contributor Author

Hmmm, for example, if you're using int32 and uint32, the encoded bytes might be the same, but the handling method would be different. As for string, it might has different collations. So just compare the binary usally doesn't get the right result.

just to confirm, let's we have column chunk with values V1..Vn,
I assume that statistic's min <= of any V1..Vn, and correspondently max >= any of V1..Vn
if I understand correctly, this may be guarantied only for min_value/max_value and only if sort order is not UNDEFINED.
If so, silent returning min/max in other cases may be wrong.

@mapleFU

mapleFU commented Jul 25, 2023

Copy link
Copy Markdown
Member

Yes, you're right. Here maybe it's better to check:

  1. If the Columnorder and min_value max_value exists, just return it
  2. If the sort-order is SIGNED, return min max is ok
  3. If the sort-order is not SIGNED, we cannot gurantee anything

Current implemention may regard hasing min max as they pretent to use SIGNED, as I mentioned here #36814 (comment) . Maybe I can try to fix it this week

@mapleFU

mapleFU commented Jul 25, 2023

Copy link
Copy Markdown
Member

As #34139 mentioned, I'll try to fix it this week.

@mapleFU

mapleFU commented Aug 27, 2023

Copy link
Copy Markdown
Member

@rip-nsk Can we close this pr? Since the statistic is already disabled.

@mapleFU

mapleFU commented Feb 19, 2024

Copy link
Copy Markdown
Member

Close this first. Feel free to reopen it

@mapleFU mapleFU closed this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants