mirror of
https://gitee.com/rulego/streamsql.git
synced 2026-03-14 14:27:27 +00:00
a47748d4c7
- Convert all Chinese function comments to English in functions package - Update interface documentation for better international readability - Maintain original logic and functionality unchanged - Improve code documentation standards for global development
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package functions
|
|
|
|
import "fmt"
|
|
|
|
// AggregatorFunction defines the interface for aggregator functions that support incremental computation
|
|
type AggregatorFunction interface {
|
|
Function
|
|
// New creates a new aggregator instance
|
|
New() AggregatorFunction
|
|
// Add adds a value for incremental computation
|
|
Add(value interface{})
|
|
// Result returns the aggregation result
|
|
Result() interface{}
|
|
// Reset resets the aggregator state
|
|
Reset()
|
|
// Clone clones the aggregator (used for window functions and similar scenarios)
|
|
Clone() AggregatorFunction
|
|
}
|
|
|
|
// AnalyticalFunction defines the interface for analytical functions with state management
|
|
// Now inherits from AggregatorFunction to support incremental computation
|
|
type AnalyticalFunction interface {
|
|
AggregatorFunction
|
|
}
|
|
|
|
// CreateAggregator creates an aggregator instance
|
|
func CreateAggregator(name string) (AggregatorFunction, error) {
|
|
fn, exists := Get(name)
|
|
if !exists {
|
|
return nil, fmt.Errorf("aggregator function %s not found", name)
|
|
}
|
|
|
|
if aggFn, ok := fn.(AggregatorFunction); ok {
|
|
return aggFn.New(), nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("function %s is not an aggregator function", name)
|
|
}
|
|
|
|
// CreateAnalytical creates an analytical function instance
|
|
func CreateAnalytical(name string) (AnalyticalFunction, error) {
|
|
fn, exists := Get(name)
|
|
if !exists {
|
|
return nil, fmt.Errorf("analytical function %s not found", name)
|
|
}
|
|
|
|
if analFn, ok := fn.(AnalyticalFunction); ok {
|
|
return analFn.New().(AnalyticalFunction), nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("function %s is not an analytical function", name)
|
|
}
|