Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,18 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w
buildCast[Decimal](_, d => decimalToTimestamp(d))
// TimestampWritable.doubleToTimestamp
case DoubleType =>
buildCast[Double](_, d => try {
decimalToTimestamp(Decimal(d))
} catch {
case _: NumberFormatException => null
})
buildCast[Double](_, d => doubleToTimestamp(d))
// TimestampWritable.floatToTimestamp
case FloatType =>
buildCast[Float](_, f => try {
decimalToTimestamp(Decimal(f))
} catch {
case _: NumberFormatException => null
})
buildCast[Float](_, f => doubleToTimestamp(f.toDouble))
}

private[this] def decimalToTimestamp(d: Decimal): Long = {
(d.toBigDecimal * 1000000L).longValue()
}
private[this] def doubleToTimestamp(d: Double): Any = {
if (d.isNaN || d.isInfinite) null else (d * 1000000L).toLong
}

// converting milliseconds to us
private[this] def longToTimestamp(t: Long): Long = t * 1000L
Expand Down Expand Up @@ -396,8 +391,7 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w
buildCast[InternalRow](_, row => {
var i = 0
while (i < row.length) {
val v = row(i)
newRow.update(i, if (v == null) null else casts(i)(v))
newRow.update(i, if (row.isNullAt(i)) null else casts(i)(row(i)))
i += 1
}
newRow.copy()
Expand Down