Skip to content
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

[Beyonce]: Support inverted indexes #37

Merged
merged 5 commits into from Jul 27, 2020

Conversation

jcarver989
Copy link
Contributor

@jcarver989 jcarver989 commented Jul 23, 2020

This PR adds support for creating an "inverted index" -- which is a particular flavor of a GSI.

You can click the link above for more context, but the basic idea is it's often useful to flip your primary table's partition and sort keys in a GSI. Often this "unlocks" several new query patterns -- e.g. querying the "other side" of a relationship.

Previously, when defining a GSI we wouldn't allow you to use "key fields" on a model (i.e. a field that is synthesized when you call FooModel.create({ ... })). Now we allow you to specify your table's partition key or sort key.

A nice future improvement that's out of scope for this PR would be to split model definitions into "data fields" and "key fields". This would allow for defining arbitrary fields on your model that would be automatically synthesized when you call .create({ ... }). You can think of "partitionKey" and "sortKey" as being special cases of that idea -- e.g.:

        Item:
          keys:
            partitionKey: [Item, $id]
            sortKey: [Item, $id]
            index1PartitionKey: [User, $creatorId]
            index1SortKey: [Item, $createdAt, $id]
          fields:
            id: string
            creatorId: string
            createdAt: string // ISO date string
            jsonData: string
GSIs:
  index1:
    partitionKey: $index1PartitionKey
    sortKey: $index1SortKey
const item = Item.create({ 
  id: "...", 
  creatorId: "...", 
  createdAt: "...", 
  jsonData: "..." 
})  // all the keys get auto-appended

@jcarver989 jcarver989 requested a review from cjoelrun July 23, 2020 14:46
@jcarver989 jcarver989 requested a review from a team July 23, 2020 14:53
@jcarver989 jcarver989 merged commit 6b3714a into master Jul 27, 2020
@jcarver989 jcarver989 deleted the feature/support-inverted-index branch July 27, 2020 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant