1.第一步先在impala-shell 根据命令创建一张表:
创建表的时候根据年和月份对数据进行分区,存储格式为parquet.
create table if not exists people(id int,name string,age int) partitioned by(year int,month int) STORED AS PARQUET;
2.java中的存储数据的sql 语句
给分区的年和月赋值,即可把数据存在相应的分区里
String sql = "insert into people partition (year="+year+",month="+month+") values(1,'小明',23)";
举个例子:(ReporterVo 我写的一个实例类,根据自己的类进行替换,里面所用到的获取Impala连接和year和month变量赋值的方法,在文章的下面)
public static void insertTopic(ReporterVo reporterVo) {
List<Integer> list=ImpalaHelper.getCurrentDate();
int year = list.get(0);
int month = list.get(1);
Connection conn = getImpalaConnect();
try {
String sql = "insert into testTable partition (year="+year+",month="+month+") value

本文介绍了如何在Impala中创建分区表,并通过Java代码演示了如何将数据按年和月进行分区存储,使用Parquet格式。步骤包括在impala-shell创建分区表,以及在Java中设置分区字段值和建立Impala连接。
最低0.47元/天 解锁文章
1万+

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



