Skip to content

ReQL proposal: add a default to r.merge #1737

Open

Description

@coffeemug

The r.merge command is about to accept a function (#1345). I think the command should have a default, as follows:

r.expr([{a: 1}, {b: 2}]).merge(function(doc) { return { c: doc('a').add(1) } })
=> [{a: 1, c: 2}
    {b: 2}]

I.e. we don't drop the row, we drop the "merge", so the default should be an empty object.

@mlucy is skeptical:

my initial reaction is skepticism. If you try to reference a non-existent field in e.g. an update you get an error. This is important because if we just silently skip merging elements like this, people might think that they're performing a write when in fact nothing gets written to disk. I might be able to be convinced otherwise, though.

Specifically, I'm worried about your semantics for queries like:

table.update{|row| {c: row['a']+1} # error
table.update{|row| {subrows: row['subrows'].merge{|subrow| {c: subrow['a']+1}}}} # not an error

Activity

  1. neumino commented on Dec 4, 2013

    @neumino
    Member

    I'm also opposed to having merge silently ignoring errors.

    The merge comnand is common in write queries and we shouldn't let users get inconsistent data in their model.
    I think it's for that reason that we didn't have null propagates when errors were occurring.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions