@@ -45,26 +45,26 @@ private[sql] object JdbcResultSetRDD extends Logging {
4545 jdbcResultSet.map(asRow(_, row, schema.fields))
4646 }
4747
48- private def asRow (rs : ResultSet , row : GenericMutableRow , schema : Seq [StructField ]): Row = {
49- schema.zipWithIndex.foreach {
50- case (StructField (name, dataType, nullable), i) => {
51- dataType match {
52- case StringType => row.update(i, rs.getString(i + 1 ))
53- case DecimalType => row.update(i, rs.getBigDecimal(i + 1 ))
54- case BooleanType => row.update(i, rs.getBoolean(i + 1 ))
55- case ByteType => row.update(i, rs.getByte(i + 1 ))
56- case ShortType => row.update(i, rs.getShort(i + 1 ))
57- case IntegerType => row.update(i, rs.getInt(i + 1 ))
58- case LongType => row.update(i, rs.getLong(i + 1 ))
59- case FloatType => row.update(i, rs.getFloat(i + 1 ))
60- case DoubleType => row.update(i, rs.getDouble(i + 1 ))
61- case BinaryType => row.update(i, rs.getBytes(i + 1 ))
62- case TimestampType => row.update(i, rs.getTimestamp(i + 1 ))
63- case _ => sys.error(
64- s " Unsupported jdbc datatype " )
65- }
66- if (rs.wasNull) row.update(i, null )
48+ private def asRow (rs : ResultSet , row : GenericMutableRow , schemaFields : Seq [StructField ]): Row = {
49+ var i = 0
50+ while (i < schemaFields.length) {
51+ schemaFields(i).dataType match {
52+ case StringType => row.update(i, rs.getString(i + 1 ))
53+ case DecimalType => row.update(i, rs.getBigDecimal(i + 1 ))
54+ case BooleanType => row.update(i, rs.getBoolean(i + 1 ))
55+ case ByteType => row.update(i, rs.getByte(i + 1 ))
56+ case ShortType => row.update(i, rs.getShort(i + 1 ))
57+ case IntegerType => row.update(i, rs.getInt(i + 1 ))
58+ case LongType => row.update(i, rs.getLong(i + 1 ))
59+ case FloatType => row.update(i, rs.getFloat(i + 1 ))
60+ case DoubleType => row.update(i, rs.getDouble(i + 1 ))
61+ case BinaryType => row.update(i, rs.getBytes(i + 1 ))
62+ case TimestampType => row.update(i, rs.getTimestamp(i + 1 ))
63+ case _ => sys.error(
64+ s " Unsupported jdbc datatype " )
6765 }
66+ if (rs.wasNull) row.update(i, null )
67+ i += 1
6868 }
6969
7070 row
0 commit comments