我正在尝试读取一些表(拼接文件),做一些连接,并在S3中将它们写成拼接格式,但我得到了一个错误或花了几个多小时来写表。
错误:
An error was encountered:
Invalid status code '400' from https://.... with error payload: {"msg":"requirement failed: session isn't active."}除了那张桌子之外,我还能写出其他的表格作为拼花。
这是我的示例代码:
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
spark = SparkSession.builder.config("spark.sql.catalogImplementation", "in-memory").getOrCreate()
table1 = spark.read.parquet("s3://.../table1")
table1.createOrReplaceTempView("table1")
table2 = spark.read.parquet("s3://.../table2")
table2.createOrReplaceTempView("table2")
table3 = spark.read.parquet("s3://.../table3")
table3.createOrReplaceTempView("table3")
table4 = spark.read.parquet("s3://.../table4")
table4.createOrReplaceTempView("table4")
Final_table = spark.sql("""
select
a.col1
a.col2
...
d.coln
from
table1 a
left outer join
table2 b
on
cond1
cond2
cond3
left outer join
table3 c
on
...
""")
Final_table.count()
# 3813731240
output_file="s3://.../final_table/"
final_table.write.option("partitionOverwriteMode", "dynamic").mode('overwrite').partitionBy("col1").parquet(output_file)为了添加更多内容,我尝试了重新分区,但不起作用。此外,我还尝试了不同的电子病历集群,比如Cluster1: Master m5.24xlarge
Cluster2: Master m5.24xlarge 1核m5.24xlarge
Cluster3: Master m5d.2xlarge 8核m5d.2xlarge
EMR版本5.29.0
发布于 2020-07-13 13:07:52
大多数spark作业都可以通过可视化它们的DAG进行优化。
在这个场景中,如果您能够在最短的时间内运行sql并获得计数,并且您所有的时间都被用于编写,那么以下是一些建议
你可以这样做
df.repartition('col1', 100).write此外,如果您知道分区计数,也可以根据分区计数来设置该数量。
https://stackoverflow.com/questions/62830812
复制相似问题