@@ -48,7 +48,7 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister {
48
48
partitionColumns : Option [StructType ],
49
49
parameters : Map [String , String ]): HadoopFsRelation = {
50
50
dataSchema.foreach(verifySchema)
51
- new TextRelation (None , partitionColumns, paths)(sqlContext)
51
+ new TextRelation (None , dataSchema, partitionColumns, paths)(sqlContext)
52
52
}
53
53
54
54
override def shortName (): String = " text"
@@ -68,15 +68,16 @@ class DefaultSource extends HadoopFsRelationProvider with DataSourceRegister {
68
68
69
69
private [sql] class TextRelation (
70
70
val maybePartitionSpec : Option [PartitionSpec ],
71
+ val textSchema : Option [StructType ],
71
72
override val userDefinedPartitionColumns : Option [StructType ],
72
73
override val paths : Array [String ] = Array .empty[String ],
73
74
parameters : Map [String , String ] = Map .empty[String , String ])
74
75
(@ transient val sqlContext : SQLContext )
75
76
extends HadoopFsRelation (maybePartitionSpec, parameters) {
76
77
77
- /** Data schema is always a single column, named "value". */
78
- override def dataSchema : StructType = new StructType ().add( " value " , StringType )
79
-
78
+ /** Data schema is always a single column, named "value" if original Data source has no schema . */
79
+ override def dataSchema : StructType =
80
+ textSchema.getOrElse( new StructType ().add( " value " , StringType ))
80
81
/** This is an internal data source that outputs internal row format. */
81
82
override val needConversion : Boolean = false
82
83
0 commit comments