@@ -23,27 +23,24 @@ import org.apache.spark.sql.catalyst.CatalystTypeConverters
2323import org .apache .spark .sql .catalyst .analysis .MultiInstanceRelation
2424import org .apache .spark .sql .catalyst .expressions .{Attribute , GenericMutableRow , SpecificMutableRow }
2525import org .apache .spark .sql .catalyst .plans .logical .{LogicalPlan , Statistics }
26- import org .apache .spark .sql .types .StructType
26+ import org .apache .spark .sql .types .{ DataType , StructType }
2727import org .apache .spark .sql .{Row , SQLContext }
2828
2929/**
3030 * :: DeveloperApi ::
3131 */
3232@ DeveloperApi
3333object RDDConversions {
34- def productToRowRdd [A <: Product ](data : RDD [A ], schema : StructType ): RDD [Row ] = {
34+ def productToRowRdd [A <: Product ](data : RDD [A ], outputTypes : Seq [ DataType ] ): RDD [Row ] = {
3535 data.mapPartitions { iterator =>
3636 if (iterator.isEmpty) {
3737 Iterator .empty
3838 } else {
3939 val bufferedIterator = iterator.buffered
40- val mutableRow = new SpecificMutableRow (schema.fields.map(_.dataType))
41- val schemaFields = schema.fields
42- assert(mutableRow.length == schemaFields.length,
43- s " Input row has ${mutableRow.length} fields but schema has ${schemaFields.length}" )
44- val converters = schemaFields.map {
45- f => CatalystTypeConverters .createToCatalystConverter(f.dataType)
46- }
40+ val mutableRow = new SpecificMutableRow (outputTypes)
41+ assert(mutableRow.length == outputTypes.length,
42+ s " Input row has ${mutableRow.length} fields but outputTypes has ${outputTypes.length}" )
43+ val converters = outputTypes.map(CatalystTypeConverters .createToCatalystConverter)
4744 bufferedIterator.map { r =>
4845 var i = 0
4946 while (i < mutableRow.length) {
@@ -60,19 +57,16 @@ object RDDConversions {
6057 /**
6158 * Convert the objects inside Row into the types Catalyst expected.
6259 */
63- def rowToRowRdd (data : RDD [Row ], schema : StructType ): RDD [Row ] = {
60+ def rowToRowRdd (data : RDD [Row ], outputTypes : Seq [ DataType ] ): RDD [Row ] = {
6461 data.mapPartitions { iterator =>
6562 if (iterator.isEmpty) {
6663 Iterator .empty
6764 } else {
6865 val bufferedIterator = iterator.buffered
69- val mutableRow = new GenericMutableRow (bufferedIterator.head.toSeq.toArray)
70- val schemaFields = schema.fields
71- assert(mutableRow.length == schemaFields.length,
72- s " Input row has ${mutableRow.length} fields but schema has ${schemaFields.length}" )
73- val converters = schemaFields.map {
74- f => CatalystTypeConverters .createToCatalystConverter(f.dataType)
75- }
66+ val mutableRow = new SpecificMutableRow (outputTypes)
67+ assert(mutableRow.length == outputTypes.length,
68+ s " Input row has ${mutableRow.length} fields but outputTypes has ${outputTypes.length}" )
69+ val converters = outputTypes.map(CatalystTypeConverters .createToCatalystConverter)
7670 bufferedIterator.map { r =>
7771 var i = 0
7872 while (i < mutableRow.length) {
0 commit comments