This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
forked from yanana/agni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
150 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package agni.internal | ||
|
||
import java.util.concurrent.CompletionStage | ||
|
||
import agni.{ Cql, RowDecoder } | ||
import agni.util.Par | ||
import cats.MonadError | ||
import cats.instances.stream._ | ||
import cats.syntax.functor._ | ||
import cats.syntax.traverse._ | ||
import cats.syntax.applicative._ | ||
import cats.syntax.flatMap._ | ||
import com.datastax.oss.driver.api.core.CqlSession | ||
import com.datastax.oss.driver.api.core.cql._ | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
trait Pageable { self: Cql.type => | ||
|
||
def getRows[F[_]: MonadError[*[*], Throwable]](session: CqlSession, stmt: BoundStatement)( | ||
implicit | ||
par: Par.Aux[CompletionStage, F] | ||
): F[Stream[Row]] = { | ||
def go(result: F[AsyncResultSet]): F[Stream[Row]] = | ||
result >>= { i => | ||
val page = i.currentPage().asScala.toStream | ||
if (!i.hasMorePages) page.pure[F] | ||
else go(par.parallel(i.fetchNextPage())).map(page ++ _) | ||
} | ||
|
||
go(executeAsync(session, stmt)) | ||
} | ||
|
||
def getRowsAs[F[_], A](session: CqlSession, stmt: BoundStatement)( | ||
implicit | ||
F: MonadError[F, Throwable], | ||
decodeA: RowDecoder[A], | ||
parF: Par.Aux[CompletionStage, F] | ||
): F[Stream[A]] = { | ||
val ver = session.getContext().getProtocolVersion() | ||
getRows[F](session, stmt) >>= (_.traverse(row => F.fromEither(decodeA(row, ver)))) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/main/scala_2.12-/agni/internal/ScalaVersionSpecifics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package agni.internal | ||
|
||
import scala.collection.generic.CanBuildFrom | ||
import scala.collection.mutable | ||
|
||
private[agni] object ScalaVersionSpecifics { | ||
private[agni] type Factory[-E, +T] = CanBuildFrom[Nothing, E, T] | ||
|
||
implicit private[agni] class FactoryOps[F, E, T](val bf: Factory[E, T]) extends AnyVal { | ||
def newBuilder: mutable.Builder[E, T] = bf.apply() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package agni.internal | ||
|
||
import java.util.concurrent.CompletionStage | ||
|
||
import agni.{ Cql, RowDecoder } | ||
import agni.util.Par | ||
import cats.MonadError | ||
import cats.instances.lazyList._ | ||
import cats.syntax.functor._ | ||
import cats.syntax.traverse._ | ||
import cats.syntax.applicative._ | ||
import cats.syntax.flatMap._ | ||
import com.datastax.oss.driver.api.core.CqlSession | ||
import com.datastax.oss.driver.api.core.cql._ | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
trait Pageable { self: Cql.type => | ||
|
||
def getRows[F[_]: MonadError[*[*], Throwable]](session: CqlSession, stmt: BoundStatement)( | ||
implicit | ||
par: Par.Aux[CompletionStage, F] | ||
): F[LazyList[Row]] = { | ||
def go(result: F[AsyncResultSet]): F[LazyList[Row]] = | ||
result >>= { i => | ||
val page = LazyList.concat(i.currentPage().asScala) | ||
if (!i.hasMorePages) page.pure[F] | ||
else go(par.parallel(i.fetchNextPage())).map(page ++ _) | ||
} | ||
|
||
go(executeAsync(session, stmt)) | ||
} | ||
|
||
def getRowsAs[F[_], A](session: CqlSession, stmt: BoundStatement)( | ||
implicit | ||
F: MonadError[F, Throwable], | ||
decodeA: RowDecoder[A], | ||
parF: Par.Aux[CompletionStage, F] | ||
): F[LazyList[A]] = { | ||
val ver = session.getContext().getProtocolVersion() | ||
getRows[F](session, stmt) >>= (_.traverse(row => F.fromEither(decodeA(row, ver)))) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core/src/main/scala_2.13+/agni/internal/ScalaVersionSpecifics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package agni.internal | ||
|
||
private[agni] object ScalaVersionSpecifics { | ||
private[agni] type Factory[-E, +T] = scala.collection.Factory[E, T] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2") | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") | ||
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") | ||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3") | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1") | ||
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1") | ||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") | ||
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.9") | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3") | ||
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.12") | ||
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7") |