kylin rest api 发送curl创建、build query查询
程序员文章站
2022-07-14 21:47:16
...
kylin rest
1、创建cube和buildcube
1.create cube
curl -X POST -H "Authorization: Basic QURNSU46S1lMSU4=" -H "Content-Type: application/json" -d '{"cubeDescData": "{\"uuid\": \"3273a7b1-b338-4523-a9f0-092a1993a5d4\",\"last_modified\": 0,\"version\": \"2.4.0.20500\",\"name\": \"cube_user_basic_test\",\"is_draft\": false,\"model_name\": \"model_user_basic\",\"description\": \"\",\"null_string\": null,\"dimensions\": [{\"name\": \"DATE_DT\",\"table\": \"DM_ORDER_BASIC\",\"column\": \"DATE_DT\",\"derived\": null}],\"measures\": [{\"name\": \"_COUNT_\",\"function\": {\"expression\": \"COUNT\",\"parameter\": {\"type\": \"constant\",\"value\": \"1\"},\"returntype\": \"bigint\"}},{\"name\": \"SUM_AMOUNT\",\"function\": {\"expression\": \"SUM\",\"parameter\": {\"type\": \"column\",\"value\": \"DM_ORDER_BASIC.NO_AMOUNT_30_CNT\"},\"returntype\": \"double\"}},{\"name\": \"SUM_AMOUNT_60\",\"function\": {\"expression\": \"SUM\",\"parameter\": {\"type\": \"column\",\"value\": \"DM_ORDER_BASIC.NO_AMOUNT_60_CNT\"},\"returntype\": \"double\"}}],\"dictionaries\": [],\"rowkey\": {\"rowkey_columns\": [{\"column\": \"DM_ORDER_BASIC.DATE_DT\",\"encoding\": \"dict\",\"encoding_version\": 1,\"isShardBy\": false}]},\"hbase_mapping\": {\"column_family\": [{\"name\": \"F1\",\"columns\": [{\"qualifier\": \"M\",\"measure_refs\": [\"_COUNT_\",\"SUM_AMOUNT\",\"SUM_AMOUNT_60\"]}]}]},\"aggregation_groups\": [{\"includes\": [\"DM_ORDER_BASIC.DATE_DT\"],\"select_rule\": {\"hierarchy_dims\": [],\"mandatory_dims\": [],\"joint_dims\": []}}],\"signature\": \"YEsNRXBlv0ZSyToPui5CUg==\",\"notify_list\": [],\"status_need_notify\": [\"ERROR\",\"DISCARDED\",\"SUCCEED\"],\"partition_date_start\": 0,\"partition_date_end\": 3153600000000,\"auto_merge_time_ranges\": [604800000,2419200000],\"volatile_range\": 0,\"retention_range\": 0,\"engine_type\": 2,\"storage_type\": 2,\"override_kylin_properties\": {},\"cuboid_black_list\": [],\"parent_forward\": 3,\"mandatory_dimension_set_list\": [],\"snapshot_table_desc_list\": []}","cubeName": "cube_user_basic_test","project": "bap_dm"}' http://master:7070/kylin/api/cubes
2.build cube
curl -X PUT -H "Authorization: Basic QURNSU46S1lMSU4=" -H 'Content-Type: application/json' -d '{"startTime":'1576512000000', "endTime":'1576598400000', "buildType":"BUILD"}' http://master:7070/kylin/api/cubes/cube_user_basic_test/build
2、发送查询
curl -X POST --user ADMIN:KYLIN -H "Content-Type: application/json" -d '{
"sql":"select part_dt, sum(price) as total_sold, count(distinct seller_id) as sellers from kylin_sales group by part_dt order by part_dt",
"project":"learn_kylin" }' http://192.168.49.100:7070/kylin/api/query
kylin 使用java的方式查询
1.创建一个maven项目 加入依赖
<dependencies>
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-jdbc</artifactId> <version>2.5.1</version>
</dependency>
</dependencies>
version 根据你的版本而定
2、简单的demo
public class TestDemo {
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://192.168.49.100:7070/learn_kylin";
//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 part_dt,
sum(price) as total_sold, count(distinct seller_id) as sellers from kylin_sales group by part_dt order by part_dt");
//执行查询
ResultSet resultSet = ps.executeQuery();
//遍历打印
while (resultSet.next()) {
System.out.println(resultSet.getInt(1));
}
}
}
使用脚本定期执行
#!/bin/bash
################
#kylin的自动运行
##############
kylinMinusTime=$((8 * 60 * 60 * 1000))
onedayTime=$((24 * 60 * 60 * 1000))
yesterday=`date -d yesterday +%Y-%m-%d`
TimeStamp=`date -d "$yesterday 00:00:00" +%s`
startTime=$(($TimeStamp + $kylinMinusTime))
endTime=$(($startTime + $onedayTime))
cubeName=DM_ORDER_BASIC
curl -X PUT --user ADMIN:KYLIN -H "Content-Type: application/json" -d '{"startTime":'$(( $startTime * 1000 ))', "endTime":'$(( $endTime * 1000 ))', "buildType":"BUILD"}' http://192.168.28.100:7070/kylin/api/cubes/{$cubeName}/build
上一篇: zeppelin配置hive解释器
下一篇: 三言两语谈团队合作