// projectAndGroupBy takes the resulting table and projects its contents and
// groups it by if needed.
421417
func (p *queryPlan) projectAndGroupBy() error {
	grp := p.stm.GroupByBindings()
	if len(grp) == 0 { // The table only needs to be projected.
		tracer.Trace(p.tracer, func() []string {
			return []string{fmt.Sprintf("Running projection for %v", grp)}
		})
		p.tbl.AddBindings(p.stm.OutputBindings())
		// For each row, copy each input binding value to its appropriate alias.
		for _, prj := range p.stm.Projections() {
			for _, row := range p.tbl.Rows() {
				row[prj.Alias] = row[prj.Binding]
			}
		}
		tracer.Trace(p.tracer, func() []string {
			return []string{fmt.Sprintf("Output bindings projected %v", p.stm.OutputBindings())}
		})
		return p.tbl.ProjectBindings(p.stm.OutputBindings())
	}
	tracer.Trace(p.tracer, func() []string {
		return []string{"Starting group reduce and projection"}
	})
	// The table needs to be group reduced.
	// Project only binding involved in the group operation.
	tmpBindings := []string{}
	mapBindings := make(map[string]bool)
	// The table requires group reduce.
	cfg := table.SortConfig{}
	aaps := []table.AliasAccPair{}
	for _, prj := range p.stm.Projections() {
		tracer.Trace(p.tracer, func() []string {
			return []string{"Analysing projection " + prj.String()}
		})
		// Only include used incoming bindings.
		tmpBindings = append(tmpBindings, prj.Binding)
		// Update sorting configuration.
		found := false
		for _, g := range p.stm.GroupByBindings() {
			if prj.Binding == g {
				found = true
			}
		}
		if found && !mapBindings[prj.Binding] {
			cfg = append(cfg, table.SortConfig{{Binding: prj.Binding}}...)
			mapBindings[prj.Binding] = true
		}
		aap := table.AliasAccPair{
			InAlias: prj.Binding,
		}
		if prj.Alias == "" {
			aap.OutAlias = prj.Binding
		} else {
			aap.OutAlias = prj.Alias
		}
		// Update accumulators.
		switch prj.OP {
		case lexer.ItemCount:
			if prj.Modifier == lexer.ItemDistinct {
				aap.Acc = table.NewCountDistinctAccumulator()
			} else {
				aap.Acc = table.NewCountAccumulator()
			}
		case lexer.ItemSum:
			cell := p.tbl.Rows()[0][prj.Binding]
			if cell.L == nil {
				return fmt.Errorf("can only sum int64 and float64 literals; found %s instead for binding %q", cell, prj.Binding)
			}
			switch cell.L.Type() {
			case literal.Int64:
				aap.Acc = table.NewSumInt64LiteralAccumulator(0)
			case literal.Float64:
				aap.Acc = table.NewSumFloat64LiteralAccumulator(0)
			default:
				return fmt.Errorf("can only sum int64 and float64 literals; found literal type %s instead for binding %q", cell.L.Type(), prj.Binding)
			}
		}
		aaps = append(aaps, aap)
	}
	tracer.Trace(p.tracer, func() []string {
		return []string{fmt.Sprintf("Projecting %v", tmpBindings)}
	})
	if err := p.tbl.ProjectBindings(tmpBindings); err != nil {
		return err
	}
	tracer.Trace(p.tracer, func() []string {
		return []string{"Reducing the table using configuration " + cfg.String()}
	})
	p.tbl.Reduce(cfg, aaps)
	return nil
}
1202664
func (r *marathonClient) GroupBy(name string, opts *GetGroupOpts) (*Group, error) {
	path, err := addOptions(fmt.Sprintf("%s/%s", marathonAPIGroups, trimRootPath(name)), opts)
	if err != nil {
		return nil, err
	}
	group := new(Group)
	if err := r.apiGet(path, nil, group); err != nil {
		return nil, err
	}
	return group, nil
}
344941
func FilterByProjects(apps []argoappv1.Application, projects []string) []argoappv1.Application {
	if len(projects) == 0 {
		return apps
	}
	projectsMap := make(map[string]bool)
	for i := range projects {
		projectsMap[projects[i]] = true
	}
	items := make([]argoappv1.Application, 0)
	for i := 0; i < len(apps); i++ {
		a := apps[i]
		if _, ok := projectsMap[a.Spec.GetProject()]; ok {
			items = append(items, a)
		}
	}
	return items

}
983307
func (g *BuilderGroup) Groups() []*BuilderGroup {
	groups := []*BuilderGroup{}
	for child, parent := range g.builder.ring.GroupToGroup {
		if parent == g.index {
			groups = append(groups, g.builder.groups[child])
		}
	}
	return groups
}
436198
func generalizedGroupBy(funcName string, entries interface{}, getValue func(interface{}) (interface{}, error), addEntry func(map[string][]interface{}, interface{}, interface{})) (map[string][]interface{}, error) {
	entriesVal, err := getArrayValues(funcName, entries)

	if err != nil {
		return nil, err
	}

	groups := make(map[string][]interface{})
	for i := 0; i < entriesVal.Len(); i++ {
		v := reflect.Indirect(entriesVal.Index(i)).Interface()
		value, err := getValue(v)
		if err != nil {
			return nil, err
		}
		if value != nil {
			addEntry(groups, value, v)
		}
	}
	return groups, nil
}
980232
func TypeGroupByName(name string) *WorkItemTypeGroup {
	for _, t := range TypeGroups() {
		if t.Name == name {
			return &t
		}
	}
	return nil
}
859589
func (b *SelectStmt) GroupBy(col ...string) *SelectStmt {
	for _, group := range col {
		b.Group = append(b.Group, Expr(group))
	}
	return b
}
297599
func (s *SelectQuery) GroupBy(cols ...string) *SelectQuery {
	s.groupBy = cols
	return s
}
1056745
func GetAllProjects(c context.Context) ([]Project, error) {
	q := datastore.NewQuery("Project")
	projs := []Project{}

	if err := datastore.GetAll(c, q, &projs); err != nil {
		return nil, errors.Annotate(err, "getting projects").Err()
	}
	result := []Project{}
	for _, proj := range projs {
		switch allowed, err := IsAllowed(c, proj.ID); {
		case err != nil:
			return nil, err
		case allowed:
			result = append(result, proj)
		}
	}
	return result, nil
}
1149561
func (statement *Statement) GroupBy(keys string) *Statement {
	statement.GroupByStr = keys
	return statement
}
1279557
func (ns *Namespace) Group(key interface{}, items interface{}) (interface{}, error) {
	if key == nil {
		return nil, errors.New("nil is not a valid key to group by")
	}

	if g, ok := items.(collections.Grouper); ok {
		return g.Group(key, items)
	}

	in := newSliceElement(items)

	if g, ok := in.(collections.Grouper); ok {
		return g.Group(key, items)
	}

	return nil, fmt.Errorf("grouping not supported for type %T %T", items, in)
}
57488
func (b *SelectBuilder) GroupBy(columns ...string) *SelectBuilder {
	b.groupBy = append(b.groupBy, columns...)
	return b
}
196149
func (o querySet) GroupBy(exprs ...string) QuerySeter {
	o.groups = exprs
	return &o
}
1256554
func (stmt SelectStmt) GroupBy(columns ...ColumnElem) SelectStmt {
	stmt.groupBy = columns
	return stmt
}
1373238
func (p Pages) GroupByDate(format string, order ...string) (PagesGroup, error) {
	sorter := func(p Pages) Pages {
		return p.ByDate()
	}
	formatter := func(p Page) string {
		return p.Date().Format(format)
	}
	return p.groupByDateField(sorter, formatter, order...)
}
128846
func (rb *route) SetGroupBy(groupBy sqlparser.GroupBy) error {
	rb.Select.(*sqlparser.Select).GroupBy = groupBy
	return nil
}
288533
func (info Info) GetGroupByID(groupID string) *Group {
	for _, group := range info.Groups {
		if group.ID == groupID {
			return &group
		}
	}
	return nil
}