vendor: update github.com/VictoriaMetrics/metricsql from v0.4.3 to v0.5.1

The new version of the package supports binary operations on string literals:

    * "foo" + "bar"     => "foobar"
    * "foo" == "bar"    => NaN
    * "foo" == "foo"    => 1
    * "foo" >bool "bar" => 1
    * "foo" < "bar"     => NaN

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/717
This commit is contained in:
Aliaksandr Valialkin 2020-09-03 16:11:46 +03:00
parent 478d8f8393
commit fcde009e11
5 changed files with 51 additions and 12 deletions

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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 {

View File

@ -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) {

2
vendor/modules.txt vendored
View File

@ -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