ing-bank / scruid

Scala + Druid: Scruid. A library that allows you to compose queries in Scala, and parse the result back into typesafe classes.
Apache License 2.0
115 stars 29 forks source link

Fixes library and compilation warnings, defaults to Scala 2.13 #100

Closed anskarl closed 4 years ago

anskarl commented 4 years ago

For Scala 2.12 and 2.13 there aren't any incompatibilities among library dependencies. For 2.11 there are minor info messages for scala-reflect and jawn-parser:

sbt:scruid> ++2.11.12 evicted
[info] Setting Scala version to 2.11.12 on 1 projects.
[info] Reapplying settings...
[info] Updating ...
[info] Done updating.
[info] Here are other dependency conflicts that were resolved:
[info]  * org.scala-lang:scala-reflect:2.11.12 is selected over 2.11.11
[info]      +- org.typelevel:machinist_2.11:0.6.6                 (depends on 2.11.12)
[info]      +- com.typesafe.scala-logging:scala-logging_2.11:3.9.2 (depends on 2.11.11)
[info]  * org.typelevel:jawn-parser_2.11:0.14.2 is selected over 0.14.1
[info]      +- org.mdedetrich:akka-stream-json_2.11:0.5.0         (depends on 0.14.2)
[info]      +- io.circe:circe-jawn_2.11:0.11.1 ()                 (depends on 0.14.1)
[success]
sbt:scruid> ++2.12.11 evicted
[info] Setting Scala version to 2.12.11 on 1 projects.
[info] Reapplying settings...
[info] Updating ...
[info] Done updating.
[success]
sbt:scruid> ++2.13.2 evicted
[info] Setting Scala version to 2.13.2 on 1 projects.
[info] Reapplying settings...
[info] Set current project to scruid (in build file:/Users/anskarl/work/Personal/dev/scruid/)
[info] Updating ...
[info] Done updating.
[success]

In Scala 2.13 Either is right-biased, therefore .right is deprecated:

[warn] src/main/scala/ing/wbaa/druid/client/DruidClient.scala:155:52: method right in class Either is deprecated (since 2.13.0): Either is now right-biased, use methods directly on Either
[warn]               decode[List[DruidScanResults]](json).right
[warn]                                                    ^
[warn] src/main/scala/ing/wbaa/druid/client/DruidClient.scala:158:40: method right in class Either is deprecated (since 2.13.0): Either is now right-biased, use methods directly on Either
[warn]               decode[List[Json]](json).right
[warn]                                        ^
[warn] src/main/scala/ing/wbaa/druid/client/DruidClient.scala:161:47: method right in class Either is deprecated (since 2.13.0): Either is now right-biased, use methods directly on Either
[warn]               decode[List[DruidResult]](json).right

To overcome this issue, I've added Scala-specific version of a helper function in ing.wbaa.druid.client.CirceDecoders that performs the desired map operation.

Specifically in Scala 2.11:

import io.circe.java8.time._

trait CirceDecoders extends JavaTimeDecoders {

  protected def mapRightProjection[L, R, R1](either: Either[L,R])(f: R => R1): Either[L,R1] = either match {
    case Right(value) => Right(f(value))
    case _ => either.asInstanceOf[Either[L, R1]]
  }

}

Similarly in Scala 2.12:

trait CirceDecoders {

  protected def mapRightProjection[L, R, R1](either: Either[L,R])(f: R => R1): Either[L,R1] = either match {
    case Right(value) => Right(f(value))
    case _ => either.asInstanceOf[Either[L, R1]]
  }

}

While in Scala 2.13 is simply:

trait CirceDecoders {

  protected def mapRightProjection[L, R, R1](either: Either[L,R])(f: R => R1): Either[L,R1] = either.map(f(_))

}
anskarl commented 4 years ago

ok I am not going to do any other update, it is ready for review :)