diff options
author | sandy <phalodi@gmail.com> | 2016-08-02 10:34:01 -0700 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2016-08-02 10:34:01 -0700 |
commit | cbdff49357d6ce8d41b76b44628d90ead193eb5f (patch) | |
tree | a52d46c60bd27ff02204a582ebc1a3988e69626b /examples/src | |
parent | 2330f3ecbbd89c7eaab9cc0d06726aa743b16334 (diff) | |
download | spark-cbdff49357d6ce8d41b76b44628d90ead193eb5f.tar.gz spark-cbdff49357d6ce8d41b76b44628d90ead193eb5f.tar.bz2 spark-cbdff49357d6ce8d41b76b44628d90ead193eb5f.zip |
[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 <phalodi@gmail.com>
Closes #14436 from phalodi/SPARK-16816.
Diffstat (limited to 'examples/src')
-rw-r--r-- | examples/src/main/java/org/apache/spark/examples/sql/JavaSQLDataSourceExample.java | 16 |
1 files changed, 16 insertions, 0 deletions
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 52e3b62b79..fc92446783 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$ } |