前提条件:hive中创建分区表,并指定分区键
create table test(
id stirng
)partitioned by (name string)
stored as orc;
创建sparksession,不需要认证的话去掉config中内容
SparkSession ss = SparkSession.builder()
.appName("test ")
.master("local[2]"
.enableHiveSupport()
.config("spark.sql.authorization.enabled", true)
.config("hive.security.authorization.enabled", true)
.getOrCreate();
读取oracle中数据
String sql = "(select xxx.*, 'a' as name from xxx where time >= trunc(sysdate) ) a";
Dataset<Row> table = ss.read()
.format("jdbc")
.option("driver", "oracle.jdbc.OracleDriver")
.option("url", "jdbc:oracle:thin:@1.1.1.1:1521:orcl")
.option("user", &#

本文介绍了如何使用SparkSQL动态插入Hive分区表,包括创建Hive分区表的步骤,设置Sparksession,从Oracle读取数据,以及动态分区的配置。还探讨了在HDFS上对数据进行重分布的场景,如使用coalesce和repartition方法,并讨论了它们在不同分区数量情况下的适用性。最后,展示了插入后的Hive分区表在HDFS上的结构。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



