Procházet zdrojové kódy

fix(func): analytic func nil cache (#2221)

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
ngjaying před 1 rokem
rodič
revize
2bdc4fc29f

+ 9 - 1
internal/binder/function/funcs_analytic_test.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -1180,6 +1180,14 @@ func TestLatestExec(t *testing.T) {
 	}{
 		{ // 1
 			args: []interface{}{
+				nil,
+				true,
+				"self",
+			},
+			result: nil,
+		},
+		{ // 1
+			args: []interface{}{
 				"foo",
 				true,
 				"self",

+ 3 - 6
internal/xsql/valuer.go

@@ -284,12 +284,9 @@ func (v *ValuerEval) Eval(expr ast.Expr) interface{} {
 	case *ast.Call:
 		// The analytic functions are calculated prior to all ops, so just get the cached field value
 		if expr.Cached && expr.CachedField != "" {
-			val, ok := v.Valuer.Value(expr.CachedField, "")
-			if ok {
-				return val
-			} else {
-				return fmt.Errorf("call %s error: %v", expr.Name, val)
-			}
+			val, _ := v.Valuer.Value(expr.CachedField, "")
+			// nil is also cached
+			return val
 		}
 		if _, ok := implicitValueFuncs[expr.Name]; ok {
 			if vv, ok := v.Valuer.(FuncValuer); ok {