lql

package
v0.1.48 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

lql package contains parser's functions and structures for working with Logrange Query Language (LQL) The LQL supports the following constructions so far:

SELECT [<format string>] [FROM ({<tags>}|<tags expression)] [RANGE <time range>] [WHERE <fields expression>] [POSITION (head|tail|<specific pos>)] [OFFSET <number>][LIMIT <number>]
SHOW PARTITIONS [({<tags>}|<tags expression)][OFFSET <number>][LIMIT <number>]
SHOW PIPES [OFFSET <number>][LIMIT <number>]
DESCRIBE PARTITION {<tags>}
DESCRIBE PIPE <pipe name>
TRUNCATE  [({<tags>}|<tags expression)][MINSIZE <size>][MAXSIZE <size>][BEFORE <timestamp>][MAXDBSIZE <size>]
CREATE PIPE <pipe name> [FROM ({<tags>}|<tags expression)] [WHERE <fields expression>]
DELETE PIPE <pipe name>

This file is copied from github.com/alecthomas/participle/lexer and modified to provide choosing longest match regexp functionality

Index

Constants

View Source
const (
	CMP_CONTAINS   = "CONTAINS"
	CMP_HAS_PREFIX = "PREFIX"
	CMP_HAS_SUFFIX = "SUFFIX"
	CMP_LIKE       = "LIKE"
)
View Source
const (
	OPND_TIMESTAMP = "ts"
	OPND_MESSAGE   = "msg"
)

fixed operands names

Variables

View Source
var PositiveTagsExpFunc = func(tag.Set) bool { return true }

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Ident *Identifier `  @@`
	Op    string      ` (@("<"|">"|">="|"<="|"!="|"="|"CONTAINS"|"PREFIX"|"SUFFIX"|"LIKE"))`
	Value string      ` (@String|@Ident|@Number)`
}

func (*Condition) String

func (c *Condition) String() string

type Create

type Create struct {
	Pipe *Pipe `(@@)?`
}

type DateTime

type DateTime int64

func (*DateTime) Capture

func (dt *DateTime) Capture(values []string) error

func (*DateTime) GetValue

func (dt *DateTime) GetValue() uint64

func (*DateTime) String

func (dt *DateTime) String() string

type Delete

type Delete struct {
	PipeName *string `("PIPE" @Ident)?`
}

type Describe

type Describe struct {
	Partition *TagsVal `("PARTITION" @Tags`
	Pipe      *string  `|"PIPE" @Ident)`
}

func (*Describe) String

func (d *Describe) String() string

type Expression

type Expression struct {
	Or []*OrCondition `@@ { "OR" @@ }`
}

func ParseExpr

func ParseExpr(where string) (*Expression, error)

func (*Expression) String

func (ex *Expression) String() string

type Identifier added in v0.1.1

type Identifier struct {
	Operand string        `  (@Ident|@Keyword)`
	Params  []*Identifier ` ("("@@ {"," @@} ")")?`
}

func (*Identifier) String added in v0.1.1

func (id *Identifier) String() string

type Lql

type Lql struct {
	Select   *Select   `("SELECT" (@@)?`
	Describe *Describe `|"DESCRIBE" (@@)?`
	Truncate *Truncate `|"TRUNCATE" (@@)?`
	Show     *Show     `|"SHOW" (@@)?`
	Create   *Create   `|"CREATE" (@@)?`
	Delete   *Delete   `|"DELETE" (@@)?)`
}

func ParseLql

func ParseLql(lql string) (*Lql, error)

func (*Lql) String

func (l *Lql) String() string

type OrCondition

type OrCondition struct {
	And []*XCondition `@@ { "AND" @@ }`
}

type Partitions

type Partitions struct {
	Source *Source `(@@)?`
	Offset *int    `("OFFSET" @Number)?`
	Limit  *int    `("LIMIT" @Number)?`
}

type Pipe

type Pipe struct {
	Name  string      `"PIPE" @Ident`
	From  *Source     `("FROM" @@)?`
	Where *Expression `("WHERE" @@)?`
}

func (*Pipe) String

func (p *Pipe) String() string

type Pipes

type Pipes struct {
	// The Void is not going to be used, but it is here to full the parser to parse
	// `show pipes` properly
	Void   *Source `(@@)?`
	Offset *int64  `("OFFSET" @Number)?`
	Limit  *int64  `("LIMIT" @Number)?`
}

type Position

type Position struct {
	PosId string `(@"TAIL"|@"HEAD"|@String|@Ident)`
}

type Range added in v0.1.0

type Range struct {
	TmPoint1 *DateTime `("[")? (@String)?`
	TmPoint2 *DateTime `(":" @String "]")?`
}

func (*Range) String added in v0.1.0

func (r *Range) String() string

type Select

type Select struct {
	Format   *string     `(@String)?`
	Source   *Source     `("FROM" @@)?`
	Range    *Range      `("RANGE" @@)?`
	Where    *Expression `("WHERE" @@)?`
	Position *Position   `("POSITION" @@)?`
	Offset   *int64      `("OFFSET" @Number)?`
	Limit    *int64      `("LIMIT" @Number)?`
}

type Show

type Show struct {
	Partitions *Partitions `("PARTITIONS" (@@)?`
	Pipes      *Pipes      `|"PIPES" (@@)?)`
}

func (*Show) String

func (s *Show) String() string

type Size

type Size uint64

func (*Size) Capture

func (sz *Size) Capture(values []string) error

func (*Size) GetValue

func (sz *Size) GetValue() uint64

type Source

type Source struct {
	Tags *TagsVal    ` @Tags`
	Expr *Expression ` | @@ `
}

func ParseSource

func ParseSource(source string) (*Source, error)

func (*Source) String

func (src *Source) String() string

type TagsExpFunc

type TagsExpFunc func(tags tag.Set) bool

TagsExpFunc returns true if the provided tag are matched with the expression

func BuildTagsExpFunc

func BuildTagsExpFunc(tagsCond string) (TagsExpFunc, error)

BuildTagsExpFuncByCond receives a condition line and parses it to the TagsExpFunc The tagCond could be provided in one of the following 2 forms:

  • conditions like: name=app1 and ip like '123.*'
  • tag-line like: {name=app1,ip=123.46.32.44}

func BuildTagsExpFuncBySource

func BuildTagsExpFuncBySource(src *Source) (TagsExpFunc, error)

BuildTagsExpFuncBySource

type TagsVal

type TagsVal struct {
	Tags tag.Set
}

func (*TagsVal) Capture

func (tv *TagsVal) Capture(values []string) error

type Truncate

type Truncate struct {
	DryRun    bool      `(@"DRYRUN")?`
	Source    *Source   `(@@)?`
	MinSize   *Size     `("MINSIZE" @Number)?`
	MaxSize   *Size     `("MAXSIZE" @Number)?`
	Before    *DateTime `("BEFORE" @String)?`
	MaxDbSize *Size     `("MAXDBSIZE" @Number)?`
}

func (*Truncate) GetBefore

func (t *Truncate) GetBefore() uint64

func (*Truncate) GetMaxSize

func (t *Truncate) GetMaxSize() uint64

func (*Truncate) GetMinSize

func (t *Truncate) GetMinSize() uint64

func (*Truncate) GetTagsCond

func (t *Truncate) GetTagsCond() string

func (*Truncate) IsDryRun

func (t *Truncate) IsDryRun() bool

func (*Truncate) String

func (t *Truncate) String() string

type WhereExpFunc

type WhereExpFunc func(le *model.LogEvent) bool

WhereExpFunc returns true if the provided LogEvent matches the where condition

func BuildWhereExpFunc

func BuildWhereExpFunc(wCond string) (WhereExpFunc, error)

BuildWhereExpFunc buildw WHERE condition by the condition human readable form like `a=b AND c=d`

func BuildWhereExpFuncByExpression

func BuildWhereExpFuncByExpression(exp *Expression) (WhereExpFunc, error)

BuildWhereExpFuncByExpression builds where function by the Expression provided

type XCondition

type XCondition struct {
	Not  bool        ` [@"NOT"] `
	Cond *Condition  `( @@`
	Expr *Expression `| "(" @@ ")")`
}

Jump to

Keyboard shortcuts

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