sparkSQL实现对hive动态分区

1.开始hive动态分区参数
val spark = SparkSession
.builder()
.appName(“test”)
.enableHiveSupport()
.config(“spark.sql.adaptive.enabled”,true)
.config(“spark.sql.adaptive.shuffle.targetPostShuffleInputSize”,134217728)
.config(“hive.exec.dynamic.partition”, true) // 支持 Hive 动态分区
.config(“hive.exec.dynamic.partition.mode”, “nonstrict”) // 非严格模式
.getOrCreate()
2. 动态分区
spark.sql(
“insert overwrite table test1 partition(day,hour) " +
“select” +
" a.platform,” +
" a.aid," +
" a.request_num," +
" b.play_num," +
" b.accomplish_num," +
" b.click_num," +
" a.day," +
" a.hour" +
" from test"
)
注意:动态分区的字段day\hour必须放最后,测试过放前面还是以最后两个字段作为分区,也说明动态分区字段以字段位置来进行分区的

你可能感兴趣的:(Spark)