Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneguow committed Aug 5, 2024
1 parent 9964496 commit 6812f9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private[sql] class AvroDeserializer(
updater.setFloat(ordinal, value.asInstanceOf[Float])

case (FLOAT, DoubleType) => (updater, ordinal, value) =>
updater.setDouble(ordinal, value.asInstanceOf[Float])
updater.setDouble(ordinal, value.asInstanceOf[Float].toString.toDouble)

case (DOUBLE, DoubleType) => (updater, ordinal, value) =>
updater.setDouble(ordinal, value.asInstanceOf[Double])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,17 @@ abstract class AvroSuite
)

// Float -> Double
val floatPath = s"$tempPath/float_data1"
val floatDf = Seq(1, -1f, 2f).toDF("col")
val floatPath = s"$tempPath/float_data"
val floatDf = Seq(1.34F,
Float.MinValue, Float.MinPositiveValue, Float.MaxValue,
Float.NaN, Float.NegativeInfinity, Float.PositiveInfinity
).toDF("col")
floatDf.write.format("avro").save(floatPath)
checkAnswer(
spark.read.schema("col Double").format("avro").load(floatPath),
Seq(Row(1D), Row(-1D), Row(2D))
Seq(Row(1.34D),
Row(-3.4028235E38D), Row(1.4E-45D), Row(3.4028235E38D),
Row(Double.NaN), Row(Double.NegativeInfinity), Row(Double.PositiveInfinity))
)
}
}
Expand Down

0 comments on commit 6812f9b

Please sign in to comment.