Repository navigation
Conversation
tstats aggregates fields of a Splunk data model. It is not a stats stage with a different source: it names a data model, accepts acceleration options, and writes fields as Dataset.attribute, so it gets its own IR node. Keeping the data model, the options, and the span separate lets an emitter resolve each one on its own terms. The grammar parses the options, then the aggregations, then FROM, WHERE, and BY in that order. FROM, WHERE, and BY are excluded from the aggregation word so `tstats count by host` is unambiguously one aggregation and a BY clause; the choice is made from the token type alone, because SLL prediction cannot consult a semantic predicate to make it. `datamodel` after FROM is parsed as an identifier and validated by the builder, so a misspelling is refused at that word with the expected spelling in the message. earliest and latest are lifted out of WHERE with the same helper a search stage uses, because they are global search modifiers there too. A later span= wins over an earlier one, matching bin. tstatsAggWord admits every keyword as an aggregation name except the three clause starts, so `tstats count by by` still groups by a field named by. Tests: stage, aggregation, option, clause, and time-bound lowering with exact positions; a table of missing-argument positions; and the FROM datamodel-name refusal.
tstats names a data model, not an index, and the two namespaces are unrelated: `datamodel=Endpoint.Processes` says nothing about where those events live in Elasticsearch. Add a `datamodels` key that supplies the index pattern for a data-model name, alongside `indexes`. The lookup returns (string, bool) rather than a bare string so an unmapped data model is distinguishable from one mapped to the empty string. Falling back to the default index is the emitter's decision to make, and it needs to warn when it happens. Tests cover the default mapping having no data models, a mapped value, an empty-string entry not counting as a mapping, and case-sensitive names.
A tstats stage lowers to the same pieces as a search followed by an aggregation, so the emitter builds a search from the stage's WHERE clause and then a STATS line, and the existing search and aggregation code does the work. Aggregations gain values, earliest, and latest, which tstats detections use heavily. The FROM value is resolved in the order that keeps the query's own intent first: --index, then an index= filter inside WHERE, then the mapping's datamodels, then the default index. An unmapped data model warns at its name rather than silently searching the wrong index, and an empty mapping value is not a mapping. Data-model field references keep their Dataset.attribute spelling for the whole pipeline, so a later table or stats stage resolves them exactly as tstats did. The prefix is dropped to the attribute name and the field dictionary is applied after that. Stripping is lossy in general, so the first dropped prefix produces one tstats-field-prefix warning. Options are handled by what they mean. summariesonly, allow_old_summaries, and prestats only describe Splunk's summary index, so they do not change the result and produce one info diagnostic; fillnull_value=null is the natural state of COUNT and passes; any other value is refused, because ES|QL has no equivalent fill. An unknown option is refused at its name instead of being ignored. A span applies to _time only, so it becomes BUCKET(@timestamp, N unit) when _time is grouped and warns when it is not. tstats after stage 0 is refused with tstats-position, since the data model determines FROM.
Thirteen cases for the new stage: the full form with options, aggregations, and a data model that is mapped; a mapped data model with a prefix on every field; a span bucketing _time; a span without _time; an index filter in WHERE overriding the data model; no source at all; an unmapped data model; time bounds lifted out of WHERE; a later stage resolving a prefixed field; and the four refusals — non-null fill, an unknown option, a tstats after another stage, and PromQL. Each carries its own mapping fixture so the cases do not depend on the default one. The corpus is re-recorded: 584 previously refused detections now parse, and 669 compile end to end, because tstats queries are a large share of the refusal baseline.
Move tstats out of the refused-command list and give it a row in the support tables. The compatibility page records the source-resolution order, the option policy, span handling, and the seven new diagnostic codes. The mapping page gains the datamodels key and explains why prefix stripping warns. The README report table and its prose are regenerated from the corpus: 679 queries parse (24.1%), 669 (23.8%) compile to ES|QL, and 6 (0.2%) to PromQL. The refusal breakdowns are measured rather than estimated, and name what is left — IN value lists and commands such as fillnull, bucket, and spath on the parser side, and tstats on the PromQL side.
be-thomas
commented
Oct 26, 2026
be-thomas
commented
Oct 26, 2026
be-thomas
commented
Oct 26, 2026
Review of the tstats support found that prefix stripping ran on every dotted
name once a tstats stage had been emitted, because a single boolean governed
the whole pipeline. ECS names are dotted by design, so
tstats count FROM datamodel=Web WHERE source.address="10.0.0.1"
emitted `WHERE address == ...`, and `host.name` in a later eval became
`name`. The mapping does not correct it: `host.name` is not a key in the
field dictionary, so an already-correct name was silently corrupted.
Stripping now depends on the data model rather than on having seen a
tstats stage. The emitter holds the names a data-model reference can be
prefixed with — the model name and its root dataset, longest first — and
drops only a prefix that matches one of them followed by a dot. Everything
else is a column name and resolves through the mapping as before.
The same review found the `tstats-field-prefix` warning was emitted at the
end of the tstats stage, so a prefix first used later
(`tstats … | table Web.src`) was dropped silently. The warning now comes
at the end of the pipeline walk, which also covers that case; diagnostics
are sorted before they are returned, so the position is unchanged for the
in-stage case.
tstatsOptionValue allowed an unsigned number, so `fillnull_value=-1` was a syntax error at the minus instead of the value refusal the emitter has for every non-null fill. Allow a sign before the number; the builder slices the source, so the value reaches the emitter as "-1" and is refused there with tstats-fillnull at the option name.
Three cases from the review of the tstats support: - dotted-names: `source.address` in WHERE and a `Web.src` group. Only the data-model prefix is dropped, so the ECS column is unchanged and the warning points at Web.src. - late-prefix: a prefixed field first referenced after the tstats stage is resolved the same way and still warns. - fillnull-negative: `fillnull_value=-1` parses and is refused by value.
Record that only the data model name or its root dataset is dropped from a tstats field, that other dotted names are columns, and that a prefix first used in a later stage also warns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
Adds
tstats, Splunk's data-model aggregation, across the parser, the IR, themapping, and the ES|QL emitter. PromQL refuses the stage.
tstatsgets its own IR node because it is not astatsstage over adifferent source: it names a data model, accepts acceleration options, and
writes fields as
Dataset.attribute. Keeping those three parts separate letseach emitter resolve them on its own terms.
--index, elseindex=inWHERE, elsedatamodels[<name>], elsedefault_indexsummariesonly,allow_old_summaries,prestatsignored with atstats-optioninfo;fillnull_value=nullaccepted; anything else refusedProcesses.dest→dest, then throughfields; onetstats-field-prefixwarning_time→@timestamp; withspan=→BUCKET(@timestamp, N unit)tstats-positionotherwisevalues,earliest, andlatestadded to ES|QLFiles
pkg/parser/spl1/grammar/SPL1.g4:tstatsBody,tstatsAgg*, option,FROM/WHERE/BY rules, and the
TSTATS/FROMkeyword tokens.pkg/ast/ast.go:TstatsStageandTstatsOption.pkg/parser/spl1/build.go: lowering, including thedatamodel=check.pkg/mapping/mapping.go:datamodelskey andConfig.Datamodel.pkg/emitter/esql/esql.go:tstatsIndex,emitTstats,tstatsOptions,tstatsGroups, prefix stripping, and the three new aggregations.cases/tstats/(13 cases) andfixtures/mappings/tstats.json.Two grammar notes that matter for review:
FROM,WHERE, andBYare excluded fromtstatsAggWord. SLL predictioncannot use a semantic predicate to choose between "another aggregation" and
"the next clause", so the choice is made from the token type alone.
datamodelafterFROMis parsed as an identifier and validated in thebuilder. That way a misspelling is refused at the word itself, with the
expected spelling in the message, instead of as a generic syntax error.
Tests run
make check— format, vet, tests, build: pass.go test -race ./...: pass.make generate-check: generated parsers are current.go test ./conformance -count=1: pass.make corpus-update;TestCorpuspasses.Measured over the corpus, 679 of 2,812 queries now parse (24.1%), 669 compile
end to end to ES|QL (23.8%), and 6 to PromQL (0.2%). 584 queries (567
detections and 17 documented examples) moved from
error:unsupported-commandto
accepted. Another 428 detections moved fromunsupported-commandtoerror:syntax, because the tstats stage now parses and then refuses the restof the pipeline at its real cause, often an
IN (...)value list.Open questions
Processes.destand a baredestare notguaranteed to be the same column, which is why it warns rather than being
silent. An alternative is a
datamodel_fieldsmapping key that names theECS column per
Dataset.attribute, at the cost of a larger mapping file.I kept the simpler form first; say if you want the explicit one.
fillnull_valueis refused unless it isnull. ES|QL has no fill stepin this translation. Emitting
COALESCEin a laterEVALwould change thecolumn shape, so refusing seemed closer to the "exact, warned, or refused"
rule than an approximation.
chunk_sizewouldbe harmless for results, but an unrecognised option may also be a typo for
one that does change results, so it fails loudly. Tell me if you prefer a
warning.
_timewarns and is dropped. Splunk appliesspan=to_time; if_timeis not grouped there is nothing to bucket, so thewarning names the reason rather than inventing a bucket column.