Skip to content

Rename and generalize zip #325

Closed
Closed

Description

@coffeemug

Currently our zip operator has two flaws:

  1. It's different from what one would expect zip to be (which is described in Add multi-stream zip operator #324)
  2. It's very oddly specific in that it hardcodes left and right.

Here's what I think we should do:

  1. Rename zip to flatten
  2. Generalize it so that it can do more arbitrary object flattening:
r.expr({ left: {a : 1}, right: { b: 2}}).flatten('left', 'right') ==> { a: 1, b: 2 }

The generalization should also account for nested objects, so we should probably wait until we work out pluck before we do this.

Activity

  1. jdoliner commented on Feb 13, 2013

    @jdoliner
    Contributor

    Just to make sure I understand, flatten is sugar for:

    seq.flatten() = seq.reduce(lambda x,y: map_merge(x["value"], y["value"]))
    

    I think this is a very intuitive meaning for flatten. And flatten can also take arguments which is equivalent to:

    seq.flatten(foo, bar) = seq.pluck(foo, bar).flatten()
    
  2. coffeemug commented on Feb 13, 2013

    @coffeemug
    ContributorAuthor

    I think flatten should be polymorphic on sequences and objects. On sequences

    seq.flatten() = seq.map(r.row.flatten())
    

    On objects:

    obj.flatten(...) = obj.map_merge(...)
    

    As to what specific arguments flatten accepts and what it does with them, I think you're roughly correct, but we still have to work out what to do with pluck. But basically, the whole thing is sugar for merge.

  3. jdoliner commented on Feb 13, 2013

    @jdoliner
    Contributor

    So polymorphism here seems very inconsistent with how we do pick and pluck. Pick and pluck are the same operation but one is for an object while the other is for a sequence of objects. I feel fairly strongly that we should either have both of these be polymorphic or neither.

    I'm in favor of making them polymorphic and I remember we argued about this at one point and judging by our current solution the other side won. Does anyone remember what the arguments were, @coffeemug I feel like you were the main opponent of polymorphism for pluck and pick but I could be misremembering.

  4. coffeemug commented on Feb 13, 2013

    @coffeemug
    ContributorAuthor

    The pick and pluck duality is going away -- we're going to use pluck for both. In fact, in the new language as many things as possible will be polymorphic -- whenever something is defined on an object, whenever possible it will also be defined as a map over a stream.

    We couldn't do it before because of the type system, but now that it's gone, we can make everything polymorphic on objects and streams and use the same name without confusing users.

    Also, I think that in the new language we should define pick as follows (it would of course also be polymorphic on streams):

    r.expr({a : 1, b: 2}).pick('a', 'b') => [1, 2]
    
  5. al3xandru commented on Feb 14, 2013

    @al3xandru
    Contributor

    I think in PL this operation (named here pick) applied to dict/hash/etc is called values.

  6. coffeemug commented on Feb 14, 2013

    @coffeemug
    ContributorAuthor

    values is cool, though it would be hard to use because of its inherent keywordness.

  7. al3xandru commented on Feb 14, 2013

    @al3xandru
    Contributor

    Where is values a keyword?

  8. coffeemug commented on Feb 14, 2013

    @coffeemug
    ContributorAuthor

    I could have sworn it's a keyword in Python, but upon checking, it isn't.

  9. jdoliner commented on Feb 14, 2013

    @jdoliner
    Contributor

    We're sort of conflating keyword and library function here. I don't know of any language in which it's a try keyword (I don't know many languages though) but I think it's a builtin function in a lot. In most cases I think we'll be fine because it's normally a method on a dict object while we'd have it being a method on an ast object.

    However I do have some concern that values has a different meaning in some languages than we're giving it here. In python

    {"a" : 1, "b" : 2}.values() == ["a", "b"]
    

    Ruby behaves the same but has a values_at method which is the same as what we're describing.

    How do we feel about values_of?

  10. al3xandru commented on Feb 14, 2013

    @al3xandru
    Contributor

    @jdoliner: in case you are not using a different Python than mine, this is not true:

    {"a" : 1, "b" : 2}.values() == ["a", "b"]
    
    {"a" : 1, "b": 2}.values() == [1, 2]
    

    Same in Ruby.

  11. jdoliner commented on Feb 14, 2013

    @jdoliner
    Contributor

    Whoops, sorry I did the behavior of keys there. Values is as you describe.

  12. coffeemug commented on Jan 14, 2014

    @coffeemug
    ContributorAuthor

    Closing in favor of #1855.

  13. modified the milestones: duplicate, backlog on Feb 13, 2014
  14. sunjay commented on Apr 28, 2016

    @sunjay

    Note that this is still referenced in the docs here: https://rethinkdb.com/docs/table-joins/

    Given that this has been superseded by a new issue and given that the new issue is on the backlog that should probably be updated.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions