Add join_natural method
See original GitHub issueThis 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.