query

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//DataTypeTimestamp is timestamp datatype
	DataTypeTimestamp = "TIMESTAMP"
	//DataTypeDate is date datatype
	DataTypeDate = "DATE"
)
View Source
const (
	//MetricTypeCount is metric type of count
	MetricTypeCount = "COUNT"
	//MetricTypeNullCount is metric type of null count
	MetricTypeNullCount = "NULLCOUNT"
	//MetricTypeSum is metric type of sum
	MetricTypeSum = "SUM"
	//MetricTypeCountForRepeated is metric type of count
	MetricTypeCountForRepeated = "COUNTFORREPEATED"
	//MetricTypeNullCountForRepeated is metric type of count
	MetricTypeNullCountForRepeated = "NULLCOUNTFORREPEATED"
	//MetricTypeUniqueCount is metric type of unique count
	MetricTypeUniqueCount = "UNIQUECOUNT"
	//MetricTypeInvalidCount is metric type of invalid count
	MetricTypeInvalidCount = "INVALIDCOUNT"
)

Variables

View Source
var ErrorMetricTypeNotFound = errors.New("error : Metric type is not found")

ErrorMetricTypeNotFound is error when metric type is undefined, or not found from the list

Functions

This section is empty.

Types

type AllPartitionFilter

type AllPartitionFilter struct {
	PartitionColumn string
}

AllPartitionFilter is used to select all partition data

func (*AllPartitionFilter) Build

func (af *AllPartitionFilter) Build() string

Build all partition filter clause

func (*AllPartitionFilter) Equal

func (af *AllPartitionFilter) Equal(other FilterClause) bool

Equal implementation

type CustomFilterExpression

type CustomFilterExpression struct {
	Expression string
}

CustomFilterExpression filter by custom expression

func (*CustomFilterExpression) Build

func (c *CustomFilterExpression) Build() string

func (*CustomFilterExpression) Equal

func (c *CustomFilterExpression) Equal(other FilterClause) bool

type DataType

type DataType string

DataType is type of data

type Date

type Date struct {
	Year  int
	Month int
	Day   int

	TimestampExpr Expression
	Timezone      *time.Location
}

Date is DATE function, it takes any timestamp expression

func (*Date) Build

func (d *Date) Build() (string, error)

type DateTrunc

type DateTrunc struct {
	Target       Expression
	TruncateType TruncType
}

DateTrunc is type of DATE_TRUNC() function in bigquery SQL syntax

func (*DateTrunc) Build

func (d *DateTrunc) Build() (string, error)

type Expression

type Expression interface {
	Build() (string, error)
	// contains filtered or unexported methods
}

Expression is any expression

type FieldIdentifier

type FieldIdentifier struct {
	FieldID string
}

func (*FieldIdentifier) Build

func (f *FieldIdentifier) Build() (string, error)

type FilterClause

type FilterClause interface {
	Build() string
	Equal(other FilterClause) bool
	// contains filtered or unexported methods
}

FilterClause interface of types intended to do filter in where clause

type FromClause

type FromClause struct {
	TableID       string
	UnnestClauses []*Unnest
}

FromClause is a definition of from clause in sql

func (*FromClause) Build

func (fc *FromClause) Build() string

Build is a method to build from clause sql string

func (*FromClause) Equal

func (fc *FromClause) Equal(other *FromClause) bool

Equal is comparison

type GroupByClause

type GroupByClause interface {
	Build() string
	// contains filtered or unexported methods
}

GroupByClause builder of group by expression

type GroupByExpression

type GroupByExpression struct {
	Expression string
}

GroupByExpression is group by any kind of expression an Expression can be a column for example : GROUP BY created_date or can be an select expression for example : GROUP BY date(created_timestamp)

func (*GroupByExpression) Build

func (g *GroupByExpression) Build() string

Build build group by expression based on groupByTemplate template

type MetricExpression

type MetricExpression struct {
	Arg        string
	Alias      string
	MetricType MetricType
}

MetricExpression is definition type of calculation, and the alias produced of from a column

func NewMetricExpression

func NewMetricExpression(arg string, alias string, metricType MetricType) *MetricExpression

NewMetricExpression is constructor for metric expression

func (*MetricExpression) Build

func (m *MetricExpression) Build() (string, error)

Build is process of constructing script from metric definition

type MetricExpressionList

type MetricExpressionList []*MetricExpression

MetricExpressionList list of metric expression

func (MetricExpressionList) Build

func (m MetricExpressionList) Build() (string, error)

Build build each metric expression and join them

type MetricType

type MetricType string

MetricType is type of metric

func ParseMetricType

func ParseMetricType(_type metric.Type, mode meta.Mode) MetricType

ParseMetricType to parse metric name to metric type

type NoFilter

type NoFilter struct {
}

NoFilter is used to filter nothing on sql expression

func (*NoFilter) Build

func (nf *NoFilter) Build() string

Build no filter clause

func (*NoFilter) Equal

func (nf *NoFilter) Equal(other FilterClause) bool

Equal implementation

type NoGroupBy

type NoGroupBy struct {
}

func (*NoGroupBy) Build

func (n *NoGroupBy) Build() string

type PartitionFilter

type PartitionFilter struct {
	DataType        DataType
	PartitionDate   string
	PartitionColumn string
}

PartitionFilter is filter for select data based on partition column

func (*PartitionFilter) Build

func (pf *PartitionFilter) Build() string

Build is a method to build sql expression of filtering based on partition

func (*PartitionFilter) Equal

func (pf *PartitionFilter) Equal(other FilterClause) bool

Equal implementation

type Query

type Query struct {
	Expressions SelectExpressionList
	Metrics     MetricExpressionList
	From        *FromClause
	Where       FilterClause

	//GroupBy is optional
	GroupBy GroupByClause
}

Query is an SQL query

func (*Query) Merge

func (q *Query) Merge(other *Query) (*Query, error)

Merge is to merge two queries into one will result new Query that contains both of the queries metrics will return error when the Where and FromClause from both of the queries is different

func (*Query) String

func (q *Query) String() string

NewQuery is a function to build a sql to calculate metric

type SelectExpression

type SelectExpression struct {
	Expression string
	Alias      string
}

func (*SelectExpression) Build

func (s *SelectExpression) Build() string

type SelectExpressionList

type SelectExpressionList []*SelectExpression

func (SelectExpressionList) Build

func (s SelectExpressionList) Build() string

type TimestampTrunc

type TimestampTrunc struct {
	TimestampExpr Expression
	TruncateType  TruncType
	Timezone      *time.Location
}

func (*TimestampTrunc) Build

func (t *TimestampTrunc) Build() (string, error)

type TimestampValue

type TimestampValue struct {
	Value string
}

func (*TimestampValue) Build

func (t *TimestampValue) Build() (string, error)

type TruncType

type TruncType string

TruncType is trunc type of date_trunc() and timestamp_trunc() function

var TruncTypeDay TruncType = "DAY"
var TruncTypeHour TruncType = "HOUR"
var TruncTypeMonth TruncType = "MONTH"
var TruncTypeYear TruncType = "YEAR"

func (TruncType) String

func (t TruncType) String() string

type Unnest

type Unnest struct {
	ColumnName string
	Alias      string
}

Unnest is a definition clause for unnesting array columns, to become a normal columns

func (*Unnest) Build

func (u *Unnest) Build() string

Build is method to build unnest string

func (*Unnest) Equal

func (u *Unnest) Equal(other *Unnest) bool

Equal comparable

Jump to

Keyboard shortcuts

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