本文整理汇总了Golang中common.NewQueryError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewQueryError函数的具体用法?Golang NewQueryError怎么用?Golang NewQueryError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewQueryError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewCountAggregator
func NewCountAggregator(q *parser.SelectQuery, v *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
if len(v.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function count() requires exactly one argument")
}
if v.Elems[0].Type == parser.ValueWildcard {
return nil, common.NewQueryError(common.InvalidArgument, "function count() doesn't work with wildcards")
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
if v.Elems[0].Type != parser.ValueSimpleName {
innerName := strings.ToLower(v.Elems[0].Name)
init := registeredAggregators[innerName]
if init == nil {
return nil, common.NewQueryError(common.InvalidArgument, fmt.Sprintf("Unknown function %s", innerName))
}
inner, err := init(q, v.Elems[0], defaultValue)
if err != nil {
return nil, err
}
return NewCompositeAggregator(&CountAggregator{AbstractAggregator{}, wrappedDefaultValue, v.Alias}, inner)
}
return &CountAggregator{AbstractAggregator{}, wrappedDefaultValue, v.Alias}, nil
}
示例2: NewTopOrBottomAggregator
func NewTopOrBottomAggregator(name string, v *parser.Value, isTop bool, defaultValue *parser.Value) (Aggregator, error) {
if len(v.Elems) != 2 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, fmt.Sprintf("function %s() requires at exactly 2 arguments", name))
}
if v.Elems[1].Type != parser.ValueInt {
return nil, common.NewQueryError(common.InvalidArgument, fmt.Sprintf("function %s() second parameter expect int", name))
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
limit, err := strconv.ParseInt(v.Elems[1].Name, 10, 64)
if err != nil {
return nil, err
}
return &TopOrBottomAggregator{
AbstractAggregator: AbstractAggregator{
value: v.Elems[0],
},
name: name,
isTop: isTop,
defaultValue: wrappedDefaultValue,
alias: v.Alias,
limit: limit}, nil
}
示例3: NewPercentileAggregator
func NewPercentileAggregator(_ *parser.SelectQuery, value *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
if len(value.Elems) != 2 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function percentile() requires exactly two arguments")
}
percentile, err := strconv.ParseFloat(value.Elems[1].Name, 64)
if err != nil || percentile <= 0 || percentile >= 100 {
return nil, common.NewQueryError(common.InvalidArgument, "function percentile() requires a numeric second argument between 0 and 100")
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
return &PercentileAggregator{
AbstractAggregator: AbstractAggregator{
value: value.Elems[0],
},
functionName: "percentile",
percentile: percentile,
float_values: make(map[string]map[interface{}][]float64),
defaultValue: wrappedDefaultValue,
}, nil
}
示例4: NewPercentileAggregator
func NewPercentileAggregator(_ *parser.SelectQuery, value *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
if len(value.Elems) != 2 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function percentile() requires exactly two arguments")
}
if value.Elems[0].Type == parser.ValueWildcard {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "wildcard cannot be used with percentile")
}
percentile, err := strconv.ParseFloat(value.Elems[1].Name, 64)
if err != nil || percentile <= 0 || percentile >= 100 {
return nil, common.NewQueryError(common.InvalidArgument, "function percentile() requires a numeric second argument between 0 and 100")
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
functionName := "percentile"
if value.Alias != "" {
functionName = value.Alias
}
return &PercentileAggregator{
AbstractAggregator: AbstractAggregator{
value: value.Elems[0],
},
functionName: functionName,
percentile: percentile,
defaultValue: wrappedDefaultValue,
}, nil
}
示例5: NewStandardDeviationAggregator
func NewStandardDeviationAggregator(q *parser.Query, v *parser.Value) (Aggregator, error) {
if len(v.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function stddev() requires exactly one argument")
}
if v.Elems[0].Type == parser.ValueWildcard {
return nil, common.NewQueryError(common.InvalidArgument, "function stddev() doesn't work with wildcards")
}
return &StandardDeviationAggregator{
fieldName: v.Elems[0].Name,
running: make(map[string]map[interface{}]*StandardDeviationRunning),
}, nil
}
示例6: NewDerivativeAggregator
func NewDerivativeAggregator(q *parser.Query, v *parser.Value) (Aggregator, error) {
if len(v.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function derivative() requires exactly one argument")
}
if v.Elems[0].Type == parser.ValueWildcard {
return nil, common.NewQueryError(common.InvalidArgument, "function derivative() doesn't work with wildcards")
}
return &DerivativeAggregator{
fieldName: v.Elems[0].Name,
lastValues: make(map[string]map[interface{}]*protocol.Point),
points: make(map[string]map[interface{}][]*protocol.FieldValue),
}, nil
}
示例7: executeCountQueryWithGroupBy
func (self *QueryEngine) executeCountQueryWithGroupBy(query *parser.SelectQuery, yield func(*protocol.Series) error) error {
self.aggregateYield = yield
duration, err := query.GetGroupByClause().GetGroupByTime()
if err != nil {
return err
}
self.isAggregateQuery = true
self.duration = duration
self.aggregators = []Aggregator{}
for _, value := range query.GetColumnNames() {
if !value.IsFunctionCall() {
continue
}
lowerCaseName := strings.ToLower(value.Name)
initializer := registeredAggregators[lowerCaseName]
if initializer == nil {
return common.NewQueryError(common.InvalidArgument, fmt.Sprintf("Unknown function %s", value.Name))
}
aggregator, err := initializer(query, value, query.GetGroupByClause().FillValue)
if err != nil {
return common.NewQueryError(common.InvalidArgument, fmt.Sprintf("%s", err))
}
self.aggregators = append(self.aggregators, aggregator)
}
for _, elem := range query.GetGroupByClause().Elems {
if elem.IsFunctionCall() {
continue
}
self.elems = append(self.elems, elem)
}
self.fillWithZero = query.GetGroupByClause().FillWithZero
self.initializeFields()
err = self.distributeQuery(query, func(series *protocol.Series) error {
if len(series.Points) == 0 {
return nil
}
return self.aggregateValuesForSeries(series)
})
return err
}
示例8: NewMedianAggregator
func NewMedianAggregator(_ *parser.SelectQuery, value *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
if len(value.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function median() requires exactly one argument")
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
functionName := "median"
if value.Alias != "" {
functionName = value.Alias
}
aggregator := &PercentileAggregator{
AbstractAggregator: AbstractAggregator{
value: value.Elems[0],
},
functionName: functionName,
percentile: 50.0,
defaultValue: wrappedDefaultValue,
alias: value.Alias,
}
return aggregator, nil
}
示例9: NewCumulativeArithmeticAggregator
func NewCumulativeArithmeticAggregator(name string, value *parser.Value, initialValue float64, defaultValue *parser.Value, operation Operation) (Aggregator, error) {
if len(value.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function max() requires only one argument")
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
if value.Alias != "" {
name = value.Alias
}
return &CumulativeArithmeticAggregator{
AbstractAggregator: AbstractAggregator{
value: value.Elems[0],
},
name: name,
values: make(map[string]map[interface{}]float64),
operation: operation,
initialValue: initialValue,
defaultValue: wrappedDefaultValue,
}, nil
}
示例10: RunQuery
func (self *QueryEngine) RunQuery(user common.User, database string, query string, yield func(*protocol.Series) error) (err error) {
// don't let a panic pass beyond RunQuery
defer func() {
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, "********************************BUG********************************\n")
buf := make([]byte, 1024)
n := runtime.Stack(buf, false)
fmt.Fprintf(os.Stderr, "Database: %s\n", database)
fmt.Fprintf(os.Stderr, "Query: [%s]\n", query)
fmt.Fprintf(os.Stderr, "Error: %s. Stacktrace: %s\n", err, string(buf[:n]))
err = common.NewQueryError(common.InternalError, "Internal Error")
}
}()
q, err := parser.ParseQuery(query)
if err != nil {
return err
}
if isAggregateQuery(q) {
return self.executeCountQueryWithGroupBy(user, database, q, yield)
} else {
return self.distributeQuery(user, database, q, yield)
}
return nil
}
示例11: NewModeAggregator
func NewModeAggregator(_ *parser.SelectQuery, value *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
if len(value.Elems) < 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function mode() requires at least one argument")
}
// TODO: Mode can in fact take two argument, the second specifies
// the "size", but it's not clear if size is set to 2 whether to
// return at least 2 elements, or return the most common values and
// the second most common values. The difference will be apparent if
// the data set is multimodel and there are two most common
// values. In the first case, the two most common values will be
// returned, but in the second case the two most common values and
// the second most common values will be returned
if len(value.Elems) > 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function mode() takes at most one arguments")
}
size := 1
if len(value.Elems) == 2 {
switch value.Elems[1].Type {
case parser.ValueInt:
var err error
size, err = strconv.Atoi(value.Elems[1].Name)
if err != nil {
return nil, common.NewQueryError(common.InvalidArgument, "Cannot parse %s into an int", value.Elems[1].Name)
}
default:
return nil, common.NewQueryError(common.InvalidArgument, "Cannot parse %s into a int", value.Elems[1].Name)
}
}
wrappedDefaultValue, err := wrapDefaultValue(defaultValue)
if err != nil {
return nil, err
}
return &ModeAggregator{
AbstractAggregator: AbstractAggregator{
value: value.Elems[0],
},
defaultValue: wrappedDefaultValue,
alias: value.Alias,
size: size,
}, nil
}
示例12: HashPassword
func HashPassword(password string) ([]byte, error) {
if length := len(password); length < 4 || length > 56 {
return nil, common.NewQueryError(common.InvalidArgument, "Password must be more than 4 and less than 56 characters")
}
// The second arg is the cost of the hashing, higher is slower but makes it harder
// to brute force, since it will be really slow and impractical
return bcrypt.GenerateFromPassword([]byte(password), 10)
}
示例13: NewModeAggregator
func NewModeAggregator(_ *parser.Query, value *parser.Value) (Aggregator, error) {
if len(value.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function mode() requires exactly one argument")
}
return &ModeAggregator{
fieldName: value.Elems[0].Name,
counts: make(map[string]map[interface{}]map[float64]int),
}, nil
}
示例14: InitializeFieldsMetadata
func (self *CumulativeArithmeticAggregator) InitializeFieldsMetadata(series *protocol.Series) error {
for idx, field := range series.Fields {
if field == self.fieldName {
self.fieldIndex = idx
return nil
}
}
return common.NewQueryError(common.InvalidArgument, fmt.Sprintf("Unknown column name %s", self.fieldName))
}
示例15: NewHistogramAggregator
func NewHistogramAggregator(q *parser.SelectQuery, v *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
if len(v.Elems) < 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function histogram() requires at least one arguments")
}
if len(v.Elems) > 2 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "function histogram() takes at most two arguments")
}
if v.Elems[0].Type == parser.ValueWildcard {
return nil, common.NewQueryError(common.InvalidArgument, "function histogram() doesn't work with wildcards")
}
bucketSize := 1.0
if len(v.Elems) == 2 {
switch v.Elems[1].Type {
case parser.ValueInt, parser.ValueFloat:
var err error
bucketSize, err = strconv.ParseFloat(v.Elems[1].Name, 64)
if err != nil {
return nil, common.NewQueryError(common.InvalidArgument, "Cannot parse %s into a float", v.Elems[1].Name)
}
default:
return nil, common.NewQueryError(common.InvalidArgument, "Cannot parse %s into a float", v.Elems[1].Name)
}
}
columnNames := []string{"bucket_start", "count"}
if v.Alias != "" {
columnNames[0] = fmt.Sprintf("%s_bucket_start", v.Alias)
columnNames[1] = fmt.Sprintf("%s_count", v.Alias)
}
return &HistogramAggregator{
AbstractAggregator: AbstractAggregator{
value: v.Elems[0],
},
bucketSize: bucketSize,
histograms: make(map[string]map[interface{}]map[int]int),
columnNames: columnNames,
}, nil
}