question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add join_natural method

See original GitHub issue

This issue captures a missing feature that’s bothered me a little too; a quick and dirty way to join tables on shared keys as in tidyverse’s inner_join or MySQL’s NATURAL JOIN. Especially without named arguments in JS, it’s hard to remember how to do this with existing joins.

In observable I’ve started adding a join_natural function that mimics their behavior: I wonder if you’d consider adding something similar as a method.

  aq.internal.Table.prototype.join_natural = function(right) {
    const names = this.columnNames()
    return this.join(right, undefined, [names,right.columnNames().filter(d => names.indexOf(d) == -1)])
  }

Would probably be best if it threw an error if there are no shared keys. (?)

Thanks again for your work–still greatly enjoying this library’s contribution.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Nov 26, 2020

Thanks! You both convinced me to have Arquero throw an error when there are no shared columns. I’ve also updated the PR to (1) ensure proper handling of natural left, right, and full joins, and (2) suppress duplicated key column output.

The handling of full outer joins is a bit subtle. In SQL, natural full joins are not allowed. In dplyr, they are allowed but cause the “duplicate” key columns to be merged, using the value of whichever column is non-empty. I’ve followed the dplyr semantics here in Arquero when de-duplicating shared key columns in a full outer join.

0reactions
jubacommented, Nov 25, 2020

I think this would be great, and I also agree with @bmschmidt caution about the potential danger of non explicitly asked for cartesian product : I already ended several times with a hanged session in R doing these sort of things, too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL natural join - w3resource
A NATURAL JOIN compares all columns of two tables which have the same column-name and the resulting joined table contains those columns once ......
Read more >
SQLite Join: Natural Left Outer, Inner, Cross with Tables ...
SQLite supports different types of SQL Joins, like INNER JOIN, LEFT OUTER JOIN, and CROSS JOIN. Each type of JOIN is used for...
Read more >
natural_join | Deephaven
natural_join joins data from a pair of tables - a left and right table - based upon one or more match columns. The...
Read more >
Join (SQL) - Wikipedia
A join clause in SQL – corresponding to a join operation in relational algebra – combines columns from one or more tables into...
Read more >
sql - MySQL - Update join natural order - Stack Overflow
Thanks for your reply; actually my table t1 has random values, so I cannot use your solution. – toni07. Jun 19, 2014 at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found