Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ All notable changes to this project are documented here. The format follows

### Added

- The `tstats` command, the first stage of a pipeline only. Its data model is
resolved to an Elasticsearch index through a new `datamodels` mapping key
(`--index` first, then an `index=` filter in `WHERE`, then
`datamodels[<name>]`, then `default_index`), and its aggregation becomes an
ES\|QL `STATS`. Data-model field references (`Processes.dest`) lose the data
model name or root-dataset prefix and then run through `fields`; the prefix is
dropped with a `tstats-field-prefix` warning wherever it first appears, while
other dotted names such as `source.address` are left alone. An unmapped data
model falls back with
`tstats-datamodel`. `span=` with `_time` becomes `BUCKET(@timestamp, N unit)`
and is ignored elsewhere with `tstats-span`. `summariesonly`,
`allow_old_summaries`, and `prestats` are accepted and ignored with a
`tstats-option` info; every other option is refused with
`tstats-unknown-option`, a non-null `fillnull_value` with `tstats-fillnull`,
and a `tstats` after stage 0 with `tstats-position`. PromQL refuses the stage.
- `values`, `earliest`, and `latest` aggregations in ES\|QL, which `tstats`
detections use heavily.
- The `rename` command, translated to one ES\|QL `RENAME` command carrying
every pair. Wildcard patterns (`EU* AS EMEA*`, `properties.* AS *`) parse but
are refused with `rename-wildcard`, because ES\|QL `RENAME` has no wildcard
Expand Down
1 change: 1 addition & 0 deletions CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ conformance/
│ ├── search/ search expressions, wildcards, time bounds
│ ├── stats/ aggregations and grouping
│ ├── timechart/ bucketed aggregation
│ ├── tstats/ data-model aggregation and its refusals
│ ├── eval/ expression lowering
│ ├── rex/ extraction lowering
│ ├── shaping/ table, fields, sort, head
Expand Down
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ openspl transpile --strict -f savedsearch.spl
|---|---|---|---|
| `search` / implicit search | ✅ | ⚠️ | Free text becomes `MATCH`; PromQL needs explicit fields |
| `where` | ✅ | ⚠️ | Full expression pushdown to `WHERE` |
| `stats` | ✅ | ⚠️ | `count`, `dc`, `sum`, `avg`, `min`, `max`; PromQL: `count` only |
| `stats` | ✅ | ⚠️ | `count`, `dc`, `sum`, `avg`, `min`, `max`, `values`, `earliest`, `latest`; PromQL: `count` only |
| `timechart` | ✅ | ✅ | Time bucket → `BUCKET` or `increase(...[span])` |
| `tstats` | ⚠️ | ⛔ | Data-model aggregation; resolves through `datamodels` in the mapping and drops data-model field prefixes with a warning |
| `eval` | ✅ | ⛔ | Arithmetic, comparisons, common functions |
| `rex` | ⚠️ | ⛔ | Regex → Grok; always warns |
| `table` | ✅ | ⛔ | `KEEP` |
Expand Down Expand Up @@ -214,22 +215,30 @@ override.

| Collection | Queries | → IR | SPL→IR | → ES\|QL | SPL→ES\|QL | IR→ES\|QL | → PromQL | SPL→PromQL | IR→PromQL |
|---|---|---|---|---|---|---|---|---|---|
| `spl1` | 549 | 71 | 12.9% | 61 | 11.1% | 85.9% | 6 | 1.1% | 8.5% |
| `spl1-detections` | 2,171 | 24 | 1.1% | 11 | 0.5% | 45.8% | 0 | 0.0% | 0.0% |
| `spl1` | 549 | 88 | 16.0% | 80 | 14.6% | 90.9% | 6 | 1.1% | 6.8% |
| `spl1-detections` | 2,171 | 591 | 27.2% | 589 | 27.1% | 99.7% | 0 | 0.0% | 0.0% |
| `spl2` | 92 | 0 | 0.0% | 0 | 0.0% | — | 0 | 0.0% | — |
| **Total** | **2,812** | **95** | **3.4%** | **72** | **2.6%** | **75.8%** | **6** | **0.2%** | **6.3%** |

95 of 2,812 queries (3.4%) parse to the IR, 72 (2.6%) compile end-to-end to
ES\|QL, and 6 (0.2%) to PromQL. The low SPL1 detection figure is parser
coverage, not emitter coverage — `tstats` alone accounts for 1,022 of the
refusals. Where a query does parse, ES\|QL emits for 75.8% and PromQL for 6.3%.

The 89 PromQL refusals are deliberate. The largest single cause is
`promql-no-aggregation` (21): the pipeline does not end in an aggregation, so
it produces rows rather than a time series. Another 44 use a stage with no
PromQL form — `eval` 18, `table` 10, `rex` 7, `rename` 6, `fields` 2, `bin` 1 —
and 16 combine or name an aggregation PromQL cannot express. The remaining 8
are refused over ordering, free-text terms, or row filters.
| **Total** | **2,812** | **679** | **24.1%** | **669** | **23.8%** | **98.5%** | **6** | **0.2%** | **0.9%** |

679 of 2,812 queries (24.1%) parse to the IR, 669 (23.8%) compile end-to-end to
ES\|QL, and 6 (0.2%) to PromQL. Where a query does parse, ES\|QL emits for
98.5% and PromQL for 0.9%.

The remaining parser refusals are commands and value syntax the front-end does
not implement yet — `IN (...)` value lists, `fillnull`, `bucket`, `spath`,
`mstats`, `transaction`, `chart`, `lookup`, `metadata`, and `top`, plus hex
literals and free-text runs such as `*GetCurrent()*`.

The 10 ES\|QL refusals are aggregations and spans with no verified translation:
`range`, `per_day`/`per_hour`/`per_minute`, and `first`/`last` (6), regexes
with no named capture (2), one timechart span with a week alignment, and one
`tstats` placed after another stage.

The 673 PromQL refusals are deliberate. The largest cause is a stage with no
PromQL form (628): `tstats` 584, `eval` 18, `table` 10, `rex` 7, `rename` 6,
`fields` 2, `bin` 1. Another 21 do not end in an aggregation, 16 combine or
name an aggregation PromQL cannot express, and 8 are refused over ordering,
free-text terms, or row filters.

Regenerate with `make corpus-report`; it prints this table from the corpus.

Expand Down
2 changes: 2 additions & 0 deletions conformance/cases/tstats/aggregations.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM logs-endpoint-processes-*
| STATS count = COUNT(*), firstSeen = EARLIEST(`@timestamp`), lastSeen = LATEST(`@timestamp`), firstTime = MIN(`@timestamp`), lastTime = MAX(`@timestamp`), process_names = VALUES(process_name), hosts = COUNT_DISTINCT(`destination.address`) BY `destination.address`
22 changes: 22 additions & 0 deletions conformance/cases/tstats/aggregations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"description": "acceleration options are ignored with an info diagnostic; earliest, latest, values, and dc become ES|QL aggregations",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-option",
"severity": "info",
"line": 1,
"col": 1
},
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 188
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/aggregations.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats summariesonly=false allow_old_summaries=true fillnull_value=null count earliest(_time) as firstSeen latest(_time) as lastSeen min(_time) as firstTime max(_time) as lastTime values(Processes.process_name) as process_names dc(Processes.dest) as hosts FROM datamodel=Endpoint.Processes BY Processes.dest
3 changes: 3 additions & 0 deletions conformance/cases/tstats/basic.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM logs-web-*
| WHERE status == 500
| STATS count = COUNT(*) BY `source.address`, `destination.address`
16 changes: 16 additions & 0 deletions conformance/cases/tstats/basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "tstats resolves the data model to an index and drops data-model field prefixes before the field dictionary runs",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 39
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/basic.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web WHERE Web.status=500 BY Web.src, Web.dest
3 changes: 3 additions & 0 deletions conformance/cases/tstats/dotted-names.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM logs-web-*
| WHERE `source.address` == "10.0.0.1"
| STATS count = COUNT(*) BY `source.address`
16 changes: 16 additions & 0 deletions conformance/cases/tstats/dotted-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "only a data-model node prefix is dropped; source.address is a column and is left alone",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 68
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/dotted-names.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web WHERE source.address="10.0.0.1" BY Web.src
4 changes: 4 additions & 0 deletions conformance/cases/tstats/downstream.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM logs-web-*
| WHERE status == 500
| STATS count = COUNT(*) BY `source.address`
| KEEP `source.address`, count
16 changes: 16 additions & 0 deletions conformance/cases/tstats/downstream.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "data-model field references resolve the same way in later stages",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 39
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/downstream.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web WHERE Web.status=500 BY Web.src | table Web.src, count
13 changes: 13 additions & 0 deletions conformance/cases/tstats/fillnull-negative.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "a signed fillnull_value parses and is refused by value, not as a syntax error",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"error": {
"code": "tstats-fillnull",
"line": 1,
"col": 8
}
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/fillnull-negative.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats fillnull_value=-1 count FROM datamodel=Web
13 changes: 13 additions & 0 deletions conformance/cases/tstats/fillnull-value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "a non-null fillnull_value has no exact translation and is refused at the option",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"error": {
"code": "tstats-fillnull",
"line": 1,
"col": 8
}
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/fillnull-value.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats fillnull_value="n/a" count FROM datamodel=Web
3 changes: 3 additions & 0 deletions conformance/cases/tstats/index-filter.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM legacy
| WHERE status == 500
| STATS count = COUNT(*) BY `source.address`
16 changes: 16 additions & 0 deletions conformance/cases/tstats/index-filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "an index filter in the WHERE clause wins over the data model's mapped index",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 52
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/index-filter.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web WHERE index=legacy Web.status=500 BY Web.src
3 changes: 3 additions & 0 deletions conformance/cases/tstats/late-prefix.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM logs-web-*
| STATS count = COUNT(*)
| KEEP `source.address`
16 changes: 16 additions & 0 deletions conformance/cases/tstats/late-prefix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "a data-model field first referenced after the tstats stage is resolved and still warns",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 35
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/late-prefix.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web | table Web.src
2 changes: 2 additions & 0 deletions conformance/cases/tstats/no-source.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM logs-*
| STATS count = COUNT(*) BY `host.name`
3 changes: 3 additions & 0 deletions conformance/cases/tstats/no-source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"description": "a data-model aggregation with neither a data model nor an index filter searches the default index"
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/no-source.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count BY host
13 changes: 13 additions & 0 deletions conformance/cases/tstats/not-first.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "tstats reads a data model, so it cannot follow another stage",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"error": {
"code": "tstats-position",
"line": 1,
"col": 13
}
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/not-first.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index=web | tstats count FROM datamodel=Web
13 changes: 13 additions & 0 deletions conformance/cases/tstats/promql.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "PromQL has no data-model aggregation, so tstats is refused at its token",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"promql": {
"error": {
"code": "promql-unsupported-stage",
"line": 1,
"col": 1
}
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/promql.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web
2 changes: 2 additions & 0 deletions conformance/cases/tstats/span-without-time.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM logs-web-*
| STATS count = COUNT(*) BY `source.address`
22 changes: 22 additions & 0 deletions conformance/cases/tstats/span-without-time.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"description": "a span without _time in the BY list is ignored with a warning",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 36
},
{
"code": "tstats-span",
"severity": "warning",
"line": 1,
"col": 44
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/span-without-time.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web BY Web.src span=5m
2 changes: 2 additions & 0 deletions conformance/cases/tstats/span.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM logs-web-*
| STATS count = COUNT(*) BY BUCKET(`@timestamp`, 5 minutes), `source.address`
16 changes: 16 additions & 0 deletions conformance/cases/tstats/span.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "a span on _time becomes BUCKET on the timestamp field",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 50
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/span.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web BY _time span=5m Web.src
3 changes: 3 additions & 0 deletions conformance/cases/tstats/time-bounds.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM logs-web-*
| WHERE `@timestamp` >= NOW() - 7 days AND status == 500
| STATS count = COUNT(*) BY `source.address`
16 changes: 16 additions & 0 deletions conformance/cases/tstats/time-bounds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "earliest and latest are lifted out of the data-model WHERE clause",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"diagnostics": [
{
"code": "tstats-field-prefix",
"severity": "warning",
"line": 1,
"col": 52
}
]
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/time-bounds.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats count FROM datamodel=Web WHERE earliest=-7d Web.status=500 BY Web.src
13 changes: 13 additions & 0 deletions conformance/cases/tstats/unknown-option.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "an unknown tstats option is refused at its name",
"mapping": "../../fixtures/mappings/tstats.json",
"targets": {
"esql": {
"error": {
"code": "tstats-unknown-option",
"line": 1,
"col": 8
}
}
}
}
1 change: 1 addition & 0 deletions conformance/cases/tstats/unknown-option.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tstats chunk_size=1000 count FROM datamodel=Web
3 changes: 3 additions & 0 deletions conformance/cases/tstats/unmapped-datamodel.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM logs-*
| WHERE action == "created"
| STATS count = COUNT(*) BY user
Loading
Loading