Skip to content

Instantly share code, notes, and snippets.

@manishkkatoch
Created January 1, 2019 17:10
Show Gist options
  • Save manishkkatoch/c747a510c956721a27df153769ffde26 to your computer and use it in GitHub Desktop.
Save manishkkatoch/c747a510c956721a27df153769ffde26 to your computer and use it in GitHub Desktop.
class JoinDataSet[L, R](lhs: Dataset[L], rhs: Dataset[R], joinType: String) {
def withKey[K](column: Witness.Lt[Symbol])(implicit
lhsExists: PropertyExists[L, column.T, K],
rhsExists: PropertyExists[R, column.T, K]): DataFrame =
doJoin(Seq(column.value.name))
private def doJoin(columns: Seq[String]) = lhs.join(rhs, columns, joinType)
}
object JoinDataSet {
def apply[L, R](lhs: Dataset[L], rhs: Dataset[R], joinType: String) = new JoinDataSet(lhs, rhs, joinType)
def leftJoin[L, R](lhs: Dataset[L], rhs: Dataset[R]) = JoinDataSet(lhs, rhs, "leftOuter")
def rightJoin[L, R](lhs: Dataset[L], rhs: Dataset[R]) = JoinDataSet(lhs, rhs, "rightOuter")
def fullOuterJoin[L, R](lhs: Dataset[L], rhs: Dataset[R]) = JoinDataSet(lhs, rhs, "fullOuter")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment