enhance: [2.4] update the expr version to support automatic conversion of variable types (#36847)

/kind improvement
- pr: #36832

Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
SimFG 2024-10-15 10:55:23 +08:00 committed by GitHub
parent 44564f0403
commit 6b9e28bc8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 6 deletions

2
go.mod
View File

@ -248,7 +248,7 @@ replace (
github.com/apache/arrow/go/v12 => github.com/milvus-io/arrow/go/v12 v12.0.1
github.com/apache/pulsar-client-go => github.com/milvus-io/pulsar-client-go v0.6.10
github.com/bketelsen/crypt => github.com/bketelsen/crypt v0.0.4 // Fix security alert for core-os/etcd
github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20240919063422-9ca3d5925361
github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20241012101405-9f20ab151517
github.com/go-kit/kit => github.com/go-kit/kit v0.1.0
// github.com/milvus-io/milvus-storage/go => ../milvus-storage/go
github.com/ianlancetaylor/cgosymbolizer => github.com/milvus-io/cgosymbolizer v0.0.0-20240722103217-b7dee0e50119

4
go.sum
View File

@ -76,8 +76,8 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/SimFG/expr v0.0.0-20240919063422-9ca3d5925361 h1:BaPdIKqIEp7dkTUoTM4I9GOCod8kZ50VT/cdKR+h4YU=
github.com/SimFG/expr v0.0.0-20240919063422-9ca3d5925361/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/SimFG/expr v0.0.0-20241012101405-9f20ab151517 h1:5GKGDLgoXHDyrYMWltZmNMVGTJW+8iQIFPi2Mlka2lg=
github.com/SimFG/expr v0.0.0-20241012101405-9f20ab151517/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/actgardner/gogen-avro/v10 v10.1.0/go.mod h1:o+ybmVjEa27AAr35FRqU98DJu1fXES56uXniYFv4yDA=
github.com/actgardner/gogen-avro/v10 v10.2.1/go.mod h1:QUhjeHPchheYmMDni/Nx7VB0RsT/ee8YIgGY/xpEQgQ=
github.com/actgardner/gogen-avro/v9 v9.1.0/go.mod h1:nyTj6wPqDJoxM3qdnjcLv+EnMDSDFqE0qDpva2QRmKc=

View File

@ -471,6 +471,9 @@ func (m *MetaCache) update(ctx context.Context, database, collectionName string,
if collectionName == "" {
collectionName = collection.Schema.GetName()
}
if database == "" {
log.Warn("database is empty, use default database name", zap.String("collectionName", collectionName), zap.Stack("stack"))
}
m.mu.Lock()
defer m.mu.Unlock()
_, dbOk := m.collInfo[database]

View File

@ -183,7 +183,7 @@ require (
replace (
github.com/apache/pulsar-client-go => github.com/milvus-io/pulsar-client-go v0.6.10
github.com/bketelsen/crypt => github.com/bketelsen/crypt v0.0.4 // Fix security alert for core-os/etcd
github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20240919063422-9ca3d5925361
github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20241012101405-9f20ab151517
github.com/go-kit/kit => github.com/go-kit/kit v0.1.0
github.com/ianlancetaylor/cgosymbolizer => github.com/milvus-io/cgosymbolizer v0.0.0-20240722103217-b7dee0e50119
github.com/streamnative/pulsarctl => github.com/xiaofan-luan/pulsarctl v0.5.1

View File

@ -60,8 +60,8 @@ github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwS
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/SimFG/expr v0.0.0-20240919063422-9ca3d5925361 h1:BaPdIKqIEp7dkTUoTM4I9GOCod8kZ50VT/cdKR+h4YU=
github.com/SimFG/expr v0.0.0-20240919063422-9ca3d5925361/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/SimFG/expr v0.0.0-20241012101405-9f20ab151517 h1:5GKGDLgoXHDyrYMWltZmNMVGTJW+8iQIFPi2Mlka2lg=
github.com/SimFG/expr v0.0.0-20241012101405-9f20ab151517/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/actgardner/gogen-avro/v10 v10.1.0/go.mod h1:o+ybmVjEa27AAr35FRqU98DJu1fXES56uXniYFv4yDA=
github.com/actgardner/gogen-avro/v10 v10.2.1/go.mod h1:QUhjeHPchheYmMDni/Nx7VB0RsT/ee8YIgGY/xpEQgQ=
github.com/actgardner/gogen-avro/v9 v9.1.0/go.mod h1:nyTj6wPqDJoxM3qdnjcLv+EnMDSDFqE0qDpva2QRmKc=

View File

@ -21,10 +21,12 @@ package expr
import (
"context"
"fmt"
"unsafe"
"github.com/expr-lang/expr"
"github.com/expr-lang/expr/vm"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/paramtable"
@ -40,6 +42,13 @@ func Init() {
v = &vm.VM{}
env = map[string]any{
"ctx": context.TODO(),
"objSize": func(p any) int {
message, ok := p.(proto.Message)
if !ok {
return int(unsafe.Sizeof(p))
}
return proto.Size(message)
},
}
authKey = paramtable.Get().EtcdCfg.RootPath.GetValue()
}

View File

@ -19,13 +19,20 @@
package expr
import (
"context"
"fmt"
"testing"
"unsafe"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)
type FooID = int64
func TestExec(t *testing.T) {
paramtable.Init()
t.Run("not init", func(t *testing.T) {
@ -34,6 +41,13 @@ func TestExec(t *testing.T) {
})
Init()
Register("foo", "hello")
Register("FuncWithContext", func(ctx context.Context, i FooID) int {
return int(100 + i)
})
mockMessage := &milvuspb.UserEntity{Name: "foo"}
Register("GetMockMessage", func() proto.Message {
return mockMessage
})
t.Run("empty code", func(t *testing.T) {
_, err := Exec("", "by-dev")
@ -60,4 +74,30 @@ func TestExec(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "hello", out)
})
t.Run("context function", func(t *testing.T) {
out, err := Exec("FuncWithContext(100)", "by-dev")
assert.NoError(t, err)
assert.Equal(t, "200", out)
})
innerSize := func(p any) int {
message, ok := p.(proto.Message)
if !ok {
return int(unsafe.Sizeof(p))
}
return proto.Size(message)
}
t.Run("size", func(t *testing.T) {
out, err := Exec("objSize(1)", "by-dev")
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("%d", innerSize(1)), out)
})
t.Run("proto size", func(t *testing.T) {
out, err := Exec("objSize(GetMockMessage())", "by-dev")
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("%d", innerSize(mockMessage)), out)
})
}