添加
分区(列)
在你的插入中。
val spark = SparkSession.builder.appName("test").config("hive.exec.dynamic.partition", "true").config("hive.exec.dynamic.partition.mode", "nonstrict").enableHiveSupport().getOrCreate
spark.sql("drop table table_1")
spark.sql("CREATE EXTERNAL TABLE table_1 (id string, name string) PARTITIONED BY (key1 int) stored as parquet location '/directory/your location/'")
spark.sql("insert into table_1 values('a','a1', 1)")
spark.sql("insert into table_1 values ('b','b2', 2)")
spark.sql("select * from table_1").show()
spark.sql("insert OVERWRITE table table_1 PARTITION(key1) values ('b','b3', 2)")
spark.sql("select * from table_1").show()
CODE IMAGE