Skip to content

Commit

Permalink
Update codec for resolve decoding error between mysql bit(1) and `s…
Browse files Browse the repository at this point in the history
…cala Bealean`

cause by `java.lang.IllegalStateException: Value 'RawValue(16,63,true,[B@64697949)' can't be decoded to 'boolean'`
  • Loading branch information
Liam.M(엄익훈) authored and ikhoon committed Mar 31, 2016
1 parent fa51ee7 commit a68ba27
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ trait FinagleMysqlDecoders {
implicit val booleanDecoder: Decoder[Boolean] =
decoder[Boolean] {
case ByteValue(byte) => byte == (1: Byte)
case v: RawValue => v.bytes.head == (1: Byte)
}
implicit val byteDecoder: Decoder[Byte] =
decoder[Byte] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,31 @@ class FinagleMysqlEncodingSpec extends EncodingSpec {
}
}
}

"decode boolean types" - {
case class BooleanEncodingTestEntity(v1: Boolean, v2: Boolean)
val decodeBoolean = (entity: BooleanEncodingTestEntity) => {
val delete = quote(query[BooleanEncodingTestEntity].delete)
val insert = quote(query[BooleanEncodingTestEntity].insert)
val r = for {
_ <- testDB.run(delete)
_ <- testDB.run(insert)(List(entity))
result <- testDB.run(query[BooleanEncodingTestEntity])
} yield result
Await.result(r).head
}
"true" in {
val entity = BooleanEncodingTestEntity(true, true)
val r = decodeBoolean(entity)
r.v1 mustEqual true
r.v2 mustEqual true
}

"false" in {
val entity = BooleanEncodingTestEntity(false, false)
val r = decodeBoolean(entity)
r.v1 mustEqual false
r.v2 mustEqual false
}
}
}
5 changes: 5 additions & 0 deletions quill-sql/src/test/sql/mysql-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Create TABLE DateEncodingTestEntity(
v3 timestamp
);

Create TABLE BooleanEncodingTestEntity(
v1 BOOLEAN,
v2 BIT(1)
);

CREATE TABLE TestEntity(
s VARCHAR(255),
i INTEGER,
Expand Down
4 changes: 2 additions & 2 deletions quill-sql/src/test/sql/postgres-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE TABLE EncodingTestEntity(
v6 INTEGER,
v7 BIGINT,
v8 FLOAT,
v9 DOUBLE PRECISIOn,
v9 DOUBLE PRECISION,
v10 BYTEA,
v11 TIMESTAMP,
o1 VARCHAR(255),
Expand All @@ -43,7 +43,7 @@ CREATE TABLE EncodingTestEntity(
o6 INTEGER,
o7 BIGINT,
o8 FLOAT,
o9 DOUBLE PRECISIOn,
o9 DOUBLE PRECISION,
o10 BYTEA,
o11 TIMESTAMP
);
Expand Down

0 comments on commit a68ba27

Please sign in to comment.