Giter Club home page Giter Club logo

Comments (5)

jdoliner avatar jdoliner commented on July 2, 2024

I'd say without should error here.

My feeling is that we should error by default and offer people a way to have it not error if it's not found. Maybe we'd also want a way to have a default value for the plucks. I prefer this because compensating for missing parameters winds up being a big pain since it comes up in so many places and I don't think it's good to make people learn different rules for each case. Better to just consistently error if a parameter is missing and give people ways to have default values.

from rethinkdb.

codingcampbell avatar codingcampbell commented on July 2, 2024

Hi - I am woogley from IRC. To quickly illustrate my point:

r.db('test').tableCreate('shows').run()
r.db('test').table('shows').insert([ { name: 'Star Trek' }, { name: 'Breaking Bad', rating: 5 } ]).run()

Now, a vanilla run() will return:

[{"name":"Star Trek","id":"960e0533-4aa7-4c27-ae63-557f7dee92ca"},{"name":"Breaking Bad","rating":5,"id":"9d9690d5-e7bc-42e6-bab6-2e73c6c90422"}]

(The Star Trek entry simply lacks the rating key)

However, if you pluck:

r.db('test').table('shows').pluck('name', 'rating').run()

It throws this error:

Runtime Error: Attempting to pick missing attribute rating from data:

So I would say the inconsistency has less to do with without() and more to do with a vanilla run() on the table.

I would expect the pluck() to behave the same as a normal run() and let my application code deal with the missing key.

from rethinkdb.

coffeemug avatar coffeemug commented on July 2, 2024

I think the behavior is correct as is. The server always behaves consistently -- if the query tries to evaluate an attribute and the attribute doesn't exist, it throws an error. If the query doesn't need to evaluate the attribute, the server proceeds as planned. In case of without, the value of the attribute isn't evaluated, so the error isn't thrown. Similarly, in case of run, the server evaluates the row, not the attribute, so everything works as expected as well.

As far as making dealing with these errors easier on the user, I agree with @jdoliner -- we'll address it via #27.

from rethinkdb.

jdoliner avatar jdoliner commented on July 2, 2024

So the way to do this right now is as follows:

r.db('test').table('shows').map(lambda x: r.merge({"rating" : null}, x).pluck('name', 'rating').run()

Not pretty but it will let you run the query and have nulls filled in for the other values. Having defaults is in essence sugar for this command.

from rethinkdb.

coffeemug avatar coffeemug commented on July 2, 2024

Added an issue to make it more pleasant, see #45.

from rethinkdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.