spl-to-apl
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSPL to APL Translator
SPL 转 APL 转换器
Type safety: Fields like status are often stored as strings. Always cast before numeric comparison: toint(status) >= 500, not status >= 500.
类型安全:像status这类字段通常以字符串形式存储。进行数值比较前务必先转换类型:使用toint(status) >= 500,而非status >= 500。
Critical Differences
关键差异
- Time is explicit in APL: SPL time pickers don't translate — add
where _time between (ago(1h) .. now()) - Structure: SPL → APL
index=... | command['dataset'] | operator - Join is preview: limited to 50k rows, inner/innerunique/leftouter only
- cidrmatch args reversed: SPL → APL
cidrmatch(cidr, ip)ipv4_is_in_range(ip, cidr)
- APL中时间需显式声明:SPL的时间选择器无法直接转换——需添加
where _time between (ago(1h) .. now()) - 结构差异:SPL → APL
index=... | command['dataset'] | operator - Join为预览功能:限制最多50k行,仅支持inner/innerunique/leftouter类型
- cidrmatch参数顺序反转:SPL → APL
cidrmatch(cidr, ip)ipv4_is_in_range(ip, cidr)
Core Command Mappings
核心命令映射
| SPL | APL | Notes |
|---|---|---|
| | Dataset replaces index |
| | Explicit where |
| | Same |
| | Different aggregation syntax |
| | Create/modify fields |
| | Select columns |
| | Remove columns |
| | Rename |
| | Sort |
| | Limit rows |
| | Two-step |
| | Keep latest |
| | Regex extraction |
| | Preview feature |
| | Combine datasets |
| | Expand arrays |
| | Manual binning |
| | Bottom N |
| | JSON access |
| No direct equivalent | Use summarize + make_list |
Complete mappings:
reference/command-mapping.md| SPL | APL | 说明 |
|---|---|---|
| | Dataset替代index |
| | 显式使用where |
| | 用法一致 |
| | 聚合语法不同 |
| | 创建/修改字段 |
| | 选择列 |
| | 删除列 |
| | 重命名字段 |
| | 排序 |
| | 限制行数 |
| | 分两步实现 |
| | 保留最新记录 |
| | 正则提取 |
| | 预览功能 |
| | 合并数据集 |
| | 展开数组 |
| | 手动分箱 |
| | 获取底部N条 |
| | JSON访问 |
| 无直接等效命令 | 使用summarize + make_list替代 |
完整映射列表:
reference/command-mapping.mdStats → Summarize
Stats → Summarize
undefinedundefinedSPL
SPL
| stats count by status
| stats count by status
APL
APL
| summarize count() by status
undefined| summarize count() by status
undefinedKey function mappings
核心函数映射
| SPL | APL |
|---|---|
| |
| |
| |
| Same |
| |
| |
| |
| |
| |
| SPL | APL |
|---|---|
| |
| |
| |
| 用法一致 |
| |
| |
| |
| |
| |
Conditional count pattern
条件计数示例
undefinedundefinedSPL
SPL
| stats count(eval(status>=500)) as errors by host
| stats count(eval(status>=500)) as errors by host
APL
APL
| summarize errors = countif(status >= 500) by host
Complete function list: `reference/function-mapping.md`
---| summarize errors = countif(status >= 500) by host
完整函数列表:`reference/function-mapping.md`
---Eval → Extend
Eval → Extend
undefinedundefinedSPL
SPL
| eval new_field = old_field * 2
| eval new_field = old_field * 2
APL
APL
| extend new_field = old_field * 2
undefined| extend new_field = old_field * 2
undefinedKey function mappings
核心函数映射
| SPL | APL | Notes |
|---|---|---|
| | Double 'f' |
| | Requires default |
| | |
| | |
| | 0-indexed in APL |
| | |
| | Explicit types |
| | Operator |
| | Same |
| | Join array |
| | Array length |
| SPL | APL | 说明 |
|---|---|---|
| | 多一个'f' |
| | 必须包含默认值 |
| | |
| | |
| | APL中为0起始索引 |
| | |
| | 显式指定类型 |
| | 使用运算符形式 |
| | 用法一致 |
| | 数组合并为字符串 |
| | 数组长度 |
Case statement pattern
Case语句示例
undefinedundefinedSPL
SPL
| eval level = case(
status >= 500, "error",
status >= 400, "warning",
1==1, "ok"
)
| eval level = case(
status >= 500, "error",
status >= 400, "warning",
1==1, "ok"
)
APL
APL
| extend level = case(
status >= 500, "error",
status >= 400, "warning",
"ok"
)
Note: SPL's `1==1` catch-all becomes implicit default in APL.
---| extend level = case(
status >= 500, "error",
status >= 400, "warning",
"ok"
)
注意:SPL中用`1==1`作为兜底条件,在APL中是隐式默认值。
---Rex → Parse/Extract
Rex → Parse/Extract
undefinedundefinedSPL
SPL
| rex field=message "user=(?<username>\w+)"
| rex field=message "user=(?<username>\w+)"
APL - parse with regex
APL - 正则解析
| parse kind=regex message with @"user=(?P<username>\w+)"
| parse kind=regex message with @"user=(?P<username>\w+)"
APL - extract function
APL - 提取函数
| extend username = extract("user=(\w+)", 1, message)
undefined| extend username = extract("user=(\w+)", 1, message)
undefinedSimple pattern (non-regex)
简单模式(非正则)
undefinedundefinedSPL
SPL
| rex field=uri "^/api/(?<version>v\d+)/(?<endpoint>\w+)"
| rex field=uri "^/api/(?<version>v\d+)/(?<endpoint>\w+)"
APL
APL
| parse uri with "/api/" version "/" endpoint
---| parse uri with "/api/" version "/" endpoint
---Time Handling
时间处理
SPL time pickers don't translate. Always add explicit time range:
undefinedSPL的时间选择器无法直接转换,务必添加显式时间范围:
undefinedSPL (time picker: Last 24 hours)
SPL(时间选择器:最近24小时)
index=logs
index=logs
APL
APL
['logs'] | where _time between (ago(24h) .. now())
undefined['logs'] | where _time between (ago(24h) .. now())
undefinedTimechart translation
Timechart转换
undefinedundefinedSPL
SPL
| timechart span=5m count by status
| timechart span=5m count by status
APL
APL
| summarize count() by bin(_time, 5m), status
---| summarize count() by bin(_time, 5m), status
---Common Patterns
常见模式示例
Error rate calculation
错误率计算
undefinedundefinedSPL
SPL
| stats count(eval(status>=500)) as errors, count as total by host
| eval error_rate = errors/total*100
| stats count(eval(status>=500)) as errors, count as total by host
| eval error_rate = errors/total*100
APL
APL
| summarize errors = countif(status >= 500), total = count() by host
| extend error_rate = toreal(errors) / total * 100
undefined| summarize errors = countif(status >= 500), total = count() by host
| extend error_rate = toreal(errors) / total * 100
undefinedSubquery (subsearch)
子查询(subsearch)
undefinedundefinedSPL
SPL
index=logs [search index=errors | fields user_id | format]
index=logs [search index=errors | fields user_id | format]
APL
APL
let error_users = ['errors'] | where _time between (ago(1h) .. now()) | distinct user_id;
['logs']
| where _time between (ago(1h) .. now())
| where user_id in (error_users)
undefinedlet error_users = ['errors'] | where _time between (ago(1h) .. now()) | distinct user_id;
['logs']
| where _time between (ago(1h) .. now())
| where user_id in (error_users)
undefinedJoin datasets
数据集关联
undefinedundefinedSPL
SPL
| join user_id [search index=users | fields user_id, name]
| join user_id [search index=users | fields user_id, name]
APL
APL
| join kind=inner (['users'] | project user_id, name) on user_id
undefined| join kind=inner (['users'] | project user_id, name) on user_id
undefinedTransaction-like grouping
类Transaction分组
undefinedundefinedSPL
SPL
| transaction session_id maxspan=30m
| transaction session_id maxspan=30m
APL (no direct equivalent — reconstruct with summarize)
APL(无直接等效命令——用summarize重构)
| summarize
start_time = min(_time),
end_time = max(_time),
events = make_list(pack("time", _time, "action", action)),
duration = max(_time) - min(_time)
by session_id
| where duration <= 30m
---| summarize
start_time = min(_time),
end_time = max(_time),
events = make_list(pack("time", _time, "action", action)),
duration = max(_time) - min(_time)
by session_id
| where duration <= 30m
---String Matching Performance
字符串匹配性能对比
| SPL | APL | Speed |
|---|---|---|
| | Fastest |
| | Moderate |
| | Fast |
| | Slowest |
Prefer over (word-boundary matching is faster). Use variants for case-sensitive (faster).
hascontains_cs| SPL | APL | 速度 |
|---|---|---|
| | 最快 |
| | 中等 |
| | 快 |
| | 最慢 |
优先使用而非(词边界匹配速度更快)。如需区分大小写,使用变体(速度更快)。
hascontains_csReference
参考资料
- — complete command list
reference/command-mapping.md - — complete function list
reference/function-mapping.md - — full query translation examples
reference/examples.md - APL docs: https://axiom.co/docs/apl/introduction
- — 完整命令列表
reference/command-mapping.md - — 完整函数列表
reference/function-mapping.md - — 完整查询转换示例
reference/examples.md - APL官方文档:https://axiom.co/docs/apl/introduction