Skip to content

Commit d305e68

Browse files
Olivier Girardotrxin
authored andcommitted
SPARK-6988 : Fix documentation regarding DataFrames using the Java API
This patch includes : * adding how to use map after an sql query using javaRDD * fixing the first few java examples that were written in Scala Thank you for your time, Olivier. Author: Olivier Girardot <[email protected]> Closes #5564 from ogirardot/branch-1.3 and squashes the following commits: 9f8d60e [Olivier Girardot] SPARK-6988 : Fix documentation regarding DataFrames using the Java API (cherry picked from commit 6b528dc) Signed-off-by: Reynold Xin <[email protected]>
1 parent 59e206d commit d305e68

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/sql-programming-guide.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ df.groupBy("age").count().show()
193193

194194
<div data-lang="java" markdown="1">
195195
{% highlight java %}
196-
val sc: JavaSparkContext // An existing SparkContext.
197-
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
196+
JavaSparkContext sc // An existing SparkContext.
197+
SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc)
198198

199199
// Create the DataFrame
200200
DataFrame df = sqlContext.jsonFile("examples/src/main/resources/people.json");
@@ -308,8 +308,8 @@ val df = sqlContext.sql("SELECT * FROM table")
308308

309309
<div data-lang="java" markdown="1">
310310
{% highlight java %}
311-
val sqlContext = ... // An existing SQLContext
312-
val df = sqlContext.sql("SELECT * FROM table")
311+
SQLContext sqlContext = ... // An existing SQLContext
312+
DataFrame df = sqlContext.sql("SELECT * FROM table")
313313
{% endhighlight %}
314314
</div>
315315

@@ -435,7 +435,7 @@ DataFrame teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AN
435435

436436
// The results of SQL queries are DataFrames and support all the normal RDD operations.
437437
// The columns of a row in the result can be accessed by ordinal.
438-
List<String> teenagerNames = teenagers.map(new Function<Row, String>() {
438+
List<String> teenagerNames = teenagers.javaRDD().map(new Function<Row, String>() {
439439
public String call(Row row) {
440440
return "Name: " + row.getString(0);
441441
}
@@ -599,7 +599,7 @@ DataFrame results = sqlContext.sql("SELECT name FROM people");
599599

600600
// The results of SQL queries are DataFrames and support all the normal RDD operations.
601601
// The columns of a row in the result can be accessed by ordinal.
602-
List<String> names = results.map(new Function<Row, String>() {
602+
List<String> names = results.javaRDD().map(new Function<Row, String>() {
603603
public String call(Row row) {
604604
return "Name: " + row.getString(0);
605605
}
@@ -860,7 +860,7 @@ DataFrame parquetFile = sqlContext.parquetFile("people.parquet");
860860
//Parquet files can also be registered as tables and then used in SQL statements.
861861
parquetFile.registerTempTable("parquetFile");
862862
DataFrame teenagers = sqlContext.sql("SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19");
863-
List<String> teenagerNames = teenagers.map(new Function<Row, String>() {
863+
List<String> teenagerNames = teenagers.javaRDD().map(new Function<Row, String>() {
864864
public String call(Row row) {
865865
return "Name: " + row.getString(0);
866866
}

0 commit comments

Comments
 (0)