Skip to content
Closed
Show file tree
Hide file tree
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 @@ -3578,6 +3578,7 @@ case class ArrayUnion(left: Expression, right: Expression) extends ArrayBinaryLi
val arrayBuffer = new scala.collection.mutable.ArrayBuffer[Any]
val hs = new SQLOpenHashSet[Any]()
val isNaN = SQLOpenHashSet.isNaN(elementType)
val valueNaN = SQLOpenHashSet.valueNaN(elementType)
Seq(array1, array2).foreach { array =>
var i = 0
while (i < array.numElements()) {
Expand All @@ -3590,7 +3591,7 @@ case class ArrayUnion(left: Expression, right: Expression) extends ArrayBinaryLi
val elem = array.get(i, elementType)
if (isNaN(elem)) {
if (!hs.containsNaN) {
arrayBuffer += elem
arrayBuffer += valueNaN
hs.addNaN
}
} else {
Expand Down Expand Up @@ -3688,16 +3689,18 @@ case class ArrayUnion(left: Expression, right: Expression) extends ArrayBinaryLi

def withNaNCheck(body: String): String = {
(elementType match {
case DoubleType => Some(s"java.lang.Double.isNaN((double)$value)")
case FloatType => Some(s"java.lang.Float.isNaN((float)$value)")
case DoubleType =>
Some((s"java.lang.Double.isNaN((double)$value)", "java.lang.Double.NaN"))
case FloatType =>
Some((s"java.lang.Float.isNaN((float)$value)", "java.lang.Float.NaN"))
case _ => None
}).map { isNaN =>
}).map { case (isNaN, valueNaN) =>
s"""
|if ($isNaN) {
| if (!$hashSet.containsNaN()) {
| $size++;
| $hashSet.addNaN();
| $builder.$$plus$$eq($value);
| $builder.$$plus$$eq($valueNaN);
| }
|} else {
| $body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ object SQLOpenHashSet {
case _ => (_: Any) => false
}
}

def valueNaN(dataType: DataType): Any = {
dataType match {
case DoubleType => java.lang.Double.NaN
case FloatType => java.lang.Float.NaN
case _ => null
}
}
}