Skip to content

Commit

Permalink
Failing test in LitTest:
Browse files Browse the repository at this point in the history
```
- support value class *** FAILED *** (101 milliseconds)
[info]   Array(Q(1,[0,1000000005,6d65726f4c]), Q(2,[0,1000000005,6d65726f4c])) was not equal to List(Q(1,Lorem), Q(2,Lorem)) (LitTests.scala:70)
```
  • Loading branch information
cchantep committed Aug 29, 2021
1 parent 985e1b8 commit a4f8950
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dataset/src/main/scala/frameless/RecordEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class RecordEncoder[F, G <: HList, H <: HList]
}
}

final class RecordFieldEncoder[T](val encoder: TypedEncoder[T])
final class RecordFieldEncoder[T](
val encoder: TypedEncoder[T]) extends Serializable

object RecordFieldEncoder extends RecordFieldEncoderLowPriority {

Expand Down
33 changes: 28 additions & 5 deletions dataset/src/test/scala/frameless/LitTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package frameless

import frameless.functions.lit

import org.scalacheck.Prop
import org.scalacheck.Prop._
import org.scalatest.matchers.should.Matchers

class LitTests extends TypedDatasetSuite {
import org.scalacheck.{ Arbitrary, Gen, Prop }, Prop._

import RecordEncoderTests.Name

class LitTests extends TypedDatasetSuite with Matchers {
def prop[A: TypedEncoder](value: A): Prop = {
val df: TypedDataset[Int] = TypedDataset.create(1 :: Nil)

Expand All @@ -21,7 +24,6 @@ class LitTests extends TypedDatasetSuite {
.run()
.toVector


(localElems ?= Vector(value)) && (elems ?= Vector(value))
}

Expand All @@ -45,10 +47,29 @@ class LitTests extends TypedDatasetSuite {

check(prop[Food] _)

implicit def nameArb: Arbitrary[Name] =
Arbitrary(Gen.alphaStr.map(new Name(_)))

check(prop[Name] _)

// doesn't work, object has to be serializable
// check(prop[frameless.LocalDateTime] _)
}

test("support value class") {
val initial = Seq(
Q(name = new Name("Foo"), id = 1),
Q(name = new Name("Bar"), id = 2))
val ds = TypedDataset.create(initial)

ds.collect.run() shouldBe initial

val lorem = new Name("Lorem")

ds.withColumnReplaced('name, lit(lorem)).
collect.run() shouldBe initial.map(_.copy(name = lorem))
}

test("#205: comparing literals encoded using Injection") {
import org.apache.spark.sql.catalyst.util.DateTimeUtils
implicit val dateAsInt: Injection[java.sql.Date, Int] =
Expand All @@ -58,8 +79,10 @@ class LitTests extends TypedDatasetSuite {
val data = Vector(P(42, today))
val tds = TypedDataset.create(data)

tds.filter(tds('d) === today).collect().run()
tds.filter(tds('d) === today).collect.run().map(_.i) shouldBe Seq(42)
}
}

final case class P(i: Int, d: java.sql.Date)

final case class Q(id: Int, name: Name)
4 changes: 3 additions & 1 deletion dataset/src/test/scala/frameless/RecordEncoderTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ object RecordEncoderTests {
case class B(a: Seq[A])
case class C(b: B)

class Name(val value: String) extends AnyVal with Serializable
class Name(val value: String) extends AnyVal with Serializable {
override def toString = value
}

case class Person(name: Name, age: Int)

Expand Down

0 comments on commit a4f8950

Please sign in to comment.