Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults to getattr, and defaults command on streams #27

Closed
sojin opened this issue Nov 11, 2012 · 11 comments
Closed

Add defaults to getattr, and defaults command on streams #27

sojin opened this issue Nov 11, 2012 · 11 comments
Labels
Milestone

Comments

@sojin
Copy link

sojin commented Nov 11, 2012

Tried to add following document in addition to what is mentioned in
http://www.rethinkdb.com/docs/tutorials/superheroes/ (i.e after Inserting Multiple Documents as well)

.............
heroes.insert({
"hero": "Wolverine",
"name": "James 'Logan' Howlett",
"magazine_titles": ["Amazing Spider-Man vs. Wolverine", "Avengers", "X-MEN Unlimited", "Magneto War", "Prime"],
"age": "26",
"appearances_count": 98
}).run()
.............

i.e added extra field 'age'.

But apparently the filter on heroes.filter({'age': '26'}).run() throws below error:

rethinkdb.net.ExecutionError: Error while executing query on server: Object:
{
"appearances_count": 98,
"hero": "Wolverine",
"name": "James 'Logan' Howlett",
"magazine_titles": ["Amazing Spider-Man vs. Wolverine", "Avengers", "X-MEN Unlimited", "Magneto War", "Prime"],
"id": "fcd1ca53-9c78-4ce1-9b50-3e962cff2220"
}
is missing attribute "age"
db('python_tutorial').table('heroes').filter(((r['age'] == expr('26'))))

I'd expect, being Rethinkdb is schema-less, we could certainly add/remove any fields as required and filter later on.

@coffeemug
Copy link
Contributor

@sojin this is because some of the documents don't have age as an attribute and rethink is strict about errors (if an attribute is missing and you try to use it, it'll throw an error). We'll make an api much nicer to deal with cases like this, but in the meantime you can try this:

db('python_tutorial').table('heroes').filter(lambda row: row.contains('age') & (r['age'] ==26)).run()

@sojin
Copy link
Author

sojin commented Nov 11, 2012

Thanks, that did the trick.We are evaluating Rethink as an alternative for MongoDB, still trying to get my head around the docs. :)

@coffeemug
Copy link
Contributor

Great, all questions are welcome (irc, here, or google groups)!

@coffeemug
Copy link
Contributor

Ok, we need to add the following two enhacements:

# Defaults in attr access
table('foo').filter(r['bar', 0] == 1).run()

# Defaults command on streams
table('foo').defaults({ 'bar': 0 }).filter(r['bar'] == 1).run()

Moving to backlog, will address when some pressing initial issues are worked out.

@nviennot
Copy link
Contributor

Can we have something to also have every attribute to default to nil? (I don't want to spend my time specifying the name of each attribute I'm going to use in the filter)

@coffeemug
Copy link
Contributor

I reopened #183, so we may try to find a different approach to this problem (although adding a modifier to evaluate missing attributes to nil is one option).

@craigyk
Copy link

craigyk commented Feb 24, 2013

I think a default command would be a good thing, though it shouldn't be used to address #183. I think there should be a ni | undefined value that behaves a lot like NaN and causes the row to be removed by default.

@jdoliner
Copy link
Contributor

The discussion if this has become a bit fractures but I think that were all
in agreement (although we haven't explicitly said it) that filter and
similar commands will be looking for Nothing and dropping those rows.
On Feb 23, 2013 6:27 PM, "Craig" notifications@github.com wrote:

I think a default command would be a good thing, though it shouldn't be
used to address #183 #183.
I think there should be a ni | undefined value that behaves a lot
like NaN and causes the row to be removed by default.


Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-14002217.

@coffeemug
Copy link
Contributor

This may or may not be a dup of #183, depending on how we look at it. I'll consider this shortly.

@coffeemug
Copy link
Contributor

FYI -- defaults on streams could be implemented as a special kind of merge, which would require a new merge function to do right, which would require a map over objects to do right (of course we could also just do it, and fill in the architectural foundation later). Anyway, this is all discussed on google groups, and the link to the discussion is in the body of the issue #186. (Just so we don't lose track of the fact that these things are related).

@coffeemug
Copy link
Contributor

This issue has now been subsumed by #570. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants