Uh oh!
There was an error while loading. Please reload this page.
[SPARK-15031][EXAMPLE] Use SparkSession in Scala/Python/Java example. - #12809
[SPARK-15031][EXAMPLE] Use SparkSession in Scala/Python/Java example.#12809dongjoon-hyun wants to merge 1 commit into
Conversation
dongjoon-hyun
commented
Apr 30, 2016
I thought this is a bug fix, but I think I need to update to use |
rxin
commented
Apr 30, 2016
Are there other examples that we should update? |
dongjoon-hyun
commented
Apr 30, 2016
Oh, sure. May I proceed this PR for all examples and all testsuites together? |
dongjoon-hyun
commented
Apr 30, 2016
If you don't mind, I prefer to do as a single one. |
dongjoon-hyun
commented
Apr 30, 2016
I mean |
SparkQA
commented
Apr 30, 2016
Test build #57422 has finished for PR 12809 at commit
|
SparkQA
commented
Apr 30, 2016
Test build #57424 has finished for PR 12809 at commit
|
rxin
commented
Apr 30, 2016
I'd put all the example changes together, and have a separate pr for the test changes. |
dongjoon-hyun
commented
Apr 30, 2016
I see. No problem. Then, I'll use this one for all the example changes (including some fix like here). |
dongjoon-hyun
commented
Apr 30, 2016
As you know, for the example, I need to verify the result manually. |
SparkQA
commented
Apr 30, 2016
Test build #57438 has finished for PR 12809 at commit
|
SparkQA
commented
Apr 30, 2016
Test build #57440 has finished for PR 12809 at commit
|
SparkQA
commented
Apr 30, 2016
Test build #57441 has finished for PR 12809 at commit
|
dongjoon-hyun
commented
Apr 30, 2016
Hi, @rxin . For this issue, I'll add new constructor for Please let me know if there is some problem for this. |
rxin
commented
Apr 30, 2016
Yea that makes sense. For this one, I think we should also have a SparkSession ctor that takes in SparkConf, which calls SparkContext.getOrCreate to load a SparkContext. Then users can use this without declaring two things! |
dongjoon-hyun
commented
Apr 30, 2016
I updated Java examples with SparkSession(JavaSparkContext). For |
dongjoon-hyun
commented
Apr 30, 2016
Now, I addressed all comments so far. |
SparkQA
commented
Apr 30, 2016
Test build #57453 has finished for PR 12809 at commit
|
SparkQA
commented
Apr 30, 2016
Test build #57454 has finished for PR 12809 at commit
|
dongjoon-hyun
commented
May 1, 2016
Rebased. |
SparkQA
commented
May 1, 2016
Test build #57462 has finished for PR 12809 at commit
|
SparkQA
commented
May 1, 2016
Test build #57465 has finished for PR 12809 at commit
|
dongjoon-hyun
commented
May 1, 2016
Hi, @rxin . |
Hey @dongjoon-hyun Give me a day or two to think about the API for creating SparkSession. It'd be great to finalize that and then update the examples to reflect that. My current thinking is to have a factory method that can be used to instantiate SparkSession, something like SparkSession
.withMaster("local[4]")
.withConfig("...", "...")
.getOrCreate() |
dongjoon-hyun
commented
May 1, 2016
Thank you for feedback, @rxin . Sure! |
rxin
commented
May 2, 2016
I've merged #12830 want to update the example using that? |
dongjoon-hyun
commented
May 2, 2016
Sure! I'm waiting for it. :) Thank you! |
dongjoon-hyun
commented
May 4, 2016
Rebased to resolve conflicts. |
dongjoon-hyun
commented
May 4, 2016
Hi, @rxin and @andrewor14 . |
SparkQA
commented
May 4, 2016
Test build #57779 has finished for PR 12809 at commit
|
| SparkConf conf = new SparkConf().setAppName("JavaAFTSurvivalRegressionExample"); | ||
| JavaSparkContext jsc = new JavaSparkContext(conf); | ||
| SQLContext jsql = new SQLContext(jsc); | ||
| SparkSession spark = SparkSession.builder().appName("JavaAFTSurvivalRegressionExample").getOrCreate(); |
There was a problem hiding this comment.
line too long, can you break it into multiple lines (here and other places)
There was a problem hiding this comment.
Sure! Two or more?
Two Lines
SparkSession spark = SparkSession
.builder().appName("JavaAFTSurvivalRegressionExample").getOrCreate();
More Lines
SparkSession spark = SparkSession
.builder()
.appName("JavaAFTSurvivalRegressionExample")
.getOrCreate();
There was a problem hiding this comment.
Anyway, thank you for fast review! :)
There was a problem hiding this comment.
more lines looks better to me
There was a problem hiding this comment.
Thanks. I'll use that format for all languages.
andrewor14
commented
May 4, 2016
Thanks @dongjoon-hyun. This is mostly straightforward and it LGTM. I pointed out a few parts that were not totally straightforward for other reviewers. |
dongjoon-hyun
commented
May 4, 2016
Thank you for review, again! |
andrewor14
commented
May 4, 2016
I'm going to merge this one first to avoid conflicts since it's such a big patch. |
andrewor14
commented
May 4, 2016
Merging into master 2.0 |
## What changes were proposed in this pull request? This PR aims to update Scala/Python/Java examples by replacing `SQLContext` with newly added `SparkSession`. - Use **SparkSession Builder Pattern** in 154(Scala 55, Java 52, Python 47) files. - Add `getConf` in Python SparkContext class: `python/pyspark/context.py` - Replace **SQLContext Singleton Pattern** with **SparkSession Singleton Pattern**: - `SqlNetworkWordCount.scala` - `JavaSqlNetworkWordCount.java` - `sql_network_wordcount.py` Now, `SQLContexts` are used only in R examples and the following two Python examples. The python examples are untouched in this PR since it already fails some unknown issue. - `simple_params_example.py` - `aft_survival_regression.py` ## How was this patch tested? Manual. Author: Dongjoon Hyun <dongjoon@apache.org> Closes#12809 from dongjoon-hyun/SPARK-15031. (cherry picked from commit cdce4e6) Signed-off-by: Andrew Or <andrew@databricks.com>
dongjoon-hyun
commented
May 4, 2016
Oh, thank you, @andrewor14 . |
This PR removes `sqlContext` in examples. Actual usage was all replaced in #12809 but there are some in comments. Manual style checking. Author: hyukjinkwon <gurwls223@gmail.com> Closes#13006 from HyukjinKwon/minor-docs. (cherry picked from commit 2992a21) Signed-off-by: Andrew Or <andrew@databricks.com>
…with SparkSession ## What changes were proposed in this pull request? It seems most of Python examples were changed to use SparkSession by #12809. This PR said both examples below: - `simple_params_example.py` - `aft_survival_regression.py` are not changed because it dose not work. It seems `aft_survival_regression.py` is changed by #13050 but `simple_params_example.py` is not yet. This PR corrects the example and make this use SparkSession. In more detail, it seems `threshold` is replaced to `thresholds` here and there by 5a23213. However, when it calls `lr.fit(training, paramMap)` this overwrites the values. So, `threshold` was 5 and `thresholds` becomes 5.5 (by `1 / (1 + thresholds(0) / thresholds(1)`). According to the comment below. this is not allowed, https://github.com/apache/spark/blob/354f8f11bd4b20fa99bd67a98da3525fd3d75c81/mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala#L58-L61. So, in this PR, it sets the equivalent value so that this does not throw an exception. ## How was this patch tested? Manully (`mvn package -DskipTests && spark-submit simple_params_example.py`) Author: hyukjinkwon <gurwls223@gmail.com> Closes#13135 from HyukjinKwon/SPARK-15031. (cherry picked from commit e2ec32d) Signed-off-by: Nick Pentreath <nickp@za.ibm.com>
…with SparkSession ## What changes were proposed in this pull request? It seems most of Python examples were changed to use SparkSession by #12809. This PR said both examples below: - `simple_params_example.py` - `aft_survival_regression.py` are not changed because it dose not work. It seems `aft_survival_regression.py` is changed by #13050 but `simple_params_example.py` is not yet. This PR corrects the example and make this use SparkSession. In more detail, it seems `threshold` is replaced to `thresholds` here and there by 5a23213. However, when it calls `lr.fit(training, paramMap)` this overwrites the values. So, `threshold` was 5 and `thresholds` becomes 5.5 (by `1 / (1 + thresholds(0) / thresholds(1)`). According to the comment below. this is not allowed, https://github.com/apache/spark/blob/354f8f11bd4b20fa99bd67a98da3525fd3d75c81/mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala#L58-L61. So, in this PR, it sets the equivalent value so that this does not throw an exception. ## How was this patch tested? Manully (`mvn package -DskipTests && spark-submit simple_params_example.py`) Author: hyukjinkwon <gurwls223@gmail.com> Closes#13135 from HyukjinKwon/SPARK-15031.
What changes were proposed in this pull request?
This PR aims to update Scala/Python/Java examples by replacing
SQLContextwith newly addedSparkSession.getConfin Python SparkContext class:python/pyspark/context.pySqlNetworkWordCount.scalaJavaSqlNetworkWordCount.javasql_network_wordcount.pyNow,
SQLContextsare used only in R examples and the following two Python examples. The python examples are untouched in this PR since it already fails some unknown issue.simple_params_example.pyaft_survival_regression.pyHow was this patch tested?
Manual.