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 =