func (ev *evaluator) eval(row sqlbase.EncDatumRow) (sqlbase.EncDatumRow, error) { for i := range ev.exprs { datum, err := (&ev.exprs[i]).eval(row) if err != nil { return nil, err } ev.tuple[i] = datum } outRow := ev.rowAlloc.AllocRow(len(ev.tuple)) if err := sqlbase.DTupleToEncDatumRow(outRow, ev.tuple); err != nil { return nil, err } return outRow, nil }
func (ag *aggregator) computeAggregates() error { // Render the results. tuple := make(parser.DTuple, 0, len(ag.funcs)) for bucket := range ag.buckets { for _, f := range ag.funcs { datum := f.get(bucket) tuple = append(tuple, datum) } row := ag.rowAlloc.AllocRow(len(tuple)) err := sqlbase.DTupleToEncDatumRow(row, tuple) if err != nil { return err } if ok := ag.rows.PushRow(row); !ok { return errors.Errorf("unable to add row %s", row) } tuple = tuple[:0] } return nil }
func (ag *aggregator) computeAggregates() error { // Queries like `SELECT MAX(n) FROM t` expect a row of NULLs if nothing was // aggregated. if len(ag.buckets) < 1 && len(ag.groupCols) == 0 { ag.buckets[""] = struct{}{} } // Render the results. tuple := make(parser.DTuple, 0, len(ag.funcs)) for bucket := range ag.buckets { for _, f := range ag.funcs { datum := f.get(bucket) tuple = append(tuple, datum) } row := ag.rowAlloc.AllocRow(len(tuple)) sqlbase.DTupleToEncDatumRow(row, ag.outputTypes, tuple) if ok := ag.rows.PushRow(row); !ok { return errors.Errorf("unable to add row %s", row) } tuple = tuple[:0] } return nil }