spl-to-apl

โดย axiomhq

แปลคำค้นหา Splunk SPL เป็น Axiom APL ให้การแมปคำสั่ง ฟังก์ชันที่เทียบเท่า และการแปลงไวยากรณ์ ใช้เมื่อย้ายจาก Splunk,…

npx skills add https://github.com/axiomhq/skills --skill spl-to-apl

SPL to APL Translator

Type safety: Fields like status are often stored as strings. Always cast before numeric comparison: toint(status) >= 500, not status >= 500.


Critical Differences

  1. Time is explicit in APL: SPL time pickers don't translate — add where _time between (ago(1h) .. now())
  2. Structure: SPL index=... | command → APL ['dataset'] | operator
  3. Join is preview: limited to 50k rows, inner/innerunique/leftouter only
  4. cidrmatch args reversed: SPL cidrmatch(cidr, ip) → APL ipv4_is_in_range(ip, cidr)

Core Command Mappings

SPLAPLNotes
search index=...['dataset']Dataset replaces index
search field=valuewhere field == "value"Explicit where
wherewhereSame
statssummarizeDifferent aggregation syntax
evalextendCreate/modify fields
table / fieldsprojectSelect columns
fields -project-awayRemove columns
rename x as yproject-rename y = xRename
sort / sort -order by ... asc/descSort
head Ntake NLimit rows
top N fieldsummarize count() by field | top N by count_Two-step
dedup fieldsummarize arg_max(_time, *) by fieldKeep latest
rexparse or extract()Regex extraction
joinjoinPreview feature
appendunionCombine datasets
mvexpandmv-expandExpand arrays
timechart span=Xsummarize ... by bin(_time, X)Manual binning
rare N fieldsummarize count() by field | order by count_ asc | take NBottom N
spathparse_json() or json['path']JSON access
transactionNo direct equivalentUse summarize + make_list

Complete mappings: reference/command-mapping.md


Stats → Summarize

# SPL
| stats count by status

# APL  
| summarize count() by status

Key function mappings

SPLAPL
countcount()
count(field)countif(isnotnull(field))
dc(field)dcount(field)
avg/sum/min/maxSame
median(field)percentile(field, 50)
perc95(field)percentile(field, 95)
first/lastarg_min/arg_max(_time, field)
list(field)make_list(field)
values(field)make_set(field)

Conditional count pattern

# SPL
| stats count(eval(status>=500)) as errors by host

# APL
| summarize errors = countif(status >= 500) by host

Complete function list: reference/function-mapping.md


Eval → Extend

# SPL
| eval new_field = old_field * 2

# APL
| extend new_field = old_field * 2

Key function mappings

SPLAPLNotes
if(c, t, f)iff(c, t, f)Double 'f'
case(c1,v1,...)case(c1,v1,...,default)Requires default
len(str)strlen(str)
lower/uppertolower/toupper
substrsubstring0-indexed in APL
replacereplace_string
tonumbertoint/tolong/torealExplicit types
match(s,r)s matches regex "r"Operator
split(s, d)split(s, d)Same
mvjoin(mv, d)strcat_array(arr, d)Join array
mvcount(mv)array_length(arr)Array length

Case statement pattern

# SPL
| eval level = case(
    status >= 500, "error",
    status >= 400, "warning",
    1==1, "ok"
  )

# APL  
| extend level = case(
    status >= 500, "error",
    status >= 400, "warning",
    "ok"
  )

Note: SPL's 1==1 catch-all becomes implicit default in APL.


Rex → Parse/Extract

# SPL
| rex field=message "user=(?<username>\w+)"

# APL - parse with regex
| parse kind=regex message with @"user=(?P<username>\w+)"

# APL - extract function  
| extend username = extract("user=(\\w+)", 1, message)

Simple pattern (non-regex)

# SPL
| rex field=uri "^/api/(?<version>v\d+)/(?<endpoint>\w+)"

# APL
| parse uri with "/api/" version "/" endpoint

Time Handling

SPL time pickers don't translate. Always add explicit time range:

# SPL (time picker: Last 24 hours)
index=logs

# APL
['logs'] | where _time between (ago(24h) .. now())

Timechart translation

# SPL
| timechart span=5m count by status

# APL
| summarize count() by bin(_time, 5m), status

Common Patterns

Error rate calculation

# SPL
| stats count(eval(status>=500)) as errors, count as total by host
| eval error_rate = errors/total*100

# APL
| summarize errors = countif(status >= 500), total = count() by host
| extend error_rate = toreal(errors) / total * 100

Subquery (subsearch)

# SPL
index=logs [search index=errors | fields user_id | format]

# 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)

Join datasets

# SPL
| join user_id [search index=users | fields user_id, name]

# APL
| join kind=inner (['users'] | project user_id, name) on user_id

Transaction-like grouping

# SPL
| transaction session_id maxspan=30m

# APL (no direct equivalent — reconstruct with 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

String Matching Performance

SPLAPLSpeed
field="value"field == "value"Fastest
field="*value*"field contains "value"Moderate
field="value*"field startswith "value"Fast
match(field, regex)field matches regex "..."Slowest

Prefer has over contains (word-boundary matching is faster). Use _cs variants for case-sensitive (faster).


Reference

  • reference/command-mapping.md — complete command list
  • reference/function-mapping.md — complete function list
  • reference/examples.md — full query translation examples
  • APL docs: https://axiom.co/docs/apl/introduction

Skills เพิ่มเติมจาก axiomhq

axiom-apl
axiomhq
เอกสารอ้างอิงภาษาแบบสอบถาม APL สำหรับ Axiom ให้ตัวดำเนินการ ฟังก์ชัน รูปแบบ และการใช้งาน CLI ถูกเรียกใช้โดยอัตโนมัติโดยทักษะ Axiom เฉพาะทางเมื่อเขียนหรือ…
official
detect-anomalies
axiomhq
ตรวจจับความผิดปกติในชุดข้อมูล Axiom โดยใช้การวิเคราะห์ทางสถิติ ใช้เมื่อต้องการหารูปแบบที่ผิดปกติ ปริมาณที่พุ่งสูง ค่าผิดปกติ หรือประเภทข้อผิดพลาดใหม่ใน…
official
explore-dataset
axiomhq
สำรวจชุดข้อมูล Axiom เพื่อทำความเข้าใจสคีมา ฟิลด์ ปริมาณ และรูปแบบ ใช้เมื่อค้นพบชุดข้อมูลใหม่ ตรวจสอบโครงสร้างข้อมูล หรือ...
official
find-traces
axiomhq
วิเคราะห์ distributed traces ของ OpenTelemetry จาก Axiom ใช้เมื่อตรวจสอบ trace ID, ค้นหา traces ตามเกณฑ์ (ข้อผิดพลาด, ความหน่วง, บริการ) หรือกำลังดีบัก…
official
gilfoyle
axiomhq
เอเจนต์ SRE ที่ทำในสิ่งที่คุณทำไม่ได้ ค้นหาสแต็กการสังเกตการณ์ของคุณ ค้นหาสาเหตุที่แท้จริง ไม่ตื่นตระหนก ไม่เดาสุ่ม ไม่สนใจความรู้สึกของคุณ ใช้…
official
axiom-sre
axiomhq
ผู้เชี่ยวชาญด้าน SRE สำหรับการตรวจสอบเหตุการณ์และการดีบัก ใช้วิธีการที่ขับเคลื่อนด้วยสมมติฐานและการคัดแยกอย่างเป็นระบบ สามารถสอบถามข้อมูลการสังเกตการณ์ของ Axiom ได้เมื่อพร้อมใช้งาน…
official
building-dashboards
axiomhq
ออกแบบและสร้างแดชบอร์ด Axiom ผ่าน API ครอบคลุมประเภทแผนภูมิ รูปแบบการสอบถาม APL และ metrics/MPL, SmartFilters, เค้าโครง และตัวเลือกการกำหนดค่า ใช้เมื่อ...
official
controlling-costs
axiomhq
วิเคราะห์รูปแบบการค้นหา Axiom เพื่อหาข้อมูลที่ไม่ได้ใช้งาน จากนั้นสร้างแดชบอร์ดและระบบตรวจสอบเพื่อปรับต้นทุนให้เหมาะสม ใช้เมื่อถูกขอให้ลดต้นทุน Axiom ค้นหาข้อมูลที่ไม่ได้ใช้…
official