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

Add support for sparse indexes #18

Closed
3 tasks done
whimzyLive opened this issue Dec 2, 2020 · 5 comments
Closed
3 tasks done

Add support for sparse indexes #18

whimzyLive opened this issue Dec 2, 2020 · 5 comments

Comments

@whimzyLive
Copy link
Member

whimzyLive commented Dec 2, 2020

Proposed

When parsing entity indexes, allow for sparse indexes

I.e
for Index with sortKey: PUB_ID#${id} do not auto parse, when index is marked as sparse index

Implementation

  • Add sparse index option on @entity -> indexes (ideally isSparse: boolean)
  • Allow optional values when parsing sparse marked key
  • If parsing an sparse index and referenced variable is missing value, DO NOT ADD partition or sort key attributes for that index
@whimzyLive whimzyLive created this issue from a note in TypeDORM (To do) Dec 2, 2020
@whimzyLive whimzyLive self-assigned this Dec 2, 2020
@whimzyLive whimzyLive added the enhancement New feature or request label Dec 2, 2020
@whimzyLive whimzyLive moved this from To do to Selected for development in TypeDORM Dec 2, 2020
@whimzyLive whimzyLive added the p2 label Dec 3, 2020
@whimzyLive whimzyLive moved this from Selected for development to In progress in TypeDORM Jan 12, 2021
@whimzyLive whimzyLive moved this from In progress to Released on beta in TypeDORM Jan 24, 2021
TypeDORM automation moved this from Released on beta to Done Jan 24, 2021
@whimzyLive whimzyLive moved this from Done to Released on beta in TypeDORM Jan 24, 2021
@whimzyLive whimzyLive reopened this Jan 24, 2021
TypeDORM automation moved this from Released on beta to In progress Jan 24, 2021
@whimzyLive whimzyLive moved this from In progress to Released on beta in TypeDORM Jan 24, 2021
@typedorm-bot
Copy link
Member

🎉 This issue has been resolved in version 1.6.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

TypeDORM automation moved this from Released on beta to Done Jan 25, 2021
@typedorm-bot
Copy link
Member

🎉 This issue has been resolved in version 1.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@michael-pont
Copy link
Contributor

Hi @whimzyLive
Just wanted to understand the exact behavior of isSparse
From documentation:

(property) isSparse?: boolean
DynamoDB only adds item to index if both Partition Key and Sort Key defined for any given GSI contains value

Indexes missing sort key value will not be added to index.

However, when I define false for a sparseIndex I expect undefined/optional values to be allowed for sort key

    GSI2: {
      partitionKey: 'COMPANY#{{companyId}}',
      sortKey: 'DEPT#{{deptId}}',
      type: INDEX_TYPE.GSI,
      isSparse: false,
    },

...
  @Attribute()
  companyId: string;

  @Attribute()
  deptId?: string;
...

This is not working though when I try to create a new user with companyId defined but deptId empty.
I get the following error:

"deptId" was referenced in DEPT#{
    {deptId
    }
} but it's value could not be resolved.

Additionally, if i define a default value for deptId, the same error occurs, so it appears as if the code here is running before default value is set.

  @Attribute({
    default: '',
  })
  deptId?: string;

So my question is what exactly is the expected behavior when isSparse: false?

@michael-pont
Copy link
Contributor

As a followup to my previous comment, I observed the opposite behavior with the same entity but a different index:

    GSI3: {
      partitionKey: 'COMPANY#{{companyId}}',
      sortKey: {
        alias: 'officeStatus',
      },
      type: INDEX_TYPE.GSI,
    },

...
  @Attribute({
    default: OfficeStatus.REMOTE,
  })
  officeStatus: OfficeStatus;
...

When I create a user and leave officeStatus undefined it will create the default value for me and will not throw any error like the one from the previous comment. Querying then with PK = companyId and officeStatus = remote works and returns users

@structurr
Copy link

I'm running into the same issue as @michael-pont mentioned above. Please allow sort keys to be optional when defining GSIs on a table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
TypeDORM
Done 🚀
Development

No branches or pull requests

4 participants