### SLICE Function for Array Subsets Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The SLICE function extracts a subset of an array. It takes the array, a start index (positive for head, negative for tail), and the number of elements. ```SQL SELECT SLICE(array[99,87,16,43,25],2,3) ``` -------------------------------- ### YOW: Get ISO Calendar Year of Week Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The YOW function returns the year of the week according to the ISO calendar. It is equivalent to the YEAR_OF_WEEK function. The input KEY can be a field or an expression of Timestamp or Date type, and the output is a Bigint representing the ISO year. ```SQL SELECT CURRENT_TIMESTAMP, YOW(CURRENT_TIMESTAMP) ``` -------------------------------- ### TLS检索分析语句结构示例 Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb TLS语句由检索条件和SQL分析语句组成,两者通过竖线(|)分隔。检索条件用于筛选数据,SQL分析语句用于分析和计算。当不需要分析时,SQL分析语句可省略。 ```tls <检索条件> | ``` -------------------------------- ### Python: Stream Completion API Response Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb This Python script demonstrates how to interact with a completion API. It sends a POST request with a specified payload, including a model, prompt, and various parameters. The script streams the response, prints headers like 'Target Pod' and 'Request ID', and calculates Time To First Token (TTFT) and total response time. ```Python import httpx import time import json ENDPOINT = "14.103.150.251:80" API_KEY = "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" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json", "routing-strategy": "prefix-cache", } prompt = "* | SELECT COUNT(*) AS slacount FROM (SELECT account_id AS `主账号 id`, event_time AS `上报时间`, sli_time AS `sla 时间`, sli_key AS `sla 指标`, unique_key AS `接口名` FROM (SELECT account_id, MIN(report_type) = -1 AS fail, DATE_FORMAT(MAX(event_time) * 1000, 'Y-MM-dd H:mm:ss' ) AS event_time, DATE_FORMAT(sli_time * 1000, 'Y-MM-dd H:mm:ss' ) AS sli_time, sli_key, unique_key FROM (SELECT account_id, MAX(event_time) AS event_time, sli_time, sli_key, unique_key, MAX(report_type) AS report_type WHERE sli_key = 'addTask_success_rate' AND report_type <> 0 AND (account_id = 2000001066 OR account_id = 2100420468 OR account_id <> 2100428166) GROUP BY account_id, sli_key, sli_time, unique_key HAVING COUNT(unique_key) > 1) GROUP BY account_id, sli_key, sli_time, unique_key ORDER BY account_id, sli_time desc) WHERE fail = true)" payload = { "model": "deepseek-r1-distill-llama-8b", "prompt": prompt, "max_tokens": 1028, "temperature": 0, "stream": True, } with httpx.Client(timeout=None) as client: start_time = time.time() first_token_time = None with client.stream( "POST", f"http://{ENDPOINT}/v1/completions", headers=headers, json=payload, ) as response: print(f"Status code: {response.status_code}") print("=== Response Headers ===") print(f"Target Pod: {response.headers.get('target-pod')}") print(f"Request ID: {response.headers.get('request-id')}") print("========================\n") print("=== Streamed Content ===") for line in response.iter_lines(): if not line.strip(): continue if line.startswith("data: "): data = line[len("data: "):] if data == "[DONE]": break parsed = json.loads(data) text = parsed["choices"][0].get("text", "") if first_token_time is None: first_token_time = time.time() print(f"\nTTFT: {first_token_time - start_time:.3f}s\n") print(text, end="", flush=True) total_time = time.time() - start_time print(f"\n\nTotal Time: {total_time:.3f}s") ``` -------------------------------- ### TLS转义字符示例 Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用反斜杠(\)转义特殊字符。例如,'__path__:\/images\/log'搜索路径为'/images/log'的日志。 ```tls __path__:\/images\/log ``` -------------------------------- ### TLS SQL分析语句示例(COUNT) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb SQL分析语句语法类似通用SQL,用于分析检索到的日志。例如,'SELECT COUNT(*) AS PV'统计日志数量。 ```tls SELECT COUNT(*) AS PV ``` -------------------------------- ### TLS字符串匹配示例(带引号) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 当关键词包含空格时,必须使用双引号或单引号将其括起来作为整体进行检索。例如,'"ERROR WARNING"'搜索包含'ERROR WARNING'的日志。 ```tls "ERROR WARNING" ``` -------------------------------- ### TLS全文检索示例 Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 全文检索通过输入关键词来匹配所有日志字段。例如,输入'ERROR'将筛选出所有包含'ERROR'关键词的日志。 ```tls ERROR ``` -------------------------------- ### TLS SQL函数示例(CEIL) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb CEIL函数用于向上取整。例如,'SELECT ceil(ReqTime) AS ReqTime'对ReqTime字段向上取整。 ```tls SELECT ceil(ReqTime) AS ReqTime ``` -------------------------------- ### TLS字符串匹配示例(空格分隔) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 多个关键词用空格分隔且无引号时,被视为用'AND'逻辑连接。例如,'ERROR WARNING'搜索同时包含'ERROR'和'WARNING'的日志。 ```tls ERROR WARNING ``` -------------------------------- ### TLS模糊查询示例(问号) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用问号(?)进行模糊查询,匹配单个字符。例如,'TopicId:'6d?78''检索TopicId为6dx78的日志,x为任意字符。 ```tls TopicId:'6d?78' ``` -------------------------------- ### TLS数字字段范围查询示例(不包含边界) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用'TO'操作符进行范围查询。例如,'status:{400 TO 500]'筛选status字段值在400到500之间(不含400,含500)的日志。 ```tls status:{400 TO 500] ``` -------------------------------- ### LOG Function for Natural Logarithm Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The LOG function calculates the natural logarithm of a target value. The input key must be of Double type. ```SQL SELECT LOG(ReqSize) ``` -------------------------------- ### TLS逻辑操作符嵌套示例 Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 逻辑运算符可嵌套使用,需用括号指定优先级。例如,'status:500 AND (level:"ERROR" OR level:"WARN")'。 ```tls status:500 AND (level:"ERROR" OR level:"WARN") ``` -------------------------------- ### TLS数字字段范围查询示例(包含边界) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用'TO'操作符进行范围查询。例如,'status:[400 TO 500]'筛选status字段值在400到500之间(含边界)的日志。 ```tls status:[400 TO 500] ``` -------------------------------- ### ASIN: Calculate Arc Sine Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The ASIN function calculates the arc sine (inverse sine) of a given value. The input KEY should be of Double type and within the range of [-1, 1]. Values outside this range will result in NaN. The output is a Double representing the angle in radians. ```SQL SELECT asin(pi()/4) ``` -------------------------------- ### TLS逻辑操作符示例(AND) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用'AND'连接多个条件。例如,'status:500 AND level:ERROR'筛选status为500且level为ERROR的日志。 ```tls status:500 AND level:ERROR ``` -------------------------------- ### TLS模糊查询示例(星号) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用星号(*)进行模糊查询,匹配任意字符。例如,'cn*'匹配所有以'cn'开头的字符串。注意模糊查询时,需使用单引号括起,如''cn*'。' ```tls 'cn*' ``` -------------------------------- ### EXP: Calculate e to the Power of x Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The EXP function calculates the value of the natural base 'e' raised to the power of 'x'. The input 'x' should be of Double type, and the output is a Double. ```SQL SELECT EXP(4) ``` -------------------------------- ### POWER: Calculate Value to the Power of Y Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The POWER function calculates the value of the first argument raised to the power of the second argument. Both KEY and y should be of Double type, and the output is a Double. ```SQL SELECT POWER(ReqSize, 3) ``` -------------------------------- ### TLS键值检索示例 Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 键值检索通过指定字段名和值来筛选日志。例如,'status:500'将筛选出所有status字段值为500的日志。 ```tls status:500 ``` -------------------------------- ### LN: Calculate Natural Logarithm Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The LN function calculates the natural logarithm (base e) of a given value. The input KEY must be of Double type and greater than 0. The output is a double. ```SQL SELECT LN(5) ``` -------------------------------- ### TLS逻辑操作符示例(OR) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用'OR'连接多个条件。例如,'status:500 OR level:ERROR'筛选status为500或level为ERROR的日志。 ```tls status:500 OR level:ERROR ``` -------------------------------- ### COSH: Calculate Hyperbolic Cosine Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The COSH function calculates the hyperbolic cosine of a given value. The input KEY should be of Double type, and the output is also a Double. ```SQL SELECT cosh(pi()/3) ``` -------------------------------- ### SIN Function for Sine Calculation Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The SIN function calculates the sine of a target value. The input key must be of Double type. ```SQL SELECT SIN(pi()/3) ``` -------------------------------- ### CBRT: Calculate Cube Root Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The CBRT function calculates the cube root of a given value. The input 'x' should be of Double type, and the output is a Double. ```SQL SELECT CBRT(64) ``` -------------------------------- ### MAX: Find Maximum Value Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The MAX function finds the maximum value within a set of values. The input KEY can be a log field or an expression of any data type, and the return value's data type will match the input parameter's data type. ```SQL SELECT MAX(ReqTime) AS max_reqtime ``` -------------------------------- ### TLS数字字段比较示例(大于) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 对于数字类型字段,可使用比较操作符。例如,'status:>500'筛选status字段值大于500的日志。 ```tls status:>500 ``` -------------------------------- ### KURTOSIS: Calculate Kurtosis of Values Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The KURTOSIS function calculates the kurtosis of a set of values, which measures the 'tailedness' of the probability distribution. The input KEY can be a log field or an expression of Double or Bigint data type, and the output is a Double. ```SQL SELECT KURTOSIS(status) ``` -------------------------------- ### CARDINALITY: Count Array Elements Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The CARDINALITY function counts the number of elements in an array. The input KEY should be an Array type field or expression, and the output is a Bigint representing the count. ```SQL SELECT CARDINALITY(CAST(JSON_PARSE(test_text) as ARRAY(bigint))) ``` -------------------------------- ### TLS逻辑操作符示例(NOT) Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb 使用'NOT'排除条件。例如,'NOT status:500'排除status为500的日志。 ```tls NOT status:500 ``` -------------------------------- ### QUARTER Function for Date Quarter Extraction Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The QUARTER function returns the quarter of the year for a given date. The input key must be of Timestamp or Date type. ```SQL SELECT CURRENT_TIMESTAMP, QUARTER(CURRENT_TIMESTAMP) ``` -------------------------------- ### TANH: Calculate Hyperbolic Tangent Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The TANH function calculates the hyperbolic tangent of a given value. The input KEY should be of Double type, and the output is also a Double. ```SQL SELECT TANH(pi()/3) ``` -------------------------------- ### TAN: Calculate Tangent Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The TAN function calculates the tangent of a given angle. The input KEY should be of Double type, representing the angle in radians, and the output is a Double. ```SQL SELECT TAN(pi()/3) ``` -------------------------------- ### ABS Function for Absolute Value Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The ABS function calculates the absolute value of a target value. It supports various numeric types. ```SQL SELECT abs(RespSize) ``` -------------------------------- ### BAR Function for ANSI Bar Chart Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The BAR function draws an ANSI bar chart. It can be customized with colors and width, and accepts a proportion 'x' to determine the segment of the bar to return. ```SQL SELECT BAR(0.5, 100) ``` -------------------------------- ### ACOS Function for Inverse Cosine Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The ACOS function computes the inverse cosine of a value. The input key must be a Double type within the range of [-1, 1]. ```SQL SELECT ACOS(pi()/4) ``` -------------------------------- ### COS Function for Cosine Calculation Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The COS function calculates the cosine of a target value. The input key must be of Double type. ```SQL SELECT COS(pi()/3) ``` -------------------------------- ### WEEK Function for Week of Year Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The WEEK function calculates the week number of the year for a given date. It is equivalent to WEEK_OF_YEAR and returns a Bigint type. ```SQL SELECT CURRENT_TIMESTAMP, WEEK(CURRENT_TIMESTAMP) ``` -------------------------------- ### PI Function for Pi Value Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The PI function returns the value of Pi, accurate to 15 decimal places. It returns a Double type. ```SQL SELECT PI() ``` -------------------------------- ### ROUND Function for Number Rounding Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The ROUND function rounds a target value to a specified number of decimal places. It accepts numeric types for the key and an integer for precision. ```SQL SELECT ROUND(SQRT(ReqSize)) ``` ```SQL SELECT ROUND(diff [3],4) FROM ( SELECT COMPARE(PV, 86400) AS diff FROM ( SELECT COUNT(*) AS PV ) ) ``` -------------------------------- ### ATAN: Calculate Arc Tangent Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The ATAN function calculates the arc tangent (inverse tangent) of a given value. The input KEY should be of Double type, and the output is a Double representing the angle in radians. ```SQL SELECT ATAN(pi()/4) ``` -------------------------------- ### WINDOW_FUNNEL: Calculate Max Consecutive Events in Time Window Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The WINDOW_FUNNEL function calculates the maximum number of consecutive events within a sliding time window. It matches event chains based on a defined sequence, returning the longest continuous match. It supports two syntaxes depending on whether the event_id is a defined column or part of the event list. ```SQL SELECT user_key, WINDOW_FUNNEL(86400,time/1000,ARRAY [stage_key='stage1', stage_key='stage2',stage_key='stage3']) AS levels GROUP BY user_key ORDER BY user_key ``` ```SQL SELECT user_key, WINDOW_FUNNEL(86400,time/1000,stage_key, ARRAY ['stage1', 'stage2', 'stage3']) AS levels GROUP BY user_key ORDER BY user_key ``` -------------------------------- ### DOY: Extract Day of Year from Date Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The DOY function extracts the day of the year from a given date or timestamp. It is equivalent to the DAY_OF_YEAR function. The input KEY can be a field or an expression of Timestamp or Date type, and the output is a Bigint representing the day of the year. ```SQL SELECT CURRENT_DATE, DOY(CURRENT_DATE) ``` -------------------------------- ### CAST: Convert Data Type Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The CAST function converts the data type of a given key or expression. If any value fails to convert, the entire retrieval analysis operation will terminate. The output data type matches the specified 'type' parameter, which can be bigint, varchar, double, boolean, timestamp, decimal, array, or map. ```SQL SELECT CAST(JSON_PARSE(child_type) AS MAP(varchar, varchar)) ``` -------------------------------- ### DOW: Extract Day of Week from Date Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The DOW function extracts the day of the week from a given date or timestamp. It is equivalent to the DAY_OF_WEEK function. The input KEY can be a field or an expression of Timestamp or Date type, and the output is a Bigint representing the day of the week. ```SQL SELECT CURRENT_DATE, DOW(CURRENT_DATE) ``` -------------------------------- ### JSON_EXTRACT: Extract Values from JSON Source: https://github.com/vllm-project/aibrix/blob/main/samples/volcano-engine/prefix-cache-routing.ipynb The JSON_EXTRACT function extracts a set of JSON values (arrays or objects) from a JSON object or array. It will error on invalid JSON types; consider using JSON_EXTRACT_SCALAR for such cases. The output is a String type. ```SQL SELECT JSON_EXTRACT('[{"SIZE":100},{"STATUS":200}}]', '$.0.SIZE') ```