You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by sr...@apache.org on 2016/08/02 17:34:04 UTC

spark git commit: [SPARK-16816] Modify java example which is also reflect in documentation exmaple

Repository: spark
Updated Branches:
  refs/heads/master 2330f3ecb -> cbdff4935


[SPARK-16816] Modify java example which is also reflect in documentation exmaple

## What changes were proposed in this pull request?

Modify java example which is also reflect in document.

## How was this patch tested?

run test cases.

Author: sandy <ph...@gmail.com>

Closes #14436 from phalodi/SPARK-16816.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/cbdff493
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/cbdff493
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/cbdff493

Branch: refs/heads/master
Commit: cbdff49357d6ce8d41b76b44628d90ead193eb5f
Parents: 2330f3e
Author: sandy <ph...@gmail.com>
Authored: Tue Aug 2 10:34:01 2016 -0700
Committer: Sean Owen <so...@cloudera.com>
Committed: Tue Aug 2 10:34:01 2016 -0700

----------------------------------------------------------------------
 .../examples/sql/JavaSQLDataSourceExample.java      | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/cbdff493/examples/src/main/java/org/apache/spark/examples/sql/JavaSQLDataSourceExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/spark/examples/sql/JavaSQLDataSourceExample.java b/examples/src/main/java/org/apache/spark/examples/sql/JavaSQLDataSourceExample.java
index 52e3b62..fc92446 100644
--- a/examples/src/main/java/org/apache/spark/examples/sql/JavaSQLDataSourceExample.java
+++ b/examples/src/main/java/org/apache/spark/examples/sql/JavaSQLDataSourceExample.java
@@ -19,10 +19,13 @@ package org.apache.spark.examples.sql;
 // $example on:schema_merging$
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 // $example off:schema_merging$
 
 // $example on:basic_parquet_example$
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
 import org.apache.spark.api.java.function.MapFunction;
 import org.apache.spark.sql.Encoders;
 // $example on:schema_merging$
@@ -213,6 +216,19 @@ public class JavaSQLDataSourceExample {
     // +------+
     // |Justin|
     // +------+
+
+    // Alternatively, a DataFrame can be created for a JSON dataset represented by
+    // an RDD[String] storing one JSON object per string.
+    List<String> jsonData = Arrays.asList(
+            "{\"name\":\"Yin\",\"address\":{\"city\":\"Columbus\",\"state\":\"Ohio\"}}");
+    JavaRDD<String> anotherPeopleRDD = new JavaSparkContext(spark.sparkContext()).parallelize(jsonData);
+    Dataset anotherPeople = spark.read().json(anotherPeopleRDD);
+    anotherPeople.show();
+    // +---------------+----+
+    // |        address|name|
+    // +---------------+----+
+    // |[Columbus,Ohio]| Yin|
+    // +---------------+----+
     // $example off:json_dataset$
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org