CQL reference

Sources, fields, operators, stages, aggregates, limits and error messages.

Verified against v1.0.0-rc.1 · sources

On this page

Model#

  • A query is search | stage | stage ....
  • The time range comes from the time picker, never from query text. Time fields cannot be filtered: the error is '<f>' is a time field: use the time picker.
  • Every literal is a bound ClickHouse parameter. Query text is never spliced into SQL.
  • Tenant isolation is a ClickHouse row policy, not the compiler.
  • Only one of stats, timechart, top, rare is allowed per query.

Sources#

Select a source with source=<name> as the first term of the query. The default is events.

SourceReadsFree text
eventslog eventsyes
gapsreconciler runs with missing eventsno
maskingmasked-value counts per ruleno
alertsalert state changesno
auditUI audit logno

Fields per source#

SourceFields
eventsts, ingest_ts, tenant, log_type, src, boot_id, seq, level, service, host, msg, http_status, http_path, duration_ms, user_tok, k8s_ns, auth_result, orig_ts, mask_flags, signature, norm_version; any other name is read from attrs
gapsat, win, run_id, tenant, src, boot_id, expected, stored, missing, dups, cause
maskingwin, tenant, log_type, rule, n
alertsat, rule_id, state, value
auditseq, at, user_id, action, target, result

An unknown field on a source other than events is an error that lists the valid fields.

Search expression#

FormMeaning
wordMessage contains the word, case-insensitive
"a phrase"Message contains the phrase, case-insensitive
c"Phrase"Message contains the phrase, case-sensitive
field=value, field!=valueEqual, not equal
field>n, >=, <, <=Numeric comparison. On a text field it is an error, except an attrs field with an unquoted number
field~patternRegular expression. A pattern without regex characters is a substring match. Not allowed on numeric fields
field IN (a,b,c)Any of the values
field:existsThe attr or text field is present and non-empty
AND, OR, NOT, ( )Boolean logic. Adjacent terms mean AND

Free text needs at least one letter or digit. Words of length 1 do not narrow the search on their own.

Stages#

The stage list is closed:

StageForm
wherewhere <expression>
statsstats <agg>[, <agg>...] [by f1, f2]
timecharttimechart span=<n><s|m|h|d> <agg> [by field] (span at most 30 days, one aggregate, one optional by)
toptop <n> <field>
rarerare <n> <field>
sortsort <field> ascending or sort -<field> descending
limitlimit <n> with 1 <= n <= 10000
fieldsfields f1, f2, ...

Aggregates#

count(), count_if(<condition>), dc(f) (distinct count), sum(f), avg(f), min(f), max(f), p50(f), p90(f), p95(f), p99(f). Add as <alias>; an alias cannot contain .. All except count and count_if need a field.

Limits#

LimitValue
Query length8192 bytes
Nesting depth64
Bound literals512
Result row cap10,000
Raw (no stats) result500 rows
Series in a timechart20, the rest fold into other
Execution time30 s
Rows read2,000,000,000
Bytes read200 GiB
Maximum range31 days. The viewer role is limited to 7 days

Errors#

The compiler returns an error with a 0-based byte offset pos and a message. The API answers 400 with position. Messages you can see:

Message
unterminated string
unbalanced ')'
unknown stage '<x>' (expected where, stats, timechart, top, rare, sort, limit, fields)
unknown aggregate '<x>' (expected one of count, count_if, dc, sum, avg, min, max, p50, p90, p95, p99)
<f>() needs a field
invalid field name '<x>'
expected integer 1..10000
query nested too deeply
bad duration (e.g. 30s, 5m, 1h, 1d; max 30d)
source= must be the first term of the query
only one of stats/timechart/top/rare per query
free-text search only works on source=events (use field=value for source=<name>)

Not in CQL#

Joins, subqueries, field extraction, lookups, several sources in one query, and a time range in the query text. See Not supported.

Sources

This page was checked against: crates/cql/src/lib.rs, crates/cql/tests/golden.rs, crates/cql/tests/safety.rs.

Report an inaccuracy (opens a new issue in the Drillo repository; nothing is sent from this page)