Skip to content

Commit

Permalink
Adjust tests and explanations to limitations of the current Instant e…
Browse files Browse the repository at this point in the history
…ncoding
  • Loading branch information
pomadchin committed Mar 5, 2022
1 parent 952c79a commit 9273128
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dataset/src/test/scala/frameless/ColumnTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package frameless

import java.time.Instant
import java.time.{Instant, Duration}
import org.scalacheck.Prop._
import org.scalacheck.{Arbitrary, Gen, Prop}, Arbitrary.arbitrary
import org.scalatest.matchers.should.Matchers
Expand All @@ -13,7 +13,12 @@ final class ColumnTests extends TypedDatasetSuite with Matchers {
private implicit object OrderingImplicits {
implicit val sqlDateOrdering: Ordering[SQLDate] = Ordering.by(_.days)
implicit val sqlTimestmapOrdering: Ordering[SQLTimestamp] = Ordering.by(_.us)
implicit val arbInstant: Arbitrary[Instant] = Arbitrary(Gen.choose[Instant](Instant.EPOCH, Instant.now))
/**
* DateTimeUtils.instantToMicros supports dates starting 1970-01-01T00:00:00Z, which is Instant.EPOCH.
* This function also overflows on Instant.MAX, to be sure it never overflows we use Instant.MAX / 4.
* For implementation details check the org.apache.spark.sql.catalyst.util.DateTimeUtils.instantToMicros function details.
*/
implicit val arbInstant: Arbitrary[Instant] = Arbitrary(Gen.choose[Instant](Instant.EPOCH, Instant.ofEpochMilli(Instant.MAX.getEpochSecond / 4)))
}

test("select('a < 'b, 'a <= 'b, 'a > 'b, 'a >= 'b)") {
Expand Down Expand Up @@ -44,6 +49,7 @@ final class ColumnTests extends TypedDatasetSuite with Matchers {
check(forAll(prop[SQLTimestamp] _))
check(forAll(prop[String] _))
check(forAll(prop[Instant] _))
check(forAll(prop[Duration] _))
}

test("between") {
Expand Down Expand Up @@ -71,6 +77,7 @@ final class ColumnTests extends TypedDatasetSuite with Matchers {
check(forAll(prop[SQLTimestamp] _))
check(forAll(prop[String] _))
check(forAll(prop[Instant] _))
check(forAll(prop[Duration] _))
}

test("toString") {
Expand Down

0 comments on commit 9273128

Please sign in to comment.