github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/aggregate_funcs.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tree 12 13 import "context" 14 15 // AggregateFunc accumulates the result of a function of a Datum. 16 type AggregateFunc interface { 17 // Add accumulates the passed datums into the AggregateFunc. 18 // Most implementations require one and only one firstArg argument. 19 // If an aggregate function requires more than one argument, 20 // all additional arguments (after firstArg) are passed in as a 21 // variadic collection, otherArgs. 22 // This interface (as opposed to `args ...Datum`) avoids unnecessary 23 // allocation of otherArgs in the majority of cases. 24 Add(_ context.Context, firstArg Datum, otherArgs ...Datum) error 25 26 // Result returns the current value of the accumulation. This value 27 // will be a deep copy of any AggregateFunc internal state, so that 28 // it will not be mutated by additional calls to Add. 29 Result() (Datum, error) 30 31 // Reset resets the aggregate function which allows for reusing the same 32 // instance for computation without the need to create a new instance. 33 // Any memory is kept, if possible. 34 Reset(context.Context) 35 36 // Close closes out the AggregateFunc and allows it to release any memory it 37 // requested during aggregation, and must be called upon completion of the 38 // aggregation. 39 Close(context.Context) 40 41 // Size returns the size of the AggregateFunc implementation in bytes. It 42 // does *not* account for additional memory used during accumulation. 43 Size() int64 44 }