Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kellen committed Aug 23, 2024
1 parent f3f2fc7 commit dc5a39e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion beam/src/main/scala/magnolify/beam/BeamSchemaType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ object BeamSchemaField {

// BYTE An 8-bit signed value
implicit val bsfByte: BeamSchemaField[Byte] = id[Byte](_ => FieldType.BYTE)
implicit val bsfChar: BeamSchemaField[Char] = from[Byte](_.toChar)(_.toByte)
// INT16 A 16-bit signed value
implicit val bsfShort: BeamSchemaField[Short] = id[Short](_ => FieldType.INT16)
implicit val bsfChar: BeamSchemaField[Char] = from[Short](_.toChar)(_.toShort)
// INT32 A 32-bit signed value
implicit val bsfInt: BeamSchemaField[Int] = id[Int](_ => FieldType.INT32)
// INT64 A 64-bit signed value
Expand Down
10 changes: 6 additions & 4 deletions beam/src/test/scala/magnolify/beam/BeamSchemaTypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import org.apache.beam.sdk.schemas.Schema
import org.joda.time as joda
import org.scalacheck.{Arbitrary, Gen, Prop}

import java.time.{Instant, LocalDate, LocalDateTime, LocalTime}
import java.nio.ByteBuffer
import java.time.{Duration, Instant, LocalDate, LocalDateTime, LocalTime}
import java.util.UUID
import scala.reflect.ClassTag
import scala.jdk.CollectionConverters.*
Expand Down Expand Up @@ -67,7 +68,7 @@ class BeamSchemaTypeSuite extends MagnolifySuite {
test[Collections]
test[MoreCollections]

test[Bs]
test[Others]
test[Maps]
test[Logical]
test[Decimal]
Expand Down Expand Up @@ -140,7 +141,7 @@ class BeamSchemaTypeSuite extends MagnolifySuite {
}
}

case class Bs(bs: ByteString)
case class Others(bs: ByteString, cs: CharSequence, bb: ByteBuffer, c: Char)
case class Decimal(bd: BigDecimal, bdo: Option[BigDecimal])
case class Logical(
u: UUID,
Expand All @@ -160,7 +161,8 @@ case class JodaDate(jd: joda.LocalDate)
case class JavaTime(
i: Instant,
dt: LocalDateTime,
t: LocalTime
t: LocalTime,
d: Duration
)
case class JodaTime(
i: joda.Instant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ package object logical {
override protected val unit = TimeUnit.NANOS

// TIMESTAMP
implicit val pfTimestampMillis: Primitive[Instant] =
implicit val pfTimestampNanos: Primitive[Instant] =
ParquetField.logicalType[Long](ts(true))(nanosToInstant)(nanosFromInstant)
implicit val pfLocalDateTimeMillis: Primitive[LocalDateTime] =
implicit val pfLocalDateTimeNanos: Primitive[LocalDateTime] =
ParquetField.logicalType[Long](ts(false))(nanosToLocalDateTime)(nanosFromLocalDateTime)

// TIME
Expand Down
21 changes: 21 additions & 0 deletions parquet/src/test/scala/magnolify/parquet/ParquetTypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ class ParquetTypeSuite extends MagnolifySuite {
Arbitrary(Gen.choose(-max, max).map(BigDecimal.apply))
}

test("Decimal range") {
intercept[IllegalArgumentException] {
ParquetField.decimal32(0, 0)
}
intercept[IllegalArgumentException] {
ParquetField.decimal32(1, 10)
}
intercept[IllegalArgumentException] {
ParquetField.decimal64(0, 0)
}
intercept[IllegalArgumentException] {
ParquetField.decimal64(1, 19)
}
intercept[IllegalArgumentException] {
ParquetField.decimalFixed(0, 1)
}
intercept[IllegalArgumentException] {
ParquetField.decimalFixed(2, 5) // capacity = 4
}
}

{
implicit val arbBigDecimal: Arbitrary[BigDecimal] = decimal(9)
implicit val pfBigDecimal: ParquetField[BigDecimal] = ParquetField.decimal32(9, 0)
Expand Down

0 comments on commit dc5a39e

Please sign in to comment.