本文整理匯總了Golang中parser.SelectQuery.GetResultColumns方法的典型用法代碼示例。如果您正苦於以下問題:Golang SelectQuery.GetResultColumns方法的具體用法?Golang SelectQuery.GetResultColumns怎麽用?Golang SelectQuery.GetResultColumns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類parser.SelectQuery
的用法示例。
在下文中一共展示了SelectQuery.GetResultColumns方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Filter
func Filter(query *parser.SelectQuery, series *protocol.Series) (*protocol.Series, error) {
if query.GetWhereCondition() == nil {
return series, nil
}
columns := map[string]struct{}{}
if query.GetFromClause().Type == parser.FromClauseInnerJoin {
outer:
for t, cs := range query.GetResultColumns() {
for _, c := range cs {
// if this is a wildcard select, then drop all columns and
// just use '*'
if c == "*" {
columns = make(map[string]struct{}, 1)
columns[c] = struct{}{}
break outer
}
columns[t.Name+"."+c] = struct{}{}
}
}
} else {
for _, cs := range query.GetResultColumns() {
for _, c := range cs {
columns[c] = struct{}{}
}
}
}
points := series.Points
series.Points = nil
for _, point := range points {
ok, err := matches(query.GetWhereCondition(), series.Fields, point)
if err != nil {
return nil, err
}
if ok {
fmt.Printf("columns: %v, fields: %v\n", columns, series.Fields)
filterColumns(columns, series.Fields, point)
series.Points = append(series.Points, point)
}
}
if _, ok := columns["*"]; !ok {
newFields := []string{}
for _, f := range series.Fields {
if _, ok := columns[f]; !ok {
continue
}
newFields = append(newFields, f)
}
series.Fields = newFields
}
return series, nil
}