Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/FSharp.AWS.DynamoDB/Picklers/RecordPickler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ type RecordPickler<'T>(ctor: obj[] -> obj, properties: PropertyMetadata[]) =
let field = prop.PropertyInfo.GetValue value
match prop.Pickler.PickleUntyped field with
| None -> ()
| Some av -> values.Add(prop.Name, av)

| Some av ->
let exists, value = values.TryGetValue prop.Name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match to avoid the allocation?

if not exists then
values.Add(prop.Name, av)
values

member __.ToRecord(ro: RestObject) : 'T =
Expand Down
35 changes: 35 additions & 0 deletions tests/FSharp.AWS.DynamoDB.Tests/MultipleKeyAttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ module MultiKeyTypes =
[<GlobalSecondaryHashKey(indexName = "Inverted")>]
SortKey: string }

type InverseKeyRecordUsingCustomName =
{ [<HashKey>]
PrimaryKey: string
[<RangeKey>]
SortKey: string
[<GlobalSecondaryHashKey(indexName = "GSIReversed"); CustomName("SortKey")>]
GSIReverseHashKey: string
[<GlobalSecondaryRangeKey(indexName = "GSIReversed"); CustomName("PrimaryKey")>]
GSIReverseRangeKey: string }

type SharedRangeKeyRecord =
{ [<HashKey>]
HashKey: string
Expand Down Expand Up @@ -51,6 +61,31 @@ type ``Inverse GSI Table Operation Tests``(fixture: TableFixture) =

interface IClassFixture<TableFixture>

type ``Inverse GSI Table with Custom Names Operation Tests``(fixture: TableFixture) =

let rand = let r = Random.Shared in fun () -> int64 <| r.Next()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let rand = let r = Random.Shared in fun () -> int64 <| r.Next()
let rand = let r = Random.Shared in fun () -> r.Next() |> int64

let mkItem () =
let hashKey = ((int (rand ())) % 50).ToString()
let sortKey = ((int (rand ())) % 50).ToString()
{ PrimaryKey = hashKey
SortKey = sortKey
GSIReverseHashKey = sortKey
GSIReverseRangeKey = hashKey }

let table = fixture.CreateEmpty<InverseKeyRecordUsingCustomName>()

[<Fact>]
let ``Query by Table Key and GSI`` () =
let values = set [ for _ in 1L .. 1000L -> mkItem () ]
for batch in values |> Set.toSeq |> Seq.chunkBySize 25 do
table.BatchPutItems batch =! [||]
let queriedTable = table.Query <@ fun (i: InverseKeyRecordUsingCustomName) -> i.PrimaryKey = "1" && i.SortKey.StartsWith "2" @>
test <@ set queriedTable = set (values |> Set.filter (fun i -> i.PrimaryKey = "1" && i.SortKey.StartsWith "2")) @>
let queriedGSI = table.Query <@ fun (i: InverseKeyRecordUsingCustomName) -> i.SortKey = "1" && i.PrimaryKey.StartsWith "2" @>
test <@ set queriedGSI = set (values |> Set.filter (fun i -> i.SortKey = "1" && i.PrimaryKey.StartsWith "2")) @>

interface IClassFixture<TableFixture>

type ``Shared Range Key Table Operation Tests``(fixture: TableFixture) =

let rand = let r = Random.Shared in fun () -> int64 <| r.Next()
Expand Down