Skip to content

Commit

Permalink
Update CustomCoders usages to implement verifyDeterministic (#4428)
Browse files Browse the repository at this point in the history
* Update CustomCoders usages to implement verifyDeterministic

* fix scala 2.12 issue

* rename test
  • Loading branch information
clairemcginty authored Jun 22, 2022
1 parent b1045d8 commit c8f09ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ final private class SpecificFixedCoder[A <: SpecificFixed](cls: Class[A]) extend
override def consistentWithEquals(): Boolean = true

override def structuralValue(value: A): AnyRef = value

override def verifyDeterministic(): Unit = {}
}

private object SpecificFixedCoder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GuavaBloomFilterCoder[T](implicit val funnel: g.Funnel[T])
value.writeTo(outStream)
override def decode(inStream: InputStream): BloomFilter[T] =
BloomFilter.readFrom[T](inStream, funnel)
override def verifyDeterministic(): Unit = {}
}

trait GuavaCoders {
Expand Down
16 changes: 15 additions & 1 deletion scio-test/src/test/scala/com/spotify/scio/coders/CoderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import com.google.api.services.bigquery.model.{TableFieldSchema, TableSchema}
import com.twitter.algebird.Moments
import org.scalatest.Assertion

import java.nio.charset.Charset

final case class UserId(bytes: Seq[Byte])
final case class User(id: UserId, username: String, email: String)

Expand Down Expand Up @@ -447,7 +449,9 @@ final class CoderTest extends AnyFlatSpec with Matchers {

it should "support specific fixed data" in {
val bytes = (0 to 15).map(_.toByte).toArray
new FixedSpecificDataExample(bytes) coderShould roundtrip()
val specificFixed = new FixedSpecificDataExample(bytes)
specificFixed coderShould beDeterministic()
specificFixed coderShould roundtrip()
}

it should "#1604: not throw on null" in {
Expand Down Expand Up @@ -623,6 +627,16 @@ final class CoderTest extends AnyFlatSpec with Matchers {
Coder.xmap[Int, String](Coder[Int])(_.toString, _.toInt)
)
}

it should "support Guava Bloom Filters" in {
import com.google.common.hash.{BloomFilter, Funnels}

implicit val funnel = Funnels.stringFunnel(Charset.forName("UTF-8"))
val bloomFilter = BloomFilter.create(funnel, 5L)

bloomFilter coderShould roundtrip()
bloomFilter coderShould beDeterministic()
}
}

object RecursiveCase {
Expand Down

0 comments on commit c8f09ba

Please sign in to comment.