From ad801e5cd13375f852ef95e494c4cfb05a4aced4 Mon Sep 17 00:00:00 2001 From: Michel Davit Date: Mon, 21 Aug 2023 16:59:29 +0200 Subject: [PATCH] Update to sbt-typelevel 0.5.0 (#783) * Update to sbt-typelevel 0.5.0 compliation now fails for public implicit if type is not explicitelly specified * Move frequency to cron sytax scala-steward validate-repo-config failed with previous syntax. Use cron syntax for every month * Update to RC7 * Fix RC7 update * Update to v0.5.0-RC8 * Update to RC12 * Update to RC12 --- .github/workflows/ci.yml | 243 ++++++++++-------- .scala-steward.conf | 2 +- .../scala/magnolify/avro/unsafe/package.scala | 6 +- .../magnolify/bigquery/TableRowType.scala | 23 +- .../magnolify/bigquery/unsafe/package.scala | 10 +- .../magnolify/bigtable/BigtableType.scala | 43 ++-- build.sbt | 3 +- .../magnolify/datastore/EntityType.scala | 18 +- .../magnolify/datastore/unsafe/package.scala | 10 +- .../magnolify/parquet/ParquetField.scala | 18 +- .../magnolify/parquet/unsafe/package.scala | 3 +- .../magnolify/parquet/PredicateSuite.scala | 7 +- project/build.properties | 2 +- project/plugins.sbt | 2 +- .../magnolify/protobuf/ProtobufType.scala | 16 +- .../magnolify/protobuf/unsafe/package.scala | 6 +- .../magnolify/tensorflow/ExampleType.scala | 9 +- .../magnolify/tensorflow/unsafe/package.scala | 17 +- 18 files changed, 242 insertions(+), 196 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56ad27727..3dd479c35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,74 +15,57 @@ on: tags: [v*] env: - PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }} - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - PGP_SECRET: ${{ secrets.PGP_SECRET }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +concurrency: + group: ${{ github.workflow }} @ ${{ github.ref }} + cancel-in-progress: true + jobs: build: name: Build and Test strategy: matrix: os: [ubuntu-latest] - scala: [2.13.11, 2.12.18] + scala: [2.13, 2.12] java: [corretto@17, corretto@11] exclude: - - scala: 2.12.18 + - scala: 2.12 java: corretto@11 runs-on: ${{ matrix.os }} + timeout-minutes: 60 steps: - name: Checkout current branch (full) uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Download Java (corretto@17) - id: download-java-corretto-17 - if: matrix.java == 'corretto@17' - uses: typelevel/download-java@v2 - with: - distribution: corretto - java-version: 17 - - name: Setup Java (corretto@17) + id: setup-java-corretto-17 if: matrix.java == 'corretto@17' uses: actions/setup-java@v3 with: - distribution: jdkfile + distribution: corretto java-version: 17 - jdkFile: ${{ steps.download-java-corretto-17.outputs.jdkFile }} + cache: sbt - - name: Download Java (corretto@11) - id: download-java-corretto-11 - if: matrix.java == 'corretto@11' - uses: typelevel/download-java@v2 - with: - distribution: corretto - java-version: 11 + - name: sbt update + if: matrix.java == 'corretto@17' && steps.setup-java-corretto-17.outputs.cache-hit == 'false' + run: sbt +update - name: Setup Java (corretto@11) + id: setup-java-corretto-11 if: matrix.java == 'corretto@11' uses: actions/setup-java@v3 with: - distribution: jdkfile + distribution: corretto java-version: 11 - jdkFile: ${{ steps.download-java-corretto-11.outputs.jdkFile }} + cache: sbt - - name: Cache sbt - uses: actions/cache@v3 - with: - path: | - ~/.sbt - ~/.ivy2/cache - ~/.coursier/cache/v1 - ~/.cache/coursier/v1 - ~/AppData/Local/Coursier/Cache/v1 - ~/Library/Caches/Coursier/v1 - key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + - name: sbt update + if: matrix.java == 'corretto@11' && steps.setup-java-corretto-11.outputs.cache-hit == 'false' + run: sbt +update - name: Check that workflows are up to date run: sbt githubWorkflowCheck @@ -101,11 +84,11 @@ jobs: - name: Make target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: mkdir -p test/target refined/target target shared/target tensorflow/target parquet/target tools/target protobuf/target jmh/target bigquery/target avro/target scalacheck/target datastore/target neo4j/target cats/target bigtable/target guava/target project/target + run: mkdir -p refined/target shared/target tensorflow/target parquet/target tools/target protobuf/target jmh/target bigquery/target avro/target scalacheck/target datastore/target neo4j/target cats/target bigtable/target guava/target project/target - name: Compress target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: tar cf targets.tar test/target refined/target target shared/target tensorflow/target parquet/target tools/target protobuf/target jmh/target bigquery/target avro/target scalacheck/target datastore/target neo4j/target cats/target bigtable/target guava/target project/target + run: tar cf targets.tar refined/target shared/target tensorflow/target parquet/target tools/target protobuf/target jmh/target bigquery/target avro/target scalacheck/target datastore/target neo4j/target cats/target bigtable/target guava/target project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') @@ -121,7 +104,6 @@ jobs: strategy: matrix: os: [ubuntu-latest] - scala: [2.13.11] java: [corretto@17] runs-on: ${{ matrix.os }} steps: @@ -130,91 +112,83 @@ jobs: with: fetch-depth: 0 - - name: Download Java (corretto@17) - id: download-java-corretto-17 - if: matrix.java == 'corretto@17' - uses: typelevel/download-java@v2 - with: - distribution: corretto - java-version: 17 - - name: Setup Java (corretto@17) + id: setup-java-corretto-17 if: matrix.java == 'corretto@17' uses: actions/setup-java@v3 with: - distribution: jdkfile + distribution: corretto java-version: 17 - jdkFile: ${{ steps.download-java-corretto-17.outputs.jdkFile }} + cache: sbt - - name: Download Java (corretto@11) - id: download-java-corretto-11 - if: matrix.java == 'corretto@11' - uses: typelevel/download-java@v2 - with: - distribution: corretto - java-version: 11 + - name: sbt update + if: matrix.java == 'corretto@17' && steps.setup-java-corretto-17.outputs.cache-hit == 'false' + run: sbt +update - name: Setup Java (corretto@11) + id: setup-java-corretto-11 if: matrix.java == 'corretto@11' uses: actions/setup-java@v3 with: - distribution: jdkfile + distribution: corretto java-version: 11 - jdkFile: ${{ steps.download-java-corretto-11.outputs.jdkFile }} + cache: sbt - - name: Cache sbt - uses: actions/cache@v3 - with: - path: | - ~/.sbt - ~/.ivy2/cache - ~/.coursier/cache/v1 - ~/.cache/coursier/v1 - ~/AppData/Local/Coursier/Cache/v1 - ~/Library/Caches/Coursier/v1 - key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} - - - name: Download target directories (2.13.11) + - name: sbt update + if: matrix.java == 'corretto@11' && steps.setup-java-corretto-11.outputs.cache-hit == 'false' + run: sbt +update + + - name: Download target directories (2.13) uses: actions/download-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.11 + name: target-${{ matrix.os }}-${{ matrix.java }}-2.13 - - name: Inflate target directories (2.13.11) + - name: Inflate target directories (2.13) run: | tar xf targets.tar rm targets.tar - - name: Download target directories (2.12.18) + - name: Download target directories (2.12) uses: actions/download-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18 + name: target-${{ matrix.os }}-${{ matrix.java }}-2.12 - - name: Inflate target directories (2.12.18) + - name: Inflate target directories (2.12) run: | tar xf targets.tar rm targets.tar - name: Import signing key if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == '' + env: + PGP_SECRET: ${{ secrets.PGP_SECRET }} + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} run: echo $PGP_SECRET | base64 -di | gpg --import - name: Import signing key and strip passphrase if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != '' + env: + PGP_SECRET: ${{ secrets.PGP_SECRET }} + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} run: | echo "$PGP_SECRET" | base64 -di > /tmp/signing-key.gpg echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg (echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1) - name: Publish - run: sbt '++ ${{ matrix.scala }}' tlCiRelease - - avro-legacy: - name: Test with legacy avro + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }} + run: sbt tlCiRelease + + dependency-submission: + name: Submit Dependencies + if: github.event_name != 'pull_request' strategy: matrix: os: [ubuntu-latest] - scala: [2.13.11] - java: [corretto@11] + java: [corretto@17] runs-on: ${{ matrix.os }} steps: - name: Checkout current branch (full) @@ -222,49 +196,102 @@ jobs: with: fetch-depth: 0 - - name: Download Java (corretto@17) - id: download-java-corretto-17 + - name: Setup Java (corretto@17) + id: setup-java-corretto-17 if: matrix.java == 'corretto@17' - uses: typelevel/download-java@v2 + uses: actions/setup-java@v3 with: distribution: corretto java-version: 17 + cache: sbt + + - name: sbt update + if: matrix.java == 'corretto@17' && steps.setup-java-corretto-17.outputs.cache-hit == 'false' + run: sbt +update + + - name: Setup Java (corretto@11) + id: setup-java-corretto-11 + if: matrix.java == 'corretto@11' + uses: actions/setup-java@v3 + with: + distribution: corretto + java-version: 11 + cache: sbt + + - name: sbt update + if: matrix.java == 'corretto@11' && steps.setup-java-corretto-11.outputs.cache-hit == 'false' + run: sbt +update + + - name: Submit Dependencies + uses: scalacenter/sbt-dependency-submission@v2 + with: + modules-ignore: test_2.13 test_2.12 magnolify_2.13 magnolify_2.12 + configs-ignore: test scala-tool scala-doc-tool test-internal + + validate-steward: + name: Validate Steward Config + strategy: + matrix: + os: [ubuntu-latest] + java: [temurin@11] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (fast) + uses: actions/checkout@v3 + + - name: Setup Java (temurin@11) + id: setup-java-temurin-11 + if: matrix.java == 'temurin@11' + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + + - uses: coursier/setup-action@v1 + with: + apps: scala-steward + + - run: scala-steward validate-repo-config .scala-steward.conf + + avro-legacy: + name: Test with legacy avro + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.13.11] + java: [corretto@11] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Setup Java (corretto@17) + id: setup-java-corretto-17 if: matrix.java == 'corretto@17' uses: actions/setup-java@v3 with: - distribution: jdkfile + distribution: corretto java-version: 17 - jdkFile: ${{ steps.download-java-corretto-17.outputs.jdkFile }} + cache: sbt - - name: Download Java (corretto@11) - id: download-java-corretto-11 - if: matrix.java == 'corretto@11' - uses: typelevel/download-java@v2 - with: - distribution: corretto - java-version: 11 + - name: sbt update + if: matrix.java == 'corretto@17' && steps.setup-java-corretto-17.outputs.cache-hit == 'false' + run: sbt +update - name: Setup Java (corretto@11) + id: setup-java-corretto-11 if: matrix.java == 'corretto@11' uses: actions/setup-java@v3 with: - distribution: jdkfile + distribution: corretto java-version: 11 - jdkFile: ${{ steps.download-java-corretto-11.outputs.jdkFile }} + cache: sbt - - name: Cache sbt - uses: actions/cache@v3 - with: - path: | - ~/.sbt - ~/.ivy2/cache - ~/.coursier/cache/v1 - ~/.cache/coursier/v1 - ~/AppData/Local/Coursier/Cache/v1 - ~/Library/Caches/Coursier/v1 - key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + - name: sbt update + if: matrix.java == 'corretto@11' && steps.setup-java-corretto-11.outputs.cache-hit == 'false' + run: sbt +update - name: Build project env: diff --git a/.scala-steward.conf b/.scala-steward.conf index 7545bbccf..9c0aa2872 100644 --- a/.scala-steward.conf +++ b/.scala-steward.conf @@ -7,6 +7,6 @@ dependencyOverrides = [ # version includes revision date. reduce PR frequency { dependency = { groupId = "com.google.apis", artifactId = "google-api-services-bigquery" }, - pullRequests = { frequency = "1 month" }, + pullRequests = { frequency = "0 0 1 * ?" }, } ] diff --git a/avro/src/main/scala/magnolify/avro/unsafe/package.scala b/avro/src/main/scala/magnolify/avro/unsafe/package.scala index e9290f90a..17492792b 100644 --- a/avro/src/main/scala/magnolify/avro/unsafe/package.scala +++ b/avro/src/main/scala/magnolify/avro/unsafe/package.scala @@ -19,9 +19,9 @@ package magnolify.avro import magnolify.shared._ package object unsafe { - implicit val afByte = AvroField.from[Int](_.toByte)(_.toInt) - implicit val afChar = AvroField.from[Int](_.toChar)(_.toInt) - implicit val afShort = AvroField.from[Int](_.toShort)(_.toInt) + implicit val afByte: AvroField[Byte] = AvroField.from[Int](_.toByte)(_.toInt) + implicit val afChar: AvroField[Char] = AvroField.from[Int](_.toChar)(_.toInt) + implicit val afShort: AvroField[Short] = AvroField.from[Int](_.toShort)(_.toInt) implicit def afUnsafeEnum[T: EnumType]: AvroField[UnsafeEnum[T]] = AvroField.from[String](UnsafeEnum.from[T])(UnsafeEnum.to[T]) diff --git a/bigquery/src/main/scala/magnolify/bigquery/TableRowType.scala b/bigquery/src/main/scala/magnolify/bigquery/TableRowType.scala index 1e661cfa3..96c031d83 100644 --- a/bigquery/src/main/scala/magnolify/bigquery/TableRowType.scala +++ b/bigquery/src/main/scala/magnolify/bigquery/TableRowType.scala @@ -23,6 +23,7 @@ import magnolia1._ import magnolify.shared.{CaseMapper, Converter} import magnolify.shims.FactoryCompat +import java.time.{Instant, LocalDate, LocalDateTime, LocalTime} import scala.collection.concurrent import scala.annotation.{implicitNotFound, StaticAnnotation} import scala.jdk.CollectionConverters._ @@ -200,23 +201,25 @@ object TableRowField { override def to(v: T)(cm: CaseMapper): Any = g(v) } - implicit val trfBool = at[Boolean]("BOOL")(_.toString.toBoolean)(identity) - implicit val trfLong = at[Long]("INT64")(_.toString.toLong)(identity) - implicit val trfDouble = at[Double]("FLOAT64")(_.toString.toDouble)(identity) - implicit val trfString = at[String]("STRING")(_.toString)(identity) - implicit val trfNumeric = + implicit val trfBool: TableRowField[Boolean] = at[Boolean]("BOOL")(_.toString.toBoolean)(identity) + implicit val trfLong: TableRowField[Long] = at[Long]("INT64")(_.toString.toLong)(identity) + implicit val trfDouble: TableRowField[Double] = + at[Double]("FLOAT64")(_.toString.toDouble)(identity) + implicit val trfString: TableRowField[String] = at[String]("STRING")(_.toString)(identity) + implicit val trfNumeric: TableRowField[BigDecimal] = at[BigDecimal]("NUMERIC")(NumericConverter.toBigDecimal)(NumericConverter.fromBigDecimal) - implicit val trfByteArray = + implicit val trfByteArray: TableRowField[Array[Byte]] = at[Array[Byte]]("BYTES")(x => BaseEncoding.base64().decode(x.toString))(x => BaseEncoding.base64().encode(x) ) import TimestampConverter._ - implicit val trfInstant = at("TIMESTAMP")(toInstant)(fromInstant) - implicit val trfDate = at("DATE")(toLocalDate)(fromLocalDate) - implicit val trfTime = at("TIME")(toLocalTime)(fromLocalTime) - implicit val trfDateTime = at("DATETIME")(toLocalDateTime)(fromLocalDateTime) + implicit val trfInstant: TableRowField[Instant] = at("TIMESTAMP")(toInstant)(fromInstant) + implicit val trfDate: TableRowField[LocalDate] = at("DATE")(toLocalDate)(fromLocalDate) + implicit val trfTime: TableRowField[LocalTime] = at("TIME")(toLocalTime)(fromLocalTime) + implicit val trfDateTime: TableRowField[LocalDateTime] = + at("DATETIME")(toLocalDateTime)(fromLocalDateTime) implicit def trfOption[T](implicit f: TableRowField[T]): TableRowField[Option[T]] = new Aux[Option[T], f.FromT, f.ToT] { diff --git a/bigquery/src/main/scala/magnolify/bigquery/unsafe/package.scala b/bigquery/src/main/scala/magnolify/bigquery/unsafe/package.scala index 7bd95e19c..f2033e97f 100644 --- a/bigquery/src/main/scala/magnolify/bigquery/unsafe/package.scala +++ b/bigquery/src/main/scala/magnolify/bigquery/unsafe/package.scala @@ -19,11 +19,11 @@ package magnolify.bigquery import magnolify.shared._ package object unsafe { - implicit val trfByte = TableRowField.from[Long](_.toByte)(_.toLong) - implicit val trfChar = TableRowField.from[Long](_.toChar)(_.toLong) - implicit val trfShort = TableRowField.from[Long](_.toShort)(_.toLong) - implicit val trfInt = TableRowField.from[Long](_.toInt)(_.toLong) - implicit val trfFloat = TableRowField.from[Double](_.toFloat)(_.toDouble) + implicit val trfByte: TableRowField[Byte] = TableRowField.from[Long](_.toByte)(_.toLong) + implicit val trfChar: TableRowField[Char] = TableRowField.from[Long](_.toChar)(_.toLong) + implicit val trfShort: TableRowField[Short] = TableRowField.from[Long](_.toShort)(_.toLong) + implicit val trfInt: TableRowField[Int] = TableRowField.from[Long](_.toInt)(_.toLong) + implicit val trfFloat: TableRowField[Float] = TableRowField.from[Double](_.toFloat)(_.toDouble) implicit def trfEnum[T](implicit et: EnumType[T]): TableRowField[T] = TableRowField.from[String](et.from)(et.to) diff --git a/bigtable/src/main/scala/magnolify/bigtable/BigtableType.scala b/bigtable/src/main/scala/magnolify/bigtable/BigtableType.scala index 07aeba9c4..4421f7f88 100644 --- a/bigtable/src/main/scala/magnolify/bigtable/BigtableType.scala +++ b/bigtable/src/main/scala/magnolify/bigtable/BigtableType.scala @@ -205,26 +205,35 @@ object BigtableField { } } - implicit val btfByte = primitive[Byte](java.lang.Byte.BYTES)(_.get)(_.put(_)) - implicit val btChar = primitive[Char](java.lang.Character.BYTES)(_.getChar)(_.putChar(_)) - implicit val btfShort = primitive[Short](java.lang.Short.BYTES)(_.getShort)(_.putShort(_)) - implicit val btfInt = primitive[Int](java.lang.Integer.BYTES)(_.getInt)(_.putInt(_)) - implicit val btfLong = primitive[Long](java.lang.Long.BYTES)(_.getLong)(_.putLong(_)) - implicit val btfFloat = primitive[Float](java.lang.Float.BYTES)(_.getFloat)(_.putFloat(_)) - implicit val btfDouble = primitive[Double](java.lang.Double.BYTES)(_.getDouble)(_.putDouble(_)) - implicit val btfBoolean = from[Byte](_ == 1)(if (_) 1 else 0) - implicit val btfUUID = primitive[UUID](16)(bb => new UUID(bb.getLong, bb.getLong)) { (bb, uuid) => - bb.putLong(uuid.getMostSignificantBits) - bb.putLong(uuid.getLeastSignificantBits) - } + implicit val btfByte: Primitive[Byte] = primitive[Byte](java.lang.Byte.BYTES)(_.get)(_.put(_)) + implicit val btChar: Primitive[Char] = + primitive[Char](java.lang.Character.BYTES)(_.getChar)(_.putChar(_)) + implicit val btfShort: Primitive[Short] = + primitive[Short](java.lang.Short.BYTES)(_.getShort)(_.putShort(_)) + implicit val btfInt: Primitive[Int] = + primitive[Int](java.lang.Integer.BYTES)(_.getInt)(_.putInt(_)) + implicit val btfLong: Primitive[Long] = + primitive[Long](java.lang.Long.BYTES)(_.getLong)(_.putLong(_)) + implicit val btfFloat: Primitive[Float] = + primitive[Float](java.lang.Float.BYTES)(_.getFloat)(_.putFloat(_)) + implicit val btfDouble: Primitive[Double] = + primitive[Double](java.lang.Double.BYTES)(_.getDouble)(_.putDouble(_)) + implicit val btfBoolean: Primitive[Boolean] = from[Byte](_ == 1)(if (_) 1 else 0) + implicit val btfUUID: Primitive[UUID] = + primitive[UUID](16)(bb => new UUID(bb.getLong, bb.getLong)) { (bb, uuid) => + bb.putLong(uuid.getMostSignificantBits) + bb.putLong(uuid.getLeastSignificantBits) + } - implicit val btfByteString = new Primitive[ByteString] { + implicit val btfByteString: Primitive[ByteString] = new Primitive[ByteString] { override val size: Option[Int] = None override def fromByteString(v: ByteString): ByteString = v override def toByteString(v: ByteString): ByteString = v } - implicit val btfByteArray = from[ByteString](_.toByteArray)(ByteString.copyFrom) - implicit val btfString = from[ByteString](_.toStringUtf8)(ByteString.copyFromUtf8) + implicit val btfByteArray: Primitive[Array[Byte]] = + from[ByteString](_.toByteArray)(ByteString.copyFrom) + implicit val btfString: Primitive[String] = + from[ByteString](_.toStringUtf8)(ByteString.copyFromUtf8) implicit def btfEnum[T](implicit et: EnumType[T]): Primitive[T] = from[String](et.from)(et.to) @@ -232,9 +241,9 @@ object BigtableField { implicit def btfUnsafeEnum[T: EnumType]: Primitive[UnsafeEnum[T]] = from[String](UnsafeEnum.from[T])(UnsafeEnum.to[T]) - implicit val btfBigInt = + implicit val btfBigInt: Primitive[BigInt] = from[ByteString](bs => BigInt(bs.toByteArray))(bi => ByteString.copyFrom(bi.toByteArray)) - implicit val btfBigDecimal = from[ByteString] { bs => + implicit val btfBigDecimal: Primitive[BigDecimal] = from[ByteString] { bs => val bb = bs.asReadOnlyByteBuffer() val scale = bb.getInt val unscaled = BigInt(bs.substring(java.lang.Integer.BYTES).toByteArray) diff --git a/build.sbt b/build.sbt index 3d9d25f1a..e887640d9 100644 --- a/build.sbt +++ b/build.sbt @@ -176,9 +176,8 @@ lazy val keepExistingHeader = ) val commonSettings = Seq( - tlFatalWarningsInCi := false, + tlFatalWarnings := false, tlJdkRelease := Some(8), - tlSkipIrrelevantScalas := true, scalacOptions ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((3, _)) => diff --git a/datastore/src/main/scala/magnolify/datastore/EntityType.scala b/datastore/src/main/scala/magnolify/datastore/EntityType.scala index ca6478d3f..bb8358576 100644 --- a/datastore/src/main/scala/magnolify/datastore/EntityType.scala +++ b/datastore/src/main/scala/magnolify/datastore/EntityType.scala @@ -238,23 +238,25 @@ object EntityField { // //////////////////////////////////////////////// // Entity key supports `Long` and `String` natively - implicit val efLong = at[Long](_.getIntegerValue)(makeValue) - implicit val efString = at[String](_.getStringValue)(makeValue) + implicit val efLong: EntityField[Long] = at[Long](_.getIntegerValue)(makeValue) + implicit val efString: EntityField[String] = at[String](_.getStringValue)(makeValue) // `Boolean`, `Double` and `Unit` should not be used as keys - implicit def efBool(implicit kf: KeyField[Boolean]) = at[Boolean](_.getBooleanValue)(makeValue) - implicit def efDouble(implicit kf: KeyField[Double]) = at[Double](_.getDoubleValue)(makeValue) - implicit def efUnit(implicit kf: KeyField[Unit]) = + implicit def efBool(implicit kf: KeyField[Boolean]): EntityField[Boolean] = + at[Boolean](_.getBooleanValue)(makeValue) + implicit def efDouble(implicit kf: KeyField[Double]): EntityField[Double] = + at[Double](_.getDoubleValue)(makeValue) + implicit def efUnit(implicit kf: KeyField[Unit]): EntityField[Unit] = at[Unit](_ => ())(_ => Value.newBuilder().setNullValue(NullValue.NULL_VALUE)) // User must provide `KeyField[T]` instances for `ByteString` and `Array[Byte]` - implicit def efByteString(implicit kf: KeyField[ByteString]) = + implicit def efByteString(implicit kf: KeyField[ByteString]): EntityField[ByteString] = at[ByteString](_.getBlobValue)(makeValue) - implicit def efByteArray(implicit kf: KeyField[Array[Byte]]) = + implicit def efByteArray(implicit kf: KeyField[Array[Byte]]): EntityField[Array[Byte]] = at[Array[Byte]](_.getBlobValue.toByteArray)(v => makeValue(ByteString.copyFrom(v))) // Encode `Instant` key as `Long` - implicit val efTimestamp = { + implicit val efTimestamp: EntityField[Instant] = { implicit val kfInstant = KeyField.at[Instant](_.toEpochMilli) at(TimestampConverter.toInstant)(TimestampConverter.fromInstant) } diff --git a/datastore/src/main/scala/magnolify/datastore/unsafe/package.scala b/datastore/src/main/scala/magnolify/datastore/unsafe/package.scala index a578d688f..de5b3543c 100644 --- a/datastore/src/main/scala/magnolify/datastore/unsafe/package.scala +++ b/datastore/src/main/scala/magnolify/datastore/unsafe/package.scala @@ -19,11 +19,11 @@ package magnolify.datastore import magnolify.shared._ package object unsafe { - implicit val efByte = EntityField.from[Long](_.toByte)(_.toLong) - implicit val efChar = EntityField.from[Long](_.toChar)(_.toLong) - implicit val efShort = EntityField.from[Long](_.toShort)(_.toLong) - implicit val efInt = EntityField.from[Long](_.toInt)(_.toLong) - implicit val efFloat = EntityField.from[Double](_.toFloat)(_.toDouble) + implicit val efByte: EntityField[Byte] = EntityField.from[Long](_.toByte)(_.toLong) + implicit val efChar: EntityField[Char] = EntityField.from[Long](_.toChar)(_.toLong) + implicit val efShort: EntityField[Short] = EntityField.from[Long](_.toShort)(_.toLong) + implicit val efInt: EntityField[Int] = EntityField.from[Long](_.toInt)(_.toLong) + implicit val efFloat: EntityField[Float] = EntityField.from[Double](_.toFloat)(_.toDouble) implicit def efEnum[T](implicit et: EnumType[T]): EntityField[T] = EntityField.from[String](et.from)(et.to) diff --git a/parquet/src/main/scala/magnolify/parquet/ParquetField.scala b/parquet/src/main/scala/magnolify/parquet/ParquetField.scala index 1f123a325..383241ada 100644 --- a/parquet/src/main/scala/magnolify/parquet/ParquetField.scala +++ b/parquet/src/main/scala/magnolify/parquet/ParquetField.scala @@ -217,58 +217,58 @@ object ParquetField { override type ParquetT = UnderlyingT } - implicit val pfBoolean = + implicit val pfBoolean: Primitive[Boolean] = primitive[Boolean, java.lang.Boolean]( _.addBoolean, TypeConverter.newBoolean, PrimitiveTypeName.BOOLEAN ) - implicit val pfByte = + implicit val pfByte: Primitive[Byte] = primitive[Byte, Integer]( c => v => c.addInteger(v.toInt), TypeConverter.newInt.map(_.toByte), PrimitiveTypeName.INT32, LogicalTypeAnnotation.intType(8, true) ) - implicit val pfShort = + implicit val pfShort: Primitive[Short] = primitive[Short, Integer]( c => v => c.addInteger(v.toInt), TypeConverter.newInt.map(_.toShort), PrimitiveTypeName.INT32, LogicalTypeAnnotation.intType(16, true) ) - implicit val pfInt = + implicit val pfInt: Primitive[Int] = primitive[Int, Integer]( _.addInteger, TypeConverter.newInt, PrimitiveTypeName.INT32, LogicalTypeAnnotation.intType(32, true) ) - implicit val pfLong = + implicit val pfLong: Primitive[Long] = primitive[Long, java.lang.Long]( _.addLong, TypeConverter.newLong, PrimitiveTypeName.INT64, LogicalTypeAnnotation.intType(64, true) ) - implicit val pfFloat = + implicit val pfFloat: Primitive[Float] = primitive[Float, java.lang.Float](_.addFloat, TypeConverter.newFloat, PrimitiveTypeName.FLOAT) - implicit val pfDouble = + implicit val pfDouble: Primitive[Double] = primitive[Double, java.lang.Double]( _.addDouble, TypeConverter.newDouble, PrimitiveTypeName.DOUBLE ) - implicit val pfByteArray = + implicit val pfByteArray: Primitive[Array[Byte]] = primitive[Array[Byte], Binary]( c => v => c.addBinary(Binary.fromConstantByteArray(v)), TypeConverter.newByteArray, PrimitiveTypeName.BINARY ) - implicit val pfString = + implicit val pfString: Primitive[String] = primitive[String, Binary]( c => v => c.addBinary(Binary.fromString(v)), TypeConverter.newString, diff --git a/parquet/src/main/scala/magnolify/parquet/unsafe/package.scala b/parquet/src/main/scala/magnolify/parquet/unsafe/package.scala index af560878d..1b22dde70 100644 --- a/parquet/src/main/scala/magnolify/parquet/unsafe/package.scala +++ b/parquet/src/main/scala/magnolify/parquet/unsafe/package.scala @@ -16,10 +16,11 @@ package magnolify.parquet +import magnolify.parquet.ParquetField.Primitive import magnolify.shared._ package object unsafe { - implicit val pfChar = ParquetField.from[Int](_.toChar)(_.toInt) + implicit val pfChar: Primitive[Char] = ParquetField.from[Int](_.toChar)(_.toInt) implicit def pfUnsafeEnum[T: EnumType]: ParquetField[UnsafeEnum[T]] = ParquetField.from[String](UnsafeEnum.from[T])(UnsafeEnum.to[T]) diff --git a/parquet/src/test/scala/magnolify/parquet/PredicateSuite.scala b/parquet/src/test/scala/magnolify/parquet/PredicateSuite.scala index 1ff8dfedf..0aef0595c 100644 --- a/parquet/src/test/scala/magnolify/parquet/PredicateSuite.scala +++ b/parquet/src/test/scala/magnolify/parquet/PredicateSuite.scala @@ -20,6 +20,7 @@ import java.{lang => jl} import java.time.Instant import cats._ import magnolify.cats.auto._ +import magnolify.parquet.ParquetField.Primitive import magnolify.parquet.logical.millis._ import magnolify.test._ import org.apache.parquet.filter2.compat.FilterCompat @@ -31,9 +32,9 @@ import scala.reflect.ClassTag class PredicateSuite extends MagnolifySuite { import magnolify.cats.TestEq._ - implicit val pfDecimal = ParquetField.decimal32(9) - implicit val projectionT = ParquetType[Projection] - implicit val projectionSubsetT = ParquetType[ProjectionSmall] + implicit val pfDecimal: Primitive[BigDecimal] = ParquetField.decimal32(9) + implicit val projectionT: ParquetType[Projection] = ParquetType[Projection] + implicit val projectionSubsetT: ParquetType[ProjectionSmall] = ParquetType[ProjectionSmall] private val records = (1 to 100).toList.map { i => Projection( diff --git a/project/build.properties b/project/build.properties index 344d39aa3..000716937 100644 --- a/project/build.properties +++ b/project/build.properties @@ -14,4 +14,4 @@ # specific language governing permissions and limitations # under the License. # -sbt.version=1.8.2 +sbt.version=1.9.1 diff --git a/project/plugins.sbt b/project/plugins.sbt index e4d7419c5..7fa90df17 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.19") +addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.5.0-RC12") addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4") diff --git a/protobuf/src/main/scala/magnolify/protobuf/ProtobufType.scala b/protobuf/src/main/scala/magnolify/protobuf/ProtobufType.scala index fe929a5e8..9f9a6ec05 100644 --- a/protobuf/src/main/scala/magnolify/protobuf/ProtobufType.scala +++ b/protobuf/src/main/scala/magnolify/protobuf/ProtobufType.scala @@ -254,14 +254,14 @@ object ProtobufField { private def id[T](_default: T): ProtobufField[T] = aux[T, T, T](_default)(identity)(identity) - implicit val pfBoolean = id[Boolean](false) - implicit val pfInt = id[Int](0) - implicit val pfLong = id[Long](0L) - implicit val pfFloat = id[Float](0.0f) - implicit val pfDouble = id[Double](0.0) - implicit val pfString = id[String]("") - implicit val pfByteString = id[ByteString](ByteString.EMPTY) - implicit val pfByteArray = + implicit val pfBoolean: ProtobufField[Boolean] = id[Boolean](false) + implicit val pfInt: ProtobufField[Int] = id[Int](0) + implicit val pfLong: ProtobufField[Long] = id[Long](0L) + implicit val pfFloat: ProtobufField[Float] = id[Float](0.0f) + implicit val pfDouble: ProtobufField[Double] = id[Double](0.0) + implicit val pfString: ProtobufField[String] = id[String]("") + implicit val pfByteString: ProtobufField[ByteString] = id[ByteString](ByteString.EMPTY) + implicit val pfByteArray: ProtobufField[Array[Byte]] = aux2[Array[Byte], ByteString](Array.emptyByteArray)(_.toByteArray)(ByteString.copyFrom) def enum[T, E <: Enum[E] with ProtocolMessageEnum](implicit diff --git a/protobuf/src/main/scala/magnolify/protobuf/unsafe/package.scala b/protobuf/src/main/scala/magnolify/protobuf/unsafe/package.scala index 632d75b75..d891e3b1e 100644 --- a/protobuf/src/main/scala/magnolify/protobuf/unsafe/package.scala +++ b/protobuf/src/main/scala/magnolify/protobuf/unsafe/package.scala @@ -18,9 +18,9 @@ package magnolify.protobuf import magnolify.shared._ package object unsafe { - implicit val pfByte = ProtobufField.from[Int](_.toByte)(_.toInt) - implicit val pfChar = ProtobufField.from[Int](_.toChar)(_.toInt) - implicit val pfShort = ProtobufField.from[Int](_.toShort)(_.toInt) + implicit val pfByte: ProtobufField[Byte] = ProtobufField.from[Int](_.toByte)(_.toInt) + implicit val pfChar: ProtobufField[Char] = ProtobufField.from[Int](_.toChar)(_.toInt) + implicit val pfShort: ProtobufField[Short] = ProtobufField.from[Int](_.toShort)(_.toInt) object Proto3Option { implicit val proto3Option: ProtobufOption = new ProtobufOption.Proto3Option diff --git a/tensorflow/src/main/scala/magnolify/tensorflow/ExampleType.scala b/tensorflow/src/main/scala/magnolify/tensorflow/ExampleType.scala index fd6424809..2a9559cb1 100644 --- a/tensorflow/src/main/scala/magnolify/tensorflow/ExampleType.scala +++ b/tensorflow/src/main/scala/magnolify/tensorflow/ExampleType.scala @@ -195,7 +195,7 @@ object ExampleField { } } - implicit val efLong = new Primitive[Long] { + implicit val efLong: Primitive[Long] = new Primitive[Long] { override type ValueT = jl.Long override def fromFeature(v: Feature): ju.List[Long] = if (v == null) { @@ -214,7 +214,7 @@ object ExampleField { FeatureSchema.newBuilder().setType(FeatureType.INT).build() } - implicit val efFloat = new Primitive[Float] { + implicit val efFloat: Primitive[Float] = new Primitive[Float] { override type ValueT = jl.Float override def fromFeature(v: Feature): ju.List[Float] = if (v == null) { @@ -234,7 +234,7 @@ object ExampleField { } - implicit val efByteString = new Primitive[ByteString] { + implicit val efByteString: Primitive[ByteString] = new Primitive[ByteString] { override type ValueT = ByteString override def fromFeature(v: Feature): ju.List[ByteString] = if (v == null) { @@ -254,7 +254,8 @@ object ExampleField { } - implicit val efByteArray = from[ByteString](_.toByteArray)(ByteString.copyFrom(_)) + implicit val efByteArray: Primitive[Array[Byte]] = + from[ByteString](_.toByteArray)(ByteString.copyFrom(_)) implicit def efOption[T](implicit ef: ExampleField[T]): ExampleField[Option[T]] = new ExampleField[Option[T]] { diff --git a/tensorflow/src/main/scala/magnolify/tensorflow/unsafe/package.scala b/tensorflow/src/main/scala/magnolify/tensorflow/unsafe/package.scala index 80c7691d8..2ed09ab51 100644 --- a/tensorflow/src/main/scala/magnolify/tensorflow/unsafe/package.scala +++ b/tensorflow/src/main/scala/magnolify/tensorflow/unsafe/package.scala @@ -18,15 +18,18 @@ package magnolify.tensorflow import com.google.protobuf.ByteString import magnolify.shared._ +import magnolify.tensorflow.ExampleField.Primitive + package object unsafe { - implicit val efByte = ExampleField.from[Long](_.toByte)(_.toLong) - implicit val efChar = ExampleField.from[Long](_.toChar)(_.toLong) - implicit val efShort = ExampleField.from[Long](_.toShort)(_.toLong) - implicit val efInt = ExampleField.from[Long](_.toInt)(_.toLong) - implicit val efDouble = ExampleField.from[Float](_.toDouble)(_.toFloat) - implicit val efBool = ExampleField.from[Long](_ == 1)(x => if (x) 1 else 0) - implicit val efString = ExampleField.from[ByteString](_.toStringUtf8)(ByteString.copyFromUtf8) + implicit val efByte: Primitive[Byte] = ExampleField.from[Long](_.toByte)(_.toLong) + implicit val efChar: Primitive[Char] = ExampleField.from[Long](_.toChar)(_.toLong) + implicit val efShort: Primitive[Short] = ExampleField.from[Long](_.toShort)(_.toLong) + implicit val efInt: Primitive[Int] = ExampleField.from[Long](_.toInt)(_.toLong) + implicit val efDouble: Primitive[Double] = ExampleField.from[Float](_.toDouble)(_.toFloat) + implicit val efBool: Primitive[Boolean] = ExampleField.from[Long](_ == 1)(x => if (x) 1 else 0) + implicit val efString: Primitive[String] = + ExampleField.from[ByteString](_.toStringUtf8)(ByteString.copyFromUtf8) implicit def efEnum[T](implicit et: EnumType[T]): ExampleField.Primitive[T] = ExampleField.from[ByteString](bs => et.from(bs.toStringUtf8))(v =>