var renderData = [
{
name: 'COUNT',
syntax: 'count(expr)',
description: 'Aggregate function is used to count the number of rows',
example: [
{
purpose: 'Total count of all logs :',
code: 'count(*)'
},
{
purpose: 'Counts the occurrences of a Client IP :',
code: 'count(client_ip)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return
You can use COUNT function by count(*), count(1) or count(field). But there are something difference:
- count(*) and count(1) will count all the rows in the table, including NULL values.
- count(field) will count all the rows in the specified field while excluding NULL values.
}
},
{
name: 'COUNT_DISTINCT',
syntax: 'count(distinct expr)',
description: 'Aggregate function is used to count only distinct(unique) rows in the specified field',
example: [
{
purpose: 'Counts the number of different Client IP :',
code: 'count(distinct client_ip)'
},
{
purpose: `Counts the number of different "Server IP" and "Server port" :`,
code: 'count(distinct server_ip, server_port)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return The COUNT DISTINCT function returns the number of unique values in the field or multiple fields.
System will uses an adaptive sampling algorithm to perform fast count distinct operations.
}
},
{
name: 'AVG',
syntax: 'avg(expr)',
description: 'Aggregate function is used to calculate the arithmetic mean in the specified field. EXPR must be Integer,Float or Decimal and returned value as Float.',
example: [
{
purpose: `Calculates the average(mean) "Byte sent (sent_bytes)" field:`,
code: 'avg(sent_bytes)'
},
{
purpose: `Calculates the average(mean) "Bytes" , rounded to 2 decimal points:`,
code: 'round(avg(sent_bytes+received_bytes),2)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return You can use ROUND(expr[,decimal_places]) or FLOOR(expr[,decimal_places]) function that rounds or
floors a value to a specified number of decimal places.
}
},
{
name: 'SUM',
syntax: 'sum(expr)',
description: 'Aggregate function is used to sum of the values of the specified field. EXPR must be Integer,Float or Decimal.',
example: [
{
purpose: `The sum of the "Byte sent (sent_bytes)" field:`,
code: 'sum(sent_bytes)'
},
{
purpose: `The sum of the "sent_bytes" and "received_bytes" fields , and rename as "Bytes ":`,
code: 'sum(sent_bytes+received_bytes) as Bytes'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return You can rename the field using the AS keyword.
}
},
{
name: 'MAX',
syntax: 'max(expr)',
description: 'Aggregate function is used to return the maximum value of the specified field.',
example: [
{
purpose: `Returns the maximum value of the "Byte sent (sent_bytes)" field:`,
code: 'max(sent_bytes)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return The MAX aggregate function can also be used with the DateTime data type, where it will sort the
DateTime values and return the last value from the sorted logs.
}
},
{
name: 'MIN',
syntax: 'min(expr)',
description: 'Aggregate function is used to return the minimum value of the specified field.',
example: [
{
purpose: `Returns the minimum value of the "Byte sent (sent_bytes)" field:`,
code: 'min(sent_bytes)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return The MIN aggregate function can also be used with the DateTime data type, where it will sort the
DateTime values and return the minimum value from the sorted logs.
}
},
{
name: 'TIME_FLOOR_WITH_FILL',
syntax: 'TIME_FLOOR_WITH_FILL(, [,])',
description: 'Rounds down a timestamp, returning it as a new timestamp,optionally from some reference fill, and fills time gaps and impute missing values.',
example: [
{
purpose: `Round the recv_time down to a 5 minutes increment and fill time gaps and impute zero value.`,
code: 'TIME_FLOOR_WITH_FILL(recv_time,\'PT5M\',\'zero\')'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return
The TIME_FLOOR_WITH_FILL function as Timeseries granularity is used for time-based grouping.
- timestamp_expr - Unix Timestamp field
- period - can be any ISO8601 period, like P3M (quarters) or PT12H (half-days)
-
fill - optionnal. Includes none, null, zero, previous, next value.
- none: empty string ""
- null:"NULL" expression
- zero:zero "0"
- previous:previous value
- next:next value
}
},
{
name: 'UNIX_TIMESTAMP',
syntax: `UNIX_TIMESTAMP(date)`,
description: `Returns a Unix timestamp the value of the argument as seconds since '1970-01-01 00:00:00' UTC.`,
example: [
{
purpose: `Specify a datetime string "2019-06-06 19:11:12", calculate the Unix timestamp:`,
code: 'UNIX_TIMESTAMP(\'2019-06-06 19:11:12\')'
},
{
purpose: `Specify a ISO8601 datetime string with time zone information "2019-10-12T14:20:50+08:00", calculate the Unix timestamp:`,
code: 'UNIX_TIMESTAMP(\'2019-10-12T14:20:50+08:00\')'
},
{
purpose: `Specify a ISO8601 datetime string with UTC+0 time zone information "2019-10-12T14:20:50Z", calculate the Unix timestamp:`,
code: 'UNIX_TIMESTAMP(\'2019-10-12T14:20:50Z\')'
},
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return
The date argument may be a DATE, DATETIME or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD,
or YYYYMMDDhhmmss format.
- Standard datetime string(UTC+0) : UNIX_TIMESTAMP('2019-06-06 19:11:12')
- ISO8601 datetime string:UNIX_TIMESTAMP('2019-10-12T14:20:50Z') or
UNIX_TIMESTAMP('2019-10-12T14:20:50+08:00')
- Date: UNIX_TIMESTAMP(DATE('2019-06-06 19:11:12'))
}
},
{
name: 'FROM_UNIXTIME',
syntax: `FROM_UNIXTIME(unix_timestamp)`,
description: `Returns a representation of unix_timestamp as a datetime or character string value. The value returned is expressed using the UTC+0 time zone.`,
example: [
{
purpose: `Specify a Unix Timestamp "1570881546", calculate the datetime string:`,
code: 'FROM_UNIXTIME(1570881546)'
},
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return The unix_timestamp is an internal timestamp value representing seconds since '1970-01-01 00:00:00'
UTC.
}
},
{
name: 'DATE_FORMAT',
syntax: 'DATE_FORMAT(date, format)',
description: `Formats the date value according to the format string.`,
example: [
{
purpose: `Specify a Unix Timestamp "1570881546", calculate the datetime string with format "%Y-%m-%d %H:%i:%s":`,
code: 'DATE_FORMAT(FROM_UNIXTIME(1570881546), \'%Y-%m-%d %H:%i:%s\')'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return
The DATE_FORMAT function accepts two parameters as given below :
- date – Specified date to be formatted.
-
format – Specified format. This list of formats used in this function are listed below:
- %Y - Year, numeric, four digits
- %y - Year, numeric (two digits)
- %M - Month name (January..December)
- %m - Month, numeric (00..12)
- %D - Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
- %d - Day of the month, numeric (00..31)
- %H - Hour (00..23)
- %h - Hour (01..12)
- %i - Minutes, numeric (00..59)
- %s - Seconds (00..59)
- %w - Day of the week (0=Sunday..6=Saturday)
}
},
{
name: 'CONVERT_TZ',
syntax: `CONVERT_TZ(dt, from_tz, to_tz)`,
description: `Converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.`,
example: [
{
purpose: `Specify a datetime string "2021-11-11 00:00:00", converted from GMT(Greenwich Mean Time) to Asia/Shanghai time zone:`,
code: 'CONVERT_TZ(\'2021-11-11 00:00:00\',\'GMT\',\'Asia/Shanghai\')'
},
{
purpose: `Specify a Unix timestamp "1636588800", converted from GMT(Greenwich Mean Time) to Asia/Shanghai time zone:`,
code: 'CONVERT_TZ(FROM_UNIXTIME(1636588800),\'GMT\',\'Asia/Shanghai\')'
},
{
purpose: `Specify a Unix timestamp "1636588800", converted from Europe/London to America/New_York time zone:`,
code: 'CONVERT_TZ(DATE_FORMAT(FROM_UNIXTIME(1636588800), \'%Y-%m-%d %H:%i:%s\'),\'Europe/London\',\'America/New_York\')'
},
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return
The CONVERT_TZ function accepts a three-parameter:
- dt - The given DateTime which we want to convert.
- from_tz - The time zone from which we want to convert DateTime.
- to_tz - The time zone in which we want to convert DateTime.
}
},
{
name: 'MEDIAN',
syntax: `MEDIAN()`,
description: `Aggregate function is used to calculate median value. expr must be Integer, Float or Decimal.`,
example: [
{
purpose: `Calculates the median "TCP Handshake Latency (tcp_handshake_latency_ms)" field:`,
code: 'MEDIAN(tcp_handshake_latency_ms)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return In Traffic logs analysis, the function can be useful in calculating the median of certain numbers,
e.g. median SSL Handshake Latency or TCP Handshake Latency.
}
},
{
name: 'QUANTILE',
syntax: `QUANTILE([, ])`,
description: `Aggregate function is used to calculate an approximate quantile of a numeric data sequence.`,
example: [
{
purpose: `Calculates the 90th percentile "TCP Handshake Latency (tcp_handshake_latency_ms)" field:`,
code: 'QUANTILE(tcp_handshake_latency_ms, 0.9)'
}
],
details () {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return
The QUANTILE function accepts a two-parameter:
- expr - The column values resulting in integer, Flot or Decimal.
- level - Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend
using a level value in the range of [0.01, 0.99]. Default value is 0.5. At level=0.5 the function calculates
MEDIAN.
}
},
]
function main () {
var functionTips = {}
renderData.forEach((item, index) => {
var data = item // 这是个闭包
functionTips[item.name] = {
name: item.name,
syntax: item.syntax,
type: 'Function',
description () {
return (
{data.name}
Syntax:{data.syntax}
Description:
{data.description}
Examples:
{item.example.map(v => {
return -
{v.purpose}
{v.code}
})}
Details:
{Object.prototype.toString.call(data.details) === '[object Function]' ?
:
{data.details}
}
)
}
}
})
return functionTips
}
export const functionList = renderData
var functionTips = main()
export default functionTips