Spark Dataset Error: Both sides of this join are outside the broadcasting threshold and computing it could be prohibitively expensive

Spark Dataset Error: Both sides of this join are outside the broadcasting threshold and computing it could be prohibitively expensive

我在本地模式下使用 Spark2.0.2。我有一个连接两个数据集的连接。

使用 spark sql 或 dataframe API (untyped Dataset[Row] ) 时相当快。 但是当我使用类型化数据集 API 时,出现以下错误。

线程中的异常 "main" org.apache.spark.sql.AnalysisException:此连接的双方都在广播阈值之外,计算它可能非常昂贵。要明确启用它,请设置 spark.sql.crossJoin.enabled = true;

我增加了"spark.sql.conf.autoBroadcastJoinThreshold",还是一样的错误。然后我将 "spark.sql.crossJoin.enabled" 设置为 "true",它有效但需要很长时间才能完成。

我没有做任何重新分区。来源是两个镶木地板。

有什么想法吗?

自动广播阈值仅限于 2GB (https://issues.apache.org/jira/browse/SPARK-6235),因此如果 table 大小超过此值,您将无法这样做。 解决方法是使用广播函数向 sparksql 提供提示,如下所示:

largeTableDf.join(broadcast(smallTableDf), "key"))

找到原因了。 在我的ds1中,还有一个字段"key2",与ds2的join key相同。 将 ds2("key2") 重命名为 ds2("key3") 后,下面的连接现在很快了。

ds1.joinWith(广播(ds2), ds1("key1") === ds2("key3"), "left_outer")

谁能解释一下原因?