1、JDBC
1)pom 依赖
<dependencies>
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-jdbc</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
2)编码
package com.alex.kylin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* @author 黑猴子的家
*/
public class TestKylinJdbc {
public static void main(String[] args) throws Exception {
//Kylin_JDBC 驱动
String KYLIN_DRIVER = "org.apache.kylin.jdbc.Driver";
//Kylin_URL
String KYLIN_URL = "jdbc:kylin://hadoop102:7070/FirstProject";
//Kylin的用户名
String KYLIN_USER = "ADMIN";
//Kylin的密码
String KYLIN_PASSWD = "KYLIN";
//添加驱动信息
Class.forName(KYLIN_DRIVER);
//获取连接
Connection connection = DriverManager.getConnection(KYLIN_URL, KYLIN_USER, KYLIN_PASSWD);
//预编译SQL
PreparedStatement ps = connection.prepareStatement("SELECT sum(sal) FROM emp group by deptno");
//执行查询
ResultSet resultSet = ps.executeQuery();
//遍历打印
while (resultSet.next()) {
System.out.println(resultSet.getInt(1));
}
}
}
3)结果展示
![9193428-8a2655df1ca7c2fe.png](https://i-blog.csdnimg.cn/blog_migrate/0d3b9af82a8cace749ae1c54fed8cc2c.png)
2、Zepplin
1)Zepplin安装与启动
(1)将zeppelin-0.8.0-bin-all.tgz上传至Linux
(2)解压zeppelin-0.8.0-bin-all.tgz之/opt/module
[alex@hadoop102 sorfware]$ tar -xzvf zeppelin-0.8.0-bin-all.tgz -C /opt/module/
(3)修改名称
[alex@hadoop102 module]$ mv zeppelin-0.8.0-bin-all/ zeppelin
(4)启动
[alex@hadoop102 zeppelin]$ bin/zeppelin-daemon.sh start
2)访问
可登录网页查看,web默认端口号为8080
http://hadoop102:8080
![9193428-caff0bb30b943aa6.png](https://i-blog.csdnimg.cn/blog_migrate/ad66fedd738b99e80febc4ff229b285f.png)
3)配置Zepplin支持Kylin
(1)点击右上角anonymous选择Interpreter
![9193428-9d62ec172fd22314.png](https://i-blog.csdnimg.cn/blog_migrate/b35731debca85e8b27186d162c02eb8f.png)
(2)搜索Kylin插件并修改相应的配置
![9193428-0a0a1c526f10ea51.png](https://i-blog.csdnimg.cn/blog_migrate/3d5e8b4ac63703f826a003a97aa9171e.png)
(3)修改完成点击Save完成
![9193428-1dda03e68ebe5fe8.png](https://i-blog.csdnimg.cn/blog_migrate/bbdc3506c6328d5b1bc15dfc597c35bb.png)
4)案例实操
需求:查询员工详细信息,并使用各种图表进行展示
(1)点击Notebook创建新的note
![9193428-d89fad5b81369aaa.png](https://i-blog.csdnimg.cn/blog_migrate/4d59f30e654717d22a342aab0c87ac34.png)
(2)填写Note Name点击Create
![9193428-19338654fa8ecb85.png](https://i-blog.csdnimg.cn/blog_migrate/b27d0e5bf4741cf877a4938b21876f6f.png)
(3)输出sql语句
![9193428-c423feddc0cf264e.png](https://i-blog.csdnimg.cn/blog_migrate/39638d2fc1af72d9b6bdb4d5f5cad66f.png)
(4)执行查询
![9193428-a5b23961c5ed8f2e.png](https://i-blog.csdnimg.cn/blog_migrate/9d36af6e99b1da9e6f43aef4cd2986d0.png)
(5)查看结果
![9193428-687e37c4f2979b7b.png](https://i-blog.csdnimg.cn/blog_migrate/c7830419a9fd329a49b9e2b384f07dcd.png)
(6)图标形式展示
![9193428-bf1a77dadc943898.png](https://i-blog.csdnimg.cn/blog_migrate/4fd0b8667a27873264b5791befbc8182.png)
条形图
![9193428-75d72876e39bef85.png](https://i-blog.csdnimg.cn/blog_migrate/e756c4ac22e4a641683088709d4e43df.png)
饼状图
![9193428-10b6703cd5b41fb7.png](https://i-blog.csdnimg.cn/blog_migrate/5aa3e39972663dd5d1cd87cb1fefda9c.png)
![9193428-8eba8ef6104b7fbe.png](https://i-blog.csdnimg.cn/blog_migrate/339b8f2befbb30bd6b59e06b989c197e.png)
折线图
![9193428-efd3960d6fad4c9c.png](https://i-blog.csdnimg.cn/blog_migrate/e3a34f250766bf90bbdf97e0c384a265.png)
散点图