Skip to content

Explicit "action" field in changefeed documents #4194

Closed

Description

@danielmewes

Suggested by Steven Perez.

In changefeed documents, we currently implicitly encode whether they are a deletion, and insertion, an update/replace or an initial result by setting some of old_val and new_val to null or by omitting old_val entirely.

The proposal is to encode this information explicitly by adding an additional field. For example
action: 'delete'
action: 'insert'
action: 'replace'
action: 'initial'

Incidentally, our current system also breaks if you have a changefeed like this:
r.table('t1')('a').changes()

and you set the value of a to null for a document. The generated change event will be indistinguishable from a deletion. Additionally, when deleting a document that currently has a: null, no change event is generated.

Activity

  1. added this to the subsequent milestone on May 6, 2015
  2. marshall007 commented on May 7, 2015

    @marshall007
    Contributor

    I like this a lot! It would allow you to easily filter by the "type" of change being emitted, which is what I was getting at in #3719 (comment).

  3. stevengpa commented on May 7, 2015

    @stevengpa

    Excellent 👍🏻

    Thanks for listen Wise Rethinkdb Partners

  4. mglukhovsky commented on May 7, 2015

    @mglukhovsky
    Member

    @danielmewes: I'm a fan of this, usually I check for the values of old_val + new_val to infer what happened, but the case you stated is definitely ambiguous!

  5. stevengpa commented on May 7, 2015

    @stevengpa

    Mike - I think you are right in terms that it is ambiguous, in the other hand, it is more syntax clear to have the action, for example:

    // Current
    r.table('t1').changes().run(conn, function(err, cursor) {
       cursor.each(function(n, el){
          if (el.old_val == null && el.new_val != null) // Do something if Inserted
             // Do something
          else if (el.old_val != null && el.new_val != null) // Do something if Updated
             // Do something
          else if (el.old_val != null && el.new_val == null) // Do something if Deleted
             // Do something
       });
    });
    
    // If action
    r.table('t1').changes().run(conn, function(err, cursor) {
       cursor.each(function(n, el){
          if (el.action == 'Inserted')
             // Do something
          else if (el.action == 'Updated')
             // Do something
          else if (el.action == 'Deleted')
             // Do something
       });
    });

    Maybe there are more critical features :), so this issue can be made in the future.

  6. mglukhovsky commented on May 7, 2015

    @mglukhovsky
    Member

    @StevenPerez: actually, I was saying that the case @danielmewes stated is ambiguous and is a good reason for adding an action to the changefeed, so we're in agreement:

    Incidentally, our current system also breaks if you have a changefeed like this:
    r.table('t1')('a').changes()
    and you set the value of a to null for a document. The generated change event will be indistinguishable from a deletion. Additionally, when deleting a document that currently has a: null, no change event is generated.

  7. stevengpa commented on May 7, 2015

    @stevengpa

    Mike - Got it 👍 , sorry It was my bad :) , I'm glad to know you are agree =)

  8. danielmewes commented on Dec 10, 2015

    @danielmewes
    MemberAuthor

    Merging with #5188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions