Skip to content
Snippets Groups Projects
Commit 84f8492c authored by Xiu Guo's avatar Xiu Guo Committed by Reynold Xin
Browse files

[SPARK-12562][SQL] DataFrame.write.format(text) requires the column name to be called value

Author: Xiu Guo <xguo27@gmail.com>

Closes #10515 from xguo27/SPARK-12562.
parent 13dab9c3
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister { ...@@ -48,7 +48,7 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister {
partitionColumns: Option[StructType], partitionColumns: Option[StructType],
parameters: Map[String, String]): HadoopFsRelation = { parameters: Map[String, String]): HadoopFsRelation = {
dataSchema.foreach(verifySchema) dataSchema.foreach(verifySchema)
new TextRelation(None, partitionColumns, paths)(sqlContext) new TextRelation(None, dataSchema, partitionColumns, paths)(sqlContext)
} }
override def shortName(): String = "text" override def shortName(): String = "text"
...@@ -68,15 +68,16 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister { ...@@ -68,15 +68,16 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister {
private[sql] class TextRelation( private[sql] class TextRelation(
val maybePartitionSpec: Option[PartitionSpec], val maybePartitionSpec: Option[PartitionSpec],
val textSchema: Option[StructType],
override val userDefinedPartitionColumns: Option[StructType], override val userDefinedPartitionColumns: Option[StructType],
override val paths: Array[String] = Array.empty[String], override val paths: Array[String] = Array.empty[String],
parameters: Map[String, String] = Map.empty[String, String]) parameters: Map[String, String] = Map.empty[String, String])
(@transient val sqlContext: SQLContext) (@transient val sqlContext: SQLContext)
extends HadoopFsRelation(maybePartitionSpec, parameters) { extends HadoopFsRelation(maybePartitionSpec, parameters) {
/** Data schema is always a single column, named "value". */ /** Data schema is always a single column, named "value" if original Data source has no schema. */
override def dataSchema: StructType = new StructType().add("value", StringType) override def dataSchema: StructType =
textSchema.getOrElse(new StructType().add("value", StringType))
/** This is an internal data source that outputs internal row format. */ /** This is an internal data source that outputs internal row format. */
override val needConversion: Boolean = false override val needConversion: Boolean = false
......
...@@ -33,8 +33,8 @@ class TextSuite extends QueryTest with SharedSQLContext { ...@@ -33,8 +33,8 @@ class TextSuite extends QueryTest with SharedSQLContext {
verifyFrame(sqlContext.read.text(testFile)) verifyFrame(sqlContext.read.text(testFile))
} }
test("writing") { test("SPARK-12562 verify write.text() can handle column name beyond `value`") {
val df = sqlContext.read.text(testFile) val df = sqlContext.read.text(testFile).withColumnRenamed("value", "adwrasdf")
val tempFile = Utils.createTempDir() val tempFile = Utils.createTempDir()
tempFile.delete() tempFile.delete()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment