view

package
v0.0.0-...-8d187f3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NODE_FLAG_METRICS       int = iota // 仅在计算层
	NODE_FLAG_METRICS_INNER            // 仅在计算层内层
	NODE_FLAG_METRICS_OUTER            // 仅在计算层外层
	NODE_FLAG_METRICS_TOP              // 仅在最外层
)
View Source
const (
	METRICS_FLAG_INNER int = iota // METRICS专用FLAG,仅在计算层内层
	METRICS_FLAG_OUTER            // METRICS专用FLAG,仅在计算层外层
	METRICS_FLAG_TOP              // METRICS专用FLAG,在整体sql外再增加一层,仅包含该FLAG的字段
)
View Source
const (
	GROUP_FLAG_DEFAULT        int = iota // GROUP专用FLAG,计算层内外都携带group,with仅放计算层内层
	GROUP_FLAG_METRICS_OUTER             // GROUP专用FLAG,仅计算层外层携带该group
	GROUP_FLAG_METRICS_INNTER            // GROUP专用FLAG,仅计算层内层携带该group
)
View Source
const (
	MODEL_METRICS_LEVEL_FLAG_UNLAY   int = iota // 计算层不需要根据算子拆层
	MODEL_METRICS_LEVEL_FLAG_LAYERED            // 计算层需要根据算子拆层
)
View Source
const (
	FUNCTION_DIV_TYPE_DEFAULT          int = iota // 默认,不做任何处理
	FUNCTION_DIV_TYPE_FILL_MINIMUM                // 除数和被除数都+1e-15
	FUNCTION_DIV_TYPE_0DIVIDER_AS_NULL            // 除数为0时,结果为NULL
	FUNCTION_DIV_TYPE_0DIVIDER_AS_0               //除数为0时,结果为0
)

Div算子类型

View Source
const (
	FUNCTION_SUM           = "Sum"
	FUNCTION_MAX           = "Max"
	FUNCTION_MIN           = "Min"
	FUNCTION_AVG           = "Avg"
	FUNCTION_COUNTER_AVG   = "Counter_Avg"
	FUNCTION_DELAY_AVG     = "Delay_Avg"
	FUNCTION_AAVG          = "AAvg"
	FUNCTION_PCTL          = "Percentile"
	FUNCTION_PCTL_EXACT    = "PercentileExact"
	FUNCTION_STDDEV        = "Stddev"
	FUNCTION_SPREAD        = "Spread"
	FUNCTION_RSPREAD       = "Rspread"
	FUNCTION_APDEX         = "Apdex"
	FUNCTION_GROUP_ARRAY   = "groupArray"
	FUNCTION_DIV           = "/"
	FUNCTION_PLUS          = "+"
	FUNCTION_MINUS         = "-"
	FUNCTION_MULTIPLY      = "*"
	FUNCTION_COUNT         = "Count"
	FUNCTION_UNIQ          = "Uniq"
	FUNCTION_UNIQ_EXACT    = "UniqExact"
	FUNCTION_PERSECOND     = "PerSecond"
	FUNCTION_PERCENTAG     = "Percentage"
	FUNCTION_HISTOGRAM     = "Histogram"
	FUNCTION_LAST          = "Last"
	FUNCTION_TOPK          = "TopK"
	FUNCTION_ANY           = "Any"
	FUNCTION_DERIVATIVE    = "nonNegativeDerivative"
	FUNCTION_COUNTDISTINCT = "countDistinct"
)
View Source
const (
	OPERATOER_UNKNOWN int = iota
	AND
	OR
	NOT
	GTE
	LTE
	EQ
	NEQ
	LIKE
	NLIKE
	REGEXP
	NREGEXP
	GT
	LT
	IN
	NIN
)

Variables

View Source
var FUNC_NAME_MAP map[string]string = map[string]string{
	FUNCTION_SUM:         "SUM",
	FUNCTION_MAX:         "MAX",
	FUNCTION_MIN:         "MIN",
	FUNCTION_AAVG:        "AVG",
	FUNCTION_PCTL:        "quantile",
	FUNCTION_PCTL_EXACT:  "quantileExact",
	FUNCTION_STDDEV:      "stddevPopStable",
	FUNCTION_GROUP_ARRAY: "groupArray",
	FUNCTION_PLUS:        "plus",
	FUNCTION_DIV:         "Div",
	FUNCTION_MINUS:       "minus",
	FUNCTION_MULTIPLY:    "multiply",
	FUNCTION_COUNT:       "COUNT",
	FUNCTION_UNIQ:        "uniq",
	FUNCTION_UNIQ_EXACT:  "uniqExact",
	FUNCTION_LAST:        "last_value",
	FUNCTION_TOPK:        "topK",
	FUNCTION_ANY:         "any",
	FUNCTION_DERIVATIVE:  "nonNegativeDerivative",
}

对外提供的算子与数据库实际算子转换

Functions

func FormatField

func FormatField(field string) string

Types

type ApdexFunction

type ApdexFunction struct {
	DefaultFunction
	// contains filtered or unexported fields
}

func (*ApdexFunction) GetWiths

func (f *ApdexFunction) GetWiths() []Node

func (*ApdexFunction) Init

func (f *ApdexFunction) Init()

func (*ApdexFunction) WriteTo

func (f *ApdexFunction) WriteTo(buf *bytes.Buffer)

type BinaryExpr

type BinaryExpr struct {
	NodeBase
	Left  Node
	Right Node
	Op    *Operator
}

func (*BinaryExpr) ToString

func (n *BinaryExpr) ToString() string

func (*BinaryExpr) WriteTo

func (n *BinaryExpr) WriteTo(buf *bytes.Buffer)

type CounterAvgFunction

type CounterAvgFunction struct {
	DefaultFunction
}

func (*CounterAvgFunction) WriteTo

func (f *CounterAvgFunction) WriteTo(buf *bytes.Buffer)

type DefaultFunction

type DefaultFunction struct {
	Name           string   // 算子名称
	Fields         []Node   // 指标量名称
	Args           []string // 其他参数
	DerivativeArgs []string // Derivative其他参数
	Alias          string   // as
	Condition      string   // 算子过滤 例:Condition:"code in [1,2]" SUMIf(byte, code in [1,2])
	Withs          []Node
	Flag           int
	IgnoreZero     bool
	FillNullAsZero bool
	IsGroupArray   bool // 是否针对list做聚合,例:SUMArray(rtt_max)
	Nest           bool // 是否为内层嵌套算子
	Time           *Time
	Math           string
	NodeBase
}

func (*DefaultFunction) GetDefaultAlias

func (f *DefaultFunction) GetDefaultAlias(inner bool) string

func (*DefaultFunction) GetFields

func (f *DefaultFunction) GetFields() []Node

func (*DefaultFunction) GetFlag

func (f *DefaultFunction) GetFlag() int

func (*DefaultFunction) GetName

func (f *DefaultFunction) GetName() string

func (*DefaultFunction) GetWiths

func (f *DefaultFunction) GetWiths() []Node

func (*DefaultFunction) Init

func (f *DefaultFunction) Init()

func (*DefaultFunction) SetAlias

func (f *DefaultFunction) SetAlias(alias string, inner bool) string

func (*DefaultFunction) SetArgs

func (f *DefaultFunction) SetArgs(args []string)

func (*DefaultFunction) SetCondition

func (f *DefaultFunction) SetCondition(condition string)

func (*DefaultFunction) SetFields

func (f *DefaultFunction) SetFields(fields []Node)

func (*DefaultFunction) SetFillNullAsZero

func (f *DefaultFunction) SetFillNullAsZero(fillNullAsZero bool)

func (*DefaultFunction) SetFlag

func (f *DefaultFunction) SetFlag(flag int)

func (*DefaultFunction) SetIgnoreZero

func (f *DefaultFunction) SetIgnoreZero(ignoreZero bool)

func (*DefaultFunction) SetIsGroupArray

func (f *DefaultFunction) SetIsGroupArray(isGroupArray bool)

func (*DefaultFunction) SetMath

func (f *DefaultFunction) SetMath(math string)

func (*DefaultFunction) SetTime

func (f *DefaultFunction) SetTime(time *Time)

func (*DefaultFunction) ToString

func (f *DefaultFunction) ToString() string

func (*DefaultFunction) WriteTo

func (f *DefaultFunction) WriteTo(buf *bytes.Buffer)

type DelayAvgFunction

type DelayAvgFunction struct {
	DefaultFunction
	// contains filtered or unexported fields
}

func (*DelayAvgFunction) GetWiths

func (f *DelayAvgFunction) GetWiths() []Node

func (*DelayAvgFunction) Init

func (f *DelayAvgFunction) Init()

func (*DelayAvgFunction) WriteTo

func (f *DelayAvgFunction) WriteTo(buf *bytes.Buffer)

type DivFunction

type DivFunction struct {
	DefaultFunction
	DivType int
}

func (*DivFunction) GetWiths

func (f *DivFunction) GetWiths() []Node

func (*DivFunction) WriteTo

func (f *DivFunction) WriteTo(buf *bytes.Buffer)

type Expr

type Expr struct {
	NodeBase
	Value string
}

func (*Expr) ToString

func (n *Expr) ToString() string

func (*Expr) WriteTo

func (n *Expr) WriteTo(buf *bytes.Buffer)

type Field

type Field struct {
	DefaultFunction
	Value string
	Withs []Node
}

func (*Field) GetDefaultAlias

func (f *Field) GetDefaultAlias(inner bool) string

func (*Field) GetWiths

func (f *Field) GetWiths() []Node

func (*Field) ToString

func (f *Field) ToString() string

func (*Field) WriteTo

func (f *Field) WriteTo(buf *bytes.Buffer)

type Filters

type Filters struct {
	Expr  Node
	Withs []Node
	NodeSetBase
}

func (*Filters) Append

func (s *Filters) Append(f *Filters)

func (*Filters) GetWiths

func (s *Filters) GetWiths() []Node

func (*Filters) IsNull

func (s *Filters) IsNull() bool

func (*Filters) ToString

func (s *Filters) ToString() string

func (*Filters) WriteTo

func (s *Filters) WriteTo(buf *bytes.Buffer)

type Function

type Function interface {
	Node
	SetFields([]Node)
	SetArgs([]string)
	SetFlag(int)
	SetAlias(string, bool) string
	GetDefaultAlias(bool) string
	SetIgnoreZero(bool)
	SetFillNullAsZero(bool)
	SetIsGroupArray(bool)
	SetCondition(string)
	SetTime(*Time)
	SetMath(string)
	GetFlag() int
	GetName() string
	GetFields() []Node
	Init()
}

func GetFunc

func GetFunc(name string) Function

type Group

type Group struct {
	Value string
	Alias string
	Flag  int
	Withs []Node
	NodeBase
}

func (*Group) GetWiths

func (n *Group) GetWiths() []Node

func (*Group) ToString

func (n *Group) ToString() string

func (*Group) WriteTo

func (n *Group) WriteTo(buf *bytes.Buffer)

type Groups

type Groups struct {
	NodeSetBase
	// contains filtered or unexported fields
}

NodeSet Group结构体集合

func (*Groups) Append

func (s *Groups) Append(g *Group)

func (*Groups) GetWiths

func (s *Groups) GetWiths() []Node

func (*Groups) IsNull

func (s *Groups) IsNull() bool

func (*Groups) ToString

func (s *Groups) ToString() string

func (*Groups) WriteTo

func (s *Groups) WriteTo(buf *bytes.Buffer)

type HistogramFunction

type HistogramFunction struct {
	DefaultFunction
}

func (*HistogramFunction) WriteTo

func (f *HistogramFunction) WriteTo(buf *bytes.Buffer)

type Limit

type Limit struct {
	NodeBase
	Limit  string
	Offset string
}

func (*Limit) ToString

func (n *Limit) ToString() string

func (*Limit) WriteTo

func (n *Limit) WriteTo(buf *bytes.Buffer)

type MinFunction

type MinFunction struct {
	DefaultFunction
}

func (*MinFunction) GetWiths

func (f *MinFunction) GetWiths() []Node

func (*MinFunction) WriteTo

func (f *MinFunction) WriteTo(buf *bytes.Buffer)

type Model

type Model struct {
	DB        string
	Time      *Time
	Tags      *Tags
	Filters   *Filters
	From      *Tables
	Groups    *Groups
	Havings   *Filters
	Orders    *Orders
	Limit     *Limit
	Callbacks map[string]func(*common.Result) error
	//Havings Havings
	MetricsLevelFlag  int //Metrics是否需要拆层的标识
	HasAggFunc        bool
	IsDerivative      bool
	DerivativeGroupBy []string
}

对外接口:

struct:
	Model 包含withs tags filters等结构用于构造view
	View  由Model生成,用于构造df-clickhouse-sql
func:
	NewModel() Model          初始化Model结构
	Model.AddTag()
	Model.AddTable()
	Model.AddGroup()
	Model.AddFilter()
	NewView(*Model) View      使用model初始化View结构
	NewView.ToString() string 生成df-clickhouse-sql

func NewModel

func NewModel() *Model

func (*Model) AddCallback

func (m *Model) AddCallback(col string, f func(*common.Result) error)

func (*Model) AddFilter

func (m *Model) AddFilter(f *Filters)

func (*Model) AddGroup

func (m *Model) AddGroup(g *Group)

func (*Model) AddHaving

func (m *Model) AddHaving(f *Filters)

func (*Model) AddTable

func (m *Model) AddTable(value string)

func (*Model) AddTag

func (m *Model) AddTag(n Node)

type Nested

type Nested struct {
	NodeBase
	Expr Node
}

括号

func (*Nested) ToString

func (n *Nested) ToString() string

func (*Nested) WriteTo

func (n *Nested) WriteTo(buf *bytes.Buffer)

type Node

type Node interface {
	ToString() string
	WriteTo(*bytes.Buffer)
	GetWiths() []Node
}

type NodeBase

type NodeBase struct{}

func (*NodeBase) GetWiths

func (n *NodeBase) GetWiths() []Node

type NodeSet

type NodeSet interface {
	Node
	IsNull() bool
	// contains filtered or unexported methods
}

type NodeSetBase

type NodeSetBase struct{ NodeBase }

type NonNegativeDerivativeFunction

type NonNegativeDerivativeFunction struct {
	DefaultFunction
}

func (*NonNegativeDerivativeFunction) WriteTo

func (f *NonNegativeDerivativeFunction) WriteTo(buf *bytes.Buffer)

type Operator

type Operator struct {
	Type int
	NodeBase
}

func GetOperator

func GetOperator(op string) (*Operator, int)

func (*Operator) ToString

func (n *Operator) ToString() string

func (*Operator) WriteTo

func (n *Operator) WriteTo(buf *bytes.Buffer)

type Order

type Order struct {
	NodeBase
	SortBy  string
	OrderBy string
	IsField bool
}

func (*Order) ToString

func (n *Order) ToString() string

func (*Order) WriteTo

func (n *Order) WriteTo(buf *bytes.Buffer)

type Orders

type Orders struct {
	NodeSetBase
	Orders []Node
}

func (*Orders) Append

func (s *Orders) Append(o Node)

func (*Orders) IsNull

func (s *Orders) IsNull() bool

func (*Orders) ToString

func (s *Orders) ToString() string

func (*Orders) WriteTo

func (s *Orders) WriteTo(buf *bytes.Buffer)

type PerSecondFunction

type PerSecondFunction struct {
	DefaultFunction
	// contains filtered or unexported fields
}

func (*PerSecondFunction) GetWiths

func (f *PerSecondFunction) GetWiths() []Node

func (*PerSecondFunction) Init

func (f *PerSecondFunction) Init()

func (*PerSecondFunction) WriteTo

func (f *PerSecondFunction) WriteTo(buf *bytes.Buffer)

type PercentageFunction

type PercentageFunction struct {
	DefaultFunction
	// contains filtered or unexported fields
}

func (*PercentageFunction) GetWiths

func (f *PercentageFunction) GetWiths() []Node

func (*PercentageFunction) Init

func (f *PercentageFunction) Init()

func (*PercentageFunction) WriteTo

func (f *PercentageFunction) WriteTo(buf *bytes.Buffer)

type RspreadFunction

type RspreadFunction struct {
	DefaultFunction
	// contains filtered or unexported fields
}

func (*RspreadFunction) GetWiths

func (f *RspreadFunction) GetWiths() []Node

func (*RspreadFunction) Init

func (f *RspreadFunction) Init()

func (*RspreadFunction) WriteTo

func (f *RspreadFunction) WriteTo(buf *bytes.Buffer)

type SpreadFunction

type SpreadFunction struct {
	DefaultFunction
	// contains filtered or unexported fields
}

func (*SpreadFunction) GetWiths

func (f *SpreadFunction) GetWiths() []Node

func (*SpreadFunction) Init

func (f *SpreadFunction) Init()

func (*SpreadFunction) WriteTo

func (f *SpreadFunction) WriteTo(buf *bytes.Buffer)

type SubView

type SubView struct {
	Tags       *Tags
	Filters    *Filters
	From       *Tables
	Groups     *Groups
	Orders     *Orders
	Limit      *Limit
	Havings    *Filters
	NoPreWhere bool
}

func (*SubView) GetWiths

func (sv *SubView) GetWiths() []Node

func (*SubView) ToString

func (sv *SubView) ToString() string

func (*SubView) WriteTo

func (sv *SubView) WriteTo(buf *bytes.Buffer)

type Table

type Table struct {
	NodeBase
	Value string
}

func (*Table) ToString

func (t *Table) ToString() string

func (*Table) WriteTo

func (t *Table) WriteTo(buf *bytes.Buffer)

type Tables

type Tables struct {
	NodeSetBase
	// contains filtered or unexported fields
}

NodeSet Table结构体集合

func (*Tables) Append

func (t *Tables) Append(g Node)

func (*Tables) IsNull

func (t *Tables) IsNull() bool

func (*Tables) ToString

func (t *Tables) ToString() string

func (*Tables) WriteTo

func (t *Tables) WriteTo(buf *bytes.Buffer)

type Tag

type Tag struct {
	Value string
	Alias string
	Flag  int
	Withs []Node
	NodeBase
}

func (*Tag) GetWiths

func (n *Tag) GetWiths() []Node

func (*Tag) ToString

func (n *Tag) ToString() string

func (*Tag) WriteTo

func (n *Tag) WriteTo(buf *bytes.Buffer)

type Tags

type Tags struct {
	NodeSetBase
	// contains filtered or unexported fields
}

NodeSet Tag结构体集合

func (*Tags) Append

func (s *Tags) Append(t Node)

func (*Tags) GetWiths

func (s *Tags) GetWiths() []Node

func (*Tags) IsNull

func (s *Tags) IsNull() bool

func (*Tags) ToString

func (s *Tags) ToString() string

func (*Tags) WriteTo

func (s *Tags) WriteTo(buf *bytes.Buffer)

type Time

type Time struct {
	TimeStart          int64
	TimeEnd            int64
	Interval           int
	DatasourceInterval int
	WindowSize         int
	Offset             int
	Fill               string
	Alias              string
	TimeStartOperator  string
	TimeEndOperator    string
}

func NewTime

func NewTime() *Time

func (*Time) AddAlias

func (t *Time) AddAlias(alias string)

func (*Time) AddFill

func (t *Time) AddFill(fill string)

func (*Time) AddInterval

func (t *Time) AddInterval(interval int)

func (*Time) AddOffset

func (t *Time) AddOffset(offset int)

func (*Time) AddTimeEnd

func (t *Time) AddTimeEnd(timeEnd int64)

func (*Time) AddTimeStart

func (t *Time) AddTimeStart(timeStart int64)

func (*Time) AddWindowSize

func (t *Time) AddWindowSize(windowSize int)

type UnaryExpr

type UnaryExpr struct {
	NodeBase
	Op   *Operator
	Expr Node
}

func (*UnaryExpr) ToString

func (n *UnaryExpr) ToString() string

func (*UnaryExpr) WriteTo

func (n *UnaryExpr) WriteTo(buf *bytes.Buffer)

type View

type View struct {
	Model         *Model     //初始化view
	SubViewLevels []*SubView //由RawView拆层
	NoPreWhere    bool       // Whether to use prewhere
}

func NewView

func NewView(m *Model) *View

使用model初始化view

func (*View) GetCallbacks

func (v *View) GetCallbacks() (callbacks map[string]func(*common.Result) error)

func (*View) ToString

func (v *View) ToString() string

type With

type With struct {
	Value string
	Alias string
	NodeBase
}

func (*With) ToString

func (n *With) ToString() string

func (*With) WriteTo

func (n *With) WriteTo(buf *bytes.Buffer)

type Withs

type Withs struct {
	Withs []Node
}

NodeSet With结构体集合

func (*Withs) Append

func (s *Withs) Append(w *With)

func (*Withs) GetWiths

func (s *Withs) GetWiths() []Node

func (*Withs) IsNull

func (s *Withs) IsNull() bool

func (*Withs) ToString

func (s *Withs) ToString() string

func (*Withs) WriteTo

func (s *Withs) WriteTo(buf *bytes.Buffer)

Jump to

Keyboard shortcuts

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