Skip to content

Add include_all optarg to .changes() #3719

Open

Description

@marshall007

Discussion started with my comment over in #3709. There are a lot of cases where the overhead of returning the entire result set on each change would be worth it for the sake of simplicity. For example if I want the top 5 users by score the performance impact of emitting all five rows on every change is minimal and I'd like to avoid writing the code necessary to keep my in-memory copy in sync/sorted correctly.

Activity

  1. added this to the milestone on Feb 3, 2015
  2. danielmewes commented on Feb 3, 2015

    @danielmewes
    Member

    This generally sounds like a good idea to me.

    An open question is what exactly the changefeed should return when the data changes.
    Assuming an orderBy(...).limit(...) changefeed, it could have old_val and new_val be arrays with all the documents in the right order.
    In that case we should probably send the initial values in the same format, that is as a single document {new_val: [val1, val2, val3, ...]}.

    I think for now the only query that this would work on is orderBy.limit?
    Even if we support return_initial for other multi-document changefeeds (like r.table().changes() or r.table().between().changes()) later, I don't think we could easily (let alone efficiently) support this opt arg for those types of changefeeds, could we?
    This makes this solution seem a bit specific, and I wonder wonder if there's a more generic solution to the problem. Though I cannot think of any.

  3. timmaxw commented on Feb 4, 2015

    @timmaxw
    Member

    I suggest the syntax r.table(...).orderBy(...).limit(...).coerceTo("ARRAY").changes(). Then it's obvious that the first message should be {new_val: [val1, val2, val3, ...]} and subsequent messages should be the same thing with old_val too.

  4. danielmewes commented on Feb 4, 2015

    @danielmewes
    Member

    Uh I like that @timmaxw .

  5. mlucy commented on Feb 4, 2015

    @mlucy
    Member

    I really don't like that, personally.

    • It's much less discoverable than an optarg to changes.
    • It doesn't make much sense in the context of our type system.
      • Why does a stream send diffs of the set and an array send the whole set?
      • Why can I only call changes on arrays produced by this one query? (We currently have the rule that you can call changes on all selections and some streams in 2.0.)
    • It's more work to implement (partially because of the above point about it not really lining up with our type system -- there's currently no place to attach changefeed information to datum arrays).

    I think we should just add an optarg to changes. I think it should work on .orderby.limit.changes, .between.changes, and .get_all.changes, with the caveat that if you use it with between or get_all we limit the size of the result set to the array size limit (which we already do for .orderby.limit).

  6. mlucy commented on Feb 4, 2015

    @mlucy
    Member

    We may also want to consider making the result with the optarg take the form {new_vals: ..., old_vals: ...} so that it's obvious you're getting back something different.

  7. marshall007 commented on Feb 4, 2015

    @marshall007
    ContributorAuthor

    @mlucy I can imagine scenarios where you'd want to generically emit changes to the client and pluralizing new_val/old_val in certain cases would complicate things. If anything I would do {new_val: ..., old_val: ..., includes_all: true}

  8. danielmewes commented on Feb 4, 2015

    @danielmewes
    Member

    We could also make the includes_all: true annotation a flag in the ResponseNotes field proposed here #3715 (comment).

  9. timmaxw commented on Feb 4, 2015

    @timmaxw
    Member

    I agree with @mlucy that it should be an optarg. But I think it should work for both changefeeds on streams and changefeeds on arrays. For example, if you do r.table(...).map(...).reduce(...) and the result is an array, you should be able to call .changes(includes_all = False) to have the server diff your arrays and send you changes in the same format as r.table(...).changes().

  10. mlucy commented on Feb 4, 2015

    @mlucy
    Member

    I talked about this with @timmaxw offline and I understand where he was coming from with the .coerce_to('ARRAY') syntax. I agree that in the future when we have changefeeds on more things being able to send diffs on datums will be a good idea.

  11. mlucy commented on Feb 4, 2015

    @mlucy
    Member

    (I.e. I still think we should use an optarg for this particular task, but changefeeds on arrays no longer seem crazy to me.)

  12. danielmewes commented on Feb 4, 2015

    @danielmewes
    Member

    Since it seems easier to implement, I agree with @mlucy that we should do the optarg for this one.

    When we support changefeeds on a query coerced to an array at some point, we can consider deprecating it or make it a rewrite rule.

  13. mlucy commented on Feb 6, 2015

    @mlucy
    Member

    Planning to mark this as settled on Monday unless anyone objects, with the following interpretation:

    • We will add an optarg include_all to changes which will default to false for all currently-existing changefeeds.
    • Setting this optarg to true will error except on .orderby.limit.changes (in the future we may also support it for small ranges, or for get_all). Setting this optarg to true will cause the server to re-send the entire ordered set every time something changes.
    • The format will be identical except that new_val and old_val will be arrays of documents rather than single documents. We will add a ResponseNote (see Add SUCCESS_ORDERED_FEED return type. #3715) indicating that we're using a variant format.
  14. marshall007 commented on Feb 7, 2015

    @marshall007
    ContributorAuthor

    After thinking about this a bit more, it might be more consistent if the result were an array containing new/old value pairs i.e. [ {new_val: ..., old_val: ...}, {new_val: ..., old_val: ...} ]. That way you don't have to manually zip the two arrays together before passing them to your code that handles the existing changefeed behavior. I don't have strong opinions either way, though.

  15. 51 remaining items

  16. removed this from the 2.2-polish milestone on Sep 17, 2015
  17. danielmewes commented on Sep 17, 2015

    @danielmewes
    Member

    I like single, all + diff

  18. coffeemug commented on Sep 27, 2015

    @coffeemug
    Contributor

    Note, the issue for diff format is #4707.

  19. modified the milestones: 2.2, 2.3 on Oct 5, 2015
  20. modified the milestones: 2.3, on Nov 19, 2015
  21. modified the milestones: subsequent, on Feb 9, 2016
  22. removed their assignment
    on Aug 16, 2016
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions