Skip to content

SPARK-2149. [MLLIB] Univariate kernel density estimation - #1093

Closed
sryza wants to merge 3 commits into
apache:masterfrom
sryza:sandy-spark-2149
Closed

sryza wants to merge 3 commits into
apache:masterfrom
sryza:sandy-spark-2149

Conversation

@sryza

@sryza sryza commented Jun 16, 2014

Copy link
Copy Markdown
Contributor

No description provided.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/15809/

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.

Is this a candidate for Experimental? in the sense that it might evolve into a fuller density estimation something-or-other later?

@sryza

sryza commented Jun 16, 2014

Copy link
Copy Markdown
Contributor Author

Thanks for the comments Sean. Updated patch checks for positive standard deviation, marks it as experimental, and tries to make the calculations a little more clear.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

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.

If some of this is copied from Commons Math I'd suggest a note about its origin. I like FastMath; I think they show it is faster than Java's version. For consistency in the past I either used all FastMath or all Math. I don't know how much it matters here, using FastMath vs Java Math vs Scala Math from a consistency standpoint?

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/15823/

@pwendell

pwendell commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

@sryza dunno if this is still something you want to submit, but if so can you tag this with MLLib? otherwise it doesn't get sorted correctly.

@sryza sryza changed the title SPARK-2149. Univariate kernel density estimation SPARK-2149. [MLLIB] Univariate kernel density estimation Sep 2, 2014
@SparkQA

SparkQA commented Feb 2, 2015

Copy link
Copy Markdown

Test build #26534 has started for PR 1093 at commit 6c91645.

  • This patch merges cleanly.

@SparkQA

SparkQA commented Feb 2, 2015

Copy link
Copy Markdown

Test build #26534 has finished for PR 1093 at commit 6c91645.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/26534/
Test FAILed.

@srowen

srowen commented Feb 7, 2015

Copy link
Copy Markdown
Member

@sryza are you interested in getting this in? @mengxr what's your opinion of adding this? My last review comment is that we should just use Math instead of FastMath as the latter isn't used elsewhere in Spark. Unless there's a clear performance reason for doing so. In which case, hey, let's use the fast version everywhere.

@mengxr

mengxr commented Feb 7, 2015

Copy link
Copy Markdown
Contributor

Does FastMath give significant performance improvement over math? I think this needs some performance testing, given that there are other overheads involved in the computation. If we don't see significant gain, maybe it is not worthing using it. People might have different versions of commons-math3 on the classpath, so we should try to use a minimal subset of its functions. From its doc (http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/util/FastMath.html), many functions are marked as "since 3.4". Another issue is the optimization used in FastMath. For example, this is the log implementation:

https://github.com/apache/commons-math/blob/master/src/main/java/org/apache/commons/math3/util/FastMath.java#L1141

It might be faster than JVM's implementation. But if anything (accuracy/performance) goes wrong there, it will be extremely hard for us the trace the problem.

About the API, is it okay to put kernelDensity as a method under Statistics and hide the implementation?

@sryza

sryza commented Feb 7, 2015

Copy link
Copy Markdown
Contributor Author

Sorry for the delay on this @mengxr @srowen. Updated patch to take out FastMath and expose the method in Statistics.

@SparkQA

SparkQA commented Feb 7, 2015

Copy link
Copy Markdown

Test build #27012 has started for PR 1093 at commit 5f06b33.

  • This patch merges cleanly.

@SparkQA

SparkQA commented Feb 7, 2015

Copy link
Copy Markdown

Test build #27012 has finished for PR 1093 at commit 5f06b33.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/27012/
Test PASSed.

@srowen

srowen commented Feb 8, 2015

Copy link
Copy Markdown
Member

Looking OK to me. I'll wait a beat for @mengxr to add any final comments.

@asfgit asfgit closed this in 0793ee1 Feb 9, 2015

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.

Math is being deprecated. Please replace it with math instead.

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, yeah I thought of that before I merged, but saw a load of usages of Math in the code. Shall I make a PR to change all of them in one go?

udaynpusa pushed a commit to mapr/spark that referenced this pull request Jan 30, 2024
…S, Spark Master and Spark Workers (apache#1093)

Co-authored-by: Egor Krivokon <>
mapr-devops pushed a commit to mapr/spark that referenced this pull request May 8, 2025
…S, Spark Master and Spark Workers (apache#1093)

Co-authored-by: Egor Krivokon <>
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Oct 29, 2026
…s the test (apache#1093)

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

The option matrix, the CI workflow that reruns the Varka suites once per emit-option configuration, stops rerunning a SQL test under a configuration that changes nothing the test compiles or emits.

A test's answers follow from what Varka compiled and emitted for it and from the rows it ran over. So a test whose compiles and kernels a configuration leaves unchanged has already been run by the defaults run.

- **The pull request's Build records it.** In the Build's varka-scoped sql jobs, which run at the defaults:
  - `VarkaCompileObserver` (main code) hears `VarkaExpressionCompiler`'s compile entries, each with a way to repeat that compile, plus the shape cache's lookups and the emitter. Each hook is behind one volatile check, and no listener is set outside the recording.
  - `VarkaTestReach` (test code) repeats each compile and emission under every configuration's values laid over the options the test gave. It writes one line per test, naming the configurations that changed anything the test compiled or emitted. A kernel whose IR an earlier compile produced inherits that compile's configurations.
- **The rules keep it sound.**
  - What a suite compiles outside a test, in its set-up or between tests, joins every test in the suite.
  - What the JVM compiles outside any suite joins every test.
  - A test that cancelled at the defaults runs under every configuration.
  - A recording that fails marks its file broken, and a broken file is read as no record. The test the recording was listening to doesn't fail.
- **Thirteen configurations run every test** (`VarkaTestReach.FULL`, each with its reason). They are:
  - the six that change which kernels a plan has;
  - the lane count;
  - the batch size;
  - `exactRefusalStatus`, which the evaluator reads as a kernel runs;
  - the configuration that sets three validity options at once.

  A test the record lacks, and a test the skip list names for the configuration, also run.
- **Four suites are left out of the recording** and run in full (`VarkaTestReach.UNRECORDED`). They build kernels of thousands of nodes, so recording them cost more than it saved. For example, `VarkaCodegenGiveUpSuite` takes 16 s plain and 225 s recorded.
- **The matrix uses it.**
  - It takes the record from its commit's Build, through the same lookup that already takes the test classes, provided every scoped job left its part.
  - A configuration's JVM skips each test the record doesn't name it for.
  - The report counts those tests in a new `atdef` column.
  - The planner weighs each suite by the share of its tests that run, and drops a suite with none.
- **The sql suites get a third job.** The Build's varka-scoped sql suites now run in three jobs rather than two, as catalyst's already do, to absorb the recording's cost. By the committed suite weights, each job's share drops from 307 s of suites to about 205 s. The matrix's lookup now names the first of the three jobs.
- `sql/varka/AGENTS.md` states the rule for future options: an option read outside the compiler and the emitter goes in `FULL`. Row 507 records the step and its measurements (`m8/results/VARKA-507-step5-local.txt`).

### Why are the changes needed?

The matrix takes over an hour of wall time against a target of 20 to 30 minutes, and most configurations change nothing in most SQL tests. Measured against the first fanned-out run's suite times, the record saves 7.6 of the matrix's 40 configuration-hours, 19%.

The cost is about 14% more time on the sql varka-scoped jobs of every Varka pull request's Build. The project's owner accepted that trade on 28 October 2026. The saving is smaller than single-suite tests suggested because of the set-up rule. `VarkaCoverageDifferentialSuite` caches views of its fixtures in `beforeAll`, and that set-up is changed by 16 of the 34 recorded configurations. So under those 16, the whole suite runs.

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

No. The main-code hooks do nothing unless the test-only recorder is listening. Everything else is tests and CI.

### How was this patch tested?

- `VarkaTestReachSuite` (10 tests) checks:
  - a planted arm names exactly the kernel whose bytes it moves;
  - a compile whose result changes, or whose recompile throws, is named;
  - an option the test already pins moves nothing;
  - the skip rule in each of its cases;
  - suite and JVM lines join their tests;
  - a broken record counts as none;
  - a paused recorder hears nothing;
  - every `FULL` entry names a matrix configuration.
- On the laptop, over the whole sql module (`m8/results/VARKA-507-step5-local.txt`):
  - the plain defaults run took 826 s, and the recording run 941 s;
  - over the record, `cse=false` took 632 s, with 424 of its 1,679 tests skipped and the rest passing;
  - the planner's bins went from 178 to 151.
- The linters pass.
- Not testable before merge: this pull request changes `build_and_test.yml`, so its own Build runs Spark's module matrix rather than the varka-scoped jobs, and no record is made. Its dispatched matrix therefore checks the no-record path, where every test runs. The recording path first runs on the next push of Varka files alone. The numbers to read there are that Build's sql shard times and the matrix's `atdef` column.

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

Generated-by: Claude Code (Opus 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Oct 29, 2026
…session (apache#1102)

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

The coverage differential suite currently checks every row of Varka's coverage table through two Spark sessions, which spends most of its time in Spark's query machinery. This PR moves two of its forms onto the session-free harness from apache#1101, and cuts the session-based suite to a sample of rows for those forms.

**This PR sits on apache#1101**, whose two commits it includes. Its own commit is the last one.

- **The answer form, under both consumers.** `VarkaCoverageHarnessSuite` already ran each row through the columnar node's `project`. It now also runs each projection through the row node's `projectFused`, which is what a direct query's plan uses.
- **The partition oracle,** in the new `VarkaPartitionOracle`. For each predicate row it checks:
  - `WHERE p`, `NOT (p)`, `(p) IS NULL` and `(p) IS NOT NULL` through Varka's filter evaluator, which must keep Spark's rows;
  - that Spark's own three sets share no row and leave none out;
  - that the known rows are exactly the true and the false ones.

  Each check runs under the default optimizer, with the three rewriting rules excluded, and for null-safe rows with `NullPropagation` excluded too. The first two filters must be served whole by a kernel.
- **The null tests as CASE conditions,** and the boolean column read at both lanes.
- **Supporting harness changes:**
  - `VarkaHarnessPlans.query` plans a whole query over a fixture, whether a projection, a filter or a filter the optimizer folded to a constant.
  - A filter check records Spark's true rows.
  - A projection that leaves an output to the row path no longer counts as served, as the session suite required.
  - A second planted test shows the filter path can fail: under `checkIntOverflow=false` the kernel answers an overflowing row Spark raises on.
- **Test names and skip lines.** Every moved test keeps its old name, so its skip-list lines move by suite name alone: 16 partition and CASE-condition lines, plus the 10 answer lines from apache#1101 under that shared name.
- **`VarkaCoverageDifferentialSuite`** keeps the answer form for the first row of each family: 27 rows, covering what only a session shows (the columnar rule's plan, the cache and the two nodes). It drops the forms the harness now holds. The ANSI form and the domains stay for now and move in later changes.

Old tests to new, each kept under its name:

| Test | Before | Harness | Kept in session |
|---|---:|---:|---:|
| `<row> matches the row engine under both consumers` | 337 | 337 | 27 |
| `<row> splits every fixture into true, false and unknown rows` | 164 | 164 | 0 |
| `<row> under IS NULL and IS NOT NULL fuses as a CASE condition` | 164 | 164 | 0 |
| the boolean column at both lanes, the planted partition oracle | 2 | 2 | 0 |

### Why are the changes needed?

These checks need only an expression, its fixture rows and Spark's own evaluation, not a session. Measured on the laptop (`sql/varka/plans/m8/results/VARKA-509-step2a-local.txt`):

| Suite | Before | After |
|---|---|---|
| `VarkaCoverageDifferentialSuite` (session-based) | 1,066 tests, about 315 s | 426 tests, 96 s |
| `VarkaCoverageHarnessSuite` | (new in apache#1101) | 670 tests, 16 s |

The coverage differential suite is the option matrix's largest cost, and this saving applies under every configuration.

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

No. Tests only.

### How was this patch tested?

- Both suites pass at the defaults.
- Under `validityByWidth=false` both suites pass in one JVM, with the 31 listed tests cancelled and no stale line.
- Under `guardUnderArm=false` all 1,095 tests pass.
- The linters pass.

This PR, apache#1101 and apache#1093 all touch `sql/varka/matrix/skips.tsv` or `dev/varka_matrix.sh`. Whichever merges later needs master merged in and a fresh matrix.

### 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.

6 participants