kylin(麒麟)分页遇到的问题

本文介绍如何使用 Apache Kylin 的 JDBC 驱动进行数据连接配置,并实现分页查询功能。文中详细解释了 Maven 依赖配置、连接参数设置及特殊的分页查询方法,还特别注意到了时区问题的解决方案。

首先对kylin有一个初步的了解。http://www.youkuaiyun.com/article/2014-10-25/2822286

首先导入kylin的jdbc驱动:

pom文件如下

             <dependency>
                <groupId>org.apache.kylin</groupId>
                <artifactId>kylin-jdbc</artifactId>
                <version>1.6.0</version>
           </dependency>

创建jdbc连接

        Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
        Properties info = new Properties();
        info.put("user", Global.getConfig("kylin.service.username"));
        info.put("password", Global.getConfig("kylin.service.password"));
        Connection conn = driver.connect(String.format(Global.getConfig("kylin.jdbc.url"), proName), info);//proName---对应的立方体

配置文件

#============================#
#=========== kylin ==========#k

#============================#
kylin.service.base=http://192.168.10.207:7070/kylin/
kylin.service.url=http://192.168.10.207:7070/kylin/api/
kylin.service.username=admin
kylin.service.password=KYLIN
kylin.jdbc.url=jdbc:kylin://192.168.10.201:7070/%s

分页获取总记录数:

select count(1) from ( select flowcode,flow_name,unit_name,rece_unit_name,sendtime,receivetime,status,date_day from T_CHANGE_SHARELOG where 1=1  group by flowcode,flow_name,unit_name,rece_unit_name,sendtime,receivetime,status,date_day )

必须group by以后再count。

分页的时候由于没有像mysql的limit   1,10;

只能有limit   10;   

分页的思路就是--------和hive一样

        // 获取第一页数据:
        // select * from table order by id asc limit
        // 10;//同时需要记录这10条中最大的id为preId,作为下一页的条件。
        // 获取第二页数据:
        // select * from table where id >preId order by id asc limit
        // 10;//同时保存数据中最大的id替换preId。

我这里是按照日志的接收时间做的排序比较,分页

最后比较坑的是麒麟的jdbc有个时区的问题,每条查询出来的记录总是和hive里面的数据差8个小时

因此每条记录设置时间的时候还要加8小时

    public String add8hours(SimpleDateFormat sdf,String dateString) throws ParseException {
        Date date = sdf.parse(dateString);
        Date resultime = DateUtils.addHours(date, 8);
        return sdf.format(resultime);
    }

转载于:https://my.oschina.net/u/3027545/blog/884516

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值