From dc5a39e108b8a2fae8be335a7acbd1ccbfd73296 Mon Sep 17 00:00:00 2001 From: Kellen Dye Date: Fri, 23 Aug 2024 13:12:27 -0400 Subject: [PATCH] coverage --- .../scala/magnolify/beam/BeamSchemaType.scala | 2 +- .../magnolify/beam/BeamSchemaTypeSuite.scala | 10 +++++---- .../magnolify/parquet/logical/package.scala | 4 ++-- .../magnolify/parquet/ParquetTypeSuite.scala | 21 +++++++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/beam/src/main/scala/magnolify/beam/BeamSchemaType.scala b/beam/src/main/scala/magnolify/beam/BeamSchemaType.scala index 05db9b5a..9f793a5e 100644 --- a/beam/src/main/scala/magnolify/beam/BeamSchemaType.scala +++ b/beam/src/main/scala/magnolify/beam/BeamSchemaType.scala @@ -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 diff --git a/beam/src/test/scala/magnolify/beam/BeamSchemaTypeSuite.scala b/beam/src/test/scala/magnolify/beam/BeamSchemaTypeSuite.scala index 129e81d6..297a8d89 100644 --- a/beam/src/test/scala/magnolify/beam/BeamSchemaTypeSuite.scala +++ b/beam/src/test/scala/magnolify/beam/BeamSchemaTypeSuite.scala @@ -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.* @@ -67,7 +68,7 @@ class BeamSchemaTypeSuite extends MagnolifySuite { test[Collections] test[MoreCollections] - test[Bs] + test[Others] test[Maps] test[Logical] test[Decimal] @@ -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, @@ -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, diff --git a/parquet/src/main/scala/magnolify/parquet/logical/package.scala b/parquet/src/main/scala/magnolify/parquet/logical/package.scala index e0b64d84..d2fcc5ba 100644 --- a/parquet/src/main/scala/magnolify/parquet/logical/package.scala +++ b/parquet/src/main/scala/magnolify/parquet/logical/package.scala @@ -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 diff --git a/parquet/src/test/scala/magnolify/parquet/ParquetTypeSuite.scala b/parquet/src/test/scala/magnolify/parquet/ParquetTypeSuite.scala index b7d6ef3a..6d1b8c89 100644 --- a/parquet/src/test/scala/magnolify/parquet/ParquetTypeSuite.scala +++ b/parquet/src/test/scala/magnolify/parquet/ParquetTypeSuite.scala @@ -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)