3.2.2 其他join类型,只需把inner改成你需要的类型即可
scala> df1.join(df2,Seq("k1"),"left").show +---+---+---+---+---+ | k1| k2| k3| k2| k4| +---+---+---+---+---+ | a| 1| 2| 2| 2| | b| 2| 3| 2| 1| | b| 2| 3| 3| 3| +---+---+---+---+---+ //左外连接 left_outer可简写为left scala> df1.join(df2,Seq("k1"),"left_outer").show +---+---+---+---+---+ | k1| k2| k3| k2| k4| +---+---+---+---+---+ | a| 1| 2| 2| 2| | b| 2| 3| 2| 1| | b| 2| 3| 3| 3| +---+---+---+---+---+ //左半连接 scala> df1.join(df2,Seq("k1"),"leftsemi").show +---+---+---+ | k1| k2| k3| +---+---+---+ | a| 1| 2| | b| 2| 3| +---+---+---+ scala> df1.join(df2,Seq("k1","k2"),"left").show +---+---+---+----+ | k1| k2| k3| k4| +---+---+---+----+ | a| 1| 2|null| | b| 2| 3| 1| +---+---+---+----+ scala> df1.join(df2,Seq("k1"),"right").show +---+----+----+---+---+ | k1| k2| k3| k2| k4| +---+----+----+---+---+ | a| 1| 2| 2| 2| | b| 2| 3| 3| 3| | b| 2| 3| 2| 1| | c|null|null| 1| 1| +---+----+----+---+---+
left是left_outer的简写
4 单表操作:列的增删改与空值处理