Repository navigation
Fix JIRA-983 and support exteranl sort for sortByKey - #931
xiajunluan wants to merge 4 commits into
Conversation
|
Merged build triggered. |
|
Merged build started. |
|
Merged build finished. |
|
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/15322/ |
There was a problem hiding this comment.
It looks like your IDE changed the style of the comments here. Please leave them as they were originally. Our style in Spark is not the default Scala one, it's this:
/**
* aaa
* bbb
*/
|
Also FYI |
There was a problem hiding this comment.
Should be ): ExternalAppendOnlyMap
|
Hey @xiajunluan, this is a good start, but I made some comments throughout. There are a few other question though:
|
|
Hi @mateiz
|
|
Merged build triggered. |
|
Merged build started. |
|
Merged build finished. |
|
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/15445/ |
|
Looks like Jenkins is complaining about a line longer than 100 characters |
There was a problem hiding this comment.
minKeyHash is no longer used (github won't let me comment a few lines above)
|
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16364/ |
|
Jenkins, retest this please. |
|
Build triggered. |
|
Build started. |
|
Build finished. |
|
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16400/ |
|
Jenkins, test this please. |
1 similar comment
|
Jenkins, test this please. |
|
@xiajunluan would you have time to update this in the next few days? It's pretty close but there were those two small issues Andrew pointed out as well as a compile error. This would be great to get into 1.1. |
|
Jenkins, test this please. @xiajunluan actually I think the main issue now is that this isn't merging cleanly. |
|
@pwendell @xiajunluan I think I'm going to send a new PR based on this because I want to use some of the changes to ExternalAppendOnlyMap in sort-based shuffle. I also noticed an issue in this one. |
There was a problem hiding this comment.
It seems unnecessary to have a combiner here: if there are multiple key-value pairs with the same key, this requires them to all fit in memory. Instead we should have an option for the ExternalAppendOnlyMap to not attempt to combine them. I'll work on this in my PR.
(Squashed version of Andrew Xia's pull request apache#931) Conflicts: core/src/main/scala/org/apache/spark/rdd/OrderedRDDFunctions.scala core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala
|
Hey, so I rebased this PR and made it mergeable in my own branch, https://github.com/mateiz/spark/tree/spark-931. However, in doing this I realized that there might be some problems here that are fundamental. The main issue is that AppendOnlyMap, and ExternalAppendOnlyMap, require there's only one value for each key. The in-memory AOM will be very inefficient otherwise, and the EAOM depends on it. This means that for sort, we have to create (Key, ArrayBuffer[Value]) pairs, which will consume more memory by default than our in-memory sort, and will make us crash if there are too many identical values (something we do today but which may happen sooner here). Thus it seems that long-term we need a very different solution here, basically an external merge-sort. A second, possibly less serious issue is that the changes to EAOM to use comparator.compare instead of hash code equality make it less efficient in the default hashing-based case, because instead of saving one key's hash code in an Int and reusing it to compare with other keys in various places, we always recompute it when we compare each pair of elements. For these reasons I'd actually hold off on merging this (even my merged version) until we implement an external merge-sort as part of sort-based shuffle. Then we can use that data structure here. |
|
QA tests have started for PR 931. This patch DID NOT merge cleanly! |
|
QA results for PR 931: |
|
@xiajunluan we can now do this using the ExternalSorter added in #1499: see the new PR at #1677. Would you mind closing this old one? The new PR avoids some of the problems I mentioned above with each key having too many values. |
This patch simply uses the ExternalSorter class from sort-based shuffle. Closes apache#931 and Closes apache#1090 Author: Matei Zaharia <matei@databricks.com> Closes apache#1677 from mateiz/spark-983 and squashes the following commits: 96b3fda [Matei Zaharia] SPARK-983. Support external sorting in sortByKey()
…apache#931) ### What changes were proposed in this pull request? Milestone 8 measures its progress in two generated files: `sql/varka/plans/m8/census.tsv`, which says for every built-in function and type which pairs Varka fuses, and `sql/varka/plans/m8/casts.tsv`, the matrix of legal casts between the thirteen types. `dev/varka_census.py` writes both from Spark's function registry, the coverage table (`sql/varka/coverage.json`) and a hand-curated file. Nothing checked any of it, so a registry change, a coverage row that stopped fusing or a hand edit could move the milestone's headline number unnoticed. This PR adds four checks and the coverage rows the documentation already claimed. **1. The census runs in CI.** The `varka-docs` job, and `dev/varka_precommit.sh` when an input is staged, now run `dev/varka_census.py --check` and `dev/varka_catalogue_move.sh --check 8 9`. Both scripts already existed but nothing ran them. The job's trigger patterns (`dev/sparktestsupport/modules.py`) now include the census's inputs: the two scripts, `coverage.json` and `FunctionRegistry.scala`. Before this, a PR touching only those files didn't run the job. The catalogue check failed on master. When milestone 8's plan opened, the old scope catalogue moved from `m8/` to `m9/`, and the script treated every `READING_*.md` left under `m8/` as a catalogue note that should have moved, including milestone 8's own reading notes. It now does that only while the old folder still holds its `SCOPE.md`. **2. `VarkaCastMatrixSuite`**, a new JUnit suite. The script copies Spark's cast legality rules by hand into its `legal()` function, and a wrong copy would stay consistent with itself. The suite asks `Cast.canCast`, `Cast.canAnsiCast` and `Cast.canTryCast` about all 169 ordered pairs of the thirteen types, every form of each type against every form of the other (two decimal precisions, two `TIME` precisions, two field ranges for each interval). It requires `casts.tsv`'s three mode columns to agree with `Cast`, and a pair absent from the file to be illegal in all three modes. **3. Fused claims rest on the right class.** The census only lets a function be marked as fused over a type if some coverage row shows it. The old check credited every class in a row with every column type that row read. So `year(d) = 2021 AND i > 0` supported an "int" claim for `Year`. `VarkaCoverageSuite` now writes, for each coverage row, the types each class's own node takes as operands, and the census credits a class only with those. A class that inherits its analysis from a replacement, such as `extract`, uses its own arguments. A condition's BOOLEAN is not credited until a BOOLEAN lane exists. The plan proposed a simpler rule, single-class rows only. That can't work for `IF`, `CASE` or `extract`, which never appear alone in a row. The census also now applies Comet's four-way rule to casts. The coverage suite records each row's cast pairs and their mode. A pair the matrix marks fused must have a coverage row that casts it. A row's cast must be legal in its mode and must not be an identity cast. And a pair some row casts must be marked fused. **4. 27 coverage rows** for what `docs/sql-varka.md` already said fuses: * the year-month comparisons and `IN` (two literals, and eleven, which the optimizer turns into an `InSet`) * the null tests on `INT`, `TIME` and both interval types * eleven comparisons on `INT`, `BIGINT`, `TIME` and day-time intervals * three cast rows Before writing the rows I checked that each expression already compiles, so this is a coverage-only change, with no compiler change. The census's fused pair count moves from 96 to 122. **What the checks found:** * The cast matrix marked `date` to `date` as fused, but it is an identity cast, which the analyzer removes before any cast exists. It's no longer marked. * The matrix claimed `int` to year-month interval for both MONTH and YEAR units. `CAST(i AS INTERVAL YEAR)` actually declines, as does `CAST(ymy AS INT)`. So the claim is now the MONTH unit only, and the plan row for integral casts (332) takes the two YEAR casts. * Three fused cast claims had no coverage row behind them. Each has one now. * `docs/sql-varka.md` said a bare `INT` column in a comparison declines. It has fused since an earlier change, and the paragraph now says so. **Generated files regenerated by their suites:** `coverage.json`, the docs table, `emitted_bytes.json` and `width_audit.json`. In `emitted_bytes.json` the new rows are added; its option-arm hashes cover the whole table, so they move too, while no existing row's bytes move. `width_audit.json` was regenerated on the host it names and gains the new rows. The plan files (`m8/PLAN.md` row 328, `VARKA-328.md` section 9) record the outcome and the scored predictions. ### Why are the changes needed? Milestone 8's done-when list states its headline as the share of fused function-and-type pairs, and the cast matrix is meant to be transcribed from Spark. Without checks, both could drift silently. The new checks already caught three overstated claims and a stale paragraph in the user documentation. Every later lane row reports its progress through these files, so they need to be trustworthy before those rows land. ### Does this PR introduce _any_ user-facing change? No behaviour change. `docs/sql-varka.md` corrects one paragraph about which comparisons fuse, and its generated coverage table gains the new rows. ### How was this patch tested? * **New suite:** `VarkaCastMatrixSuite` passes in 0.15 s. A planted wrong ANSI legality for `date` to `int` fails it. * **Planted faults:** each failed its check. They were a stale `census.tsv`, a fused cast mark with no row, a row's cast without a mark, an int claim for `year` resting on another class's operand, and a `bool` claim for `and`. * **Trigger:** `dev/is-changed.py -m varka-docs` prints `false` before and `true` after, for a scratch commit touching only `coverage.json` and for one touching only `FunctionRegistry.scala`. * **Catalogue check:** passes on this branch, and a planted citation of a moved catalogue path still fails it. * **Suites over the new rows:** * `VarkaCoverageSuite` * `VarkaCoverageDifferentialSuite`: 332 tests against Spark under ANSI, with the new int-valued cast row added to the known-decline list for the `COALESCE` position. * the family switch, family chain, width audit, cost audit, grouping bound and composition fuzz suites * `VarkaEmittedBytesSuite` * `VarkaExpressionCompilerSuite` * **Linters:** scalastyle, Maven checkstyle on catalyst, ruff and the pre-commit linters. Self-review: before committing, an independent agent read the diff against the tools and the plan. It found five defects, all fixed: * operand types taken from a replaceable class's replacement rather than its own arguments * conditions credited as BOOLEAN operands * a miscount in the outcome * a misplaced doc comment * the catalogue fix's first-move limitation, now stated in a comment It also flagged three smaller items, all fixed: a vacuous assertion, an unused map, and an over-long comment. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5 and Claude Fable 5.1)
Change class ExternalAppendOnlyMap and make it support customized comparator function(not only sorted by hashCode).