You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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).
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.
@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}
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().
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.
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.
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.
Activity
danielmewes commentedon Feb 3, 2015
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 haveold_valandnew_valbe 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_initialfor other multi-document changefeeds (liker.table().changes()orr.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.
timmaxw commentedon Feb 4, 2015
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 withold_valtoo.danielmewes commentedon Feb 4, 2015
Uh I like that @timmaxw .
mlucy commentedon Feb 4, 2015
I really don't like that, personally.
changeson arrays produced by this one query? (We currently have the rule that you can callchangeson all selections and some streams in 2.0.)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 withbetweenorget_allwe limit the size of the result set to the array size limit (which we already do for.orderby.limit).mlucy commentedon Feb 4, 2015
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.marshall007 commentedon Feb 4, 2015
@mlucy I can imagine scenarios where you'd want to generically emit changes to the client and pluralizing
new_val/old_valin certain cases would complicate things. If anything I would do{new_val: ..., old_val: ..., includes_all: true}danielmewes commentedon Feb 4, 2015
We could also make the
includes_all: trueannotation a flag in theResponseNotesfield proposed here #3715 (comment).timmaxw commentedon Feb 4, 2015
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 asr.table(...).changes().mlucy commentedon Feb 4, 2015
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.mlucy commentedon Feb 4, 2015
(I.e. I still think we should use an optarg for this particular task, but changefeeds on arrays no longer seem crazy to me.)
danielmewes commentedon Feb 4, 2015
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.
mlucy commentedon Feb 6, 2015
Planning to mark this as settled on Monday unless anyone objects, with the following interpretation:
include_alltochangeswhich will default tofalsefor all currently-existing changefeeds.truewill error except on.orderby.limit.changes(in the future we may also support it for small ranges, or forget_all). Setting this optarg totruewill cause the server to re-send the entire ordered set every time something changes.new_valandold_valwill be arrays of documents rather than single documents. We will add aResponseNote(see AddSUCCESS_ORDERED_FEEDreturn type. #3715) indicating that we're using a variant format.marshall007 commentedon Feb 7, 2015
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.51 remaining items
danielmewes commentedon Sep 17, 2015
I like
single,all+diffcoffeemug commentedon Sep 27, 2015
Note, the issue for
diffformat is #4707.