kylin3.0提供了 restful api
query接口
Request Sample
{
"sql":"select * from TEST_KYLIN_FACT",
"offset":0,
"limit":50000,
"acceptPartial":false,
"project":"DEFAULT"
}
Curl Example
curl -X POST -H "Authorization: Basic XXXXXXXXX" -H "Content-Type: application/json" -d '{ "sql":"select count(*) from TEST_KYLIN_FACT", "project":"learn_kylin" }' http://localhost:7070/kylin/api/query
Response Body
columnMetas - Column metadata information of result set.
results - Data set of result.
cube - Cube used for this query.
affectedRowCount - Count of affected row by this sql statement.
isException - Whether this response is an exception.
ExceptionMessage - Message content of the exception.
Duration - Time cost of this query
Partial - Whether the response is a partial result or not. Decided by acceptPartial of request.
Response Sample
{
"columnMetas":[
{
"isNullable":1,
"displaySize":0,
"label":"CAL_DT",
"name":"CAL_DT",
"schemaName":null,
"catelogName":null,
"tableName":null,
"precision":0,
"scale":0,
"columnType":91,
"columnTypeName":"DATE",
"readOnly":true,
"writable":false,
"caseSensitive":true,
"searchable":false,
"currency":false,
"signed":true,
"autoIncrement":false,
"definitelyWritable":false
},
{
"isNullable":1,
"displaySize":10,
"label":"LEAF_CATEG_ID",
"name":"LEAF_CATEG_ID",
"schemaName":null,
"catelogName":null,
"tableName":null,
"precision":10,
"scale":0,
"columnType":4,
"columnTypeName":"INTEGER",
"readOnly":true,
"writable":false,
"caseSensitive":true,
"searchable":false,
"currency":false,
"signed":true,
"autoIncrement":false,
"definitelyWritable":false
}
],
"results":[
[
"2013-08-07",
"32996",
"15",
"15",
"Auction",
"10000000",
"49.048952730908745",
"49.048952730908745",
"49.048952730908745",
"1"
],
[
"2013-08-07",
"43398",
"0",
"14",
"ABIN",
"10000633",
"85.78317064220418",
"85.78317064220418",
"85.78317064220418",
"1"
]
],
"cube":"test_kylin_cube_with_slr_desc",
"affectedRowCount":0,
"isException":false,
"exceptionMessage":null,
"duration":3451,
"partial":false
}
众所周知,这个返回接口返回给开发是非常不友好的,基于业务需求改造成标准的返回接口
原来的
@RequestMapping(value = "/query", method = RequestMethod.POST, produces = {"application/json"})
@ResponseBody
public SQLResponse query(@RequestBody PrepareSqlRequest sqlRequest) {
return queryService.doQueryWithCache(sqlRequest);
}
改造后:
public SQLResponse query2(@RequestBody PrepareSqlRequest sqlRequest) {
return queryService2.doQueryWithCache(sqlRequest);
List<Map> mapList = new ArrayList<Map>();
SQLResponse response = queryService.doQueryWithCache(sqlRequest);
List<List<String>> results = response.getResults();
if (results != null && results.size() > 0) {
List<SelectedColumnMeta> columnMetas = response.getColumnMetas();
Map<String, Object> map;
int size;
for (List<String> result : results) {
map = new HashMap<>();
size = result.size();
for (int i = 0; i < size; i++) {
map.put(columnMetas.get(i).getLabel(), result.get(i));
}
mapList.add(map);
}
}
return new SQLResponse(mapList, response.getCube(), response.getAffectedRowCount(), response.getIsException(),
response.getExceptionMessage(), response.isPartial(), response.isPushDown(), response.getDuration(),
response.getTotalScanCount(), response.getTotalScanBytes(), response.isStorageCacheUsed());
}
1650771882532.jpg![1650771882532.jpg](https://ucc.alicdn.com/pic/developer-ecology/42eec56238d94065a5f22f4dcfd3cbb7.jpg)
改造后返回参数
{
"results": [
{
"repay_date": "2021-11-12",
"repaid_amt": "61",
"cert_code": null,
"bill_no": "ZZD",
"adv_repay_fee": "0",
"fund_flag": "2",
"repay_status": "0
},
{
"repay_date": "2021-05-05",
"repaid_amt": "29.7",
"cert_code": null,
"bill_no": "xxxxxxx",
"adv_repay_fee": "0",
"fund_flag": "2",
"repay_status": "0"
}
],
"isException": false,
"exceptionMessage": null,
"duration": 244,
"total": 22
}