stevomitric commented on code in PR #56207:
URL: https://github.com/apache/spark/pull/56207#discussion_r3330967342
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/OrderingSuite.scala:
##########
@@ -141,6 +142,61 @@ class OrderingSuite extends SparkFunSuite with
ExpressionEvalHelper {
GenerateOrdering.generate(Array.fill(5000)(sortOrder).toImmutableArraySeq)
}
+ // SPARK-57103: ordering for nanosecond timestamp types. Not driven by the
generic
+ // `atomicTypes` loop above because `RandomDataGenerator` does not yet
support the new
+ // types (tracked separately in SPARK-57034); we hand-roll edge cases here
instead.
+ private def compareNanos(
+ dataType: AtomicType,
+ a: TimestampNanosVal,
+ b: TimestampNanosVal,
+ expected: Int): Unit = {
+ test(s"compare two $dataType values: a = $a, b = $b") {
+ val rowA = InternalRow(a)
+ val rowB = InternalRow(b)
+ Seq(Ascending, Descending).foreach { direction =>
+ val sortOrder = direction match {
+ case Ascending => BoundReference(0, dataType, nullable = true).asc
+ case Descending => BoundReference(0, dataType, nullable = true).desc
+ }
+ val expectedCompareResult = direction match {
+ case Ascending => signum(expected)
+ case Descending => -1 * signum(expected)
+ }
+ val intOrdering = new InterpretedOrdering(sortOrder :: Nil)
+ val genOrdering = new LazilyGeneratedOrdering(sortOrder :: Nil)
+ Seq(intOrdering, genOrdering).foreach { ordering =>
+ assert(ordering.compare(rowA, rowA) === 0)
+ assert(ordering.compare(rowB, rowB) === 0)
+ assert(signum(ordering.compare(rowA, rowB)) ===
expectedCompareResult)
+ assert(signum(ordering.compare(rowB, rowA)) === -1 *
expectedCompareResult)
+ }
+ }
+ }
+ }
+
+ Seq(TimestampNTZNanosType(9), TimestampLTZNanosType(9)).foreach { dt =>
Review Comment:
Added tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]