Skip to content

Commit

Permalink
[SPARK-12562][SQL] DataFrame.write.format(text) requires the column n…
Browse files Browse the repository at this point in the history
…ame to be called value

Author: Xiu Guo <[email protected]>

Closes #10515 from xguo27/SPARK-12562.

(cherry picked from commit 84f8492)
Signed-off-by: Reynold Xin <[email protected]>
  • Loading branch information
xguo27 authored and rxin committed Jan 4, 2016
1 parent 4e9dd16 commit f7a3223
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister {
partitionColumns: Option[StructType],
parameters: Map[String, String]): HadoopFsRelation = {
dataSchema.foreach(verifySchema)
new TextRelation(None, partitionColumns, paths)(sqlContext)
new TextRelation(None, dataSchema, partitionColumns, paths)(sqlContext)
}

override def shortName(): String = "text"
Expand All @@ -70,15 +70,16 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister {

private[sql] class TextRelation(
val maybePartitionSpec: Option[PartitionSpec],
val textSchema: Option[StructType],
override val userDefinedPartitionColumns: Option[StructType],
override val paths: Array[String] = Array.empty[String],
parameters: Map[String, String] = Map.empty[String, String])
(@transient val sqlContext: SQLContext)
extends HadoopFsRelation(maybePartitionSpec, parameters) {

/** Data schema is always a single column, named "value". */
override def dataSchema: StructType = new StructType().add("value", StringType)

/** Data schema is always a single column, named "value" if original Data source has no schema. */
override def dataSchema: StructType =
textSchema.getOrElse(new StructType().add("value", StringType))
/** This is an internal data source that outputs internal row format. */
override val needConversion: Boolean = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class TextSuite extends QueryTest with SharedSQLContext {
verifyFrame(sqlContext.read.text(testFile))
}

test("writing") {
val df = sqlContext.read.text(testFile)
test("SPARK-12562 verify write.text() can handle column name beyond `value`") {
val df = sqlContext.read.text(testFile).withColumnRenamed("value", "adwrasdf")

val tempFile = Utils.createTempDir()
tempFile.delete()
Expand Down

0 comments on commit f7a3223

Please sign in to comment.