我想覆盖外部表中的所有分区,当insertInto数据。如果任何分区不在数据中,它需要被删除。saveAsTable改变了表结构,所以我不能使用它。我尝试使用overwrite=True参数insertInto,但旧的分区没有删除。
insertInto
saveAsTable
overwrite=True
djmepvbi1#
from pyspark.sql import SparkSessionspark = SparkSession.builder.appName("example").getOrCreate()# Assuming you have a DataFrame with your new datanew_data = ...table_name = "your_table"table_path = "path_to_your_table"new_data.write.mode("overwrite").insertInto(table_name)spark.sql(f"MSCK REPAIR TABLE {table_name}")
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("example").getOrCreate()
# Assuming you have a DataFrame with your new data
new_data = ...
table_name = "your_table"
table_path = "path_to_your_table"
new_data.write.mode("overwrite").insertInto(table_name)
spark.sql(f"MSCK REPAIR TABLE {table_name}")
字符串insert into方法和mode("overwrite")用于用新数据覆盖整个表。要删除新数据中不存在的分区,可以使用MSCK REPAIR TABLE命令。
insert into
mode("overwrite")
MSCK REPAIR TABLE
1条答案
按热度按时间djmepvbi1#
字符串
insert into
方法和mode("overwrite")
用于用新数据覆盖整个表。要删除新数据中不存在的分区,可以使用MSCK REPAIR TABLE
命令。