Giter VIP home page Giter VIP logo

Comments (8)

d2a4u avatar d2a4u commented on August 15, 2024

Interesting, I didn't know that there is no uniqueness guarantee on GSI. Changing the signature of retrieve to Stream[F, T] is a bit weird since SimpleTable and local version of SecondarySimpleIndex use F[Option[T]] and it fits a bit better in those cases. IMHO, the hierarchy should be:

sealed abstract class SimpleIndex[F[_]: Async, P: Encoder] {
  ...
  def retrieve[T: Decoder](
    query: Query[P, Nothing],
    consistentRead: Boolean
  )(implicit RT: RaiseThrowable[F]): F[Option[T]]
}

case class SimpleLSI[F[_]: Async, P: Encoder](
  tableName: String,
  indexName: String,
  partitionKeyDef: KeyDef[P],
  jClient: DynamoDbAsyncClient
) extends SimpleIndex[F, P] {
  ...
}

case class SimpleGSI[F[_]: Async, P: Encoder](
  tableName: String,
  indexName: String,
  partitionKeyDef: KeyDef[P],
  jClient: DynamoDbAsyncClient
) extends SimpleIndex[F, P] {
  def retrieveAll[T: Decoder](
    query: Query[P, Nothing],
    consistentRead: Boolean
  )(implicit RT: RaiseThrowable[F]): Stream[F, T]
}

What I'm proposing is to replace SecondarySimpleIndex with SimpleLSI and SimpleGSI so that retrieve's signature doesn't change and retrieveAll can be introduced to SimpleGSI. WDYT?

from meteor.

jrduncans avatar jrduncans commented on August 15, 2024

Is a SimpleLSI actually possible? I believe an LSI has to have a sort key.

from meteor.

jrduncans avatar jrduncans commented on August 15, 2024

I could see either side for only having retrieve return a stream vs have a retrieve/retrieveAll. Allowing a retrieve that returns F[Option[T]] that might actually arbitrarily select the last element (and if accidentally really mis-used, only after streaming through many records -- perhaps the implementation should change to be .head.compile.last...). But it's also true that someone may have a GSI with a guaranteed-to-be-unique partition key (I have such use-cases myself) and that retrieve would read more clearly than having to add .compile.last.

from meteor.

d2a4u avatar d2a4u commented on August 15, 2024

Is a SimpleLSI actually possible? I believe an LSI has to have a sort key.

that is a good point, I think I've found a fix for this. I moved SecondarySimpleIndex to extends CompositeIndex in this branch, the signature of retrieve fits better there, the only downside is naming. WDYT? https://github.com/d2a4u/meteor/pull/234/files#diff-06c5a4f5c02eebaa484b12addf3b0efc009b69d1e93124501aac37d7dbf31183R59

from meteor.

jrduncans avatar jrduncans commented on August 15, 2024

Seems ok to me, let's me do what I need:

byAuthorIndex.retrieve[Book](
        Query(partitionKey = "Jules Verne"),
        limit = 100
      )

The hacky SecondaryCompositeIndex in my original post has the nicer ergonomics of not needing to wrap in a query though which would be nice for SecondarySimpleIndex:

byAuthorIndexFixed.retrieve[Book](
        "Jules Verne",  limit = 100
      )

from meteor.

d2a4u avatar d2a4u commented on August 15, 2024

it is a overloading method so the signature has been changed to this

from meteor.

jrduncans avatar jrduncans commented on August 15, 2024

Looks good to me!

from meteor.

d2a4u avatar d2a4u commented on August 15, 2024

This is now fixed in latest version: v1.0.14. It should have been bumped to 1.1.0 but there seems to be an issue with CI versioning bump. Apologies.

from meteor.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.