-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-2626 [DOCS] Stop SparkContext in all examples #2575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,6 @@ | |
| * Usage: JavaSparkPi [slices] | ||
| */ | ||
| public final class JavaSparkPi { | ||
|
|
||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi"); | ||
|
|
@@ -61,5 +60,7 @@ public Integer call(Integer integer, Integer integer2) { | |
| }); | ||
|
|
||
| System.out.println("Pi is roughly " + 4.0 * count / n); | ||
|
|
||
| jsc.stop(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about using the Closeable feature?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't mean call close() but use try with resources ? That would require requiring Java 7. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the sad reminder that java6 is still an anchor for spark |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,8 @@ public static void main(String[] args) throws Exception { | |
| // Load a text file and convert each line to a Java Bean. | ||
| JavaRDD<Person> people = ctx.textFile("examples/src/main/resources/people.txt").map( | ||
| new Function<String, Person>() { | ||
| public Person call(String line) throws Exception { | ||
| @Override | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these additions of "@OverRide" intentional? |
||
| public Person call(String line) { | ||
| String[] parts = line.split(","); | ||
|
|
||
| Person person = new Person(); | ||
|
|
@@ -82,6 +83,7 @@ public Person call(String line) throws Exception { | |
| // The results of SQL queries are SchemaRDDs and support all the normal RDD operations. | ||
| // The columns of a row in the result can be accessed by ordinal. | ||
| List<String> teenagerNames = teenagers.map(new Function<Row, String>() { | ||
| @Override | ||
| public String call(Row row) { | ||
| return "Name: " + row.getString(0); | ||
| } | ||
|
|
@@ -104,6 +106,7 @@ public String call(Row row) { | |
| JavaSchemaRDD teenagers2 = | ||
| sqlCtx.sql("SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19"); | ||
| teenagerNames = teenagers2.map(new Function<Row, String>() { | ||
| @Override | ||
| public String call(Row row) { | ||
| return "Name: " + row.getString(0); | ||
| } | ||
|
|
@@ -136,6 +139,7 @@ public String call(Row row) { | |
| // The results of SQL queries are JavaSchemaRDDs and support all the normal RDD operations. | ||
| // The columns of a row in the result can be accessed by ordinal. | ||
| teenagerNames = teenagers3.map(new Function<Row, String>() { | ||
| @Override | ||
| public String call(Row row) { return "Name: " + row.getString(0); } | ||
| }).collect(); | ||
| for (String name: teenagerNames) { | ||
|
|
@@ -162,12 +166,15 @@ public String call(Row row) { | |
|
|
||
| JavaSchemaRDD peopleWithCity = sqlCtx.sql("SELECT name, address.city FROM people2"); | ||
| List<String> nameAndCity = peopleWithCity.map(new Function<Row, String>() { | ||
| @Override | ||
| public String call(Row row) { | ||
| return "Name: " + row.getString(0) + ", City: " + row.getString(1); | ||
| } | ||
| }).collect(); | ||
| for (String name: nameAndCity) { | ||
| System.out.println(name); | ||
| } | ||
|
|
||
| ctx.stop(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,3 +78,5 @@ | |
| output = avro_rdd.map(lambda x: x[0]).collect() | ||
| for k in output: | ||
| print k | ||
|
|
||
| sc.stop() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,3 +57,5 @@ | |
| output = parquet_rdd.map(lambda x: x[1]).collect() | ||
| for k in output: | ||
| print k | ||
|
|
||
| sc.stop() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,5 +136,7 @@ object CassandraCQLTest { | |
| classOf[CqlOutputFormat], | ||
| job.getConfiguration() | ||
| ) | ||
|
|
||
| sc.stop() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,11 @@ object GroupByTest { | |
| arr1(i) = (ranGen.nextInt(Int.MaxValue), byteArr) | ||
| } | ||
| arr1 | ||
| }.cache | ||
| }.cache() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's scala, was it intentional to add the parens?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, all intentional. Parens should be used in Scala when methods have side effects, and @OverRide should be used in Java where an override is intended. These are just small matters of style but think worth standardizing to match other source and common practice while changing nearby code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, i learned something new and it's early on a monday - for others interested: http://docs.scala-lang.org/style/method-invocation.html |
||
| // Enforce that everything has been calculated and in cache | ||
| pairs1.count | ||
| pairs1.count() | ||
|
|
||
| println(pairs1.groupByKey(numReducers).count) | ||
| println(pairs1.groupByKey(numReducers).count()) | ||
|
|
||
| sc.stop() | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just whitespace