2023-12-07 10:03:31 +08:00
var renderData = [
{
2023-12-13 17:05:16 +08:00
name : 'COUNT' ,
syntax : 'count(expr)' ,
description : 'Aggregate function is used to count the number of rows' ,
2023-12-07 10:03:31 +08:00
example : [
{
2023-12-13 17:05:16 +08:00
purpose : 'Total count of all logs :' ,
code : 'count(*)'
2023-12-07 10:03:31 +08:00
} ,
{
2023-12-13 17:05:16 +08:00
purpose : 'Counts the occurrences of a Client IP :' ,
code : 'count(client_ip)'
}
2023-12-07 10:03:31 +08:00
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div >
You can use COUNT function by count ( * ) , count ( 1 ) or count ( field ) . But there are something difference :
< ul >
< li > count ( * ) and count ( 1 ) will count all the rows in the table , including NULL values . < / l i >
< li > count ( field ) will count all the rows in the specified field while excluding NULL values . < / l i >
< / u l >
< / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'COUNT_DISTINCT' ,
syntax : 'count(distinct expr)' ,
description : 'Aggregate function is used to count only distinct(unique) rows in the specified field' ,
2023-12-07 10:03:31 +08:00
example : [
{
2023-12-13 17:05:16 +08:00
purpose : 'Counts the number of different Client IP :' ,
code : 'count(distinct client_ip)'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` Counts the number of different "Server IP" and "Server port" : ` ,
2023-12-13 17:05:16 +08:00
code : 'count(distinct server_ip, server_port)'
}
2023-12-07 10:03:31 +08:00
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div > 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 . < / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
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.' ,
2023-12-07 10:03:31 +08:00
example : [
{
purpose : ` Calculates the average(mean) "Byte sent (sent_bytes)" field: ` ,
2023-12-13 17:05:16 +08:00
code : 'avg(sent_bytes)'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` Calculates the average(mean) "Bytes" , rounded to 2 decimal points: ` ,
2023-12-13 17:05:16 +08:00
code : 'round(avg(sent_bytes+received_bytes),2)'
}
2023-12-07 10:03:31 +08:00
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return < div > 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 . < / d i v >
2023-12-07 10:03:31 +08:00
}
} ,
{
2023-12-13 17:05:16 +08:00
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.' ,
2023-12-07 10:03:31 +08:00
example : [
{
purpose : ` The sum of the "Byte sent (sent_bytes)" field: ` ,
2023-12-13 17:05:16 +08:00
code : 'sum(sent_bytes)'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` The sum of the "sent_bytes" and "received_bytes" fields , and rename as "Bytes ": ` ,
2023-12-13 17:05:16 +08:00
code : 'sum(sent_bytes+received_bytes) as Bytes'
}
2023-12-07 10:03:31 +08:00
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div > You can rename the field using the AS keyword . < / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'MAX' ,
syntax : 'max(expr)' ,
description : 'Aggregate function is used to return the maximum value of the specified field.' ,
2023-12-07 10:03:31 +08:00
example : [
{
purpose : ` Returns the maximum value of the "Byte sent (sent_bytes)" field: ` ,
2023-12-13 17:05:16 +08:00
code : 'max(sent_bytes)'
2023-12-07 10:03:31 +08:00
}
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return < div > The < b > MAX < / b > a g g r e g a t e f u n c t i o n c a n a l s o b e u s e d w i t h t h e D a t e T i m e d a t a t y p e , w h e r e i t w i l l s o r t t h e
DateTime values and return the last value from the sorted logs . < / d i v >
2023-12-07 10:03:31 +08:00
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'MIN' ,
syntax : 'min(expr)' ,
description : 'Aggregate function is used to return the minimum value of the specified field.' ,
2023-12-07 10:03:31 +08:00
example : [
{
purpose : ` Returns the minimum value of the "Byte sent (sent_bytes)" field: ` ,
2023-12-13 17:05:16 +08:00
code : 'min(sent_bytes)'
2023-12-07 10:03:31 +08:00
}
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return < div > 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 . < / d i v >
2023-12-07 10:03:31 +08:00
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'TIME_FLOOR_WITH_FILL' ,
syntax : 'TIME_FLOOR_WITH_FILL(<timestamp_expr>, <period>[,<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.' ,
2023-12-07 10:03:31 +08:00
example : [
{
purpose : ` Round the recv_time down to a 5 minutes increment and fill time gaps and impute zero value. ` ,
2023-12-13 17:05:16 +08:00
code : 'TIME_FLOOR_WITH_FILL(recv_time,\'PT5M\',\'zero\')'
2023-12-07 10:03:31 +08:00
}
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div >
< p > The TIME _FLOOR _WITH _FILL function as Timeseries granularity is used for time - based grouping . < / p >
< ul >
< li > timestamp _expr - Unix Timestamp field < / l i >
2023-12-13 17:05:16 +08:00
< li > period - can be any ISO8601 period , like P3M ( quarters ) or PT12H ( half - days ) < / l i >
2023-12-07 10:03:31 +08:00
< li >
< span > fill - optionnal . Includes none , null , zero , previous , next value . < / s p a n >
< ul class = "sub-url" >
< li > none : empty string "" < / l i >
< li > null : "NULL" expression < / l i >
< li > zero : zero "0" < / l i >
< li > previous : previous value < / l i >
< li > next : next value < / l i >
< / u l >
< / l i >
< / u l >
< / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'UNIX_TIMESTAMP' ,
2023-12-07 10:03:31 +08:00
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: ` ,
2023-12-13 17:05:16 +08:00
code : 'UNIX_TIMESTAMP(\'2019-06-06 19:11:12\')'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` Specify a ISO8601 datetime string with time zone information "2019-10-12T14:20:50+08:00", calculate the Unix timestamp: ` ,
2023-12-13 17:05:16 +08:00
code : 'UNIX_TIMESTAMP(\'2019-10-12T14:20:50+08:00\')'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` Specify a ISO8601 datetime string with UTC+0 time zone information "2019-10-12T14:20:50Z", calculate the Unix timestamp: ` ,
2023-12-13 17:05:16 +08:00
code : 'UNIX_TIMESTAMP(\'2019-10-12T14:20:50Z\')'
2023-12-07 10:03:31 +08:00
} ,
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div >
2023-12-13 17:05:16 +08:00
< p > The date argument may be a DATE , DATETIME or TIMESTAMP string , or a number in YYMMDD , YYMMDDhhmmss , YYYYMMDD ,
or YYYYMMDDhhmmss format . < / p >
2023-12-07 10:03:31 +08:00
< ul >
< li > Standard datetime string ( UTC + 0 ) : UNIX _TIMESTAMP ( '2019-06-06 19:11:12' ) < / l i >
2023-12-13 17:05:16 +08:00
< li > ISO8601 datetime string : UNIX _TIMESTAMP ( '2019-10-12T14:20:50Z' ) or
UNIX _TIMESTAMP ( '2019-10-12T14:20:50+08:00' )
< / l i >
< li > Date : UNIX _TIMESTAMP ( DATE ( '2019-06-06 19:11:12' ) ) < / l i >
2023-12-07 10:03:31 +08:00
< / u l >
< / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'FROM_UNIXTIME' ,
2023-12-07 10:03:31 +08:00
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: ` ,
2023-12-13 17:05:16 +08:00
code : 'FROM_UNIXTIME(1570881546)'
2023-12-07 10:03:31 +08:00
} ,
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return < div > The unix _timestamp is an internal timestamp value representing seconds since '1970-01-01 00:00:00'
UTC . < / d i v >
2023-12-07 10:03:31 +08:00
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'DATE_FORMAT' ,
syntax : 'DATE_FORMAT(date, format)' ,
2023-12-07 10:03:31 +08:00
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": ` ,
2023-12-13 17:05:16 +08:00
code : 'DATE_FORMAT(FROM_UNIXTIME(1570881546), \'%Y-%m-%d %H:%i:%s\')'
2023-12-07 10:03:31 +08:00
}
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div >
< p > The DATE _FORMAT function accepts two parameters as given below : < / p >
< ul >
< li > date – Specified date to be formatted . < / l i >
< li >
< span > format – Specified format . This list of formats used in this function are listed below : < / s p a n >
< ul class = "sub-url" >
< li > % Y - Year , numeric , four digits < / l i >
< li > % y - Year , numeric ( two digits ) < / l i >
< li > % M - Month name ( January . . December ) < / l i >
< li > % m - Month , numeric ( 00. . 12 ) < / l i >
< li > % D - Day of the month with English suffix ( 0 th , 1 st , 2 nd , 3 rd , … ) < / l i >
< li > % d - Day of the month , numeric ( 00. . 31 ) < / l i >
< li > % H - Hour ( 00. . 23 ) < / l i >
< li > % h - Hour ( 01. . 12 ) < / l i >
< li > % i - Minutes , numeric ( 00. . 59 ) < / l i >
< li > % s - Seconds ( 00. . 59 ) < / l i >
< li > % w - Day of the week ( 0 = Sunday . . 6 = Saturday ) < / l i >
< / u l >
< / l i >
< / u l >
< / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'CONVERT_TZ' ,
syntax : ` CONVERT_TZ(dt, from_tz, to_tz) ` ,
2023-12-07 10:03:31 +08:00
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: ` ,
2023-12-13 17:05:16 +08:00
code : 'CONVERT_TZ(\'2021-11-11 00:00:00\',\'GMT\',\'Asia/Shanghai\')'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` Specify a Unix timestamp "1636588800", converted from GMT(Greenwich Mean Time) to Asia/Shanghai time zone: ` ,
2023-12-13 17:05:16 +08:00
code : 'CONVERT_TZ(FROM_UNIXTIME(1636588800),\'GMT\',\'Asia/Shanghai\')'
2023-12-07 10:03:31 +08:00
} ,
{
purpose : ` Specify a Unix timestamp "1636588800", converted from Europe/London to America/New_York time zone: ` ,
2023-12-13 17:05:16 +08:00
code : 'CONVERT_TZ(DATE_FORMAT(FROM_UNIXTIME(1636588800), \'%Y-%m-%d %H:%i:%s\'),\'Europe/London\',\'America/New_York\')'
2023-12-07 10:03:31 +08:00
} ,
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div >
< p > The CONVERT _TZ function accepts a three - parameter : < / p >
< ul >
< li > dt - The given DateTime which we want to convert . < / l i >
< li > from _tz - The time zone from which we want to convert DateTime . < / l i >
< li > to _tz - The time zone in which we want to convert DateTime . < / l i >
< / u l >
< / d i v >
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'MEDIAN' ,
syntax : ` MEDIAN(<expr>) ` ,
2023-12-07 10:03:31 +08:00
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: ` ,
2023-12-13 17:05:16 +08:00
code : 'MEDIAN(tcp_handshake_latency_ms)'
2023-12-07 10:03:31 +08:00
}
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
return < div > 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 . < / d i v >
2023-12-07 10:03:31 +08:00
}
} ,
{
2023-12-13 17:05:16 +08:00
name : 'QUANTILE' ,
syntax : ` QUANTILE(<expr>[, <level>]) ` ,
2023-12-07 10:03:31 +08:00
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: ` ,
2023-12-13 17:05:16 +08:00
code : 'QUANTILE(tcp_handshake_latency_ms, 0.9)'
2023-12-07 10:03:31 +08:00
}
] ,
2023-12-13 17:05:16 +08:00
details ( ) {
// 支持jsx 嵌套写法,万一测试要关键字加重呢
2023-12-07 10:03:31 +08:00
return < div >
< p > The QUANTILE function accepts a two - parameter : < / p >
< ul >
< li > expr - The column values resulting in integer , Flot or Decimal . < / l i >
2023-12-13 17:05:16 +08:00
< li > 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 .
< / l i >
2023-12-07 10:03:31 +08:00
< / u l >
< / d i v >
}
} ,
2023-12-13 17:05:16 +08:00
]
2023-12-07 10:03:31 +08:00
2023-12-13 17:05:16 +08:00
function main ( ) {
2023-12-07 10:03:31 +08:00
var functionTips = { }
renderData . forEach ( ( item , index ) => {
2023-12-13 17:05:16 +08:00
var data = item // 这是个闭包
2023-12-07 10:03:31 +08:00
functionTips [ item . name ] = {
name : item . name ,
syntax : item . syntax ,
2023-12-13 17:05:16 +08:00
type : 'Function' ,
description ( ) {
return ( < div className = "function-tips" >
2023-12-07 10:03:31 +08:00
< h2 > { data . name } < / h 2 >
< h3 > Syntax : < span > { data . syntax } < / s p a n > < / h 3 >
< h3 > Description : < / h 3 >
< p > { data . description } < / p >
< h3 > Examples : < / h 3 >
< ul >
{ item . example . map ( v => {
return < li >
< span > { v . purpose } < / s p a n >
< code > { v . code } < / c o d e >
< / l i >
} ) }
< / u l >
< h3 > Details : < / h 3 >
{ Object . prototype . toString . call ( data . details ) === '[object Function]' ?
< renderer renderFun = { data . details } > < / r e n d e r e r > : < p > { d a t a . d e t a i l s } < / p > }
< / d i v > )
}
2023-12-13 17:05:16 +08:00
}
2023-12-07 10:03:31 +08:00
} )
return functionTips
}
2023-12-13 17:05:16 +08:00
export const functionList = renderData
var functionTips = main ( )
2023-12-07 10:03:31 +08:00
export default functionTips