Spark sql 优化技巧 将 csv 加载到 hive 的 orc 格式 [英] Spark sql Optimization Techniques loading csv to orc format of hive
问题描述
我在 CSV 文件中有 90 GB 数据,我正在将此数据加载到一个临时表中,然后使用 select insert 命令从临时表到 orc 表,但是为了将数据转换和加载为 orc 格式,在 spark sql 中需要 4 小时.是否有任何一种优化技术可以用来减少这个时间.截至目前我没有使用任何类型的优化技术,我只是使用 spark sql 并将数据从 csv 文件加载到表(文本格式)然后从这个临时表到兽人表(使用选择插入)使用 spark 提交为:
spark-submit \--class 类名\--jar 文件
或者我可以在 spark submit 中添加任何额外的参数以改进优化.
scala 代码(示例):
所有进口对象演示{def main(args: Array[String]) {//sparksession 启用 hivesupportvar a1=sparksession.sql("load data inpath 'filepath' overwrite into table table_name")var b1=sparksession.sql("insert into tablename (all_column) select 'ALL_COLUMNS' from source_table")}}
我只是使用 spark sql 并将数据从 csv 文件加载到表(文本格式),然后从这个临时表到兽人表(使用选择插入)
<小时>
这里不需要两步过程..
- 像下面的示例一样读取数据框...
val DFCsv = spark.read.format("csv").option("sep", ",").option("inferSchema", "true").option("header", "true").load("你的csv")
- 如果需要,您必须执行
重新分区
(这可能是由于您尚未完成而导致实际延迟 4 小时的原因),因为它的文件很大,然后...
dfcsv.repartition(90)
意味着它将/可能将 csv 数据重新划分为 90 个几乎相等的部分.其中 90 是样本数.你可以提你想要的任何东西.
DFCsv.write.format("orc").partitionBy('你的分区列').saveAsTable('你的表')
或
DFCsv.write.format("orc").partitionBy('你的分区列').insertInto('你的桌子')
<块引用>
注意:1)对于大数据,你需要做重新分区以均匀分布数据会增加并行度,因此表现.
2) 如果您没有 patition 列并且是非分区表则不需要上面的 partitionBy
样品
Hi I have 90 GB data In CSV file I'm loading this data into one temp table and then from temp table to orc table using select insert command but for converting and loading data into orc format its taking 4 hrs in spark sql.Is there any kind of optimization technique which i can use to reduce this time.As of now I'm not using any kind of optimization technique I'm just using spark sql and loading data from csv file to table(textformat) and then from this temp table to orc table(using select insert) using spark submit as:
spark-submit \
--class class-name\
--jar file
or can I add any extra Parameter in spark submit for improving the optimization.
scala code(sample):
All Imports
object demo {
def main(args: Array[String]) {
//sparksession with enabled hivesuppport
var a1=sparksession.sql("load data inpath 'filepath' overwrite into table table_name")
var b1=sparksession.sql("insert into tablename (all_column) select 'ALL_COLUMNS' from source_table")
}
}
I'm just using spark sql and loading data from csv file to table(textformat) and then from this temp table to orc table(using select insert)
2 step process is not needed here..
- Read the dataframe like below sample...
val DFCsv = spark.read.format("csv")
.option("sep", ",")
.option("inferSchema", "true")
.option("header", "true")
.load("yourcsv")
- if needed you have to do
repartition
(may be this is cause of the actual 4hr delay since you have not done) since its large file and then...
dfcsv.repartition(90)
means it will/may repartition the csv data in to 90 almost equal parts. where 90 is sample number. you can mention what ever you want.
DFCsv.write.format("orc")
.partitionBy('yourpartitioncolumns')
.saveAsTable('yourtable')
OR
DFCsv.write.format("orc")
.partitionBy('yourpartitioncolumns')
.insertInto('yourtable')
Note: 1) For large data you need to do repartition to uniformly distribute the data will increase the parllelism and hence performance.
2) If you dont have patition columns and is non-partition table then no need of
partitionBy
in the above samples
这篇关于Spark sql 优化技巧 将 csv 加载到 hive 的 orc 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!