Kylin实战—— REST API演示和Kylin_JDBC演示代码

Posted 扫地增

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kylin实战—— REST API演示和Kylin_JDBC演示代码相关的知识,希望对你有一定的参考价值。

无论您是从笔者上篇文章过来,还是新读到本文,REST API在这里就不多说了,我们直接接给出示例:
REST API Query查询代码:

REST API Query查询代码

curl -X POST --user ADMIN:KYLIN -H "Content-Type: application/json" -d '{ "sql":"select d.loc,e.job,d.dname,sum(e.sal) from kylin_test_emp e join kylin_test_dept d on e.deptno = d.deptno group by d.dname,d.loc,e.job" , "project" : "emp_project" }' http://kb-testhadoop01:7070/kylin/api/query

REST API 查询查询结果

{
    "affectedRowCount": 0,
    "columnMetas": [
        {
            "autoIncrement": false,
            "caseSensitive": true,
            "catelogName": null,
            "columnType": 4,
            "columnTypeName": "INTEGER",
            "currency": false,
            "definitelyWritable": false,
            "displaySize": 10,
            "isNullable": 1,
            "label": "LOC",
            "name": "LOC",
            "precision": 10,
            "readOnly": true,
            "scale": 0,
            "schemaName": "TEST",
            "searchable": false,
            "signed": true,
            "tableName": "KYLIN_TEST_DEPT",
            "writable": false
        },
        {
            "autoIncrement": false,
            "caseSensitive": true,
            "catelogName": null,
            "columnType": 12,
            "columnTypeName": "VARCHAR",
            "currency": false,
            "definitelyWritable": false,
            "displaySize": 256,
            "isNullable": 1,
            "label": "JOB",
            "name": "JOB",
            "precision": 256,
            "readOnly": true,
            "scale": 0,
            "schemaName": "TEST",
            "searchable": false,
            "signed": true,
            "tableName": "KYLIN_TEST_EMP",
            "writable": false
        },
        {
            "autoIncrement": false,
            "caseSensitive": true,
            "catelogName": null,
            "columnType": 12,
            "columnTypeName": "VARCHAR",
            "currency": false,
            "definitelyWritable": false,
            "displaySize": 256,
            "isNullable": 1,
            "label": "DNAME",
            "name": "DNAME",
            "precision": 256,
            "readOnly": true,
            "scale": 0,
            "schemaName": "TEST",
            "searchable": false,
            "signed": true,
            "tableName": "KYLIN_TEST_DEPT",
            "writable": false
        },
        {
            "autoIncrement": false,
            "caseSensitive": true,
            "catelogName": null,
            "columnType": 8,
            "columnTypeName": "DOUBLE",
            "currency": false,
            "definitelyWritable": false,
            "displaySize": 15,
            "isNullable": 1,
            "label": "EXPR$3",
            "name": "EXPR$3",
            "precision": 15,
            "readOnly": true,
            "scale": 0,
            "schemaName": null,
            "searchable": false,
            "signed": true,
            "tableName": null,
            "writable": false
        }
    ],
    "cube": "CUBE[name=emp_cube]",
    "duration": 62,
    "exceptionMessage": null,
    "hitExceptionCache": false,
    "isException": false,
    "partial": false,
    "pushDown": false,
    "results": [
        [
            "1900",
            "CLERK",
            "SALES",
            "950.0"
        ],
        [
            "1700",
            "PRESIDENT",
            "ACCOUNTING",
            "5000.0"
        ],
        [
            "1700",
            "MANAGER",
            "ACCOUNTING",
            "2450.0"
        ],
        [
            "1800",
            "MANAGER",
            "RESEARCH",
            "2975.0"
        ],
        [
            "1900",
            "SALESMAN",
            "SALES",
            "5600.0"
        ],
        [
            "1800",
            "ANALYST",
            "RESEARCH",
            "6000.0"
        ],
        [
            "1900",
            "MANAGER",
            "SALES",
            "2850.0"
        ],
        [
            "1800",
            "CLERK",
            "RESEARCH",
            "1900.0"
        ],
        [
            "1700",
            "CLERK",
            "ACCOUNTING",
            "1300.0"
        ]
    ],
    "storageCacheUsed": false,
    "totalScanBytes": 369,
    "totalScanCount": 9,
    "traceUrl": null
}

Kylin_JDBC查询代码

package org.myself.kylin.JDBC;
 
import java.sql.*;
 
public class TestKylinJDBC {
 
    public static void main(String[] args) throws Exception {
 
        //TODO:Kylin_JDBC 驱动
        String KYLIN_DRIVER = "org.apache.kylin.jdbc.Driver";
 
        //TODO:Kylin_URL
        String KYLIN_URL = "jdbc:kylin://kb-testhadoop01:7070/emp_project";
 
        //TODO:Kylin的用户名
        String KYLIN_USER = "ADMIN";
 
        //TODO:Kylin的密码
        String KYLIN_PASSWD = "KYLIN";
 
        //TODO:添加驱动信息
        Class.forName(KYLIN_DRIVER);
 
        //TODO:获取连接
        Connection connection = DriverManager.getConnection(KYLIN_URL, KYLIN_USER, KYLIN_PASSWD);
 
        //TODO:预编译SQL
        PreparedStatement ps = connection.prepareStatement("select d.loc,e.job,d.dname,sum(e.sal) from kylin_test_emp e join kylin_test_dept d on e.deptno = d.deptno group by d.dname,d.loc,e.job");
 
        //TODO:执行查询
        ResultSet resultSet = ps.executeQuery();
 
        //TODO:遍历打印
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1) + "\\t" + resultSet.getString(2) + "\\t" +resultSet.getString(3) + "\\t" +resultSet.getDouble(4));
        }
 
        //TODO:关闭连接
        connection.close();
    }
}

Kylin_JDBC查询结果:

在这里插入图片描述
到此关于Kylin基本介绍完毕。如果读者有兴趣可以私信笔者,或者阅读笔者之前的博文。

以上是关于Kylin实战—— REST API演示和Kylin_JDBC演示代码的主要内容,如果未能解决你的问题,请参考以下文章

Apache Kylin 精确去重和全局字典权威指南

顶级项目孵化的故事系列——Kylin的心路历程

使用Apache Kylin搭建企业级开源大数据分析平台

解决kylin查询报错:org.apache.kylin.rest.exception.InternalErrorException

Jmeter +Eclipse测试火币网REST API 实战案例(上)

大数据Kylin:Kylin构建Cube实战