Expressions: Use enumerations rather than strings (#83741)

This commit is contained in:
Ryan McKinley
2024-03-01 19:38:32 +02:00
committed by GitHub
parent c59ebfc60f
commit 5f6bf93dd5
9 changed files with 77 additions and 41 deletions
+8 -4
View File
@@ -205,14 +205,14 @@ func (gr *ReduceCommand) Execute(ctx context.Context, _ time.Time, vars mathexp.
type ResampleCommand struct {
Window time.Duration
VarToResample string
Downsampler string
Upsampler string
Downsampler mathexp.ReducerID
Upsampler mathexp.Upsampler
TimeRange TimeRange
refID string
}
// NewResampleCommand creates a new ResampleCMD.
func NewResampleCommand(refID, rawWindow, varToResample string, downsampler string, upsampler string, tr TimeRange) (*ResampleCommand, error) {
func NewResampleCommand(refID, rawWindow, varToResample string, downsampler mathexp.ReducerID, upsampler mathexp.Upsampler, tr TimeRange) (*ResampleCommand, error) {
// TODO: validate reducer here, before execution
window, err := gtime.ParseDuration(rawWindow)
if err != nil {
@@ -271,7 +271,11 @@ func UnmarshalResampleCommand(rn *rawNode) (*ResampleCommand, error) {
return nil, fmt.Errorf("expected resample downsampler to be a string, got type %T", upsampler)
}
return NewResampleCommand(rn.RefID, window, varToResample, downsampler, upsampler, rn.TimeRange)
return NewResampleCommand(rn.RefID, window,
varToResample,
mathexp.ReducerID(downsampler),
mathexp.Upsampler(upsampler),
rn.TimeRange)
}
// NeedsVars returns the variable names (refIds) that are dependencies