QueryLogRecord
Description
The user submits a SQL query to analyze the data in the specified log set, and can only query the contents of one log set at a time. The from clause may not be included in the SQL statement. The relevant restrictions are as follows:
- The maximum number of concurrent queries supported by each account is 15
- Limit the size of the returned result set to 1MB or 1000 records.
The query syntax restrictions are as follows:
- Support input SQL (SQL92) query analysis statement, support limit to limit the number of query data.
- The supported SQL statement elements include: select, from, where, group by, having, order by, limit,
-
The query analysis syntax includes:
- Logical comparison: and, or, not, =, !=, <>, >, >=, <, <=, is null, like, in
- Arithmetic operations: +, -, *, /, %
- Date and time functions: now, current_timestamp, from_unixtime, unix_timestamp, str_to_date, year, month, day, weekday, dayofyear, dayofmonth, dayofweek
- String functions: reverse, length, lower, upper, capitalize, substr, substring, position, locate, concat
- Aggregate Function : count, sum, avg, max, min, first, last
For details of the function, please refer to SQL Syntax
Request
- Request syntax
GET /v1/logstore/{logStoreName}/logrecord HTTP/1.1
Host: <Endpoint>
Authorization: <Authorization String>
- Request header
Except for the public request header, there are no other special headers.
- Request parameter
Parameter name | Type | Required or not | Parameter position | Description |
---|---|---|---|---|
logStoreName | String | Yes | Path | Log set name |
logStreamName | String | No | Query | Log stream name |
sql | String | Yes | Query | SQL statement entered |
startDateTime | DateTime | Yes | Query | Start date and time, including start time |
endDateTime | DateTime | Yes | Query | End date and time, not including end time |
marker | String | No | Query | Used to mark the start position of the scan; if no marker is provided, return from the first in the time range |
limit | Int | No | Query | Limit the number of returned result records, and it means no limit if not transmitted |
Note: The date and time are all UTC time, in format ISO8601, for example: 2020-01-10T13:23:34Z.
Response
- Response header
Except for the public response header, there are no other special headers.
- Response parameter
Parameter name | Type | Required or not | Description |
---|---|---|---|
resultSet | Object | Yes | Return eligible result sets |
datasetScanInfo | Object | Yes | Scan the statistics of the original data set |
Among them, resultSet represents the result set obtained by this query, and its structure is defined as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
columns | List<string> | Yes | List of included field names |
rows | List<List<obj>> | Yes | Each row corresponds to the value of the column name in the columns |
isTruncated | Boolean | Yes | Whether the result set is truncated |
truncatedReason | String | No | The reason why the returned result set is truncated |
datasetScanInfo represents the statistical information of the scanned original data set, and its structure is defined as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
isTruncated | Boolean | Yes | Whether the data scan is truncated |
truncatedReason | String | No | The reason why the data scan was truncated |
nextMarker | String | No | Mark where the data scan is truncated |
marker | String | No | The marker in the pass through request is used to mark the starting position of this query |
statistics | Object | Yes | Some statistics of the data set scan |
statistics represents the statistics of the original data set scanned by this query:
Parameter name | Type | Required or not | Description |
---|---|---|---|
executionTimeInMs | Int | Yes | Time spent in this query, in milliseconds |
scanCount | Int | Yes | Number of data scanned in this query |
histogram | Object | Yes | Histogram of logs scanned by this query distributed by time |
histogram represents the histogram distribution information of the original data set scanned by this query:
Parameter name | Type | Required or not | Description |
---|---|---|---|
interval | Int | Yes | Size of a single interval in histogram statistics |
startTime | DateTime | Yes | The start time of histogram statistics is the startDateTime in the request, and the statistics include this time |
endTime | DateTime | Yes | The end time of histogram statistics is the endDateTime in the request, and the statistics does not include this time |
counts | List<Integer> | Yes | Number of scans in the histogram statistical interval |
Note: startTime/endTime follow the ISO8601 format standard, for example: 2019-12-01T00:00:00Z.
Example
- Request example
GET /v1/logstore/demo/logrecord?logStreamName=my-stream&marker=JpJYBIUoFqHA4wxXzeRGREbUVg&startDateTime=2019-09-01T22:00:00Z&endDateTime=2019-09-01T23:00:00Z&sql=select+count(*) HTTP/1.1
Host: bls-log.bj.baidubce.com
Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
- Response example
HTTP/1.1 200 OK
Date: Thu, 12 Jun 2014 09:26:46 GMT
Content-Type: application/json; charset=utf-8
X-Bce-Request-Id:47e0ef1a-9bf2-11e1-9279-0100e8cf109a
{
"resultSet": {
"columns": [
"count(*)"
],
"rows": [
[
7195
]
],
"isTruncated": false
},
"datasetScanInfo": {
"isTruncated": false,
"statistics": {
"executionTimeInMs": 1186,
"scanCount": 7195,
"histogram": {
"interval": 300000000000,
"counts": [
600,
600,
590,
600,
600,
600,
600,
600,
600,
600,
605,
600
],
"startTime": "2020-03-04T10:00:26Z",
"endTime": "2020-03-04T11:00:26Z"
}
}
}
}