文档首页/
MapReduce服务 MRS/
开发指南(LTS版)/
Spark2x开发指南(安全模式)/
开发Spark应用/
Spark同步HBase数据到CarbonData样例程序/
Spark同步HBase数据到CarbonData(Java)
更新时间:2024-10-18 GMT+08:00
Spark同步HBase数据到CarbonData(Java)
以下为Spark同步HBase数据到CarbonData的Java示例。
下面代码片段仅为演示。
具体代码参见:com.huawei.spark.examples.HBaseExternalHivetoCarbon。
public static void main(String[] args) throws Exception { spark = SparkSession.builder().appName("HBaseExternalHiveToCarbon").getOrCreate(); Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { timeEnd = timeStart + TIMEWINDOW; queryTimeStart = transferDateToStr(timeStart); queryTimeEnd = transferDateToStr(timeEnd); //run delete logic cmdsb = new StringBuilder(); cmdsb.append("delete from ") .append(carbonTableName) .append(" where key in (select key from ") .append(externalHiveTableName) .append(" where modify_time>'") .append(queryTimeStart) .append("' and modify_time<'") .append(queryTimeEnd) .append("' and valid='0')"); spark.sql(cmdsb.toString()); //run insert logic cmdsb = new StringBuilder(); cmdsb.append("insert into ") .append(carbonTableName) .append(" select * from ") .append(externalHiveTableName) .append(" where modify_time>'") .append(queryTimeStart) .append("' and modify_time<'") .append(queryTimeEnd) .append("' and valid='1'"); spark.sql(cmdsb.toString()); timeStart = timeEnd; } }, TIMEWINDOW, TIMEWINDOW); }