【问题标题】:Zero joins with null in the null-safe join在 null 安全连接中使用 null 进行零连接
【发布时间】:2022-01-19 18:57:52
【问题描述】:

我注意到在使用空安全连接 (eqNullSafe) 时,0null 连接。

df1 = spark.createDataFrame([(1, ), (None, )], ['df1_id'])
df2 = spark.createDataFrame([(None, ), (0, )], ['df2_id'])

df1.join(df2, df1.df1_id.eqNullSafe(df2.df2_id), 'right').show()
#+------+------+
#|df1_id|df2_id|
#+------+------+
#|  null|     0|
#|  null|  null|
#+------+------+

df2.join(df1, df1.df1_id.eqNullSafe(df2.df2_id), 'left').show()
#+------+------+
#|df2_id|df1_id|
#+------+------+
#|     0|  null|
#|  null|  null|
#+------+------+

如何让null 仅与null 一起加入?

【问题讨论】:

    标签: apache-spark join pyspark apache-spark-sql null-safety


    【解决方案1】:

    你需要在这里做inner join

    df1.join(df2, df1.df1_id.eqNullSafe(df2.df2_id), 'inner').show()
    

    现在右侧为 0,左侧 df 中没有匹配项,我们正在进行右连接,这就是为什么 pyspark 在右侧 df 中保留 0 并且在 df1_id 中变为 null。

    【讨论】:

      猜你喜欢
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      • 2012-01-04
      相关资源
      最近更新 更多