使用jdbc的方式访问kylin cube的数据
- 引用kylin相关的jar包
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-jdbc</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-job</artifactId>
<version>1.3.0</version>
</dependency>
- kylin的Connection URL:
url格式:jdbc:kylin://<hostname>:<port>/<kylin_project_name>
地址示例
jdbc:kylin://10.214.234.111:7070/Test_kylin
- kylin 查询sql示例:
select year_id,month_id,count(1) as cnt
,sum(seats_num) as seats_num
,sum(gov_sale_seat) as gov_sale_seat
,sum(gov_revenue) as gov_revenue
,sum(service_revenue) as service_revenue
,sum(turn_over_revenue) as turn_over_revenue
,sum(round_number) as round_number
from REPORT_GOV_HALL_MOVIE_BOX_FILM_CINEMA group by year_id,month_id
- 使用jdbc 查询kylin的的数据示例
Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
Properties info = new Properties();
info.put("user", "BI");
info.put("password", "16de#+ui9");
Connection conn = driver.connect("jdbc:kylin://10.214.234.111:7070/Test_kylin", info);
Statement state = conn.createStatement();
String sqlStr = "select year_id,month_id,count(1) as cnt\n" +
",sum(seats_num) as seats_num\n" +
",sum(gov_sale_seat) as gov_sale_seat\n" +
",sum(gov_revenue) as gov_revenue\n" +
",sum(service_revenue) as service_revenue\n" +
",sum(turn_over_revenue) as turn_over_revenue\n" +
",sum(round_number) as round_number\n" +
"from REPORT_GOV_HALL_MOVIE_BOX_FILM_CINEMA group by year_id,month_id";
ResultSet resultSet = state.executeQuery(sqlStr);
while (resultSet.next()) {
System.out.println(resultSet.getString(1) + "\t" + resultSet.getString(2) + "\t" + resultSet.getString(3));
}
使用jdbc访问kylin的资料可以访问官网文档:http://kylin.apache.org/docs20/howto/howto_jdbc.html