aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorOlivier Girardot <o.girardot@lateral-thoughts.com>2015-04-18 00:31:01 -0700
committerReynold Xin <rxin@databricks.com>2015-04-18 00:31:15 -0700
commit5f095d56054d57c54d81db1d36cd46312810fb6a (patch)
tree87f5ecbb5a5f0e25d9f25e12b4d416850f77e5ab /docs
parentd850b4bd3a294dd245881e03f7f94bf970a7ee79 (diff)
downloadspark-5f095d56054d57c54d81db1d36cd46312810fb6a.tar.gz
spark-5f095d56054d57c54d81db1d36cd46312810fb6a.tar.bz2
spark-5f095d56054d57c54d81db1d36cd46312810fb6a.zip
SPARK-6992 : Fix documentation example for Spark SQL on StructType
This patch is fixing the Java examples for Spark SQL when defining programmatically a Schema and mapping Rows. Author: Olivier Girardot <o.girardot@lateral-thoughts.com> Closes #5569 from ogirardot/branch-1.3 and squashes the following commits: c29e58d [Olivier Girardot] SPARK-6992 : Fix documentation example for Spark SQL on StructType (cherry picked from commit c9b1ba4b16a7afe93d45bf75b128cc0dd287ded0) Signed-off-by: Reynold Xin <rxin@databricks.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/sql-programming-guide.md13
1 files changed, 8 insertions, 5 deletions
diff --git a/docs/sql-programming-guide.md b/docs/sql-programming-guide.md
index d49233714a..b202254626 100644
--- a/docs/sql-programming-guide.md
+++ b/docs/sql-programming-guide.md
@@ -555,13 +555,16 @@ by `SQLContext`.
For example:
{% highlight java %}
-// Import factory methods provided by DataType.
-import org.apache.spark.sql.types.DataType;
+import org.apache.spark.api.java.function.Function;
+// Import factory methods provided by DataTypes.
+import org.apache.spark.sql.types.DataTypes;
// Import StructType and StructField
import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.types.StructField;
// Import Row.
import org.apache.spark.sql.Row;
+// Import RowFactory.
+import org.apache.spark.sql.RowFactory;
// sc is an existing JavaSparkContext.
SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
@@ -575,16 +578,16 @@ String schemaString = "name age";
// Generate the schema based on the string of schema
List<StructField> fields = new ArrayList<StructField>();
for (String fieldName: schemaString.split(" ")) {
- fields.add(DataType.createStructField(fieldName, DataType.StringType, true));
+ fields.add(DataTypes.createStructField(fieldName, DataTypes.StringType, true));
}
-StructType schema = DataType.createStructType(fields);
+StructType schema = DataTypes.createStructType(fields);
// Convert records of the RDD (people) to Rows.
JavaRDD<Row> rowRDD = people.map(
new Function<String, Row>() {
public Row call(String record) throws Exception {
String[] fields = record.split(",");
- return Row.create(fields[0], fields[1].trim());
+ return RowFactory.create(fields[0], fields[1].trim());
}
});