Translate splunk to postgresql
Skill SunnyRaymond/splunk-sql-transfer-skills/skills/translate-splunk-to-postgresql
Translate, review, and troubleshoot Splunk SPL, dashboard XML searches, macros, saved searches, and lookup-driven pipelines into behaviorally equivalent PostgreSQL or Citus SQL for Tableau Custom SQL, materialized-view pipelines, validation scripts, and migration handovers. Use when converting pipe commands such as search, eval, rex, lookup, join, dedup, streamstats, stats, eventstats, chart, or timechart; investigating Splunk-versus-SQL row, duration, ordering, classification, or percentile mismatches; deciding which logic belongs in a parameter-free materialized view versus parameterized Custom SQL; or making an existing translation deterministic, boundary-safe, and Citus-compatible.From its SKILL.md
npx -y skills add SunnyRaymond/splunk-sql-transfer-skills --skill translate-splunk-to-postgresqlAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
10.0 KB, as published. Nobody here has run it
Translate Splunk to PostgreSQL
Translate behavior, not syntax. Treat an SPL search as an ordered dataflow whose row set, grain, order, time scope, null rules, and tie behavior can change at every pipe.
Establish the parity contract
Before writing SQL, collect or inspect:
- the complete SPL after macro and token expansion;
- dashboard XML or saved-search definitions that supply time tokens, defaults, lookups, and post-process searches;
- source schemas, timestamp types, candidate stable row identifiers, and Citus distribution keys;
- lookup contents and whether matching is exact, normalized, case-sensitive, or many-to-one;
- the expected output columns, output grain, Tableau filters, and aggregation behavior;
- one reproducible comparison window and the source-data cutoff used by each system.
Do not invent missing columns, keys, sort order, lookup uniqueness, or timezone rules. State unresolved assumptions and provide a diagnostic query when the evidence is insufficient.
Create a semantic ledger with one row per SPL stage:
| Stage | Operation | Input grain | Output grain | Time field and scope | Key | Required order | Null/unmatched rule |
|---|---|---|---|---|---|---|---|
| 1 | source search | raw event | raw event | _time, half-open window | source id | none | source-specific |
| 2 | sort + dedup | raw event | one row per key | unchanged | business key | explicit | match keepempty |
| 3 | stats | event | aggregate | unchanged | group fields | aggregate-specific | profile missing groups |
Use the ledger as the translation specification and as the review checklist. Read references/migration-workflow.md for the full discovery, implementation, verification, optimization, and handover workflow.
Translate in pipeline order
Map each semantics-changing pipe to a named CTE. Preserve the original order until parity is proven. Push a predicate earlier only after demonstrating that it commutes with every intervening operation.
Follow these rules:
- Anchor source-time filtering explicitly and normally use
event_time >= start_ts AND event_time < end_ts. - Preserve the distinction between the source timestamp, derived start/end timestamps, ordering timestamp, display timestamp, and data-as-of timestamp.
- Declare the row grain after every deduplication, join, lookup, expansion, window, and aggregation.
- Reproduce the SPL sort before translating order-sensitive commands.
- Use a deterministic final tie-breaker only when a stable source field represents the SPL order. If SPL leaves ties implementation-dependent, preserve or expose the ties, or document a deterministic SQL choice as an intentional deviation; do not claim exact row-selection parity.
- Reproduce null, missing-field, unmatched-lookup, and multivalue behavior deliberately.
- Keep final output columns explicit; retain raw keys alongside normalized keys when normalization is required.
- Add comments only for business rules, non-obvious parity choices, or intentional deviations.
Read references/spl-to-sql-map.md when translating individual SPL commands or checking subtle command behavior. Read references/temporal-and-dedup-patterns.md whenever the search contains time tokens, dedup, latest, earliest, first, last, streamstats, durations, or state/event correlation.
Keep time and row identity explicit
Default to half-open windows so adjacent intervals neither overlap nor leave gaps:
WHERE e.event_time >= p.start_ts
AND e.event_time < p.end_ts
Use one declared timezone and type conversion policy. Either keep instants as timestamptz end to end with offset-aware boundaries, or keep declared local wall-clock values as timestamp without time zone. When crossing those models, use AT TIME ZONE '<declared-zone>' in the direction appropriate to the input type. Never use timestamptz::timestamp or an implicit mixed-type comparison: both can depend on the PostgreSQL session timezone.
Filter before dedup only when the source SPL filters before dedup. If the SPL sorts and then deduplicates with a source-justified total order, translate it with row_number() and that complete order:
row_number() OVER (
PARTITION BY business_key
ORDER BY event_time DESC, source_priority DESC, source_row_id DESC
) AS rn
Do not substitute SELECT DISTINCT for dedup. Do not use DISTINCT ON without a complete ORDER BY. If every row tied at the latest timestamp must survive, use max(event_time) plus an equality join or dense_rank(), not row_number().
Reproduce stateful SPL deliberately
Translate streamstats only after reconstructing its exact input order, partition, current behavior, and reset condition. Use lag or lead for simple neighboring-row access. For resets, compute reset flags, cumulatively sum them into a segment identifier, and apply the window inside that segment.
When one event stream needs the latest preceding state from another stream:
- allow the state search to reach before the displayed output window when a seed state is required;
- match on the complete entity key;
- enforce
state_time <= event_time; - choose the latest state deterministically;
- prevent a many-to-many temporal join from multiplying output rows.
Prefer a colocated LATERAL lookup for small, indexed, Citus-compatible inputs; otherwise use a filtered range join plus ranking or a union-and-carry-forward pattern. Validate the first event inside the window because that row exposes missing seed-state bugs.
Split materialized views from Custom SQL
Keep reusable materialized views parameter-free. Use them to:
- standardize source columns and timestamp types;
- preserve raw rows and stable source identifiers;
- perform source-local parsing or normalization that is invariant across dashboards;
- apply only an agreed retention horizon;
- expose fields needed by later filters, joins, ties, and diagnostics.
Do not embed Tableau date parameters, dashboard-specific mappings, final deduplication, or order-sensitive calculations in a shared base materialized view unless they are truly invariant.
Put selected-window logic in Tableau Custom SQL:
- resolve parameters once;
- filter the appropriate source rows before expensive windows and joins when parity permits;
- retain extra history for a state seed, PM sequence, or duration boundary when required;
- apply dashboard-specific mappings;
- perform final deduplication, aggregation, classification, and output shaping.
Read references/sql-recipes.md for reusable parameter, materialized-view, lookup, window, as-of join, Citus, and parity-test templates.
Make the SQL Citus-safe
Inspect table distribution before choosing a translation. Align joins and window partitions with the distribution key where possible. Keep large fact-to-fact joins colocated, make small shared dimensions reference tables when appropriate, and filter distributed facts before coordinator-heavy global operations.
Treat these as review triggers:
- a correlated subquery or
LATERALlookup across non-colocated distributed tables; - a global
DISTINCT ON, ordered aggregate,count(distinct ...), or window lacking the distribution key; - a many-to-many join before time filtering;
- an inline mapping that unexpectedly multiplies rows;
- a materialized view that centralizes a very large distributed result;
- a predicate hidden behind a cast or expression that prevents index use or shard pruning.
Choose semantic correctness first, then optimize with EXPLAIN (ANALYZE, BUFFERS) on a representative range.
Verify parity at every semantic boundary
Never rely only on the final visualization. Compare:
- input count, minimum/maximum time, null counts, and distinct business keys;
- row counts after every filter, deduplication, lookup, join, window, and aggregate;
- duplicate counts at the intended output grain;
- unmatched and multiply matched lookup keys;
- rows tied at the latest timestamp;
- missing, extra, and value-different rows using a stable comparison key;
- boundary timestamps at exactly
start_tsandend_ts; - the first row per entity in stateful calculations;
- identical source-data cutoffs in Splunk and PostgreSQL.
Use EXCEPT ALL or a full outer join for row-level comparison, not just total counts. Normalize display-only formatting before comparison, but do not normalize business values without documenting it.
If results differ, locate the first divergent stage. Change one semantic choice at a time and rerun the narrow comparison. Do not layer speculative fixes onto the final query.
Produce a handover-ready result
Return or create:
- production SQL with explicit parameters, types, grain, keys, and ordering;
- a standalone PostgreSQL validation script with literal test parameters;
- a parity note listing source cutoff, timezone, boundary convention, assumptions, and intentional deviations;
- stage-level diagnostics for unresolved mismatches;
- index or Citus-layout recommendations separately from the semantic translation;
- a concise mapping from SPL stages to SQL CTEs so a new maintainer can trace the logic.
Prefer long-form output for Tableau unless a fixed SQL pivot is a stated requirement. Preserve enough diagnostic columns in development SQL to explain a row, then expose only the required contract in the final SELECT.