aql

package
v0.0.0-...-abd831d Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2018 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QUERY tokenType = iota
	TEST
	DESCRIPTION
	TRANSFORM
	FROM
	INTO
	EXTERN
	INCLUDE
	LPAREN
	RPAREN
	PAREN_BODY
	WITH
	EQUALS
	COMMA
	QUOTED_STRING
	NUMBER
	IDENTIFIER
	GLOBAL
	CONNECTION
	BLOCK
	AS
	EOF
	AFTER
	PLUGIN
	DECLARE
	USING
	PARAMETER
	CONSOLE
	SET
	EXEC
	DATA
	ASSERTIONS
)
View Source
const MaxIncludeDepth = 8

MaxIncludeDepth is the maximum depth of includes that will be processed before an error is returned.

Variables

This section is empty.

Functions

func ParseExcelRange

func ParseExcelRange(s string) (x1 int, x2 *int, y1 int, y2 *int, err error)

ParseExcelRange parses a range of the form 'A1:C4' with possible wildcards such as 'A1:*4'

func ScanOptions

func ScanOptions(scanner OptScanner, maybeScanner MaybeOptScanner, dest interface{}) error

ScanOptions uses reflection with the "aql" struct tag to scan options. The tags are:

	aql: "<case_insensitive_option_name>"
 aql: "<case_insensitive_option_name>, optional"

Types

type Assertion

type Assertion struct {
	Global *GlobalAssertion `"IT " @@`
	Column *ColumnAssertion `| "COLUMN " @@`
}

func NewAssertion

func NewAssertion(aqlBody string) (*Assertion, error)

func ParseAssertions

func ParseAssertions(aql string) ([]Assertion, error)

type Block

type Block interface {
	GetName() string
	GetOptions() []Option
}

type ColumnAssertion

type ColumnAssertion struct {
	TargetColumn *string `@Ident "HAS" `
	Distinct     *HasN   `(@@ "DISTINCT " "VALUES"`
	NoDuplicates bool    `| @"UNIQUE " "VALUES"`
	NoNulls      bool    `|@"NO " "NULL " "VALUES")`
}

type Connection

type Connection struct {
	Name             string
	Driver           string
	ConnectionString string
	Options          []Option
}

type Data

type Data struct {
	Name         string       `DATA @QUOTED_STRING`
	Extern       *string      `[EXTERN @QUOTED_STRING]`
	Content      string       `['(' @PAREN_BODY ')']`
	Destinations []SourceSink `[INTO @@ {"," @@}]`
	Options      []Option     `[WITH '(' @@ {"," @@} ')' ]`
}

func (*Data) GetName

func (d *Data) GetName() string

func (*Data) GetOptions

func (d *Data) GetOptions() []Option

type Declaration

type Declaration struct {
	Name string `DECLARE @IDENT`
}

type Description

type Description struct {
	Content string `DESCRIPTION @QUOTED_STRING`
}

type ForwardLexer

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

func (*ForwardLexer) Next

func (f *ForwardLexer) Next() lexer.Token

func (*ForwardLexer) Peek

func (f *ForwardLexer) Peek() lexer.Token

type Global

type Global struct {
	Name    string   `GLOBAL @QUOTED_STRING`
	Content string   `'(' @PAREN_BODY ')'`
	Options []Option `[WITH '(' @@ {"," @@ } ')' ]`
}

type GlobalAssertion

type GlobalAssertion struct {
	NRows *HasN   `"OUTPUTS " @@ "ROWS"`
	Expr  *string `| "SATISFIES " @Any`
}

type GlobalOption

type GlobalOption struct {
	Key   string       `SET @IDENT '='`
	Value *OptionValue `@@`
}

type HasN

type HasN struct {
	AtLeast bool `(@"AT LEAST "`
	AtMost  bool `| @"AT MOST "`
	Exactly bool `| @"EXACTLY ")`
	N       int  `@Number `
}

type Include

type Include struct {
	Source string `INCLUDE @QUOTED_STRING`
}

type Item

type Item struct {
	ID         tokenType
	LineNumber int
	Content    string
}

func Lex

func Lex(s string) ([]Item, error)

type JobScript

type JobScript struct {
	Description   *Description         `[@@]`
	Queries       []Query              `{QUERY @@`
	Data          []Data               `| @@`
	Declarations  []Declaration        `| @@`
	Connections   []UnparsedConnection `| @@`
	Includes      []Include            `| @@ `
	Tests         []Test               `| @@ `
	Execs         []Query              `|EXEC @@ `
	Globals       []Global             `| @@ `
	GlobalOptions []GlobalOption       `| @@ `
	Transforms    []Transform          ` | @@ }`
}

func ParseFile

func ParseFile(path string) (b *JobScript, err error)

ParseFile parses an AQL file into a JobScript struct.

func ParseString

func ParseString(s string) (b *JobScript, err error)

ParseString parses an AQL string into a JobScript struct.

func (*JobScript) EvaluateParametrizedContent

func (b *JobScript) EvaluateParametrizedContent(globals []Option) error

func (*JobScript) EvaluateParametrizedExtern

func (b *JobScript) EvaluateParametrizedExtern(globals []Option) error

func (*JobScript) ParseConnections

func (b *JobScript) ParseConnections() ([]Connection, error)

func (*JobScript) ResolveExternalContent

func (b *JobScript) ResolveExternalContent(cwd string) error

type MaybeOptScanner

type MaybeOptScanner func(needle string, dest interface{}) (bool, error)

func MaybeOptionScanner

func MaybeOptionScanner(blockName, namespace string, scope ...[]Option) MaybeOptScanner

type OptScanner

type OptScanner func(needle string, dest interface{}) error

func OptionScanner

func OptionScanner(blockName, namespace string, scope ...[]Option) OptScanner

type Option

type Option struct {
	Key   string       `@IDENT '='`
	Value *OptionValue `@@`
}

func FindOption

func FindOption(options []Option, needle string) (*Option, bool)

FindOption traverses the slice of options and returns the one whose key matches the needle. The search is case-insensitive. The second argument indicates whether the needle was found or not.

func FindOverridableOption

func FindOverridableOption(needle string, namespace string, hierarchy ...[]Option) (*Option, bool)

FindOverridableOption searches for the needle in the option hierarchy, in the order that they are given, first looking for the namespaced option and then the generic. The first found option is returned. For example: Looking for SHEET option given QUERY options and CONN options, connection 'ExcelA', would be accomplished with FindOverridableOption("SHEET", "ExcelA", query.Options, conn.Options)

func StrToOpts

func StrToOpts(s string) ([]Option, error)

StrToOpts converts an option string of the form Key1:Val1,Key2:Val2 into a slice of Options.

func (Option) String

func (opt Option) String() (string, bool)

String returns the option value as a string. The boolean return parameter will be true if the option was a string and false otherwise.

func (Option) Truthy

func (opt Option) Truthy() bool

Truthy returns whether an option value is truthy. Non-zero numbers are truthy and case-insensitive variants of 'true' are truthy. All other strings and numbers are falsy.

type OptionValue

type OptionValue struct {
	Str    *string  ` @QUOTED_STRING`
	Number *float64 `| @NUMBER`
}

type Query

type Query struct {
	Name         string       `@QUOTED_STRING`
	Extern       *string      `[EXTERN @QUOTED_STRING]`
	Sources      []SourceSink `FROM @@ { "," @@ }`
	Content      string       `['(' @PAREN_BODY ')' ]`
	Parameters   []string     `[USING PARAMETER @IDENT { "," @IDENT }]`
	Destinations []SourceSink `[INTO @@ { "," @@ } ]`
	Options      []Option     `[WITH '(' @@ {"," @@ } ')' ]`
	Dependencies []string     `[AFTER @IDENT {"," @IDENT }]`
}

func (*Query) GetName

func (q *Query) GetName() string

func (*Query) GetOptions

func (q *Query) GetOptions() []Option

type SourceSink

type SourceSink struct {
	Database  *string  `( CONNECTION @IDENT`
	Global    bool     `| @GLOBAL`
	Console   bool     `| @CONSOLE`
	Variables []string `| PARAMETER '(' @IDENT {"," @IDENT } ')'`
	Block     *string  `| BLOCK @IDENT)`
	Alias     *string  `[AS @QUOTED_STRING]`
}

type Test

type Test struct {
	TargetBlock string   `TEST @IDENT WITH ASSERTIONS`
	Extern      *string  `[EXTERN @QUOTED_STRING]`
	Content     string   `['(' @PAREN_BODY ')']`
	Options     []Option `[WITH '(' @@ {"," @@ } ')' ]`
}

func (*Test) Parse

func (t *Test) Parse() ([]Assertion, error)

type Transform

type Transform struct {
	Plugin       bool          `TRANSFORM [@PLUGIN]`
	Name         string        `@QUOTED_STRING`
	Extern       *string       `[EXTERN @QUOTED_STRING]`
	Sources      []*SourceSink `FROM @@ {"," @@}`
	Content      string        `['(' @PAREN_BODY ')']`
	Destinations []SourceSink  `[INTO @@ {"," @@}]`
	Options      []Option      `[WITH '(' @@ {"," @@ } ')' ]`
	Dependencies []string      `[AFTER @IDENT {"," @IDENT }]`
}

func (*Transform) GetName

func (q *Transform) GetName() string

func (*Transform) GetOptions

func (q *Transform) GetOptions() []Option

type UnparsedConnection

type UnparsedConnection struct {
	Name    string   `CONNECTION @QUOTED_STRING`
	Content string   `'(' @PAREN_BODY ')'`
	Options []Option `[WITH '(' @@ {"," @@ } ')' ]`
}

Source Files

  • assertions.go
  • lexer.go
  • parser.go

Jump to

Keyboard shortcuts

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