Spark SQL中防止数据倾斜sqlContext.sql中添加distribute by rand()

来源:互联网 发布:c语言counter 编辑:程序博客网 时间:2024/05/22 09:05


一、在 Spark SQL中有时会因为数据倾斜影响节点间数据处理速度,可在SQL中添加distribute by rand()来防止数据倾斜

val dataRDD = sqlContext.sql(        "select A ,B from table your_table distribute by rand() "    )

二、在数据量过大时,若在Spark SQL中 使用sort排序等自定义函数会出现内存不足错误

如Total size of serialized results of 20 tasks (1058.2 MB) is bigger than spark.driver.maxResultSize (1024.0 MB)   

解决办法可在hive中单独建立一张表将数据排序,避免该步骤在spark内存中执行

0 0