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
{{ message }}
Repository navigation
Add a way to find out from ReQL which keys are defined on stored objects #181
It is currently difficult to obtain a list of keys defined on objects inside a table. This operation can however be quite helpful for administrative tools. Implementing such an operation is probably relatively easy; I propose adding a 'keys' operation (json.keys() -> json) that returns an array of keys defined on the object. E.g.:
r.expr({x:1,y:2}).keys().run()==>['x','y']
Using this, it should be possible to enumerate all keys used in a table:
The later I'm not sure about being in the new spec but I know we have talked about our lack of operations on Objects. I think the fundamental operation is just extending map to work on Objects. This would allow you to iterate over them and everything also could just be sugar on top of that. Here's how it would work in my mind:
> r.expr({x:1, y:2}).map(function (x) { return x; }).run()
[{key : "x", value : 1}, {key : "y", value : 2}]
This would be the basic operation, then keys could just be sugar for:
Also, to clarify, with the proposed scheme, keys on a table could be defined as follows: table('foo').map(r.row.map(r.row('key'))).distinct()
EDIT: actually the definition above is wrong because the data passed to distinct would include a stream of arrays (assuming map on an object returns an array, which seems to make sense). So to do this I think we'd need a concatMap here instead of map, like so: table('foo').concatMap(r.row.map(r.row('key')).arrayToStream()).distinct()
Ok, we now support typeOf and as of 1.6 (due this week) we'll also support keys. We'll deal with map over objects separately (there are at least three issues open elsewhere to that affect). Closing.
Activity
pixelspark commentedon Dec 24, 2012
Similarly, it could be useful for admin tools to have a .type() operator that returns the type of a value:
jdoliner commentedon Dec 25, 2012
Both good ideas. I think that both of these will be added with the new driver spec which is currently under active development. You can see the actual spec here: https://github.com/rethinkdb/rethinkdb/wiki/protobuf_rfc_raw_spec. Notice that there is a
typeofso that one's definitely in there.The later I'm not sure about being in the new spec but I know we have talked about our lack of operations on Objects. I think the fundamental operation is just extending map to work on Objects. This would allow you to iterate over them and everything also could just be sugar on top of that. Here's how it would work in my mind:
This would be the basic operation, then
keyscould just be sugar for:This is another case in which macros would be really nice.
coffeemug commentedon Dec 25, 2012
Moving to post-protobuf-improvements.
Also, to clarify, with the proposed scheme,
keyson a table could be defined as follows:table('foo').map(r.row.map(r.row('key'))).distinct()EDIT: actually the definition above is wrong because the data passed to distinct would include a stream of arrays (assuming
mapon an object returns an array, which seems to make sense). So to do this I think we'd need aconcatMaphere instead ofmap, like so:table('foo').concatMap(r.row.map(r.row('key')).arrayToStream()).distinct()mlucy commentedon Dec 26, 2012
I agree we should define map on objects. Ruby has this behavior, which I rather like:
coffeemug commentedon Jun 10, 2013
Ok, we now support
typeOfand as of 1.6 (due this week) we'll also supportkeys. We'll deal withmapover objects separately (there are at least three issues open elsewhere to that affect). Closing.board: tick rethinkdb#181 — RT-GAP-033 premise narrowed (loopback-def…
board: tick rethinkdb#181 — close RT-GAP-042 (loopback-default verifi…