Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/4498#discussion_r24466017
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala ---
@@ -264,8 +262,81 @@ class SQLContext(@transient val sparkContext:
SparkContext)
}
@DeveloperApi
- def applySchema(rowRDD: JavaRDD[Row], schema: StructType): DataFrame = {
- applySchema(rowRDD.rdd, schema);
+ def createDataFrame(rowRDD: JavaRDD[Row], schema: StructType): DataFrame
= {
+ createDataFrame(rowRDD.rdd, schema)
+ }
+
+ /**
+ * Creates a [[DataFrame]] from an [[RDD]] containing [[Row]]s by
applying
+ * a seq of names of columns to this RDD, the data type for each column
will
+ * be inferred by the first row.
+ *
+ * It does not support nested StructType, use createDataFrame(rdd,
schema) instead.
+ *
+ * For example:
+ *
+ * {{{
+ * val sqlContext = new org.apache.spark.sql.SQLContext(sc)
+ *
+ * val people =
sc.textFile("examples/src/main/resources/people.txt").map(
+ * _.split(",")).map(p => Row(p(0), p(1).trim.toInt))
+ * val dataFrame = sqlContext.createDataFrame(people, Seq("name",
"age"))
+ * dataFrame.printSchema
+ * // root
+ * // |-- name: string (nullable = false)
+ * // |-- age: integer (nullable = true)
+ * }}}
+ *
+ * @param rowRDD an RDD of Row
+ * @param columns names for each column
+ * @return DataFrame
+ */
+ def createDataFrame(rowRDD: RDD[Row], columns: Seq[String]): DataFrame =
{
+ def inferType: PartialFunction[Any, DataType] =
ScalaReflection.typeOfObject orElse {
+ case map: Map[_, _] =>
--- End diff --
Is the `Map` at here a `scala.collection.Map` or `Predef.Map`
(`scala.collection.immutable.Map`)? (We should use `scala.collection.Map` at
here.)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]