### SPL Scan Query Example Source: https://github.com/xingyunyang01/spl/blob/main/SPL基础语法.md An example of a scan query in SPL that first filters logs based on 'error' and 'msg:wrong', and then projects the 'level' and 'msg' fields. This demonstrates filtering and field selection capabilities. ```spl error and msg:wrong | project level, msg ``` -------------------------------- ### Access Array Elements in SPL Source: https://github.com/xingyunyang01/spl/blob/main/SPL基础语法.md Demonstrates how to access elements within an array in SPL. Array indexing starts from 1. Example shows creating an array and accessing its second element. ```SPL * | extend a = ARRAY[0, 1, 2] | extend b = a[1] ``` -------------------------------- ### SPL Wildcard Input for Real-time Consumption Source: https://github.com/xingyunyang01/spl/blob/main/SPL基础语法.md Shows how to use the wildcard '*' to input all raw data from a Logstore for real-time consumption using SPL. This enables filtering and analysis of all incoming logs, with field names being case-sensitive. An example filters logs containing 'wrong'. ```spl * | where msg like '%wrong%' ``` -------------------------------- ### SPL: Using '*' as a Placeholder for Input Data Source: https://github.com/xingyunyang01/spl/blob/main/SPL基础语法.md The '*' symbol in SPL serves as a placeholder for SLS Logstore data when it's used as input. This example demonstrates filtering and categorizing access logs based on status codes using SPL. ```sql -- SPL processing result defined as a named dataset src, as input for subsequent SPL expressions. .let src = * | where status=cast(status as BIGINT); -- Using the named dataset src as input, filter data where the status field is 5xx, define the dataset err, do not output. .let err = $src | where status >= 500 | extend msg='ERR'; -- Using the named dataset src as input, filter data where the status field is 2xx, define the dataset ok, do not output. .let ok = $src | where status >= 200 and status < 300 | extend msg='OK'; -- Output named datasets err and ok $err; $ok; ``` -------------------------------- ### Access Map Elements in SPL Source: https://github.com/xingyunyang01/spl/blob/main/SPL基础语法.md Illustrates how to access elements within a map (dictionary) in SPL. Map keys must be primitive numerical types. Example shows creating a map and accessing an element using a key. ```SPL * | extend a = MAP(ARRAY['foo', 'bar'], ARRAY[0, 1]) | extend b = a['foo'] ``` -------------------------------- ### SPL Named Dataset Definition with .let Source: https://context7.com/xingyunyang01/spl/llms.txt Create reusable named datasets for complex multi-branch processing workflows using the '.let' control instruction. This enables modularity and reusability of data processing logic. ```sql -- Define base dataset with type conversion .let src = * | where status=cast(status as BIGINT); -- Branch 1: Process error logs .let err = $src | where status >= 500 | extend msg='ERR', severity=3; -- Branch 2: Process success logs .let ok = $src | where status >= 200 and status < 300 | extend msg='OK', severity=0; -- Output both datasets $err; $ok; -- Input example: -- status: '200', body: 'this is a test' -- status: '500', body: 'internal error' -- status: '404', body: 'not found' -- Output: -- Dataset err: status: '500', body: 'internal error', msg: 'ERR', severity: 3 -- Dataset ok: status: '200', body: 'this is a test', msg: 'OK', severity: 0 ``` -------------------------------- ### SPL Command Expression Syntax Source: https://github.com/xingyunyang01/spl/blob/main/SPL基础语法.md This describes the general syntax for SPL command expressions. It shows how commands are structured with options, expressions, and output aliasing. This syntax is fundamental for writing any SPL query. ```spl cmd -option=