HA3 SQL supports four result formats: string, json, full_json, and flatbuffers. Learn how to configure and parse each format.
Return formats for query results
Query results can be returned in four formats: string, json, full_json, and flatbuffers. You can configure the format in one of the following ways:
-
Set the format in the configuration file. This setting applies globally after HA3 SQL starts. By default, all queries return results in this format.
-
Specify the format in the `kvpair` clause of a query. This setting applies only to the current query and overrides the format specified in the configuration file.
Set the return format in the kvpair clause
In the kvpair field of a query, you can use formatType:json or formatType:string to control the return format. For more information, see kvpair clause.
query=...&&kvpair=...;formatType:{json | string | full_json | flatbuffers};...
Parse string format results
The string format includes layout formatting for readability, making it suitable for development and debugging.
/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 }
Parse JSON format results
The json format is designed for programmatic parsing and contains richer information than the string format. The following sections describe the response fields.
/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 information.
"{\"Error\": ERROR_NONE}",
"format_type":
"json",
"row_count": // Number of results.
10,
"search_info": // Information related to the search, including metrics for operators such as scan and 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": // Results, returned as a 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": // Time consumed, in seconds.
0.024,
"trace": // Trace information.
[
]
}
Parse full_json format results
The `full_json` format is similar to the `json` format. The only difference is the `sql_result` field. In `json` format, this field is a string. In `full_json` format, this field is a JSON object.
{
"total_time": 34.003,
"covered_percent": 1,
"row_count": 10 ,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [
[
232953260,
"Dicos"
],
[
239745260,
"Ye's Brothers"
],
[
240084010,
"Cai Lao Bao"
],
[
240082260,
"Zhou Hei Ya"
],
[
240086260,
"Jue Wei Ya Bo"
],
[
240108260,
""
],
[
239256390,
"Everyday Life Supermarket"
],
[
240079390,
"Meiyijia"
],
[
265230260,
""
],
[
239313011,
"Da Shen Lin"
]
],
"column_name": [
"store_id",
"brand_name"
],
"column_type": [
"int64",
"multi_char"
]
},
"error_info": {
"ErrorCode": 0,
"Error": "ERROR_NONE",
"Message": ""
}
}
sql_result details
{
"column_name":[ // Column names
"nid",
"price",
"brand",
"size"
],
"column_type":[ // Column types
"uint64",
"double",
"multi_char",
"double"
],
"data":[ // Data for each row
[
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 details
The searchInfo field provides detailed metrics on the query process, useful for troubleshooting and performance tuning. To include it, add searchInfo:true to the kvpair clause.
"search_info": {
"exchangeInfos": [
{
"fillResultUseTime": 1276, // Time for the exchange kernel to get results from the response structure, in μs.
"hashKey": 413114****,
"kernelName": "ExchangeKernel", // Exchange kernel name.
"nodeName": "1", // Name of the node that hosts the exchange kernel.
"poolSize": 472, // Pool size used by the exchange kernel's worker for this query.
"rowCount": 2, // Number of valid rows after merging results from all columns.
"searcherUseTime": 7335, // Wait time to initiate the search request, in μs.
"totalAccessCount": 4 // Total number of columns for which search requests were initiated.
}
],
"rpcInfos": [ // Details of initiated RPC requests. The number of elements equals the number of columns that returned results.
{
"beginTime": 1588131436272843, // Start time of the exchange kernel call, in μs.
"rpcNodeInfos": [
{
"callUseTime": 5431, // Time consumed by this RPC node, in μs.
"isReturned": true, // Indicates whether a response was returned.
"netLatency": 664, // Network latency, in μs.
"rpcBegin": 1588131436272857, // Start timestamp of the RPC call, in μs.
"rpcEnd": 1588131436278288, // End timestamp of the RPC call, in μs.
"rpcUseTime": 5175, // Duration of the RPC call, in μs.
"specStr": "11.1.XX.XX:20412" // IP address and port of the server that was called.
},
...
],
"totalRpcCount": 4, // Number of RPC requests sent.
"useTime": 7335 // Total duration of RPC calls.
}
],
"runSqlTimeInfo": {
"sqlPlan2GraphTime": 174, // Time to convert the iquan plan to a navi graph, in μs.
"sqlPlanStartTime": 1588143112640920, // Timestamp of the plan request sent to iquan, in μs.
"sqlPlanTime": 10295, // Total time from sending the request to iquan to receiving the plan, in μs.
"sqlRunGraphTime": 13407 // Total time to execute the SQL graph, in μs.
},
"scanInfos": [
{
"hashKey": 691673167,
"kernelName": "ScanKernel", // Kernel name.
"parallelNum": 2, // Global degree of parallelism for the scan.
"parallelIndex": 1, // Index of this scan kernel in the parallel logic. Not displayed if the value is 0.
"tableName": "store", // Table name.
"totalComputeTimes": 4, // Total number of times batchScan was called.
"totalEvaluateTime": 9, // Total time for field evaluation, in μs.
"totalInitTime": 3758, // Total time for the init phase, in μs.
"totalOutputCount": 2, // Total number of output rows.
"totalOutputTime": 264, // Total time to build output data, including adding and deleting data in the table, in μs.
"totalScanCount": 2, // Total number of records found by the scan.
"totalSeekTime": 2, // Total time for seek calls, in μs.
"totalUseTime": 4217 // Total duration of the scan kernel call, in μs.
}
]
}
Flatbuffers format
The flatbuffers format uses FlatBuffers for efficient serialization, making it ideal for high-performance scenarios. Clients must deserialize the returned results before use.
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-based 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]; }
Note
`column_type`: The `multi_` prefix indicates a multi-value type, which is a list. For example, `multi_char` is a list of strings.