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
It seems that there currently is no easy way to do pivot/unpivot operations in ReQL. These operations are really useful when working with data sets such as network data (to convert back and forth between adjacency matrixes and tie lists).
An unpivot operation creates id-key-value pairs from objects, e.g.:
A pivot operation is exactly the opposite (e.g. it groups key-value pairs to create larger objects). It is different from a grouped reduce operation, as it uses an attribute's value to determine the resulting column name (e.g. the 'k' attribute determines where the value from 'v' should be placed). Syntax could be something like:
We currently support these sorts of things through a really ugly API of coercing to and from arrays. (We hope to have implemented a better API by the time we release 1.6.)
Although a bit ugly, it seems like a usable workaround for now. Thanks @mlucy! For future reference and others looking for the same functionality, here is an example of how to implement pivot and unpivot in JS syntax:
For those watching this issue, this almost certainly won't happen until Rethink hits 2.0 -- sorry. The workaround above should be sufficient for most use cases, and unfortunately there are much more important things we have to do first. If you run into a use case where this is a real showstopper, please let us know and we'll see if we can reprioritize.
Activity
pixelspark commentedon May 18, 2013
#181 and #272 are related to this request
mlucy commentedon May 18, 2013
Hi @pixelspark,
We currently support these sorts of things through a really ugly API of coercing to and from arrays. (We hope to have implemented a better API by the time we release 1.6.)
For example:
So you could write e.g. unpivot like this:
pixelspark commentedon May 19, 2013
Although a bit ugly, it seems like a usable workaround for now. Thanks @mlucy! For future reference and others looking for the same functionality, here is an example of how to implement pivot and unpivot in JS syntax:
coffeemug commentedon May 20, 2013
I'm temporarily moving this to 1.6 to see if we can find a better way of doing this.
karlgrz commentedon Jul 29, 2013
I have been finding myself wanting an easy way to do this for a while now. It would be great if rethinkdb made this really easy to do.
coffeemug commentedon Aug 6, 2013
For those watching this issue, this almost certainly won't happen until Rethink hits 2.0 -- sorry. The workaround above should be sufficient for most use cases, and unfortunately there are much more important things we have to do first. If you run into a use case where this is a real showstopper, please let us know and we'll see if we can reprioritize.
pilwon commentedon May 14, 2015
Rethink finally hit 2.0! 😋
coffeemug commentedon May 14, 2015
I moved this to subsequent because a lot of people have been asking about this, and I found myself needing these commands from time to time.
thelinuxlich commentedon Mar 12, 2018
@srh we have .fold() now, can't we close this issue?
srh commentedon Mar 26, 2018
I think it would be really annoying to write a fold that does this, so I'll leave it open.
c4lliope commentedon Nov 23, 2020
Are there any limitations to this proposal? Is this approach possible?