filter

package
v0.0.0-...-116ca14 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

Arc API filter parser

This package contains a parser to transform the filter syntax exposed by the API to a filter expression that can by used by the underlying fact storage system.

As we currently store the facts in a postgresql cloumn of type jsonb the parser currently produces a WHERE clause that uses postgresql specifc json operators.

Example:

fact1 = "1" OR fact2 != 2

is transformed to

( facts->>'fact1' = '1' OR (facts->>'fact2')::numeric <> 2 )

Implementation details

Both the lexer and parser are auto generated. The generated output parser.go and lexer.go are checked into version control, so unless you want to change the parser you don't need to bother with the following.

The lexer is generated using nex from the file filter.nex. It can be installed with go get https://github.com/blynn/nex

The parser is generated using go's yacc implmentation go tool yacc from the file filter.y. It comes with a standard go installation.

The filter.go file contains //go:generate stanzas to generate both the lexer and the parser for you. To modify the parser you just need to edit filter.y or filter.nex and run go generate in the package directory.

Documentation

Index

Constants

View Source
const AND = 57351
View Source
const FIELD = 57346
View Source
const NEQ = 57349
View Source
const NLIKE = 57350
View Source
const NOT = 57353
View Source
const NUMBER = 57348
View Source
const OR = 57352
View Source
const STRING = 57347

Variables

This section is empty.

Functions

func Postgresql

func Postgresql(query string) (string, error)

Types

type Lexer

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

func NewLexer

func NewLexer(in io.Reader) *Lexer

func NewLexerWithInit

func NewLexerWithInit(in io.Reader, initFun func(*Lexer)) *Lexer

NewLexerWithInit creates a new Lexer object, runs the given callback on it, then returns it.

func (*Lexer) Column

func (yylex *Lexer) Column() int

Column returns the current column number. The first column is 0.

func (*Lexer) Error

func (yylex *Lexer) Error(e string)

func (*Lexer) Lex

func (yylex *Lexer) Lex(lval *yySymType) int

Lex runs the lexer. Always returns 0. When the -s option is given, this function is not generated; instead, the NN_FUN macro runs the lexer.

func (*Lexer) Line

func (yylex *Lexer) Line() int

Line returns the current line number. The first line is 0.

func (*Lexer) Text

func (yylex *Lexer) Text() string

Text returns the matched text.

Jump to

Keyboard shortcuts

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