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 same-attribute if-not-exists updates #76

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

samritchie
Copy link
Collaborator

Fixes #74. Needs some additional tests to make sure all scenarios work properly.

@samritchie samritchie marked this pull request as ready for review June 25, 2024 12:52
@samritchie samritchie requested a review from bartelink June 25, 2024 12:53
@@ -295,7 +295,9 @@ let extractUpdateOps (exprs: IntermediateUpdateExprs) =
| SpecificCall2 <@ List.append @> (None, _, _, [ left; right ]) ->
UpdateValue.EList_Append (extractOperand pickler left) (extractOperand pickler right)

| SpecificCall2 <@ defaultArg @> (None, _, _, [ AttributeGet attr; operand ]) ->
| SpecificCall2 <@ defaultArg @> (None, _, _, [ AttributeGet attr; operand ])
| Some'(SpecificCall2 <@ defaultArg @> (None, _, _, [ AttributeGet attr; operand ]))
Copy link
Member

Choose a reason for hiding this comment

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

this looks very cryptic - maybe NewSome or OptionSome or SomeCaseCtor naming instead?

match e with
| NewUnionCase(uci, [ v ]) ->
let dt = uci.DeclaringType
if dt.IsGenericType && dt.GetGenericTypeDefinition() = typedefof<_ option> && uci.Name = "Some" then
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
if dt.IsGenericType && dt.GetGenericTypeDefinition() = typedefof<_ option> && uci.Name = "Some" then
if dt.IsGenericType && dt.GetGenericTypeDefinition() = typedefof<_ option> && uci.Name = (nameof Some) then

let item = mkItem ()
let key = table.PutItem item
clearAttribute table key "String"
let item' = table.UpdateItem(key, <@ fun (r: R) -> { r with String = defaultArg (Some r.String) "<undefined>" } @>)
Copy link
Member

Choose a reason for hiding this comment

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

was about to comment that this is the same as L272 as the clearAttributedid not jump out at me as being the important bit
is there any way that 263 could do let key = table.PutItem { item with .... } or is it important tha the clear is a separate call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It’s a non-optional field, it can’t be set to None on the record. I’m not convinced we need if-not-exists support for these non-optionals, it’s only likely to come about as the result of schema changes, but supporting it shouldn’t break anything important

Copy link
Member

Choose a reason for hiding this comment

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

tbh I have very little idea what the behavior and/or schema is - from my perspective it's a small piece of expression handling with supporting tests that will be used so it meets the bar regardless of whether I even get how it works ;)

AttributeUpdates = Dictionary(Map.ofSeq [ attribute, new AttributeValueUpdate(Action = AttributeAction.DELETE) ])
)
)
|> Async.AwaitTask
Copy link
Member

Choose a reason for hiding this comment

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

could make the test async rather than baking this in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In that case pretty much all the tests should be async. It’s probably a good idea but I’ll do this separately

@samritchie samritchie merged commit fe86d3c into master Jun 27, 2024
4 checks passed
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.

defaultArg/if_not_exists for the same attribute
2 participants