Skip to content

[SPARK-2119][SQL] Improved Parquet performance when reading off S3 - #1370

Closed
liancheng wants to merge 4 commits into
apache:masterfrom
liancheng:faster-parquet
Closed

liancheng wants to merge 4 commits into
apache:masterfrom
liancheng:faster-parquet

Conversation

@liancheng

Copy link
Copy Markdown
Contributor

JIRA issue: SPARK-2119

Essentially this PR fixed three issues to gain much better performance when reading large Parquet file off S3.

  1. When reading the schema, fetching Parquet metadata from a part-file rather than the _metadata file

    The _metadata file contains metadata of all row groups, and can be very large if there are many row groups. Since schema information and row group metadata are coupled within a single Thrift object, we have to read the whole _metadata to fetch the schema. On the other hand, schema is replicated among footers of all part-files, which are fairly small.

  2. Only add the root directory of the Parquet file rather than all the part-files to input paths

    HDFS API can automatically filter out all hidden files and underscore files (_SUCCESS & _metadata), there's no need to filter out all part-files and add them individually to input paths. What make it much worse is that, FileInputFormat.listStatus() calls FileSystem.globStatus() on each individual input path sequentially, each results a blocking remote S3 HTTP request.

  3. Worked around PARQUET-16

    Essentially PARQUET-16 is similar to the above issue, and results lots of sequential FileSystem.getFileStatus() calls, which are further translated into a bunch of remote S3 HTTP requests.

    FilteringParquetRowInputFormat should be cleaned up once PARQUET-16 is fixed.

Below is the micro benchmark result. The dataset used is a S3 Parquet file consists of 3,793 partitions, about 110MB per partition in average. The benchmark is done with a 9-node AWS cluster.

  • Creating a Parquet SchemaRDD (Parquet schema is fetched)

    val tweets = parquetFile(uri)
    • Before: 17.80s
    • After: 8.61s
  • Fetching partition information

    tweets.getPartitions
    • Before: 700.87s
    • After: 21.47s
  • Counting the whole file (both steps above are executed altogether)

    parquetFile(uri).count()
    • Before: ??? (haven't test yet)
    • After: 53.26s

@SparkQA

SparkQA commented Jul 11, 2014

Copy link
Copy Markdown

QA tests have started for PR 1370. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16555/consoleFull

@SparkQA

SparkQA commented Jul 11, 2014

Copy link
Copy Markdown

QA results for PR 1370:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16555/consoleFull

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we making a new assumption here that all of the data has the same schema. I know we don't promise support for that now, but it would be nice to do in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we are making this assumption, will add a comment here. (And checking schema consistency can be potentially inefficient for large Parquet file with lots of row groups.)

@SparkQA

SparkQA commented Jul 16, 2014

Copy link
Copy Markdown

QA tests have started for PR 1370. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16704/consoleFull

@SparkQA

SparkQA commented Jul 16, 2014

Copy link
Copy Markdown

QA results for PR 1370:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16704/consoleFull

@marmbrus

Copy link
Copy Markdown
Contributor

Thanks! I've merged this into master.

@asfgit asfgit closed this in efc452a Jul 16, 2014
asfgit pushed a commit that referenced this pull request Aug 27, 2014
…gle file as parameter

```if (!fs.getFileStatus(path).isDir) throw Exception``` make no sense after this commit #1370

be careful if someone is working on SPARK-2551, make sure the new change passes test case ```test("Read a parquet file instead of a directory")```

Author: chutium <teng.qiu@gmail.com>

Closes #2044 from chutium/parquet-singlefile and squashes the following commits:

4ae477f [chutium] [SPARK-3138][SQL] sqlContext.parquetFile should be able to take a single file as parameter

(cherry picked from commit 48f4278)
Signed-off-by: Michael Armbrust <michael@databricks.com>
asfgit pushed a commit that referenced this pull request Aug 27, 2014
…gle file as parameter

```if (!fs.getFileStatus(path).isDir) throw Exception``` make no sense after this commit #1370

be careful if someone is working on SPARK-2551, make sure the new change passes test case ```test("Read a parquet file instead of a directory")```

Author: chutium <teng.qiu@gmail.com>

Closes #2044 from chutium/parquet-singlefile and squashes the following commits:

4ae477f [chutium] [SPARK-3138][SQL] sqlContext.parquetFile should be able to take a single file as parameter
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
JIRA issue: [SPARK-2119](https://issues.apache.org/jira/browse/SPARK-2119)

Essentially this PR fixed three issues to gain much better performance when reading large Parquet file off S3.

1. When reading the schema, fetching Parquet metadata from a part-file rather than the `_metadata` file

   The `_metadata` file contains metadata of all row groups, and can be very large if there are many row groups. Since schema information and row group metadata are coupled within a single Thrift object, we have to read the whole `_metadata` to fetch the schema. On the other hand, schema is replicated among footers of all part-files, which are fairly small.

1. Only add the root directory of the Parquet file rather than all the part-files to input paths

   HDFS API can automatically filter out all hidden files and underscore files (`_SUCCESS` & `_metadata`), there's no need to filter out all part-files and add them individually to input paths. What make it much worse is that, `FileInputFormat.listStatus()` calls `FileSystem.globStatus()` on each individual input path sequentially, each results a blocking remote S3 HTTP request.

1. Worked around [PARQUET-16](https://issues.apache.org/jira/browse/PARQUET-16)

   Essentially PARQUET-16 is similar to the above issue, and results lots of sequential `FileSystem.getFileStatus()` calls, which are further translated into a bunch of remote S3 HTTP requests.

   `FilteringParquetRowInputFormat` should be cleaned up once PARQUET-16 is fixed.

Below is the micro benchmark result. The dataset used is a S3 Parquet file consists of 3,793 partitions, about 110MB per partition in average. The benchmark is done with a 9-node AWS cluster.

- Creating a Parquet `SchemaRDD` (Parquet schema is fetched)

  ```scala
  val tweets = parquetFile(uri)
  ```

  - Before: 17.80s
  - After: 8.61s

- Fetching partition information

  ```scala
  tweets.getPartitions
  ```

  - Before: 700.87s
  - After: 21.47s

- Counting the whole file (both steps above are executed altogether)

  ```scala
  parquetFile(uri).count()
  ```

  - Before: ??? (haven't test yet)
  - After: 53.26s

Author: Cheng Lian <lian.cs.zju@gmail.com>

Closes apache#1370 from liancheng/faster-parquet and squashes the following commits:

94a2821 [Cheng Lian] Added comments about schema consistency
d2c4417 [Cheng Lian] Worked around PARQUET-16 to improve Parquet performance
1c0d1b9 [Cheng Lian] Accelerated Parquet schema retrieving
5bd3d29 [Cheng Lian] Fixed Parquet log level
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
…gle file as parameter

```if (!fs.getFileStatus(path).isDir) throw Exception``` make no sense after this commit apache#1370

be careful if someone is working on SPARK-2551, make sure the new change passes test case ```test("Read a parquet file instead of a directory")```

Author: chutium <teng.qiu@gmail.com>

Closes apache#2044 from chutium/parquet-singlefile and squashes the following commits:

4ae477f [chutium] [SPARK-3138][SQL] sqlContext.parquetFile should be able to take a single file as parameter
@liancheng
liancheng deleted the faster-parquet branch September 24, 2014 00:09
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 5, 2026
…l requests (apache#1370)

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

Seventeen rows of `sql/varka/plans/m8/PLAN.md` still read as before work that has merged. Each is corrected against its merged pull requests, which `git log` lists by the row's `[VARKA-n]` tag:

- **Now `Done`:** row 497 (one `IN` arm for every lane, apache#1259), row 333 (apache#1260) and row 365 (the Arrow cache's small decimals read as vanilla Spark reads them, apache#1306). The done-when of each is met by that pull request, and the "left" text that waited on it is gone.
- **Still `Started` or `Done in part`, with merged parts named:** rows 157, 330, 331, 332, 333, 340, 341, 342, 343, 344, 348, 349, 377, 503 and 538. Branch names that stood for work now merged become the pull request numbers and dates (for example 348's four parts, apache#1321, apache#1323, apache#1324 and apache#1349), and a "left" item that merged is dropped (538's flip, apache#1345; 341's mask crossing, closed by 343a3 and 343a3b; 377's decimal class, apache#1055).
- Row 377 now says what is still open: the floating baseline does not state whether its data holds denormals, which its done-when of 27 October 2026 asks.
- Rows 332 and 333 are read against their done-when. Row 333 is `Done` (apache#1260: its outcome records the census, the coverage rows and the unmoved `date_add` bytes). Row 332 stays `Started`: its 14 non-identity casts fuse (apache#1291), and what is left is 332b's in-range conformance value sets, the measurement against the baseline (no results file exists), two gaps from the 2 November review, and row 352's fuzz productions.

Only row text changes; no code, result or generated file.

### Why are the changes needed?

A reader who takes a row's state at its word re-plans or restarts work that merged, which the triage of 4 November 2026 found for these rows.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

`dev/varka_plan_lint.py` and `dev/varka_quote_check.py` pass. Every pull request number and date in the new text was read from `git log` of master.

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

Generated-by: Claude Code (Sonnet 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 12, 2026
…pache#1516)

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

This is a plan-only change to milestone 8's task table (`sql/varka/plans/m8/PLAN.md`, section 3). No code moves. It closes one row, corrects the text of another, and adds two rows on the owner's word.

| row | change | evidence |
| ---: | :--- | :--- |
| 572 | Started -> Done | The row asked for every row whose text lagged merged work to be read against its pull requests and corrected in a plan-only PR. apache#1366 and apache#1370 (merged 5 November) did the first readings. apache#1509 (merged 11 November) read every row not `Done` and closed eleven. Of the rows apache#1509 read and left alone, 591 still read as before its merge, and this change fixes it. Row 414 already names apache#1454. Rows whose PRs merged after apache#1509 (578, 592, 593, 596, 603 and 606, all on 12 November) do not name those PRs yet. They are past this reading and are not corrected here. |
| 591 | Started (text) | "built" now reads "built and merged as apache#1464 on 11 November 2026". The post-merge check is still owed, so the row stays Started. |
| 608 | new, Planned | The filter fallback evaluates the left fold of the fused conjuncts, not Spark's tree (below). |
| 609 | new, Planned | A guard in an `IfElse` condition is never qualified by the arms around the `IfElse` (below). |

**Row 608.** When no conjunct is residual, `VarkaColumnarRule.rewriteFilter` builds the Varka node's condition as `fusedConjuncts.reduceLeft(And(_, _))` and passes no `wholeCondition`. `VarkaExpressionCompiler.conjuncts` flattens every `AND` of the spine first. When the filter is not whole-stage compiled, `VarkaFilterExecBase.fallbackCondition` returns that fold unchanged, so a batch the kernel declines is filtered by `Predicate.create` over the fold, while Spark's `FilterExec` uses `Predicate.create` over its own tree.

With subexpression elimination on, `GeneratePredicate` uses `generateConjunctsWithSubexprCodes`. That keeps an `AND` of the spine that is itself a common subexpression as one conjunct, and evaluates the subexpressions it contains just before it, which is ahead of its first operand (SPARK-61197's mechanism). An `AND` that only Spark's tree has can therefore make Spark raise where Varka answers.

The row carries a reproducer worked out by hand and not run, under ANSI with codegen off: `j > 0 AND (i > 1 AND make_date(2021, m, 1) < d) AND IF(i > 1 AND make_date(2021, m, 1) < d, d0, d1) < make_date(2021, m, 1)`. It also notes that this corrects `VARKA-541.md` 0 item 7, which says the two agree by construction when Spark does not compile the filter. Done when the fallback evaluates the filter's own tree and a differential test agrees with Spark under both settings of subexpression elimination. The row starts after row 541, and coordinates with row 386, because both edit `fallbackCondition`. Found in row 541's build. The cause predates that build and is outside 541's scope.

**Row 609.** `Analysis.assignArmChain` enters every `IfElse` condition with the empty chain, and the empty chain means unqualified. A guarded node that a condition reads therefore condemns the batch from any lane, including lanes of an enclosing arm that is not taken. The result is lost fusion: the batch declines to the row path, which answers as Spark does.

The example on master, found by reading the code: `abs` of a year-month interval is `IfElse(x < 0, -x, x)`, and `ym - ymm` is a checked subtraction. In `CASE WHEN <guard> < 0 THEN abs(ym - ymm) ELSE <column> END`, and as a later COALESCE argument, the extremes row's overflow condemns the batch. Spark answers there. Once step 103a1 lands, `abs(dt * 3)` is the same case.

Done when an `IfElse` condition inherits the chain that its `IfElse` is reached by. The existing own-condition and cycle rules must still hold (`VarkaGuardEdgeSuite`), and a coverage row `abs(ym - ymm)` must be served in the untaken CASE arm and the COALESCE position. Found in step 103a2's build.

### Why are the changes needed?

The owner approved this change on 12 November 2026. Row 572's work is finished, so it should stop counting as open. Both findings are outside the builds that found them, and without rows of their own nothing would track them. Row 608 is a case where Varka answers a query that vanilla Spark rejects with an error. Row 609 costs fusion on every batch that holds such a row.

### Does this PR introduce _any_ user-facing change?

No. Only the plan changes.

### How was this patch tested?

- `python3 dev/varka_plan_lint.py --check --offline`: 0 findings.
- `python3 dev/varka_quote_check.py`: 0 orphans.
- `python3 dev/varka_msg_check.py size`: 6 counted lines.
- `dev/varka_push_check.py` passes.
- Every code claim in rows 608 and 609 was checked by reading master at `e48a856f5a8`. Neither reproducer was run, and each row says so.

One `/code-review high` pass: found 5 / fixed 4 / left 1. All five were in row 608.

- The sketch first used `i = 2`. `ConstantPropagation.moveEqualitiesFirst` would move that equality first and substitute it into the `IF`, so the example would show nothing. It now uses `i > 1`.
- The row contradicted `VARKA-541.md` 0 item 7 without saying so. It now names the correction and SPARK-61197.
- The done-when asked for a served-kernel cell that no raising batch can reach. That cell is dropped.
- The row did not mention row 386, which edits the same method. It does now.
- Left as a trade-off: the dated note on `VARKA-541.md` 0 item 7 itself. Row 541's open build rewrites that file, so the note is part of row 608's done-when instead of this change. This keeps the PR to `PLAN.md` and avoids a conflict with that build.

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

Generated-by: Claude Code (Opus 5.5)
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.

3 participants