-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cats Effect context for cassanda #2202
Conversation
Nice work! Could you squash the PR into a single commit? Also a lot of files don't have new lines at the end of the file. |
quill-ce/src/main/scala-2.13/io/getquill/context/ce/CeContext.scala
Outdated
Show resolved
Hide resolved
quill-ce/src/main/scala-2.12/io/getquill/context/ce/CeContext.scala
Outdated
Show resolved
Hide resolved
import java.util.concurrent.Executor | ||
import scala.language.higherKinds | ||
|
||
object GuavaCeUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this called GuavaCeUtils
, specifically why is the Guave
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That object hold and implicit class to convert guava ListenableFuture[T]
to the F[T]
. What do you think will be an approtiate name for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is reasonable. The Cassandra session code uses Guava's Future to do Async so we have to deal with Guava in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. The Cassandra session directly uses Guava Futures so you have no choice but to wrap that stuff into F[_]
and this is a reasonable implementation of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I didn't realize that cassandra uses Guave futures, in that case its okay. I still personally think its better design to put this inside of CassandraCeContext
or CeContext
rather than making a new top level object since this is consistent with how the rest of quill works.
quill-cassandra-ce/src/main/scala-2.12/io/getquill/util/GuavaCeUtils.scala
Outdated
Show resolved
Hide resolved
quill-cassandra-ce/src/main/scala-2.13/io/getquill/util/GuavaCeUtils.scala
Show resolved
Hide resolved
quill-cassandra-ce/src/main/scala-2.12/io/getquill/CassandraCeContext.scala
Outdated
Show resolved
Hide resolved
quill-cassandra-ce/src/main/scala-2.12/io/getquill/CassandraCeContext.scala
Outdated
Show resolved
Hide resolved
import scala.language.higherKinds | ||
|
||
object GuavaCeUtils { | ||
implicit class RichListenableFuture[T](lf: ListenableFuture[T]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend doing this differently. ListenableFuture
is an eagerly-evaluating construct, similar to CompletableFuture
and Future
itself. The conversion here should really be F[ListenableFuture[T]] => F[T]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea. Please check the new implementaion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Either way works for me.
quill-cassandra-ce/src/main/scala-2.13/io/getquill/CassandraCeContext.scala
Outdated
Show resolved
Hide resolved
@voropaevp Thank you for your contribution! In terms of implementation, I think everything here is good. My main concern is with the build. Since we support ~8 different databases, it's extremely important to make sure that all the images play well together and no single image takes too many resources. In the |
override def onFailure(t: Throwable): Unit = cb(Left(t)) | ||
|
||
override def onSuccess(result: ResultSet): Unit = cb(Right(result)) | ||
}, ecExecutor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better approach here would be to get the Async[F].executionContext
, then wrap it into an Executor
by delegating execute
. All uses of global
are highly suspect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, @adamgfraser did the same thing in FutureConversions.scala
in ListenableFutureConverter.asScala
to help with ZIO interop.
Maybe something like this?
val asyncEcExecutor =
new Executor {
override def execute(command: Runnable): Unit = Async[F].executionContext.execute(command)
}
override def onFailure(t: Throwable): Unit = cb(Left(t)) | ||
|
||
override def onSuccess(result: T): Unit = cb(Right(result)) | ||
}, ecExecutor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
import cats.effect._ | ||
import cats._ | ||
import io.getquill.util.GuavaCeUtils._ | ||
import cats.implicits._ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import cats.implicits._ | |
import cats.syntax.all._ |
package object catsEffect { | ||
|
||
lazy val testCeDB: CassandraCeContext[Literal.type, IO] = { | ||
implicit val af = Async[IO] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems kind of unnecessary. You don't have to capture the Async[IO]
, you can just ask for it any time you want it. Unless there's some type witchcraft here that I'm not aware of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need it for the new CassandraCeContext
below? I imagine you could also pass it explicitly?
new CassandraCeContext(Literal, c.cluster, c.keyspace, c.preparedStatementCacheSize)(Async[IO]) with CassandraTestEntities with Encoders with Decoders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with inlining Async[F] to avoid following error:
[error] /app/quill-cassandra-ce/src/test/scala-2.12/io/getquill/context/cassandra/catEffect/package.scala:14:9: diverging implicit expansion for type cats.effect.Async[F]
[error] starting with method asyncForKleisli in object Async
[error] new CassandraCeContext(Literal, c.cluster, c.keyspace, c.preparedStatementCacheSize) with CassandraTestEntities with Encoders with Decoders
[error] ^
[error] /app/quill-cassandra-ce/src/test/scala-2.12/io/getquill/context/cassandra/catEffect/package.scala:14:5: type mismatch;
[error] found : <error> with io.getquill.context.cassandra.CassandraTestEntities with io.getquill.context.cassandra.encoding.Encoders with io.getquill.context.cassandra.encoding.Decoders
[error] required: io.getquill.CassandraCeContext[io.getquill.Literal.type,cats.effect.IO]
[error] new CassandraCeContext(Literal, c.cluster, c.keyspace, c.preparedStatementCacheSize) with CassandraTestEntities with Encoders with Decoders
When using cats.effect.syntax._
version.sbt
Outdated
@@ -1 +1 @@ | |||
version in ThisBuild := "3.7.3-SNAPSHOT" | |||
version in ThisBuild := "3.7.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa! Make sure to keep this as -SNAPSHOT
since we're not doing a release-build yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, the latest version is 3.8.1-SNAPSHOT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think PR needs to be rebased off of master
Is it possible abstract over the |
@jilen It is possible, but the amount of Tagless-Final/Free-Monadic machinery it would take to do that would ultimately be waaay more complex then all of the context-implementations combined. I've tried. I don't think it's worth it. |
(Rant warning! This comment has nothing to do with the current PR. Please feel free to skip!) @jilen The problem is that the operating paradigms of these different DB systems are different enough that we would be building abstractions that literally make no sense half the time. For example, in order to have the flexibility that Future(s) have of passing a ExecutionContext into each |
@voropaevp I think we're very close to wrapping this up. Please merge in the latest change (I think it's just version.sbt) and make sure the builds work. I can merge and then push out a release later this week. |
I think you might have more success just abstracting over ZIO, Cats Effect, and Monix. This is, after all, part of what Cats Effect was designed to accomplish. You do indeed need to build some relatively complex abstractions to solve that problem, but in the case of those three, the abstractions are already built. Future, on the other hand, and other similar types are a different story. There isn't really any meaningful way of abstracting them and being sure that things still work correctly, because the types in question have relatively weak compositional properties. Since the desire is to maintain compatibility with these unruly constructs, abstraction really is probably out of the question. |
Zstream, Observable and fs2.Stream will require abstracting over too. And these are further away from each other than Task, IO or ZIO. |
That's a good point. And abstracting over those three is pretty much not even a meaningful thing to do. |
b84f59a
to
e9a3b5d
Compare
quill-cassandra-ce/src/main/scala-2.12/io/getquill/util/GuavaCeUtils.scala
Outdated
Show resolved
Hide resolved
quill-cassandra-ce/src/main/scala-2.13/io/getquill/util/GuavaCeUtils.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions :)
quill-cassandra-ce/src/main/scala-2.12/io/getquill/CassandraCeContext.scala
Outdated
Show resolved
Hide resolved
quill-cassandra-ce/src/main/scala-2.13/io/getquill/CassandraCeContext.scala
Outdated
Show resolved
Hide resolved
quill-cassandra-ce/src/main/scala-2.13/io/getquill/CassandraCeContext.scala
Outdated
Show resolved
Hide resolved
@diesalbla thank you for the suggested improvements. All were included. |
There is one additional change that I need to merge to master before this one that adds the session directly to |
Hey guys, sorry about the wait. I just merged what is hopefully the last of a series of large refactorings that needed to be done in order to align Quill with the ProtoQuill API modifications.
@voropaevp Is there any chance you can merge in the latest code and make the above changes? I know you've already done an amazing amount of work and it's almost embarrassing for me to ask you to do more. If you're willing to make these changes please let me know. If not, also please let me know and I will try to find time to merge them in myself. |
Will do. @deusaquilus |
d853f1b
to
24dcab9
Compare
Sorry for the mess, intial merge went wrong. |
Hey, will look at this this weekend. Rosh Hashanah and Yom Kippur just happened so I'm on a backlog 😅 |
closed in favour of #2343 |
Fixes #issue_number
Problem
Cats Effect context for cassanda. Cats ecosystem currently missing cassandra orms.
Solution
Cats Effect context for cassanda
Notes
2.11 is not support. Makes empty artifact.
Increased the
ReservedCodeCacheSize
to avoid warning on 2.12 compilation.Also changed the courier directory to the
/home/sbtuser/
from/root
.Checklist
README.md
if applicable[WIP]
to the pull request title if it's work in progresssbt scalariformFormat test:scalariformFormat
to make sure that the source files are formatted@getquill/maintainers