Skip to content

Filtering records across multiple blocks - #1

Closed
onlynone wants to merge 2 commits into
apache:masterfrom
onlynone:multiple_blocks
Closed

onlynone wants to merge 2 commits into
apache:masterfrom
onlynone:multiple_blocks

Conversation

@onlynone

Copy link
Copy Markdown

Copied from: https://github.com/Parquet/parquet-mr/pull/413

However, as tomwhite mentioned, there might be a better way to do this.

I had also written this:

current ++; still doesn't seem correct even when currentValue != null. Imagine a block with 100 records, but only the record at position 50 matches our filter. In this case, the first time nextKeyValue() is called, it will call recordReader.read() which will successfully find the record at pos 50, but current will just be incremented to 1.

dsy88 referenced this pull request in dsy88/incubator-parquet-mr Jun 20, 2014
dsy88 referenced this pull request in dsy88/incubator-parquet-mr Jun 20, 2014
NULL tuples causes NPE when writing
@tomwhite

Copy link
Copy Markdown
Member

@onlynone, I agree with you, however I think the fix is still functionally correct. That's what I meant about ensuring getProgress() is correct - although since it is used to give a rough measure of MR progress this change doesn't break applications, it just underestimates progress.

Having said that, here's another fix that correctly updates current: https://github.com/tomwhite/parquet-mr/compare/pr-413-change-filtering

@rdblue

rdblue commented Jun 26, 2014

Copy link
Copy Markdown
Contributor

I think that Tom's fix is correct and that's a reasonable work-around for right now. But I'd rather get rid of the recursive call because that will increase the stack for each filtered record. Here's a version that just loops until the internal reader starts returning non-null records again. It also checks to make sure the total isn't going past the currently loaded limit so that there aren't conditions where it would loop infinitely.

      try {
        checkRead();
        currentValue = recordReader.read();
        current ++;
        // only happens with FilteredRecordReader at end of block
        while (currentValue == null && current < total && current <= totalCountLoadedSoFar) {
          checkRead();
          currentValue = recordReader.read();
          current ++;
        }
        if (DEBUG) LOG.debug("read value: " + currentValue);
      } catch (RuntimeException e) {
        throw new ParquetDecodingException(format("Can not read value at %d in block %d in file %s", current, currentBlock, file), e);
      }

Like you said, a real fix needs to correctly keep track of the records that are filtered out. How about adding a count accessor to parquet.io.RecordReader? That would be a quick fix, but I'd rather see a better contract with the record reader that strictly defines behavior when it runs out of records and maybe keeps track internally. Iterator is good inspiration.

@tomwhite

Copy link
Copy Markdown
Member

Thanks for the review @rdblue. I agree that the minimal fix is the way to go to get this fixed in the short term; for one thing changing (Filtered)RecordReader causes the semantic versioning plugin to complain.

I've updated the minimal fix to avoid the recursive call as you suggested. See https://github.com/apache/incubator-parquet-mr/pull/9. It's slightly different to your code since we need to take account of the case where there are no further non-null records - i.e. the while loop needs to return false for that case. I've added a test for that case and also for the case where only the last block has a record that matches the filter.

@julienledem

Copy link
Copy Markdown
Member

LGTM.
Could you Open a parquet JIRA and prefix the name of the PR with its ID as described in the following link ?
https://github.com/apache/incubator-parquet-mr/pull/8/files?short_path=6a33714#diff-6a3371457528722a734f3c51d9238c13

@rdblue

rdblue commented Jun 27, 2014

Copy link
Copy Markdown
Contributor

Thanks for taking a look, Julien. I've opened PARQUET-9 for this.

asfgit referenced this pull request Jul 16, 2014
Update of the minimal fix discussed in https://github.com/apache/incubator-parquet-mr/pull/1, with the recursive call changed to to a loop.

Author: Tom White <tom@cloudera.com>
Author: Steven Willis <swillis@compete.com>

Closes #9 from tomwhite/filtering-records-across-multiple-blocks and squashes the following commits:

afb08a4 [Tom White] Minimal fix
9e723ee [Steven Willis] Test for filtering records across multiple blocks
@julienledem

Copy link
Copy Markdown
Member

Was this included in https://github.com/apache/incubator-parquet-mr/pull/9 ?

@rdblue

rdblue commented Jul 21, 2014

Copy link
Copy Markdown
Contributor

@julienledem: yes. I think Tom had to create a new pull request because he couldn't push review changes to this one.

@julienledem

Copy link
Copy Markdown
Member

This is fixed:
apache/incubator-parquet-mr@2d8ebdb
@onlynone could you close this pull request?

@onlynone

Copy link
Copy Markdown
Author

Thanks Guys!

@onlynone onlynone closed this Jul 31, 2014
@julienledem

Copy link
Copy Markdown
Member

Thank you @onlynone !

rdblue referenced this pull request in rdblue/parquet-mr Aug 11, 2014
Update of the minimal fix discussed in https://github.com/apache/incubator-parquet-mr/pull/1, with the recursive call changed to to a loop.

Author: Tom White <tom@cloudera.com>
Author: Steven Willis <swillis@compete.com>

Closes apache#9 from tomwhite/filtering-records-across-multiple-blocks and squashes the following commits:

afb08a4 [Tom White] Minimal fix
9e723ee [Steven Willis] Test for filtering records across multiple blocks
parthchandra pushed a commit to parthchandra/incubator-parquet-mr that referenced this pull request Sep 4, 2014
merge apache/incubator-parquet-mr
abayer referenced this pull request in cloudera/parquet-mr Oct 13, 2014
Update of the minimal fix discussed in https://github.com/apache/incubator-parquet-mr/pull/1, with the recursive call changed to to a loop.

Author: Tom White <tom@cloudera.com>
Author: Steven Willis <swillis@compete.com>

Closes #9 from tomwhite/filtering-records-across-multiple-blocks and squashes the following commits:

afb08a4 [Tom White] Minimal fix
9e723ee [Steven Willis] Test for filtering records across multiple blocks
abayer referenced this pull request in cloudera/parquet-mr Dec 4, 2014
Update of the minimal fix discussed in https://github.com/apache/incubator-parquet-mr/pull/1, with the recursive call changed to to a loop.

Author: Tom White <tom@cloudera.com>
Author: Steven Willis <swillis@compete.com>

Closes #9 from tomwhite/filtering-records-across-multiple-blocks and squashes the following commits:

afb08a4 [Tom White] Minimal fix
9e723ee [Steven Willis] Test for filtering records across multiple blocks
asfgit pushed a commit that referenced this pull request Jan 27, 2015
…ng/binary column trunk are null

In case of all nulls in a binary column, statistics object read from file metadata is empty, and should return true for all nulls check for the column. Even if column has no values, it can be ignored.

The other way is to fix this behaviour in the writer, but is that what we want ?

Author: Yash Datta <Yash.Datta@guavus.com>
Author: Alex Levenson <alexlevenson@twitter.com>
Author: Yash Datta <saucam@gmail.com>

Closes #99 from saucam/npe and squashes the following commits:

5138e44 [Yash Datta] PARQUET-136: Remove unreachable block
b17cd38 [Yash Datta] Revert "PARQUET-161: Trigger tests"
82209e6 [Yash Datta] PARQUET-161: Trigger tests
aab2f81 [Yash Datta] PARQUET-161: Review comments for the test case
2217ee2 [Yash Datta] PARQUET-161: Add a test case for checking the correct statistics info is recorded in case of all nulls in a column
c2f8d6f [Yash Datta] PARQUET-161: Fix the write path to write statistics object in case of only nulls in the column
97bb517 [Yash Datta] Revert "revert TestStatisticsFilter.java"
a06f0d0 [Yash Datta] Merge pull request #1 from isnotinvain/alexlevenson/PARQUET-161-136
b1001eb [Alex Levenson] Fix statistics isEmpty, handle more edge cases in statistics filter
0c88be0 [Alex Levenson] revert TestStatisticsFilter.java
1ac9192 [Yash Datta] PARQUET-136: Its better to not filter chunks for which empty statistics object is returned. Empty statistics can be read in case of 1. pre-statistics files, 2. files written from current writer that has a bug, as it does not write the statistics if column has all nulls
e5e924e [Yash Datta] Revert "PARQUET-136: In case of all nulls in a binary column, statistics object read from file metadata is empty, and should return true for all nulls check for the column"
8cc5106 [Yash Datta] Revert "PARQUET-136: fix hasNulls to cater to the case where all values are nulls"
c7c126f [Yash Datta] PARQUET-136: fix hasNulls to cater to the case where all values are nulls
974a22b [Yash Datta] PARQUET-136: In case of all nulls in a binary column, statistics object read from file metadata is empty, and should return true for all nulls check for the column
dongche pushed a commit to dongche/incubator-parquet-mr that referenced this pull request Feb 3, 2015
…ng/binary column trunk are null

In case of all nulls in a binary column, statistics object read from file metadata is empty, and should return true for all nulls check for the column. Even if column has no values, it can be ignored.

The other way is to fix this behaviour in the writer, but is that what we want ?

Author: Yash Datta <Yash.Datta@guavus.com>
Author: Alex Levenson <alexlevenson@twitter.com>
Author: Yash Datta <saucam@gmail.com>

Closes apache#99 from saucam/npe and squashes the following commits:

5138e44 [Yash Datta] PARQUET-136: Remove unreachable block
b17cd38 [Yash Datta] Revert "PARQUET-161: Trigger tests"
82209e6 [Yash Datta] PARQUET-161: Trigger tests
aab2f81 [Yash Datta] PARQUET-161: Review comments for the test case
2217ee2 [Yash Datta] PARQUET-161: Add a test case for checking the correct statistics info is recorded in case of all nulls in a column
c2f8d6f [Yash Datta] PARQUET-161: Fix the write path to write statistics object in case of only nulls in the column
97bb517 [Yash Datta] Revert "revert TestStatisticsFilter.java"
a06f0d0 [Yash Datta] Merge pull request apache#1 from isnotinvain/alexlevenson/PARQUET-161-136
b1001eb [Alex Levenson] Fix statistics isEmpty, handle more edge cases in statistics filter
0c88be0 [Alex Levenson] revert TestStatisticsFilter.java
1ac9192 [Yash Datta] PARQUET-136: Its better to not filter chunks for which empty statistics object is returned. Empty statistics can be read in case of 1. pre-statistics files, 2. files written from current writer that has a bug, as it does not write the statistics if column has all nulls
e5e924e [Yash Datta] Revert "PARQUET-136: In case of all nulls in a binary column, statistics object read from file metadata is empty, and should return true for all nulls check for the column"
8cc5106 [Yash Datta] Revert "PARQUET-136: fix hasNulls to cater to the case where all values are nulls"
c7c126f [Yash Datta] PARQUET-136: fix hasNulls to cater to the case where all values are nulls
974a22b [Yash Datta] PARQUET-136: In case of all nulls in a binary column, statistics object read from file metadata is empty, and should return true for all nulls check for the column
asfgit pushed a commit that referenced this pull request Jun 17, 2015
...thod

Author: Alex Levenson <alexlevenson@twitter.com>
Author: Konstantin Shaposhnikov <Konstantin.Shaposhnikov@sc.com>
Author: kostya-sh <kostya-sh@users.noreply.github.com>

Closes #171 from kostya-sh/PARQUET-246 and squashes the following commits:

75950c5 [kostya-sh] Merge pull request #1 from isnotinvain/PR-171
a718309 [Konstantin Shaposhnikov] Merge remote-tracking branch 'refs/remotes/origin/master' into PARQUET-246
0367588 [Alex Levenson] Add regression test for PR-171
94e8fda [Alex Levenson] Merge branch 'master' into PR-171
0a9ac9f [Konstantin Shaposhnikov] [PARQUET-246] bugfix: reset all DeltaByteArrayWriter state in reset() method
asfgit pushed a commit that referenced this pull request Sep 18, 2015
In response to PARQUET-251 created an integration test that generates random values and compares the statistics against the values read from a parquet file.

There are two tools classes `DataGenerationContext` and `RandomValueGenerators` which are located in the same package as the unit test. I'm sure there is a better place to put these, but I leave that to your discretion.

Thanks
Reuben

Author: Reuben Kuhnert <sircodesalot@gmail.com>
Author: Ryan Blue <blue@apache.org>

Closes #255 from sircodesalotOfTheRound/stats-validation and squashes the following commits:

680e96a [Reuben Kuhnert] Merge pull request #1 from rdblue/PARQUET-355-stats-validation-tests
9f0033f [Ryan Blue] PARQUET-355: Use ColumnReaderImpl.
7d0b4fe [Reuben Kuhnert] PARQUET-355: Add Statistics Validation Test
asfgit pushed a commit that referenced this pull request Jan 19, 2017
In response to PARQUET-251 created an integration test that generates random values and compares the statistics against the values read from a parquet file.

There are two tools classes `DataGenerationContext` and `RandomValueGenerators` which are located in the same package as the unit test. I'm sure there is a better place to put these, but I leave that to your discretion.

Thanks
Reuben

Author: Reuben Kuhnert <sircodesalot@gmail.com>
Author: Ryan Blue <blue@apache.org>

Closes #255 from sircodesalotOfTheRound/stats-validation and squashes the following commits:

680e96a [Reuben Kuhnert] Merge pull request #1 from rdblue/PARQUET-355-stats-validation-tests
9f0033f [Ryan Blue] PARQUET-355: Use ColumnReaderImpl.
7d0b4fe [Reuben Kuhnert] PARQUET-355: Add Statistics Validation Test
gszadovszky pushed a commit to gszadovszky/parquet-mr that referenced this pull request Dec 13, 2018
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Oct 30, 2020
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Oct 30, 2020
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Oct 30, 2020
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Oct 30, 2020
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Oct 30, 2020
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Oct 30, 2020
shangxinli added a commit to shangxinli/parquet-mr that referenced this pull request Nov 1, 2020
LantaoJin pushed a commit to LantaoJin/parquet-mr that referenced this pull request Jun 15, 2021
Fokko pushed a commit that referenced this pull request Nov 5, 2026
* Introduce implementation for FileType

* address

* address comments and update spec

* update to spec

* Introduce self-reference reader/writer APIs

* Add threshold-driven inline vs self-reference storage for FILE values (#1)

* Add threshold-driven inline vs self-reference storage for FILE values

Writers hand FILE payloads to FileValueWriter, which decides from a
configured threshold whether to keep the bytes inline or store them out
of line as a self-reference. Both forms describe the same logical bytes,
so content_type and checksum are written identically either way and
consumers see no difference beyond which fields are set.

The payload is written eagerly, while the record is being written and
before the row group's column chunks are flushed. This is what makes the
offset knowable in time: offset and size are ordinary column values, and
once a value reaches a column writer it is encoded into a buffered page
and cannot be revised, so a placeholder could not be patched up later.
Writing at that point also leaves each column chunk contiguous on disk,
which the read path relies on when coalescing chunks into range reads.

Along the way, per parquet-format#603:

- Key the self-reference AAD on the file offset rather than a synthetic
  per-chunk counter. The spec defines AAD suffix field 6 as the offset,
  and the counter was not recoverable from the file: nothing stores it,
  so a reader had to walk preceding values to rebuild it, defeating the
  offset-based design that lets a value be resolved on its own. The
  ordinal parameter is gone from five signatures as a result.
- Decompress into a dynamically sized buffer, supporting every codec.
  The previous stream-drain loop was broken for all codecs, not just
  unframed ones: NonBlockedDecompressorStream throws rather than
  returning -1 once its block is consumed.
- Enforce the 2 GiB encrypted-module limit on write, directing oversized
  values to external references.
- Require inline whenever offset is declared. uri is optional per value,
  so a uri+offset+size schema still permits self-references, and one
  emitted without an inline column chunk has no reference point to
  inherit compression and encryption from.

Tests cover threshold routing, offset-keyed AAD round-trips in both GCM
and CTR modes, tamper detection when an offset is altered, and payloads
spanning several buffer doublings across SNAPPY, GZIP, ZSTD and LZ4_RAW.

Co-authored-by: Isaac

* Fix ZSTD resolution, revert schema tightening, fix test imports

Verified the change by building and running the suites locally, which
turned up three things:

ZSTD self-references could not be resolved at all. ZstandardCodec
returns null from createDecompressor because it decompresses only
through its stream, so driving the Decompressor directly failed with
"Could not obtain a decompressor". Such codecs are framed and report
end-of-input properly, so drain the stream for them and keep
grow-and-retry for the rest. Four tests were failing on this.

Reverted requiring `inline` whenever `offset` is declared, back to
requiring it only when `uri` is absent. Two existing tests
(testFileLogicalTypeExternalRangedReferenceWithoutInline,
testFileLogicalTypeOffsetWithSize) assert that a uri+offset+size schema
without `inline` is valid, so the stricter rule contradicted the
author's documented intent. The concern is real -- `uri` is optional per
value, so such a schema can still emit a self-reference with no
reference point -- but it belongs on the write path, and the FILE group
declaring `uri` is now documented as needing an always-inline threshold.

Fixed two pre-existing test compile errors that blocked the module:
TestParquetMetadataConverter used assertEquals/assertTrue with no JUnit
import (switched to the AssertJ style used throughout that file), and
TestSelfReferenceFileWrite was missing the ParquetReadOptions import.
Both fail on the base commit independently of these changes.

Also applied spotless formatting.

Local results: parquet-column 679/679 pass, parquet-hadoop 761/762. The
one failure, testEnumEquivalence on Encoding.ALP, is an artifact of the
local workaround for FileType being unreleased -- parquet.thrift was
substituted from parquet-format master, which defines an ALP encoding
the Java enum does not yet have. It is unrelated to these changes and
will not occur once a parquet-format release carries FileType.

Co-authored-by: Isaac

* remove self reference

* Add FILE value writer validation

* Added FileValueWriters and FileConverters for writes and reads

* save

* fix lint

* Prevent partial FILE projections

* Fix FILE projection formatting

* Harden FILE type validation

* Validate FILE schema replacements and expand reader coverage

Revalidate FILE fields in GroupType.withNewFields and cover duplicate names, invalid annotations, generic projections, converter lifecycle, and persisted reader/writer behavior. Apply the repository's Spotless formatting to the FILE changes.

* Address FILE logical type review feedback

---------

Co-authored-by: Alkis Evlogimenos <alkis@evlogimenos.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants