Kylin 2.6.0JDBC方式访问

版权声明:本文为博主九师兄(QQ群:spark源代码 198279782 欢迎来探讨技术)原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21383435/article/details/90072293

Kylin提供了标准的ODBC和JDBC接口,能够和传统BI工具进行很好的集成。分析师们可以用他们最熟悉的工具来享受Kylin带来的快速。

本章节介绍通过Java程序调用Kylin的JDBC接口访问Kylin的Cube数据。

1.url

首先我们来看一下连接Kylin的URL格式为:

jdbc:kylin://<hostname>:<port>/<kylin_project_name>

注:
如果“ssl”为true话,那么上面的端口号应该为Kylin服务的HTTPS端口号。
kylin_project_name必须指定,并且在Kylin服务中存在。

下面介绍几种方式访问Kylin数据:

第一种方法:使用Statement方式查询

依赖如下

 		<!-- https://mvnrepository.com/artifact/org.apache.kylin/kylin-jdbc -->
        <dependency>
            <groupId>org.apache.kylin</groupId>
            <artifactId>kylin-jdbc</artifactId>
            <version>2.6.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>27.1-jre</version>
        </dependency>

查询代码

 @Test
    public void queryTest() throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
        // 加载Kylin的JDBC驱动程序
        Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();

        // 配置登录Kylin的用户名和密码
        Properties info = new Properties();
        info.put("user", "ADMIN");
        info.put("password", "KYLIN");

        // 连接Kylin服务
        Connection conn = driver.connect("jdbc:kylin://192.168.xx.62:7070/kylin260_cdh57_Hbase120", info);
        Statement state = conn.createStatement();
        ResultSet resultSet = state.executeQuery("select count(*),PART_DT from KYLIN_SALES group by PART_DT");


        while (resultSet.next()) {
            int col1 = resultSet.getInt(1);
            String col2 = resultSet.getString(2);
            System.out.println(col1 + "\t" + col2 + "\t" );
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_21383435/article/details/90072293