Skip to content

[SPARK-2724] Python version of RandomRDDGenerators - #1628

Closed
dorx wants to merge 11 commits into
apache:masterfrom
dorx:pythonRDD
Closed

dorx wants to merge 11 commits into
apache:masterfrom
dorx:pythonRDD

Conversation

@dorx

@dorx dorx commented Jul 29, 2014

Copy link
Copy Markdown
Contributor

RandomRDDGenerators but without support for randomRDD and randomVectorRDD, which take in arbitrary DistributionGenerator.

randomRDD.py is named to avoid collision with the built-in Python random package.

@SparkQA

SparkQA commented Jul 29, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 29, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17329/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.

move mean: Double to next line

@mengxr

mengxr commented Jul 29, 2014

Copy link
Copy Markdown
Contributor

LGTM except minor inline comments. For the file name, it should be possible to have a package named random, for example, numpy.random: http://docs.scipy.org/doc/numpy/reference/routines.random.html

@dorx

dorx commented Jul 29, 2014

Copy link
Copy Markdown
Contributor Author

In NumPy's source, they had a directory named random: https://github.com/numpy/numpy/tree/master/numpy/random
It seems like having directory hierarchy is the only way to organize packages:
https://docs.python.org/2/tutorial/modules.html#packages
In the flat structure that we have right now, naming a file random.py would override the python random package. We could either break the flat structure we currently have, rename the package to something else in Scala (although I don't know what's a good alternative), or let it be named something other than random. I'm okay with any of these options.

@SparkQA

SparkQA commented Jul 29, 2014

Copy link
Copy Markdown

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

@mengxr

mengxr commented Jul 29, 2014

Copy link
Copy Markdown
Contributor

Yes, having directories is the way to organize packages in python. We can make a folder for random and include the python files in mllib/pom.xml. Otherwise, user needs from pyspark.mllib.randomRDD import RandomRDDGenerators, which is a little strange.

@SparkQA

SparkQA commented Jul 29, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17370/consoleFull

@SparkQA

SparkQA commented Jul 29, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 29, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17377/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.

For these tests to run automatically, you also need to add this file into the python/run-tests script. Otherwise it won't automatically discover it, e.g. in Jenkins.

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.

Yep caught that while looking inside run-tests. Thanks for the reminder.

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.

Add a doc comment to this package similar to the one on RandomRDDGenerators.scala

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

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

@dorx

dorx commented Jul 30, 2014

Copy link
Copy Markdown
Contributor Author

Btw from pyspark.mllib import random now works with the latest commit in the pyspark shell.

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17407/consoleFull

@mengxr

mengxr commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

@dorx I tried import pyspark.mllib.random and it failed. It has to be from pyspark.mllib import random. And to use RandomRDDGenerators, I need to call random.RandomRDDGenerators. Ideally, it should be from pyspark.mllib.random import RandomRDDGenerators. If we know how to handle the name random now, maybe we can create random.py under mllib and define class RandomRDDGenerators there. If it is not easy to do that because of python's own random package, it should be fine to rename the package name to rand in both Python and Scala.

@mateiz

mateiz commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

If you can't figure out whether this is possible, consider pinging Josh or Davies too. I'd be surprised if there's no way around this because there are a lot of top-level packages in Python. There's gotta be a way to import our own vs importing theirs.

@JoshRosen

Copy link
Copy Markdown
Contributor

@mengxr Yeah, that would be okay to use but it turns out that it doesn't solve the lin_alg.py problem.

from __future__ import absolute_import enables absolute imports, but only in the file that contains it. In the failing linalg.py example, the problematic import random occurred in third-party code. If they added from __future__ import absolute_import, things would work fine.

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17498/consoleFull

Comment thread python/pyspark/__init__.py Outdated

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.

We definitely need some comments here to explain what is going on.

and added docs for hacks that allow us to keep the module name
mllib.random.
@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

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

Comment thread python/pyspark/mllib/random.py Outdated

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.

stats = x.stats()

@mengxr

mengxr commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

LGTM except minor inline comments.

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17606/consoleFull

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA results for PR 1628:
- 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/17610/consoleFull

@mengxr

mengxr commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Merged into master. Thanks!!

@asfgit asfgit closed this in d843014 Aug 1, 2014
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
RandomRDDGenerators but without support for randomRDD and randomVectorRDD, which take in arbitrary DistributionGenerator.

`randomRDD.py` is named to avoid collision with the built-in Python `random` package.

Author: Doris Xin <doris.s.xin@gmail.com>

Closes apache#1628 from dorx/pythonRDD and squashes the following commits:

55c6de8 [Doris Xin] review comments. all python units passed.
f831d9b [Doris Xin] moved default args logic into PythonMLLibAPI
2d73917 [Doris Xin] fix for linalg.py
8663e6a [Doris Xin] reverting back to a single python file for random
f47c481 [Doris Xin] docs update
687aac0 [Doris Xin] add RandomRDDGenerators.py to run-tests
4338f40 [Doris Xin] renamed randomRDD to rand and import as random
29d205e [Doris Xin] created mllib.random package
bd2df13 [Doris Xin] typos
07ddff2 [Doris Xin] units passed.
23b2ecd [Doris Xin] WIP
sunchao pushed a commit to sunchao/spark that referenced this pull request Jun 2, 2023
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 23, 2026
…ut fusion (apache#1669)

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

This regenerates `sql/varka/plans/m8/casts_suites.tsv`, the record of Spark's cast suites under Varka, on current master. It also updates the record's counts in `VARKA-368.md` (now 193 fused, 681 declined).

### Why are the changes needed?

Master's post-merge run 45171015126 failed on `8e631d8ed41`. `VarkaCastWithAnsiOffSuite`, `VarkaCastWithAnsiOnSuite` and `VarkaTryCastSuite` aborted in `afterAll`, because their lines in the record moved.

apache#1646 added the record. It was generated and tested on a base without apache#1628, and apache#1628 merged before apache#1646. apache#1628 fuses every 64-bit decimal value as a projection output. So 120 lines changed:

- A cast to a decimal now declines with "is row 350's" instead of "is row 348's".
- Five identity casts of 64-bit decimals now fuse (for example `DECIMAL(10,0)` to `DECIMAL(10,0)`), in all three suites and modes.

apache#1652 (also in that run) changes only matrix tooling and plans.

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

No. This changes only a generated test record.

### How was this patch tested?

- Regenerated with `VARKA_SUITES_REGEN=true build/sbt 'sql/testOnly *VarkaCastWithAnsiOffSuite *VarkaCastWithAnsiOnSuite *VarkaTryCastSuite'`. The 240 changed lines are exactly the lines CI printed.
- The three suites then pass without the regen flag: 435 tests, 0 aborted.
- `dev/varka_census.py --check` passes. The census changes no other file.

`/code-review high` found no bugs and three nits. One round fixed two: the commit message now counts all five newly fused casts, and the plan's counts are updated. The third nit was the commit's placeholder author. It is kept, because the PR is squash-merged.

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

5 participants