Skip to content

Nested pluck syntax throws when it shouldn't #1095

Closed

Description

@coffeemug
r([{a: {c: 1}}, {a: 2}]).pluck({'a': 'c'})

Throws an error:

RqlRuntimeError: Expected type OBJECT but found NUMBER

I don't think it should. pluck would be a lot more useful if it dropped the row instead.

@jdoliner -- is this difficult to fix? I think we should hold the release for it, as this is fairly important.

Activity

  1. coffeemug commented on Jun 29, 2013

    @coffeemug
    ContributorAuthor

    Actually, sorry, it shouldn't drop the row (since in other cases pluck never reduces the size of the stream). I'm not sure what it should return in this case, actually. @mlucy -- can you comment?

  2. coffeemug commented on Jun 29, 2013

    @coffeemug
    ContributorAuthor

    And by "I'm not sure what it should return", I mean that I'm not sure if it should return {a: {}} for the document in question or {}.

  3. coffeemug commented on Jun 29, 2013

    @coffeemug
    ContributorAuthor

    Also: sorry for spamming, but I'm playing with the syntax and it's pretty freakin' sweet.

  4. mlucy commented on Jun 29, 2013

    @mlucy
    Member

    I think it should return [{:a => {:c => 1}}, {}].

  5. jdoliner commented on Jun 29, 2013

    @jdoliner
    Contributor

    So unfortunately this example data is small enough that these proposals don't actually fully explain the syntax. Let's just have the rule that if a pluck attempts to pluck from a field with key a and the value of field a is not a pluckable type then we treat it as if there is no field with key a.

  6. jdoliner commented on Jun 29, 2013

    @jdoliner
    Contributor

    Also @mlucy I don't understand your proposal, why do you drop a row?

  7. jdoliner commented on Jun 29, 2013

    @jdoliner
    Contributor

    Speaking in terms of examples:

    >>> {"a" : {"b" : 1, "d" : {"e" : 2}}}.pluck({"a" : {"b" : "c", "d" : "e"}})
    {"a" : {"d" : {"e" : 2}}}
    

    I think this is probably the most useful behavior. Also I feel pretty strongly that:

    r(1).pluck("foo")
    

    should still throw.

  8. mlucy commented on Jun 29, 2013

    @mlucy
    Member

    @jdoliner -- I think the behavior you want is right.

  9. jdoliner commented on Jun 29, 2013

    @jdoliner
    Contributor

    Also just to be clear because we actually weren't on the same page when we discussed before but thought we were.

    r.expr([1,2,3,4]).pluck("foo")
    

    Should throw. I feel like if you're trying to pluck directly on a non object then most likely you've just made a typo. and converting numbers to empty objects seems awfully odd.

  10. coffeemug commented on Jun 29, 2013

    @coffeemug
    ContributorAuthor

    @jdoliner -- the behavior you're describing seems right to me as well.

  11. jdoliner commented on Jul 1, 2013

    @jdoliner
    Contributor

    This is fixed and in next as of f32acd4. CR 685 by @mlucy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions