查詢結果的返回形式
目前支援返回格式有四種: string 、 json 、full_json、flatbuffers,可以通過以下幾種途徑配置:
在設定檔設定:HA3 SQL啟動後全域生效,所有query預設以設定的形式返回查詢結果。
在query的kvpair子句中指定:僅對當前query生效,當前query以設定的形式返回查詢結果(無視設定檔中的設定的形式)。
在query的kvpair中設定傳回值形式
在query的 kvpair 欄位中,通過 formatType:json 或者 formatType:string 來控制查詢結果的返回形式。更多的 kvpair 用法見kvpair子句。
query=...&&kvpair=...;formatType:{json | string | full_json | flatbuffers};...string形式結果解析
string形式的返回結果內建排版格式,結果直觀,可讀性較好。一般用於開發調試,方便使用者排查問題。
/ha3_develop/source_code/ha3_manual_example/sql $ ./search.sh -s "select nid, price, brand, size from phone"
+ python2.7 /ha3_develop/install_root/usr/local/lib/python/site-packages/ha_tools/search.py -a http://localhost:39341/ -s 'select nid, price, brand, size from phone'
USE_TIME: 0.025, ROW_COUNT: 10
------------------------------- TABLE INFO ---------------------------
nid | price | brand | size |
1 | 3599 | Huawei | 5.9 |
2 | 4388 | Huawei | 5.5 |
3 | 899 | Xiaomi | 5 |
4 | 2999 | OPPO | 5.5 |
5 | 1299 | Meizu | 5.5 |
6 | 169 | Nokia | 1.4 |
7 | 3599 | Apple | 4.7 |
8 | 5998 | Apple | 5.5 |
9 | 4298 | Apple | 4.7 |
10 | 5688 | Samsung | 5.6 |
------------------------------- TRACE INFO ---------------------------
------------------------------- SEARCH INFO ---------------------------
scanInfos { kernelName: "ScanKernel" nodeName: "0_0" tableName: "phone" hashKey: 243934**** parallelNum: 1 totalOutputCount: 10 totalScanCount: 10 totalUseTime: 86 totalSeekTime: 29 totalEvaluateTime: 13 totalOu\
tputTime: 43 totalComputeTimes: 1 }JSON形式結果解析
JSON形式的結果主要用於服務調用,方便程式解析,含有的資訊量也更大,下面主要介紹一下各個返回欄位的含義。
/ha3_develop/source_code/ha3_manual_example/sql $ ./search.sh -s "select nid, price, brand, size from phone&&kvpair=formatType:json"
+ python2.7 /ha3_develop/install_root/usr/local/lib/python/site-packages/ha_tools/search.py -a http://localhost:39341/ -s 'select nid, price, brand, size from phone&&kvpair=formatType:json'
{
"error_info": // 輸出error資訊
"{\"Error\": ERROR_NONE}",
"format_type":
"json",
"row_count": // 結果數
10,
"search_info": // search 相關的一些資訊,包括scan,sort等運算元指標
"scanInfos { kernelName: \"ScanKernel\" nodeName: \"0_0\" tableName: \"phone\" hashKey: 243934**** parallelNum: 1 totalOutputCount: 10 totalScanCount: 10 totalUseTime: 81 totalSeekTime: 28 totalEvaluateTime: 1\
1 totalOutputTime: 40 totalComputeTimes: 1 }",
"sql_result": // 結果,返回json string,
"{\"column_name\":[\"nid\",\"price\",\"brand\",\"size\"],\"column_type\":[\"uint64\",\"double\",\"multi_char\",\"double\"],\"data\":[[1,3599,\"Huawei\",5.9],[2,4388,\"Huawei\",5.5],[3,899,\"Xiaomi\",5],[4,2999\
,\"OPPO\",5.5],[5,1299,\"Meizu\",5.5],[6,169,\"Nokia\",1.4],[7,3599,\"Apple\",4.7],[8,5998,\"Apple\",5.5],[9,4298,\"Apple\",4.7],[10,5688,\"Samsung\",5.6]]}",
"total_time": // 耗時,單位s
0.024,
"trace": // trace資訊
[
]
}FULL_JSON形式結果解析
full_json形式的結構與JSON形式比較相似,唯一的不同在於sql_result欄位,JSON形式下是字串形式,full_json下是直接用JSON表示的形式。
{
"total_time": 34.003,
"covered_percent": 1,
"row_count": 10 ,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [
[
232953260,
"德克士"
],
[
239745260,
"葉氏兄弟"
],
[
240084010,
"菜老包"
],
[
240082260,
"周黑鴨"
],
[
240086260,
"絕味鴨脖"
],
[
240108260,
""
],
[
239256390,
"每一天生活超市"
],
[
240079390,
"美宜佳"
],
[
265230260,
""
],
[
239313011,
"大參林"
]
],
"column_name": [
"store_id",
"brand_name"
],
"column_type": [
"int64",
"multi_char"
]
},
"error_info": {
"ErrorCode": 0,
"Error": "ERROR_NONE",
"Message": ""
}
}sql_result詳解
{
"column_name":[ // 列名
"nid",
"price",
"brand",
"size"
],
"column_type":[ // 列類型
"uint64",
"double",
"multi_char",
"double"
],
"data":[ // 每行資料
[
1,
3599,
"Huawei",
5.9
],
[
2,
4388,
"Huawei",
5.5
],
[
3,
899,
"Xiaomi",
5
],
[
4,
2999,
"OPPO",
5.5
],
[
5,
1299,
"Meizu",
5.5
],
[
6,
169,
"Nokia",
1.4
],
[
7,
3599,
"Apple",
4.7
],
[
8,
5998,
"Apple",
5.5
],
[
9,
4298,
"Apple",
4.7
],
[
10,
5688,
"Samsung",
5.6
]
]
}searchInfo詳解
在返回結果中,searchInfo是一個較為複雜的欄位,可以協助使用者分析查詢過程,以排查問題、最佳化效能需在kvpairs中加searchInfo:true。
"search_info": {
"exchangeInfos": [
{
"fillResultUseTime": 1276, // exchange kernel從response結構中擷取結果耗時
"hashKey": 413114****,
"kernelName": "ExchangeKernel", // exchange kernel名稱
"nodeName": "1", // exchange kernel所屬節點名稱
"poolSize": 472, // exchange kernel所屬worker在本次查詢使用的pool大小
"rowCount": 2, // 所有列返回合并後的有效結果行數
"searcherUseTime": 7335, // 發起search請求的等待耗時,單位為us
"totalAccessCount": 4 // 發起search請求的總列數
}
],
"rpcInfos": [ // 發起的rpc請求詳情,該項有多少列返回就有多少元素
{
"beginTime": 1588131436272843, // exchange kernel調用起始時間,單位為us
"rpcNodeInfos": [
{
"callUseTime": 5431, // 該rpc node耗時,單位為us
"isReturned": true, // 請求是否有返回
"netLatency": 664, // 網路延時,單位為us
"rpcBegin": 1588131436272857, // rpc調用開始時間戳,單位為us
"rpcEnd": 1588131436278288, // rpc調用結束時間戳記,單位為us
"rpcUseTime": 5175, // rpc調用期間,單位為us
"specStr": "11.1.XX.XX:20412" // 調用server的ip和連接埠
},
...
],
"totalRpcCount": 4, // 發出的rpc請求數
"useTime": 7335 // rpc調用總時間長度
}
],
"runSqlTimeInfo": {
"sqlPlan2GraphTime": 174, // iquan plan轉navi graph的耗時,單位為us
"sqlPlanStartTime": 1588143112640920, // 向iquan發起plan的請求時間戳記,單位為us
"sqlPlanTime": 10295, // 向iquan發起請求到擷取plan的總時間長度,單位為us
"sqlRunGraphTime": 13407 // 執行sql圖的總時間長度,單位為us
},
"scanInfos": [
{
"hashKey": 691673167,
"kernelName": "ScanKernel", // kernel名稱
"parallelNum": 2, // scan並行度,全域有多少個
"parallelIndex": 1, // 該scan kernel屬於並行邏輯下的第幾個,為0預設不顯示
"tableName": "store", // table名稱
"totalComputeTimes": 4, // batchScan被調用的總次數
"totalEvaluateTime": 9, // 欄位求值總耗時,單位為us
"totalInitTime": 3758, // init階段總耗時,單位為us
"totalOutputCount": 2, // 輸出的總行數
"totalOutputTime": 264, // 構建輸出資料的總耗時,包括增刪表中資料,單位為us
"totalScanCount": 2, // scan出的記錄總數
"totalSeekTime": 2, // seek調用的總耗時,單位為us
"totalUseTime": 4217 // scan kernel調用的總時間長度,單位為us
}
]
}Flatbuffers形式
flatbuffers形式是基於flatbuffers實現的高效序列化結果,在對效能有高要求的情境下比較實用,該形式的返回結果需要對應的用戶端還原序列化解析。
SqlResult.fbs:
include "TwoDimTable.fbs";
namespace isearch.fbs;
table SqlErrorResult {
partitionId: string (id:0);
hostName: string (id:1);
errorCode: uint (id:2);
errorDescription: string (id:3);
}
table SqlResult {
processTime: double (id:0);
rowCount: uint32 (id:1);
errorResult: SqlErrorResult (id:2);
sqlTable: TwoDimTable (id:3);
searchInfo: string (id:4);
coveredPercent: double (id:5);
}
root_type SqlResult;TwoDimTable.fbs:
include "TsdbColumn.fbs";
namespace isearch.fbs;
// multi value
table MultiInt8 { value: [byte]; }
table MultiInt16 { value: [short]; }
table MultiInt32 { value: [int]; }
table MultiInt64 { value: [long]; }
table MultiUInt8 { value: [ubyte]; }
table MultiUInt16 { value: [ushort]; }
table MultiUInt32 { value: [uint]; }
table MultiUInt64 { value: [ulong]; }
table MultiFloat { value: [float]; }
table MultiDouble { value: [double]; }
table MultiString { value: [string]; }
// column base storage
table Int8Column { value: [byte]; }
table Int16Column { value: [short]; }
table Int32Column { value: [int]; }
table Int64Column { value: [long]; }
table UInt8Column { value: [ubyte]; }
table UInt16Column { value: [ushort]; }
table UInt32Column { value: [uint]; }
table UInt64Column { value: [ulong]; }
table FloatColumn { value: [float]; }
table DoubleColumn { value: [double]; }
table StringColumn { value: [string]; }
table MultiInt8Column { value: [MultiInt8]; }
table MultiUInt8Column { value: [MultiUInt8]; }
table MultiInt16Column { value: [MultiInt16]; }
table MultiUInt16Column { value: [MultiUInt16]; }
table MultiInt32Column { value: [MultiInt32]; }
table MultiUInt32Column { value: [MultiUInt32]; }
table MultiInt64Column { value: [MultiInt64]; }
table MultiUInt64Column { value: [MultiUInt64]; }
table MultiFloatColumn { value: [MultiFloat]; }
table MultiDoubleColumn { value: [MultiDouble]; }
table MultiStringColumn { value: [MultiString]; }
// column type
union ColumnType {
Int8Column,
Int16Column,
Int32Column,
Int64Column,
UInt8Column,
UInt16Column,
UInt32Column,
UInt64Column,
FloatColumn,
DoubleColumn,
StringColumn,
MultiInt8Column,
MultiInt16Column,
MultiInt32Column,
MultiInt64Column,
MultiUInt8Column,
MultiUInt16Column,
MultiUInt32Column,
MultiUInt64Column,
MultiFloatColumn,
MultiDoubleColumn,
MultiStringColumn,
TsdbDpsColumn,
}
table Column {
name: string;
value: ColumnType;
}
table TwoDimTable {
rowCount: uint (id:0);
columns: [Column] (id:1);
}TsdbColumn.fbs:
namespace isearch.fbs;
struct TsdbDataPoint {
ts: int64 (id:0);
value: double (id:1);
}
table TsdbDataPointSeries { points: [TsdbDataPoint]; }
table TsdbDpsColumn { value : [TsdbDataPointSeries]; }注意
column_type:multi_首碼為多實值型別,結構為list,multi_char 為string類型。