Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/15059#discussion_r78717016
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvalHelper.scala
---
@@ -289,13 +290,32 @@ trait ExpressionEvalHelper extends
GeneratorDrivenPropertyChecks {
(result, expected) match {
case (result: Array[Byte], expected: Array[Byte]) =>
java.util.Arrays.equals(result, expected)
- case (result: Double, expected: Spread[Double @unchecked]) =>
- expected.asInstanceOf[Spread[Double]].isWithin(result)
case (result: Double, expected: Double) if result.isNaN &&
expected.isNaN =>
true
+ case (result: Double, expected: Double) =>
+ relativeErrorComparison(result, expected)
case (result: Float, expected: Float) if result.isNaN &&
expected.isNaN =>
true
case _ => result == expected
}
}
+
+ /**
+ * Private helper function for comparing two values using relative
tolerance.
+ * Note that if x or y is extremely close to zero, i.e., smaller than
Double.MinPositiveValue,
+ * the relative tolerance is meaningless, so the exception will be
raised to warn users.
+ */
+ private def relativeErrorComparison(x: Double, y: Double, eps: Double =
1E-8): Boolean = {
--- End diff --
Seems fine. You could refer to the source of this code and explain the
duplication but it's not a big deal.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]