本文整理汇总了Golang中parser.SelectQuery.GetFromClause方法的典型用法代码示例。如果您正苦于以下问题:Golang SelectQuery.GetFromClause方法的具体用法?Golang SelectQuery.GetFromClause怎么用?Golang SelectQuery.GetFromClause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parser.SelectQuery
的用法示例。
在下文中一共展示了SelectQuery.GetFromClause方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendBatch
// Return the number of dropped ticks from filtering. if the series
// had more than one alias, returns the min of all dropped ticks
func (self *LevelDbDatastore) sendBatch(query *parser.SelectQuery, series *protocol.Series, yield func(series *protocol.Series) error) (int, error) {
dropped := int(math.MaxInt32)
for _, alias := range query.GetTableAliases(*series.Name) {
_alias := alias
newSeries := &protocol.Series{Name: &_alias, Points: series.Points, Fields: series.Fields}
lengthBeforeFiltering := len(newSeries.Points)
var filteredResult *protocol.Series
var err error
if query.GetFromClause().Type == parser.FromClauseInnerJoin {
filteredResult = newSeries
} else {
filteredResult, err = Filter(query, newSeries)
if err != nil {
return 0, err
}
}
_dropped := lengthBeforeFiltering - len(filteredResult.Points)
if _dropped < dropped {
dropped = _dropped
}
if err := yield(filteredResult); err != nil {
return 0, err
}
}
return dropped, nil
}
示例2: 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
}
示例3: getJoinYield
func getJoinYield(query *parser.SelectQuery, yield func(*protocol.Series) error) func(*protocol.Series) error {
var lastPoint1 *protocol.Point
var lastFields1 []string
var lastPoint2 *protocol.Point
var lastFields2 []string
table1 := query.GetFromClause().Names[0].GetAlias()
table2 := query.GetFromClause().Names[1].GetAlias()
name := table1 + "_join_" + table2
return mergeYield(table1, table2, false, query.Ascending, func(s *protocol.Series) error {
fmt.Printf("join series: %d\n", len(s.Points))
if *s.Name == table1 {
lastPoint1 = s.Points[len(s.Points)-1]
if lastFields1 == nil {
for _, f := range s.Fields {
lastFields1 = append(lastFields1, table1+"."+f)
}
}
}
if *s.Name == table2 {
lastPoint2 = s.Points[len(s.Points)-1]
if lastFields2 == nil {
for _, f := range s.Fields {
lastFields2 = append(lastFields2, table2+"."+f)
}
}
}
if lastPoint1 == nil || lastPoint2 == nil {
return nil
}
newSeries := &protocol.Series{
Name: &name,
Fields: append(lastFields1, lastFields2...),
Points: []*protocol.Point{
&protocol.Point{
Values: append(lastPoint1.Values, lastPoint2.Values...),
Timestamp: lastPoint2.Timestamp,
},
},
}
lastPoint1 = nil
lastPoint2 = nil
filteredSeries, _ := Filter(query, newSeries)
if len(filteredSeries.Points) > 0 {
return yield(newSeries)
}
return nil
})
}
示例4: distributeQuery
// distribute query and possibly do the merge/join before yielding the points
func (self *QueryEngine) distributeQuery(user common.User, database string, query *parser.SelectQuery, yield func(*protocol.Series) error) (err error) {
// see if this is a merge query
fromClause := query.GetFromClause()
if fromClause.Type == parser.FromClauseMerge {
yield = getMergeYield(fromClause.Names[0].Name.Name, fromClause.Names[1].Name.Name, query.Ascending, yield)
}
if fromClause.Type == parser.FromClauseInnerJoin {
yield = getJoinYield(query, yield)
}
return self.coordinator.DistributeQuery(user, database, query, yield)
}
示例5: distributeQuery
// distribute query and possibly do the merge/join before yielding the points
func (self *QueryEngine) distributeQuery(query *parser.SelectQuery, yield func(*protocol.Series) error) error {
// see if this is a merge query
fromClause := query.GetFromClause()
if fromClause.Type == parser.FromClauseMerge {
yield = getMergeYield(fromClause.Names[0].Name.Name, fromClause.Names[1].Name.Name, query.Ascending, yield)
}
if fromClause.Type == parser.FromClauseInnerJoin {
yield = getJoinYield(query, yield)
}
self.yield = yield
return nil
}