Ken*_*nny 6 hive scala apache-spark apache-spark-sql pyspark
参考这里关于saveastable和insertInto的区别
以下两种方法有什么区别:
df.saveAsTable("mytable");
Run Code Online (Sandbox Code Playgroud)
和
df.createOrReplaceTempView("my_temp_table");
spark.sql("drop table if exists " + my_temp_table);
spark.sql("create table mytable as select * from
my_temp_table");
Run Code Online (Sandbox Code Playgroud)
在哪种情况下表存储在内存中,在哪种情况下物理存储在磁盘上?
另外,根据我的理解,createOrReplaceTempView只注册可通过 Hive 查询访问的数据帧(已在内存中),而不实际保留它,是否正确?
我必须加入数百个表并遇到 OutOfMemory 问题。在效率方面,最好的方法是什么?
df.persist() 和 df.join(..).join(..).join(..).. #hundred joins
createOrReplaceTempView然后加入spark.sql(),
SaveAsTable (?不确定下一步)
写入磁盘Create Table然后加入spark.sql()?
让我们一步一步来。
在 的情况下df.saveAsTable("mytable"),表实际上是写入存储(HDFS/S3)。这是一个 Spark 动作。
另一方面:
df.createOrReplaceTempView("my_temp_table")是一种转变。它只是用于 DAG 的标识符df。实际上没有任何内容存储在内存或磁盘上。
spark.sql("drop table if exists " + my_temp_table) 放下桌子。
spark.sql("create table mytable as select * from my_temp_table")mytable在存储上创建。createOrReplaceTempView在global_temp数据库中创建表。
最好将查询修改为:
create table mytable as select * from global_temp.my_temp_table
createOrReplaceTempView 仅注册可通过 Hive 查询访问的数据帧(已在内存中),而没有实际保留它,是否正确?
是的,对于大型 DAG,spark 会根据spark.memory.fraction设置自动缓存数据。检查此页面。
我必须加入数百个表并遇到 OutOfMemory 问题。在效率方面,最好的方法是什么?
Run Code Online (Sandbox Code Playgroud)df.persist() and df.join(..).join(..).join(..).... #hundred joins createOrReplaceTempView then join with spark.sql(), SaveAsTable (? not sure the next step) Write to disk with Create Table then join with spark.sql()?
persist 将根据可用内存和通过连接数百个表生成的结束表以缓存格式存储一些数据,这可能不是最好的方法。
不可能建议适合您的方法,但这里有一些通用模式:
如果写入因 OOM 失败并使用默认值spark.shuffle.partitions,则起点是增加 shuffle 分区计数,以确保每个 executor 的分区大小正确取决于其内存可用性。
该spark.shuffle.partitions设置可以跨不同的连接进行设置,它不需要在 Spark 作业中保持不变。
如果涉及多个表,计算分区大小将变得困难。在这种情况下,在大表之前写入磁盘并读回是一个好主意。
对于小于 2GB 的小表,广播是可能的。默认限制为 10MB(我认为)但可以更改。
最好是将最终表存储在磁盘上,而不是通过临时表为 thrift 客户端提供服务。
祝你好运!
| 归档时间: |
|
| 查看次数: |
5563 次 |
| 最近记录: |