diff --git a/go.mod b/go.mod index 44004f217..1d1fb24a3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( // like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b github.com/VictoriaMetrics/fasthttp v1.0.5 github.com/VictoriaMetrics/metrics v1.12.3 - github.com/VictoriaMetrics/metricsql v0.4.3 + github.com/VictoriaMetrics/metricsql v0.5.1 github.com/aws/aws-sdk-go v1.34.14 github.com/cespare/xxhash/v2 v2.1.1 github.com/golang/snappy v0.0.1 diff --git a/go.sum b/go.sum index f7e60a188..8ba667348 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/VictoriaMetrics/metrics v1.12.2 h1:SG8iAmqavDNuh7GIdHPoGHUhDL23KeKfvS github.com/VictoriaMetrics/metrics v1.12.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE= github.com/VictoriaMetrics/metrics v1.12.3 h1:Fe6JHC6MSEKa+BtLhPN8WIvS+HKPzMc2evEpNeCGy7I= github.com/VictoriaMetrics/metrics v1.12.3/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE= -github.com/VictoriaMetrics/metricsql v0.4.3 h1:4lezcOTMeGOfGtrf+I2YEC98lkx4nRczTiLrL+6E3CE= -github.com/VictoriaMetrics/metricsql v0.4.3/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8= +github.com/VictoriaMetrics/metricsql v0.5.1 h1:hG6Nck7R2/amLgHECobSTXsjZ2z9JP5J3W1sYlBoqfU= +github.com/VictoriaMetrics/metricsql v0.5.1/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= diff --git a/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go b/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go index 1e7d8be53..a265af00b 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go @@ -139,7 +139,7 @@ func isBinaryOpLogicalSet(op string) bool { } } -func binaryOpEval(op string, left, right float64, isBool bool) float64 { +func binaryOpEvalNumber(op string, left, right float64, isBool bool) float64 { if IsBinaryOpCmp(op) { evalCmp := func(cf func(left, right float64) bool) float64 { if isBool { diff --git a/vendor/github.com/VictoriaMetrics/metricsql/parser.go b/vendor/github.com/VictoriaMetrics/metricsql/parser.go index 212a5f5d4..e2934e57d 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/parser.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/parser.go @@ -169,19 +169,58 @@ func simplifyConstants(e Expr) Expr { be.Left = simplifyConstants(be.Left) be.Right = simplifyConstants(be.Right) - lne, ok := be.Left.(*NumberExpr) - if !ok { + lne, lok := be.Left.(*NumberExpr) + rne, rok := be.Right.(*NumberExpr) + if lok && rok { + n := binaryOpEvalNumber(be.Op, lne.N, rne.N, be.Bool) + return &NumberExpr{ + N: n, + } + } + + // Check whether both operands are string literals. + lse, lok := be.Left.(*StringExpr) + rse, rok := be.Right.(*StringExpr) + if !lok || !rok { return be } - rne, ok := be.Right.(*NumberExpr) - if !ok { + if be.Op == "+" { + // convert "foo" + "bar" to "foobar". + return &StringExpr{ + S: lse.S + rse.S, + } + } + if !IsBinaryOpCmp(be.Op) { return be } - n := binaryOpEval(be.Op, lne.N, rne.N, be.Bool) - ne := &NumberExpr{ + // Perform string comparisons. + ok = false + switch be.Op { + case "==": + ok = lse.S == rse.S + case "!=": + ok = lse.S != rse.S + case ">": + ok = lse.S > rse.S + case "<": + ok = lse.S < rse.S + case ">=": + ok = lse.S >= rse.S + case "<=": + ok = lse.S <= rse.S + default: + panic(fmt.Errorf("BUG: unexpected comparison binaryOp: %q", be.Op)) + } + n := float64(0) + if ok { + n = 1 + } + if !be.Bool && n == 0 { + n = nan + } + return &NumberExpr{ N: n, } - return ne } func simplifyConstantsInplace(args []Expr) { diff --git a/vendor/modules.txt b/vendor/modules.txt index f60906505..5e7d0c6a2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -16,7 +16,7 @@ github.com/VictoriaMetrics/fasthttp/fasthttputil github.com/VictoriaMetrics/fasthttp/stackless # github.com/VictoriaMetrics/metrics v1.12.3 github.com/VictoriaMetrics/metrics -# github.com/VictoriaMetrics/metricsql v0.4.3 +# github.com/VictoriaMetrics/metricsql v0.5.1 github.com/VictoriaMetrics/metricsql github.com/VictoriaMetrics/metricsql/binaryop # github.com/aws/aws-sdk-go v1.34.14