Skip to content

[SPARK-2532] Consolidated shuffle fixes - #1609

Closed
mridulm wants to merge 10 commits into
apache:masterfrom
mridulm:consolidated_shuffle_fixes
Closed

mridulm wants to merge 10 commits into
apache:masterfrom
mridulm:consolidated_shuffle_fixes

Conversation

@mridulm

@mridulm mridulm commented Jul 27, 2014

Copy link
Copy Markdown
Contributor

Status of the PR

  • Cherry pick and merge changes from internal branch to spark master
  • Remove WIP comments and 2G branch references.
  • Tests for BlockObjectWriter
  • Tests for ExternalAppendOnlyMap
  • Tests for ShuffleBlockManager

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

QA results for PR 1609:
- This patch FAILED 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/17242/consoleFull

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

QA results for PR 1609:
- This patch FAILED 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/17243/consoleFull

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

QA results for PR 1609:
- This patch FAILED 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/17244/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.

Make sure to remove commented out debug code like this

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.

This is already removed - waiting for tests to pass locally :-)

@mateiz

mateiz commented Jul 27, 2014

Copy link
Copy Markdown
Contributor

@adav @andrewor14 would be good if you two take a look at this when it's merging correctly.

@SparkQA

SparkQA commented Jul 27, 2014

Copy link
Copy Markdown

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

Mridul Muralidharan added 2 commits July 28, 2014 05:20
@andrewor14

Copy link
Copy Markdown
Contributor

Did you mean @aarondav?

@SparkQA

SparkQA commented Jul 28, 2014

Copy link
Copy Markdown

QA results for PR 1609:
- This patch FAILED 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/17256/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.

One more spaces

@aarondav

Copy link
Copy Markdown
Contributor

@mridulm Thanks for submitting this! I would like to dig a little deeper into understanding the specific issues you found, in order to understand the solutions you have provided (since the specific solutions seem interleaved with a lot of new asserts and code paths).

You mention that there was an issue if shuffle writes co-occur with shuffle fetches, which is true, but should not typically occur due to the barrier before the reduce stage of a shuffle. In what situations does this happen (outside of failure conditions)?

Did you observe a prior pattern of close/revert/close on the same block writer?

How did task failures induce inconsistent state on the map side? Was it due to the same close/revert/close pattern?

@aarondav

Copy link
Copy Markdown
Contributor

I created #1678, which only includes the changes directly related to fixing the issues with shuffle file consolidation (essentially forking off a piece of this PR), intended as a simple candidate for review to make the 1.1 release. The smaller PR is not intended as a replacement for this more complete one, however -- it is merely an option to fix some of the more severe bugs in time for the next major release. If we can get this one in for 1.1 instead, then we should.

aarondav added a commit to aarondav/spark that referenced this pull request Jul 31, 2014
All changes from this PR are by @mridulm and are drawn from his work in apache#1609.
This patch is intended to fix all major issues related to shuffle file consolidation
that @mridulm found, while minimizing changes to the code, with the hope that it may
be more easily merged into 1.1.

This patch is **not** intended as a replacement for apache#1609, which provides many
additional benefits, including fixes to ExternalAppendOnlyMap, improvements to
DiskBlockObjectWriter's API, and several new unit tests.

If it is feasible to merge apache#1609 for the 1.1 deadline, that is a preferable option.

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.

Will this still compile on Java 6? I don't see any changes to pom.xml or anything to exclude it. Or maybe did you mean to call this by reflection?

@mateiz

mateiz commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

So FYI I'm going to make a more detailed pass through this soon to see if we can get all of it into 1.1. It would be nice to get all these changes in so we can QA them along with the other QA we do for 1.1, but if that doesn't work out, we can split some of them into smaller patches as Aaron did.

@mateiz

mateiz commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

So I looked through this and I also think it would be good to split it into smaller patches for 1.1. As far as I can see there are several orthogonal improvements here:

  • Shuffle file consolidation fixes that Aaron copied in SPARK-2791: Fix committing, reverting and state tracking in shuffle file consolidation #1678
  • ExternalAppendOnlyMap fixes to deal with writes past end of stream; we also need these in ExternalSorter
  • Fixes to directory creation in DiskBlockManager (I'm still not sure when this would be a problem actually if all accesses to these directories are through getFile; needs some investigation)
  • Fixes to isSymlink (though as is this seems like it would only compile on Java 7)
  • Improvements to the API of DiskBlockObjectWriter

Of these, the first two are most critical. So I'd like to get those into 1.1, and then we can do API refactoring and the other fixes on the master branch. For the directory creation fix I'd still like to understand when that can be a problem (I'm probably just missing something), but it's also one we can add in 1.1 during the QA window.

I'm going to update the JIRA to create sub-tasks for these things so we can track where each one is fixed. Thanks again for putting this together Mridul, this is very helpful.

asfgit pushed a commit that referenced this pull request Aug 1, 2014
…ile consolidation

All changes from this PR are by mridulm and are drawn from his work in #1609. This patch is intended to fix all major issues related to shuffle file consolidation that mridulm found, while minimizing changes to the code, with the hope that it may be more easily merged into 1.1.

This patch is **not** intended as a replacement for #1609, which provides many additional benefits, including fixes to ExternalAppendOnlyMap, improvements to DiskBlockObjectWriter's API, and several new unit tests.

If it is feasible to merge #1609 for the 1.1 deadline, that is a preferable option.

Author: Aaron Davidson <aaron@databricks.com>

Closes #1678 from aarondav/consol and squashes the following commits:

53b3f6d [Aaron Davidson] Correct behavior when writing unopened file
701d045 [Aaron Davidson] Rebase with sort-based shuffle
9160149 [Aaron Davidson] SPARK-2532: Minimal shuffle consolidation fixes
mateiz added a commit to mateiz/spark that referenced this pull request Aug 1, 2014
All these changes are from @mridulm's work in apache#1609, but extracted here
to fix this specific issue. This particular set of changes is to make
sure that we read exactly the right range of bytes from each spill file
in EAOM: some serializers can write bytes after the last object (e.g.
the TC_RESET flag in Java serialization) and that would confuse the
previous code into reading it as part of the next batch. There are also
improvements to cleanup to make sure files are closed.
@mateiz

mateiz commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Opened #1722 to do the second fix (map batch writing) for 1.1, including applying the same fix to ExternalSorter.

asfgit pushed a commit that referenced this pull request Aug 4, 2014
…in ExternalMap / Sorter

All these changes are from mridulm's work in #1609, but extracted here to fix this specific issue and make it easier to merge not 1.1. This particular set of changes is to make sure that we read exactly the right range of bytes from each spill file in EAOM: some serializers can write bytes after the last object (e.g. the TC_RESET flag in Java serialization) and that would confuse the previous code into reading it as part of the next batch. There are also improvements to cleanup to make sure files are closed.

In addition to bringing in the changes to ExternalAppendOnlyMap, I also copied them to the corresponding code in ExternalSorter and updated its test suite to test for the same issues.

Author: Matei Zaharia <matei@databricks.com>

Closes #1722 from mateiz/spark-2792 and squashes the following commits:

5d4bfb5 [Matei Zaharia] Make objectStreamReset counter count the last object written too
18fe865 [Matei Zaharia] Update docs on objectStreamReset
576ee83 [Matei Zaharia] Allow objectStreamReset to be 0
0374217 [Matei Zaharia] Remove super paranoid code to close file handles
bda37bb [Matei Zaharia] Implement Mridul's ExternalAppendOnlyMap fixes in ExternalSorter too
0d6dad7 [Matei Zaharia] Added Mridul's test changes for ExternalAppendOnlyMap
9a78e4b [Matei Zaharia] Add @mridulm's fixes to ExternalAppendOnlyMap for batch sizes
asfgit pushed a commit that referenced this pull request Aug 4, 2014
…in ExternalMap / Sorter

All these changes are from mridulm's work in #1609, but extracted here to fix this specific issue and make it easier to merge not 1.1. This particular set of changes is to make sure that we read exactly the right range of bytes from each spill file in EAOM: some serializers can write bytes after the last object (e.g. the TC_RESET flag in Java serialization) and that would confuse the previous code into reading it as part of the next batch. There are also improvements to cleanup to make sure files are closed.

In addition to bringing in the changes to ExternalAppendOnlyMap, I also copied them to the corresponding code in ExternalSorter and updated its test suite to test for the same issues.

Author: Matei Zaharia <matei@databricks.com>

Closes #1722 from mateiz/spark-2792 and squashes the following commits:

5d4bfb5 [Matei Zaharia] Make objectStreamReset counter count the last object written too
18fe865 [Matei Zaharia] Update docs on objectStreamReset
576ee83 [Matei Zaharia] Allow objectStreamReset to be 0
0374217 [Matei Zaharia] Remove super paranoid code to close file handles
bda37bb [Matei Zaharia] Implement Mridul's ExternalAppendOnlyMap fixes in ExternalSorter too
0d6dad7 [Matei Zaharia] Added Mridul's test changes for ExternalAppendOnlyMap
9a78e4b [Matei Zaharia] Add @mridulm's fixes to ExternalAppendOnlyMap for batch sizes
@andrewor14

Copy link
Copy Markdown
Contributor

@mridulm Are the issues in this PR taken care of by #1722 and and #1678? Do we still need this PR?

@mridulm

mridulm commented Sep 4, 2014

Copy link
Copy Markdown
Contributor Author

I think it got split into four issues, two of which got committed, not sure
of the other other two .... And the first one was regressed upon in
1.1.already.
But this or probably is defunct now .... Will close
On 04-Sep-2014 5:03 am, "andrewor14" notifications@github.com wrote:

@mridulm https://github.com/mridulm Are the issues in this PR taken
care of by #1722 #1722 and and #1678
#1678? Do we still need this PR?

—
Reply to this email directly or view it on GitHub
#1609 (comment).

@mridulm mridulm closed this Sep 4, 2014
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
…ile consolidation

All changes from this PR are by mridulm and are drawn from his work in apache#1609. This patch is intended to fix all major issues related to shuffle file consolidation that mridulm found, while minimizing changes to the code, with the hope that it may be more easily merged into 1.1.

This patch is **not** intended as a replacement for apache#1609, which provides many additional benefits, including fixes to ExternalAppendOnlyMap, improvements to DiskBlockObjectWriter's API, and several new unit tests.

If it is feasible to merge apache#1609 for the 1.1 deadline, that is a preferable option.

Author: Aaron Davidson <aaron@databricks.com>

Closes apache#1678 from aarondav/consol and squashes the following commits:

53b3f6d [Aaron Davidson] Correct behavior when writing unopened file
701d045 [Aaron Davidson] Rebase with sort-based shuffle
9160149 [Aaron Davidson] SPARK-2532: Minimal shuffle consolidation fixes
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
…in ExternalMap / Sorter

All these changes are from mridulm's work in apache#1609, but extracted here to fix this specific issue and make it easier to merge not 1.1. This particular set of changes is to make sure that we read exactly the right range of bytes from each spill file in EAOM: some serializers can write bytes after the last object (e.g. the TC_RESET flag in Java serialization) and that would confuse the previous code into reading it as part of the next batch. There are also improvements to cleanup to make sure files are closed.

In addition to bringing in the changes to ExternalAppendOnlyMap, I also copied them to the corresponding code in ExternalSorter and updated its test suite to test for the same issues.

Author: Matei Zaharia <matei@databricks.com>

Closes apache#1722 from mateiz/spark-2792 and squashes the following commits:

5d4bfb5 [Matei Zaharia] Make objectStreamReset counter count the last object written too
18fe865 [Matei Zaharia] Update docs on objectStreamReset
576ee83 [Matei Zaharia] Allow objectStreamReset to be 0
0374217 [Matei Zaharia] Remove super paranoid code to close file handles
bda37bb [Matei Zaharia] Implement Mridul's ExternalAppendOnlyMap fixes in ExternalSorter too
0d6dad7 [Matei Zaharia] Added Mridul's test changes for ExternalAppendOnlyMap
9a78e4b [Matei Zaharia] Add @mridulm's fixes to ExternalAppendOnlyMap for batch sizes
sunchao pushed a commit to sunchao/spark that referenced this pull request Jun 2, 2023
…h BosonExec enabled (apache#1609)

(cherry picked from commit e843d83b83e7351ed3c610a1ac9f016fe5732cb3)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
github-actions Bot pushed a commit to MaxGekk/spark that referenced this pull request Nov 22, 2026
…ts (apache#1613)

<!-- title: [VARKA-631] Add rows 631 and 632 on sharing work between the math ports -->
### What changes were proposed in this pull request?

Adds two task rows to milestone 8's plan, both filed from the owner's question whether Spark's optimizer folds trigonometric expressions and whether Varka should.

Spark's optimizer has no rule that simplifies a trigonometric, exponential or logarithmic expression algebraically. Its generic `ConstantFolding` replaces a call whose arguments are all literals by one literal before planning, so Varka already receives the folded literal and has nothing to fold. An algebraic rewrite such as `exp(log(x))` to `x` would change the last bit, the NaN case and overflow, against the milestone's exact default, so Varka should not make one. What a kernel can add beyond Spark is sharing work between calls of one input without changing a result.

- Row 631: the fdlibm ports share the work they have in common when a projection calls several functions of one input: the argument reduction of `exp` and `expm1`, the hyperbolics over `expm1` and `exp`, and the exponent split of the logarithms. `sin`, `cos` and `tan` are per-lane `Math` calls with no port (`VARKA-345.md` 8, point 11), so they have no reduction to share. Each function stays bit-identical to its oracle (`StrictMath` for the thirteen fdlibm functions, `Math` where Spark calls it), and the saving is measured on the EPYC 7763 against the same projection with the sharing off.
- Row 632: what two calls of one port cost. `VARKA-559.md` 2.2 records that every map and set over IR nodes in `Analysis` and `Slots` is keyed by record equality with a cached hash, so two equal port trees already collapse; the open risk is 2.3's, that `equals` over two disjoint equal copies recurses once per path, and whether the grouping keeps the overlapping ports of one projection in one kernel. The row measures `exp(x)` and `exp(x) * 2` as two outputs (distinct ops, method bytes, compile time) and, if they do not cost once, builds a keyed intern of equal trees. With `cse` off the `exp` port's 68 distinct ops expand into loop methods of about 14,600 bytes (the unmerged 345b2, apache#1609), which is why its suite now runs with `cse` on.

Only `sql/varka/plans/m8/PLAN.md` changes.

### Why are the changes needed?

The rows record two open questions and the work they lead to, so that they are scheduled and read by the census and by row 354 at the close, instead of staying in a conversation. The issue tracker's task issues are created from the plan's rows.

### Review

`/code-review high` found that the first version of the two rows assumed `sin`, `cos` and `tan` ports the plan rules out and framed the question of sharing as identity against equality, which `VARKA-559.md` 2.2 already answers. Both rows were rewritten on that basis, and the other findings were fixed: the oracle per function, the dependencies and size of row 631, the unmerged source of the 14,600-byte reading, a checkable Done-when for row 632, and the provenance wording.

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

No. A plan change only.

### How was this patch tested?

`python3 dev/varka_plan_lint.py --check --offline` and `python3 dev/varka_quote_check.py` pass, and `python3 dev/varka_msg_check.py pr` accepts this description. No code runs.

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

Generated-by: Claude Code (Claude Sonnet 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 22, 2026
…ictMath (apache#1609)

<!-- title: [VARKA-345] Emit fdlibm's exp as IR nodes in the kernel, exact to StrictMath -->

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

`exp` as the first function written on the `PORT` frame (apache#1607): `VarkaMathPort.exp` expands fdlibm 5.3's `e_exp.c` into ordinary IR nodes (lane arithmetic, compares, blends, the long bit views) inside the kernel's one method. No call is made at run time. Every branch of the C is computed in every lane and the lanes are blended in the C's order of precedence, so no lane is finished by a per-lane `StrictMath.exp`. Three planted faults of the sequence (a dropped correction term, a constant one ulp off, a moved threshold) are a package-private `Fault` argument, so the production expansion has none.

Three supporting changes:

- `D2I` (`DOUBLE` to `INT`, Java's `(int)`) passes `VarkaKernelPlan`'s conversion refusal and is lowered by `convertShape` on every host; `exp` takes its integer `k` through it. No compiler arm builds it for a SQL cast, so no SQL answer moves.
- The auto chain cap of apache#1605 (`VarkaEmitBudget.chainDepthCap`) gets a third arm, `PORT_MAX_CHAIN_DEPTH` = 64, for a tree that holds a `ReinterpretLane`, the node only the ports build. Every other tree keeps its cap (64 for an int-lane tree, 16 else), and an explicit `maxChainDepth` still wins. The emitter's analysis and the compiler's `fitsBudgets` both read `chainDepthCap`, so they agree.
- The test oracle is `io.github.vecbricks:vfdlibm:0.1.0` from Maven Central, a test-scope dependency of `sql/catalyst`. `javap` shows `VFdlibm.exp(DoubleVector[, VectorMask])` public, which is all the suite calls. No source copy, manifest or sync script.

### Why are the changes needed?

The exact default of the math family has to match `StrictMath` bit for bit, and a per-lane call is the only form that does today; it costs the scalar call and keeps the surrounding vector code but not the function. Writing the function's sequence as IR makes it vectorised, and `exp` is the template the other ports follow.

Why the result is bit-identical (the full argument is in `VARKA-345.md` 10.2): `StrictMath.exp` is fdlibm's `e_exp.c`, each step one correctly rounded IEEE double operation, and a vector add, subtract, multiply or divide on a double lane is that same operation, so a lane that follows the C's path gets the C's bits. The only difference is control flow. The port runs the far reduction for every lane with `k = 0` where the C does not reduce, which returns the C's inputs unchanged, tests `|x|`'s bits against constant words as the C tests its high word, and applies the blends in the C's order, so the last blend a lane satisfies is the C's `return`.

The cap is the real reason for the second change. `exp` is 36 levels deep (its polynomial alone ten) over the double, long and int lanes, so the auto cap declined it at 16 ("chain deeper than MAX_CHAIN_DEPTH=16"). Measured: layering `x + 1.0` over the port, the compiler's mirror admits exactly 28 more levels, a stop at 64, and the 65th is declined by the emitter with "MAX_CHAIN_DEPTH=64". At that depth the largest emitted method is 2070 bytes of the 8000-byte budget, so the cap, not the byte budget, is the stop and it is far from the method limit. The alternatives were a higher shared cap (it would change which fuzz draws and compiler folds fit) or a depth that counts only arithmetic (a second notion of depth beside `height`); a branch of the auto value touches only trees that already hold a port.

At `methodByteBudget` 0 (an option matrix arm) the op cap `MAX_FUSED_NODES` (64) applies and `exp` holds 68 ops, so the port is declined there, cleanly, and the row engine runs. A test holds that.

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

No. No compiler arm builds a port yet, so no SQL shape fuses with one and no answer moves.

### How was this patch tested?

`VarkaMathPortSuite` (its own JVM), against `StrictMath.exp` and `VFdlibm.exp` by raw bits, NaN payloads included:

- the sampled differential over four draws, 2^24 inputs;
- the fixed vectors (each `e_exp.c` threshold in both signs with 64 neighbours each way, the subnormal scale-back's start, special values, eight NaN patterns, 4136 inputs) at 2, 4 and 8 lanes over four null patterns and four lengths;
- the reference evaluator over the port's tree; `D2I` against Java's `(int)` at three widths; each planted fault caught; the constants' words;
- the depth and the stop at 64 above, the explicit cap, and the decline at `methodByteBudget` 0.

Also `VarkaEmitterFloatingCastSuite` (D2I admitted) and the option, budget, rounding, reproduction, math-contract and compiler suites around the cap. Scalastyle, scalafmt, errorprone and `dev/varka_push_check.py` are clean.

`/code-review high` (one round): 1 important finding, fixed: the port suite's kernels ran under the option matrix's `maxChainDepth` 16 or 32 and `methodByteBudget` 0, which decline `exp` by design, so the suite now builds its kernels with those two budgets put back (the decline itself has its own tests). Also fixed: errorprone's float-literal warnings on the constants, comments that still named the old cap, a decline test that did not check the cap's name. Left as nits: the port cap keys on `ReinterpretLane` (documented, only the ports build it), and a bare D2I root is untested, only D2I under a widening to long.

No issue was filed against `vfdlibm`: every `exp` lane was bit-identical to `StrictMath.exp` and nothing was measured against its node sequence.

The port's speed against the per-lane call is not measured here; the per-lane form is row 356's and the runners are dispatched separately.

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

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

<!-- title: [VARKA] Add the scripts that gate, push and watch a pull request -->
### What changes were proposed in this pull request?

The operations scripts that take a branch to an open pull request with a green option matrix are now in `dev/varka_ops/`. Until now they lived only in a private ops directory.

- Fourteen scripts. `pre-pr.sh` is the local gate: merge master, regenerate (or skip that), the extra lints and suites, the push check, and the arm sweep. `pre-pr-slot.sh` queues it, and `mark-reviewed.sh` and `review-covers.sh` record and check the review. `open-pr.sh`, `push-ci.sh` and `push-no-ci.sh` push. `start-waiter.sh`, `matrix-after-build-link.sh` and `matrix-link.sh` dispatch and link the matrix. `watch-any-ready.sh`, `watch-infra.sh` and `ops-status.sh` watch.
- `common.sh` holds the shared configuration. Personal paths and the fork owner are now variables: `VARKA_OPS_HOME` (default `~/.varka-ops`), `VARKA_WORKTREES` (the parent of the main checkout), `VARKA_FORK` (read from the `fork` remote), `VARKA_FORK_REMOTE`, `VARKA_REPO` (`vecbricks/varka`), `VARKA_VENV` and `VARKA_TRAILER`.
- The scripts call each other through their own directory, start with `#!/usr/bin/env bash` and `set -u`, and carry the ASF header.
- `README.md` explains the flow, the one-gate-at-a-time rule, the light gate, the exclusive mode, the regen skip and the configuration. `INDEX.md` lists each tool's inputs, outputs, callers and exit codes. `AGENTS.md` (with a `CLAUDE.md` link) gives the rules for agents, the order of steps and the traps of 22-23 November.
- `sql/varka/AGENTS.md` points to the index in one line.

<details>
<summary>Behaviour changes against the private copies</summary>

With `VARKA_OPS_HOME=~/varka-ops` and a `fork` remote, the scripts use the same stamps, locks and logs as before. These are the only changes:

- A worktree argument may be a path or a bare name in every script. An existing directory wins. `open-pr.sh` and `push-no-ci.sh` took only a name before.
- Running gates and watchers are counted from `ps` lines that run `pre-pr.sh` under bash in any directory and any spelling of bash. The old pattern only matched `/bin/bash` plus the private path. The new pattern also counts gates of the private copies, so both can run during the switch.
- The ops home's subdirectories are created when missing. Missing arguments print usage and exit 2.
- `push-ci.sh` and `push-no-ci.sh` stop when the push fails. Before, `| tail -1` hid the failure. `push-no-ci.sh` then cancelled the previous head's runs.
- `matrix-after-build-link.sh` links the run from its own dispatch output, not the newest URL in its log. It exits 1 when the dispatch fails.
- `watch-infra.sh` reruns nothing when no failed job was classified, for example when only a report job failed.
- `matrix-link.sh` stops when no pull request is found. Before, it got `null` and posted to `issues/null`.
- `watch-any-ready.sh` has no default `SKIP`. The old default, apache#1609, is merged.

</details>

### Why are the changes needed?

Every pull request now goes through these scripts, but only one machine had them. Other people and agents could not run the gate or read the rules it enforces.

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

No. Developer tooling and docs only.

### How was this patch tested?

- `bash -n` and `shellcheck -S warning` pass on every script. `dev/varka_precommit.sh` passes.
- A dry run with `VARKA_OPS_HOME` in a scratch directory and a scratch repository covered `pre-pr.sh`'s usage, `-j` without a value, a missing worktree and a dirty worktree. The duplicate-waiter refusal (exit 3) worked. `review-covers.sh` passed four cases: no stamp, stamp at HEAD, a regen commit after it and a master merge after it. It failed a fix commit after the stamp. The fork was parsed from ssh and https URLs.
- The process pattern was checked against sample `ps` lines. It counted a running gate of the private copies.
- The private `pre-pr-slot.sh` gate passed on this branch. It was a light gate, so there was no regen and no sweep.
- Not run: the push, PR and watcher scripts against GitHub.

### Review

`/code-review high` found 8 important items and 2 nits. I fixed three: the lost push status, the matrix linked from an older run, and the infra rerun with no classified job. The other seven are kept as the private copies behave; they are listed below. The size is 968 counted lines.

<details>
<summary>Kept as they are, for a later change</summary>

- `watch-infra.sh` treats a 429 or `toomanyrequests` anywhere in a job log as infrastructure, even when a retry recovered and a test failed later.
- `matrix-link.sh` does not record its follower's pid. An older run's follower can keep editing the shared comment.
- `review-covers.sh` trusts every merge commit, a hand-resolved conflict included. Its regen-subject match is not anchored.
- A stale exclusive marker left by a kill or reboot blocks the queue. Two exclusive waiters can race.
- The regen-skip filter does not count the generated `.tsv` files under `sql/varka/plans/` as inputs.
- `ops-status.sh` looks for `watch-ready.sh` and `watch-failed.sh` by default, which are not in this directory.
- The default commit trailer names one model.

</details>

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

Generated-by: Claude Code (Claude Opus 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 24, 2026
…che#1643)

<!-- title: [VARKA-358] Fuse exp, expm1, cbrt and the logarithms bit for bit -->
### What changes were proposed in this pull request?

Varka now fuses `exp`, `expm1`, `cbrt`, `ln`, `log` (one and two arguments), `log10`, `log1p` and `log2` over `DOUBLE`. Before this, each of them declined and the row engine ran it.

- Each lane calls the method Spark's generated code calls: `StrictMath.exp`, `expm1`, `log`, `log10`, `log1p`, and `Math.cbrt`. So every answer has Spark's bits.
- The log family's null (`x <= 0.0`, `x <= -1.0` for `log1p`) is built as `IfElse(x <= t, NULL, call)` from nodes the emitter already lowers. No new node.
- `log2(x)` and `log(b, x)` divide as Spark writes them. A constant base is folded at compile time.
- `coverage.json` gains 11 "Math functions" rows. The census marks the eight entries done.
- The math baseline benchmark marks twelve sections as fused.

<details>
<summary>Design details</summary>

`MathFn` gains `EXP`, `EXPM1`, `LOG`, `LOG10`, `LOG1P` (owner `java.lang.StrictMath`, the class Spark's code names) and `CBRT` (owner `java.lang.Math`, the host's answer, as in Spark).
They use the per-lane call that row 356 (apache#1567) built: `v.lane(k)`, the static call, `v.withLane(k, r)`, unrolled over the baked lane count.
The emitter changes only in its operator switch.

`VarkaMathDomain.nullAtOrBelow(fn, x, t, fault)` builds `IfElse(Compare(IEEE_LE, x, t), NullValue(DOUBLE), MathUnary(fn, x))`.
`IEEE_LE` is Java's `<=`. So `-0.0` is null and NaN reaches the call, as in Spark.
A null operand makes the compare unknown. That lane takes the call, whose validity is the operand's, so it stays null.

`VarkaMathCompiler`:

- `exp`, `expm1`, `cbrt`: the call.
- `ln`, `log10`, `log1p`: the call under the null.
- `log2`: `ln(x) / StrictMath.log(2)`, Java's divide (`DIV WRAP`).
- `log` with `EulerNumber` on the left (as parsed): `ln(x)`, no divide, as Spark's code generator writes it. After the optimizer folds `e`, it is a constant base, and Spark's code divides too.
- `log(b, x)` with a constant base: `ln(x)` divided by `StrictMath.log(b)`, computed by Catalyst's own `eval`. A base at or below `0.0`, a null base, or a base whose evaluation throws declines.
- `log(b, x)` with a column base: `ln(x) / ln(b)`, null where either is.
- `pow` and `hypot` still decline. They are the next part (358a2, a two-operand call node).

A test-only fault, `FloatingFault.MATH_DOMAIN_LT`, plants `<` for `<=` in the null.

</details>

### Why are the changes needed?

Queries with `exp` or a logarithm ran wholly on the row engine, together with the arithmetic around them. This part adds the exact default form, a per-lane call, bit for bit Spark's. Later parts measure Varka's fdlibm ports (`VarkaMathPort.exp`, merged in apache#1609) against it, as option arms.

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

No new setting. Projections with these functions over `DOUBLE` now fuse, with Spark's answers bit for bit.

### How was this patch tested?

`pre-pr.sh` passed on the laptop on head `7c0d498e2db`, master `194f28f6777` merged and the generated files regenerated:

- extra-gate passed: `lint-java`, Error Prone, `lint-scala` and the invariant and proof suites.
- The push check passed: six catalyst suites under the defaults, 46 tests passed and none failed. The size is 831 counted lines.
- The arm sweep passed: `VarkaCoverageSuite`, `VarkaMathCompilerSuite`, `VarkaMathExactSuite` and `VarkaMatrixSuite` under the defaults and all 58 configurations, with no failure.
- Not run: any benchmark, CI Build and the option matrix.
- The `driverOutputTable=false` skip of VarkaGroupingBoundSuite's "under the exact grouping no shape declines" test is dropped: option matrix 45123550199 (bin b086) called it stale, and on the head merged with master `c4b0475d86e` the test passes under that option and at the defaults (`dev/varka_matrix.sh --module catalyst --config driverOutputTable=false --suites VarkaGroupingBoundSuite`). `pre-pr.sh` then passed again on `f9ed820738d`, master `c685d37b8eb` merged.

<details>
<summary>Full test record and what was not run</summary>

The 20 November run of the same change on its old base (`catalyst/Test/compile`, `sql/Test/compile`, `VarkaMathExactSuite` and `VarkaMathCompilerSuite`, 11 tests passed) is recorded in `VARKA-356.md` 10.2. It ran before the rebuild on master and is not evidence for this head.
The rebuild moved the domain plant into `FloatingFault.MATH_DOMAIN_LT` and added 22 `skips.tsv` lines for the 11 new coverage rows, under `validityByWidth=false` and `lanesOverride=16`. The arm sweep passed with those lines.
The first gate failed in `VarkaMathCompilerSuite`: the failing-base test parsed its SQL through a test helper that folds a string cast to double itself, so the ANSI cast raised in the test before the compiler ran. The test now builds the expression, bare and inside an `If`, and a null-base test was added.

</details>

### Review

`/code-review high` found two important issues. One is fixed and the other is resolved by the owed regeneration. One nit is fixed and one is left. The size is 798 counted lines.

<details>
<summary>Review findings and what changed</summary>

- Important, fixed: a constant `log` base whose evaluation throws, such as an ANSI cast in a branch that no row takes, failed the query at planning. Such a base now declines and the row engine answers.
- A second `/code-review high` on the test fix: four nits fixed (null-base test, the `If` shape, a comment and the Javadoc). Left: the test helper's unguarded fold, and the decline reason not naming the exception.
- Important: the census lines said done before `coverage.json` was regenerated. The regeneration commit resolves this.
- Nit, fixed: the `log(x)` coverage note now says what the optimizer's folded `e` compiles to.
- Nit, left: the `MATH_DOMAIN_LT` plant builds its IR directly, not through the compiler. The coverage harness and differential suites compare each SQL form with the row engine, so they check the compiler's asymptotes and divisors.

</details>

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

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

6 participants