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

Support ADDing numbers #56

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

NickDarvey
Copy link

An ADD in an update expression lets you increment a number attribute which doesn't exist yet, treating it as zero. Trying to use SET to increment a non-existent attribute will throw:

The provided expression refers to an attribute that does not exist in the item

The current update operations allow ADDing to a set attribute only (let ADD (path : Set<'T>) (values : seq<'T>)), this PR proposes adding support to ADD to a number attribute.


It's in draft right now because I'm looking for guidance on how you want this contribution to be implemented, should you want this contribution. The current changes shown in this PR are just the silliest simplest thing to verify the tests would pass.

Specifically, I'm guessing we don't want various ADD_* functions, so I'm thinking of how we could support ADDing numbers without introducing those. Perhaps:

TODO

  • Change module UpdateOperators
    • to be a type UpdateOperators with static operators so ADD can be overloaded with the various number types, and
    • redeclare a module UpdateOperators which exposes the the current functions so it's not a breaking change
  • Declare a simpler record instead of working around default value for UpdateExprRecord

@NickDarvey
Copy link
Author

Specifically, I'm guessing we don't want various ADD_* functions, so I'm thinking of how we could support ADDing numbers without introducing those. Perhaps:
Change module UpdateOperators
to be a type UpdateOperators with static operators so ADD can be overloaded with the various number types

...which might look something like this...

/// Table Update operation placeholder type
type UpdateOp =
    /// Combines two update operations into one
    static member (&&&) (left : UpdateOp, right : UpdateOp) : UpdateOp =
        invalidOp "Update combiner reserved for quoted update expressions."

    static member ADD  (path : Set<'T>, values : seq<'T>) : UpdateOp =
        invalidOp "ADD operation reserved for quoted update expressions."

    static member ADD  (path : int64, value : int64) : UpdateOp =
        invalidOp "ADD operation reserved for quoted update expressions."

/// Update expression special operators
[<AutoOpen>]
module UpdateOperators =

    /// Assigns a record attribute path to given value
    let SET (path : 'T) (value : 'T) : UpdateOp =
        invalidOp "SET operation reserved for quoted update expressions."

    /// Removes a record attribute path from entry
    let REMOVE (path : 'T) : UpdateOp =
        invalidOp "REMOVE operation reserved for quoted update expressions."

    /// Adds given set of values to set attribute path
    let inline ADD (path : Set<'T>) (values : seq<'T>) : UpdateOp =
        UpdateOp.ADD (path, values)

    /// Deletes given set of values to set attribute path
    let DELETE (path : Set<'T>) (values : seq<'T>) : UpdateOp =
        invalidOp "DELETE operation reserved for quoted update expressions."

However, I'm not sure where to go after updating this block

| SpecificCall2 <@ ADD @> (None, _, _, [AttributeGet attr; value]) ->
let op = getOperand attr.Pickler value
attrs.Add attr
updateOps.Add (Add (attr.Id, op))

to

| SpecificCall2 <@ UpdateOp.ADD @> (None, _, _, [AttributeGet attr; value]) ->
 //                ~~~~~~~~~~~~~
  let op = getOperand attr.Pickler value
  attrs.Add attr
  updateOps.Add (Add (attr.Id, op))

because I run in to:

A member or object constructor 'ADD' taking 1 arguments is not accessible from this code location. All accessible versions of method 'ADD' take 2 arguments.F# Compiler503

and I'm not sure how to tackle that error.

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.

1 participant