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
Note that in this proposal, you can not move a field to a different level. E.g. you couldn't move a.b to the top level. I think that's probably fine.
It is also slightly ambiguous in the second example > r({:a => {:b => 1}, :c => 2}).rename({:a => {:b => :bar}, :a => :foo}).run
whether we refer to the field a by its old name a, or by its new name foo in the rename rule for a.b/foo.b. I suggest we always assume the old names (like I did here), so we don't need to imply any arbitrary ordering in which the renames will be applied. Basically all renames would be applied atomically in one step.
I also suggest that we error on circular/conflicting renames (e.g. {:a => :b, :b => :a} or {:a => :b, :b => :c}).
If a target field name already exists, should we just cobble it? Or error? Or have an optarg conflict: "error"|"cobble"|"merge"? Maybe with names consistent with insert instead: "error"|"replace"|"update"?
Most languages (including our datum_ts) won't let you define {:a => one thing, :a => something else} and get two pairs out of it. Some clobber, some error.
You could do r.rename({ :a => { :b => :other } }).rename({:a => :top}) as a (not so pretty) workaround.
Ouch yeah. I didn't think that through. Thanks for pointing that out @encryptio .
We could make rename variadic and allow multiple dictionaries to be passed in. Alternatively we could not do that, and require users to chain multiple renames together if they want to rename field names on multiple levels. That would also avoid the ordering ambiguity.
I can only comment on the JS syntax, but I would make it as close to the Update syntax as possible, since that's basically what you're doing. Something like:
Since this isn't a function that one should call casually, it should roll-back and spit an error by default on a conflict along the lines of:
{
message: "There were a few records that had conflicting field names."
ids: [ "1stConflictID", "2ndConflictID" ... ]
}
However, it would probably pay to make that behavior configurable. Perhaps include an options object that includes configuration for overwriting, skipping, and so on.
I think the current proposal where you can rename nested fields is good.
I think a conflict optarg is good, and that the default should be error.
I think having update be a legal option is confusing, because I associate update with mutation more than merging. I also think that being consistent with insert is desirable though. How would people feel about changing insert so it read insert(conflict: 'merge') instead of insert(conflict: 'update')? (I think replace and error are fine names.)
I think .rename should be non-destructive, so you would write r.table('posts').update{|row| row.rename(status: 'goodness')} rather than r.table('posts').rename(status: 'goodness') as in the above post.
insert(conflict: 'merge') reads very nicely to me. I like that.
I think we should change that and keep supporting the old insert(conflict: 'update') as an alias for backwards compatibility.
I agree that rename should just be a transformation, not a write operation.
@danielmewes: to elaborate on the array thing, while I agree it's probably not a typical use-case, trying to accomplish the same thing with merge is fairly cumbersome. I most often find myself wanting to do this when I'm dealing with grouped streams and need to pivot the reduction values into keys.
Given that it doesn't result in any compromises to the settled proposal, it seems like a fairly good fit here. It also gives rename similar semantics to pluck style selectors, which I think is why (to me) it feels like something that should work.
Activity
thelinuxlich commentedon Aug 18, 2014
+1
darky commentedon Oct 26, 2015
👍
OtterCode commentedon Dec 2, 2015
It's such a small feature, but oh-my-goodness, a quick, concise way to change field names throughout a table would be a miracle.
danielmewes commentedon Dec 3, 2015
This should also work for nested fields.
Proposal:
Note that in this proposal, you can not move a field to a different level. E.g. you couldn't move
a.bto the top level. I think that's probably fine.It is also slightly ambiguous in the second example
> r({:a => {:b => 1}, :c => 2}).rename({:a => {:b => :bar}, :a => :foo}).runwhether we refer to the field
aby its old namea, or by its new namefooin the rename rule fora.b/foo.b. I suggest we always assume the old names (like I did here), so we don't need to imply any arbitrary ordering in which the renames will be applied. Basically all renames would be applied atomically in one step.I also suggest that we error on circular/conflicting renames (e.g.
{:a => :b, :b => :a}or{:a => :b, :b => :c}).If a target field name already exists, should we just cobble it? Or error? Or have an optarg
conflict: "error"|"cobble"|"merge"? Maybe with names consistent withinsertinstead:"error"|"replace"|"update"?encryptio commentedon Dec 3, 2015
Most languages (including our
datum_ts) won't let you define{:a => one thing, :a => something else}and get two pairs out of it. Some clobber, some error.You could do
r.rename({ :a => { :b => :other } }).rename({:a => :top})as a (not so pretty) workaround.danielmewes commentedon Dec 3, 2015
Ouch yeah. I didn't think that through. Thanks for pointing that out @encryptio .
We could make
renamevariadic and allow multiple dictionaries to be passed in. Alternatively we could not do that, and require users to chain multiplerenames together if they want to rename field names on multiple levels. That would also avoid the ordering ambiguity.OtterCode commentedon Dec 3, 2015
I can only comment on the JS syntax, but I would make it as close to the Update syntax as possible, since that's basically what you're doing. Something like:
Since this isn't a function that one should call casually, it should roll-back and spit an error by default on a conflict along the lines of:
However, it would probably pay to make that behavior configurable. Perhaps include an options object that includes configuration for overwriting, skipping, and so on.
mlucy commentedon Dec 9, 2015
I think the current proposal where you can rename nested fields is good.
I think a
conflictoptarg is good, and that the default should beerror.I think having
updatebe a legal option is confusing, because I associateupdatewith mutation more than merging. I also think that being consistent withinsertis desirable though. How would people feel about changinginsertso it readinsert(conflict: 'merge')instead ofinsert(conflict: 'update')? (I thinkreplaceanderrorare fine names.)I think
.renameshould be non-destructive, so you would writer.table('posts').update{|row| row.rename(status: 'goodness')}rather thanr.table('posts').rename(status: 'goodness')as in the above post.danielmewes commentedon Dec 10, 2015
insert(conflict: 'merge')reads very nicely to me. I like that.I think we should change that and keep supporting the old
insert(conflict: 'update')as an alias for backwards compatibility.I agree that
renameshould just be a transformation, not a write operation.8 remaining items
mlucy commentedon Dec 18, 2015
Agreed, let's settle this with the simpler API, and once that's in we can open a new ReQL discussions for the extensions @marshall007 proposed.
marshall007 commentedon Dec 18, 2015
@danielmewes @mlucy yep, sounds good!
marshall007 commentedon Dec 18, 2015
@danielmewes: to elaborate on the array thing, while I agree it's probably not a typical use-case, trying to accomplish the same thing with
mergeis fairly cumbersome. I most often find myself wanting to do this when I'm dealing with grouped streams and need to pivot thereductionvalues into keys.Given that it doesn't result in any compromises to the settled proposal, it seems like a fairly good fit here. It also gives
renamesimilar semantics topluckstyle selectors, which I think is why (to me) it feels like something that should work.srh commentedon May 17, 2017
r.aliasis a proposed alternate name in #6331.Extarys commentedon Jun 24, 2017
I would like to rename a field while keeping it's value. +1 :D
PassTheMayo commentedon Apr 5, 2018
+1
phablulo commentedon Jun 7, 2018
+1