Help us shape the future of Go! Take the 2026 Go Developer Survey

kql

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package kql implements a subset of the Kusto Query Language for the Azure Monitor Logs emulator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTime

func FormatTime(t time.Time) string

FormatTime renders a datetime the way the query API returns it.

func FormatTimespan

func FormatTimespan(d time.Duration) string

FormatTimespan renders a timespan as [-][d.]hh:mm:ss[.fffffff].

func NormalizeJSON

func NormalizeJSON(v any) any

NormalizeJSON converts decoded JSON (float64 numbers) into engine dynamic values.

func Parse

func Parse(src string) error

Parse checks that src is syntactically valid and uses only supported operators.

func ParseDatetime

func ParseDatetime(s string) (time.Time, bool)

ParseDatetime parses the datetime formats KQL literals and ingested JSON accept.

func ParseTimespan

func ParseTimespan(s string) (time.Duration, bool)

ParseTimespan parses KQL timespan literal bodies such as 1d, 00:00:05 or 1.02:03:04.

func ResultValue

func ResultValue(t Type, v any) any

ResultValue converts a cell to its query-API JSON representation.

func ToString

func ToString(v any) string

ToString implements KQL tostring().

Types

type Col

type Col struct {
	Name string
	Type Type
}

Col is a named, typed column.

type Error

type Error struct {
	// Kind is the inner error code: SyntaxError or SemanticError.
	Kind string
	// Code is the innermost code, e.g. SYN0002 or SEM0100.
	Code    string
	Message string
}

Error is a query failure in the documented BadArgumentError shape.

func (*Error) Error

func (e *Error) Error() string

type Options

type Options struct {
	Now      time.Time
	Resolver Resolver
}

Options configures a query execution.

type Rel

type Rel struct {
	Cols []Col
	Rows [][]any
}

Rel is a materialised table. Cells hold nil, bool, int64, float64, string, time.Time, time.Duration, []any or map[string]any.

func Execute

func Execute(src string, opt Options) (*Rel, error)

Execute runs a query and returns its single result table.

type Resolver

type Resolver interface {
	// Table returns the named table of the workspace ("" is the query's own workspace).
	Table(workspace, name string) (*Rel, bool)
}

Resolver supplies workspace tables to the engine.

type Type

type Type string

Type is a KQL column type name as it appears in query results.

const (
	TBool     Type = "bool"
	TInt      Type = "int"
	TLong     Type = "long"
	TReal     Type = "real"
	TString   Type = "string"
	TDatetime Type = "datetime"
	TTimespan Type = "timespan"
	TDynamic  Type = "dynamic"
	TGUID     Type = "guid"
)

Column and expression types.

Jump to

Keyboard shortcuts

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