Page MenuHomePhabricator

[services][identity] helper function to create primary key for DynamoDB
ClosedPublic

Authored by varun on May 12 2022, 8:06 AM.
Tags
None
Referenced Files
F1774068: D4015.diff
Thu, May 16, 12:29 AM
Unknown Object (File)
Mon, May 6, 6:13 AM
Unknown Object (File)
Fri, May 3, 7:28 PM
Unknown Object (File)
Tue, Apr 30, 8:26 PM
Unknown Object (File)
Sun, Apr 28, 4:06 PM
Unknown Object (File)
Fri, Apr 26, 6:55 AM
Unknown Object (File)
Tue, Apr 23, 8:00 PM
Unknown Object (File)
Tue, Apr 23, 8:00 PM

Details

Summary

This function takes a partition key and optional sort key and returns a primary key for the DynamoDB client.

Depends on D3920

Test Plan

Unit tested

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

varun requested review of this revision.May 12 2022, 8:11 AM

Looks ok, but wouldn't it be better to add tests separately? I mean, in a different file or something?

services/identity/src/database.rs
47–48 ↗(On Diff #12578)

is it really a good practice to put tests right next to the functionality itself? Where does this come from?

This revision now requires changes to proceed.May 16 2022, 12:45 AM
varun requested review of this revision.May 16 2022, 8:14 AM

Replied inline

services/identity/src/database.rs
47–48 ↗(On Diff #12578)

by convention, unit tests go in the same file as the function they are testing. https://doc.rust-lang.org/book/ch11-03-test-organization.html#unit-tests

integration tests, on the other hand, should go in a separate tests directory.

karol added inline comments.
services/identity/src/database.rs
47–48 ↗(On Diff #12578)

Interesting! Thanks for clarifying!

jim requested changes to this revision.May 17 2022, 8:11 AM
jim added inline comments.
services/identity/src/database.rs
23 ↗(On Diff #12578)

If these are in an unordered HashMap, how will DynamoDB know which is the partition key and which is the sort key?

This revision now requires changes to proceed.May 17 2022, 8:11 AM

I think this would be better as two functions create_simple_primary_key(partition_key) and create_composite_primary_key(partition_key, sort_key). Terminology from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey.

services/identity/src/database.rs
23 ↗(On Diff #12578)

Sorry, ignore this, I misunderstood what this does

This revision is now accepted and ready to land.May 19 2022, 7:21 AM