logsql

package
v0.6.45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logsql builds VictoriaLogs LogsQL queries. Values enter only through its functions, quoted (and turned into escaped regular expressions where a pattern is needed); field names are the caller's constants, checked and quoted too. There is no raw LogsQL input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field string

Field is a stored field name.

func (Field) Contains

func (f Field) Contains(value string, fold bool) Filter

Contains: the field contains value, case-insensitive when fold.

func (Field) Eq

func (f Field) Eq(value string) Filter

Eq: the field equals value exactly (the stream id matches by id).

func (Field) Name

func (f Field) Name() string

Name is the field as a pipe argument.

func (Field) Prefix

func (f Field) Prefix(value string) Filter

Prefix: the field starts with value.

func (Field) Regexp

func (f Field) Regexp(pattern string) Filter

Regexp: the field matches a pattern the caller built from constants.

func (Field) Set

func (f Field) Set() Filter

Set: the field is stored and not empty (LogsQL does not tell them apart).

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter is a LogsQL filter expression.

func All

func All() Filter

All matches every record.

func And

func And(filters ...Filter) Filter

And holds when every filter holds (empty ones skipped).

func Not

func Not(f Filter) Filter

Not negates.

func Or

func Or(filters ...Filter) Filter

Or holds when any filter holds (empty ones skipped).

func Range

func Range(start, end time.Time) Filter

Range: records in [start, end).

func (Filter) IsZero

func (f Filter) IsZero() bool

IsZero reports an empty filter (matches nothing is never implied).

func (Filter) String

func (f Filter) String() string

String is the filter as LogsQL.

type Order

type Order struct {
	Field Field
	Desc  bool
}

Order is one sort key.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a filter followed by pipes.

func From

func From(filter Filter) Query

From starts a query over filter.

func (Query) CountByTime

func (q Query) CountByTime(timeField Field, step time.Duration, hits Field) Query

CountByTime counts rows per step of time as hits.

func (Query) Fields

func (q Query) Fields(fields ...Field) Query

Fields keeps only fields.

func (Query) Hash

func (q Query) Hash(as Field) Query

Hash adds as the hash of the whole record (packed as JSON).

func (Query) LastBy

func (q Query) LastBy(by, partition Field) Query

LastBy keeps, per value of partition, the record with the greatest by.

func (Query) Sort

func (q Query) Sort(limit int, keys ...Order) Query

Sort orders by keys and keeps the first limit.

func (Query) Stats

func (q Query) Stats(key Field, stats ...Stat) Query

Stats aggregates per value of by.

func (Query) String

func (q Query) String() string

String is the query as LogsQL.

func (Query) Sum

func (q Query) Sum(a, b, alias Field) Query

Sum sets as to a + b; math takes plain names (aliases of Stats).

func (Query) Where

func (q Query) Where(f Filter) Query

Where filters the pipe's rows.

type Stat

type Stat struct {
	// contains filtered or unexported fields
}

Stat is one aggregate of Stats.

func CountIf

func CountIf(cond Filter, as Field) Stat

CountIf counts rows matching if.

func CountUniqIf

func CountUniqIf(field Field, cond Filter, as Field) Stat

CountUniqIf counts distinct values of field among rows matching if.

func Max

func Max(field, as Field) Stat

Max is the greatest value of field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL