Skip to content

GH-34139: [C++][Parquet] disable UNSIGNED min-max when not has min_value and max_value - #36866

Closed
mapleFU wants to merge 1 commit into
apache:mainfrom
mapleFU:parquet/disable-min-max-when-order-not-signed
Closed

mapleFU wants to merge 1 commit into
apache:mainfrom
mapleFU:parquet/disable-min-max-when-order-not-signed

Conversation

@mapleFU

@mapleFU mapleFU commented Jul 25, 2023 •

Copy link
Copy Markdown
Member

Rationale for this change

As mentioned:

  1. [C++][Parquet] Ignore corrupted or invalid statistics  #34139
  2. PARQUET-2327: get min/max column statistics by isset flag #36814

disable min max when min_value max_value is not reachable. And sort-order is not SIGNED

What changes are included in this PR?

add a can_has_legacy_min_max check here.

Are these changes tested?

no

Are there any user-facing changes?

Yes, some user may cannot get the statistics here.

@mapleFU
mapleFU requested a review from wgtmac as a code owner July 25, 2023 11:43
@mapleFU

mapleFU commented Jul 25, 2023

Copy link
Copy Markdown
Member Author

@wgtmac @pitrou
Also cc @rip-nsk

@pitrou

pitrou commented Jul 25, 2023

Copy link
Copy Markdown
Member

What does parquet-mr do in this situation?

Comment thread cpp/src/parquet/metadata.cc Resolved
@mapleFU
mapleFU force-pushed the parquet/disable-min-max-when-order-not-signed branch from 62b8050 to 83f6a2a Compare July 25, 2023 13:48
metadata.statistics.null_count, metadata.statistics.distinct_count,
metadata.statistics.__isset.max || metadata.statistics.__isset.min,
can_use_legacy_min_max &&
(metadata.statistics.__isset.max || metadata.statistics.__isset.min),

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.

Note that parquet-mr uses && rather than ||. It probably doesn't make a difference in practice (either min/max are both available, or none is available).

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 tried to change || to && in an old PR and it caused some test failure because filter pushdown of dataset scanner can handle the case when either min or max is missing.

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.

Ah, funny. Let's keep it like this, then.

@pitrou

pitrou commented Jul 25, 2023

Copy link
Copy Markdown
Member

@mapleFU Would it be easy to add a test here?

@mapleFU

mapleFU commented Jul 25, 2023

Copy link
Copy Markdown
Member Author

I can try to add one in metadata_test.cc tomorrow, so tired today

@mapleFU

mapleFU commented Jul 26, 2023

Copy link
Copy Markdown
Member Author

Oops, I found a HasCorrectStats here:

// Reference:
// parquet-mr/parquet-column/src/main/java/org/apache/parquet/CorruptStatistics.java
// PARQUET-686 has more discussion on statistics
bool ApplicationVersion::HasCorrectStatistics(Type::type col_type,
                                              EncodedStatistics& statistics,
                                              SortOrder::type sort_order) const {
  // parquet-cpp version 1.3.0 and parquet-mr 1.10.0 onwards stats are computed
  // correctly for all types
  if ((application_ == "parquet-cpp" && VersionLt(PARQUET_CPP_FIXED_STATS_VERSION())) ||
      (application_ == "parquet-mr" && VersionLt(PARQUET_MR_FIXED_STATS_VERSION()))) {
    // Only SIGNED are valid unless max and min are the same
    // (in which case the sort order does not matter)
    bool max_equals_min = statistics.has_min && statistics.has_max
                              ? statistics.min() == statistics.max()
                              : false;
    if (SortOrder::SIGNED != sort_order && !max_equals_min) {
      return false;
    }

    // Statistics of other types are OK
    if (col_type != Type::FIXED_LEN_BYTE_ARRAY && col_type != Type::BYTE_ARRAY) {
      return true;
    }
  }
  // created_by is not populated, which could have been caused by
  // parquet-mr during the same time as PARQUET-251, see PARQUET-297
  if (application_ == "unknown") {
    return true;
  }

  // Unknown sort order has incorrect stats
  if (SortOrder::UNKNOWN == sort_order) {
    return false;
  }

  // PARQUET-251
  if (VersionLt(PARQUET_251_FIXED_VERSION())) {
    return false;
  }

  return true;
}

Though Statistics would be wrong when parsing from ColumnMetadata, however, when calling ColumnChunkMetadata::statistics(), it will found that it's an old file and discard it.

Should I keep this code to avoid generate Statistics with ambigious min-max? Or just leave the code here? @pitrou @wgtmac

@wgtmac

wgtmac commented Jul 26, 2023

Copy link
Copy Markdown
Member

In this case, I would prefer the current behavior and close this PR.

@pitrou

pitrou commented Jul 26, 2023

Copy link
Copy Markdown
Member

HasCorrectStatistics isn't used by MakeTypedStatistics, is it?

@pitrou

pitrou commented Jul 26, 2023 •

Copy link
Copy Markdown
Member

Ah, I see, it's the other way round: Statistics uses both HasCorrectStatistics and MakeTypedColumnStats under the hood. So I agree this can be closed.

@mapleFU

mapleFU commented Jul 27, 2023

Copy link
Copy Markdown
Member Author

Close as already fixed

@mapleFU mapleFU closed this Jul 27, 2023
@mapleFU
mapleFU deleted the parquet/disable-min-max-when-order-not-signed branch July 30, 2023 12:23
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.

[C++][Parquet] Ignore corrupted or invalid statistics

3 participants