Skip to content

Commit

Permalink
Bump version & make Collection Option EnableDynamicSchema work (#625)
Browse files Browse the repository at this point in the history
Bump proto version to v2.3.3 and change go sdk verison

Also make create collection enable dynamic schema work

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Nov 10, 2023
1 parent 087d17c commit 17be3e5
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 99 deletions.
3 changes: 3 additions & 0 deletions client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func (c *GrpcClient) CreateCollection(ctx context.Context, collSchema *entity.Sc
}

func (c *GrpcClient) requestCreateCollection(ctx context.Context, sch *entity.Schema, opt *createCollOpt, shardNum int32) error {
if opt.EnableDynamicSchema {
sch.EnableDynamicField = true
}
bs, err := proto.Marshal(sch.ProtoMessage())
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
// SDKVersion const value for current version
SDKVersion = `v2.3.2`
SDKVersion = `v2.3.3`
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-faker/faker/v4 v4.1.0
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.2
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.3
github.com/stretchr/testify v1.8.1
github.com/tidwall/gjson v1.14.4
google.golang.org/grpc v1.48.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.2 h1:tBcKiEUcX6i3MaFYvMJO1F7R6fIoeLFkg1kSGE1Tvpk=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.2/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.3 h1:j6Ru7Lq421Ukp+XH8I+ny7dsVF2rLDLLoWpuFgoDZLM=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.3/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
58 changes: 28 additions & 30 deletions test/testcases/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,40 +267,38 @@ func TestQueryEmptyOutputFields(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
// connect
mc := createMilvusClient(ctx, t)
for _, enableDynamic := range []bool{true, false} {
// create, insert, index
collName, ids := createCollectionWithDataIndex(ctx, t, mc, true, true, client.WithEnableDynamicSchema(enableDynamic))

// Load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)
enableDynamic := false
// create, insert, index
collName, ids := createCollectionWithDataIndex(ctx, t, mc, true, true, client.WithEnableDynamicSchema(enableDynamic))

//query with empty output fields []string{}-> output "int64"
queryEmptyOutputs, _ := mc.QueryByPks(
ctx, collName, []string{common.DefaultPartition},
entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:10]),
[]string{},
)
common.CheckOutputFields(t, queryEmptyOutputs, []string{common.DefaultIntFieldName})
// Load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)

//query with empty output fields []string{""}-> output "int64" and dynamic field
queryEmptyOutputs, err := mc.QueryByPks(
ctx, collName, []string{common.DefaultPartition},
entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:10]),
[]string{""},
)
//query with empty output fields []string{}-> output "int64"
queryEmptyOutputs, _ := mc.QueryByPks(
ctx, collName, []string{common.DefaultPartition},
entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:10]),
[]string{},
)
common.CheckOutputFields(t, queryEmptyOutputs, []string{common.DefaultIntFieldName})

common.CheckErr(t, err, false, "not exist")
//query with empty output fields []string{""}-> output "int64" and dynamic field
_, err := mc.QueryByPks(
ctx, collName, []string{common.DefaultPartition},
entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:10]),
[]string{""},
)

// query with "float" output fields -> output "int64, float"
queryFloatOutputs, _ := mc.QueryByPks(
ctx, collName, []string{common.DefaultPartition},
entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:10]),
[]string{common.DefaultFloatFieldName},
)
common.CheckOutputFields(t, queryFloatOutputs, []string{common.DefaultIntFieldName, common.DefaultFloatFieldName})
}
common.CheckErr(t, err, false, "not exist")

// query with "float" output fields -> output "int64, float"
queryFloatOutputs, _ := mc.QueryByPks(
ctx, collName, []string{common.DefaultPartition},
entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:10]),
[]string{common.DefaultFloatFieldName},
)
common.CheckOutputFields(t, queryFloatOutputs, []string{common.DefaultIntFieldName, common.DefaultFloatFieldName})
}

// test query output int64 and float and floatVector fields
Expand Down Expand Up @@ -933,7 +931,7 @@ func TestQueryOutputInvalidOutputFieldCount(t *testing.T) {

// create, insert, index
collName, _ := createCollectionWithDataIndex(ctx, t, mc, true, true,
client.WithEnableDynamicSchema(true), client.WithConsistencyLevel(entity.ClStrong))
client.WithEnableDynamicSchema(false), client.WithConsistencyLevel(entity.ClStrong))

// Load collection
errLoad := mc.LoadCollection(ctx, collName, false)
Expand Down
133 changes: 66 additions & 67 deletions test/testcases/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,52 +267,51 @@ func TestSearchEmptyOutputFields(t *testing.T) {
// connect
mc := createMilvusClient(ctx, t)

for _, enableDynamic := range []bool{true, false} {
// create collection with data
collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, true, client.WithEnableDynamicSchema(enableDynamic))
enableDynamic := false
// create collection with data
collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, true, client.WithEnableDynamicSchema(enableDynamic))

// load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)
// load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)

// search vector output fields []string{} -> []
sp, _ := entity.NewIndexHNSWSearchParam(74)
searchResPkOutput, errSearch := mc.Search(
ctx, collName,
[]string{},
"",
[]string{},
common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
common.DefaultFloatVecFieldName,
entity.L2,
common.DefaultTopK,
sp,
)
common.CheckErr(t, errSearch, true)
common.CheckOutputFields(t, searchResPkOutput[0].Fields, []string{})
common.CheckSearchResult(t, searchResPkOutput, common.DefaultNq, common.DefaultTopK)
// search vector output fields []string{} -> []
sp, _ := entity.NewIndexHNSWSearchParam(74)
searchResPkOutput, errSearch := mc.Search(
ctx, collName,
[]string{},
"",
[]string{},
common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
common.DefaultFloatVecFieldName,
entity.L2,
common.DefaultTopK,
sp,
)
common.CheckErr(t, errSearch, true)
common.CheckOutputFields(t, searchResPkOutput[0].Fields, []string{})
common.CheckSearchResult(t, searchResPkOutput, common.DefaultNq, common.DefaultTopK)

// search vector output fields []string{""}
_, errSearchExist := mc.Search(
ctx, collName,
[]string{},
"",
[]string{""},
common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
common.DefaultFloatVecFieldName,
entity.L2,
common.DefaultTopK,
sp,
)
// search vector output fields []string{""}
_, errSearchExist := mc.Search(
ctx, collName,
[]string{},
"",
[]string{""},
common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
common.DefaultFloatVecFieldName,
entity.L2,
common.DefaultTopK,
sp,
)

//if enableDynamic {
// common.CheckErr(t, errSearchExist, true)
// common.CheckOutputFields(t, sp1[0].Fields, []string{""})
//} else {
common.CheckErr(t, errSearchExist, false, "not exist")
//}
common.CheckSearchResult(t, searchResPkOutput, common.DefaultNq, common.DefaultTopK)
}
//if enableDynamic {
// common.CheckErr(t, errSearchExist, true)
// common.CheckOutputFields(t, sp1[0].Fields, []string{""})
//} else {
common.CheckErr(t, errSearchExist, false, "not exist")
//}
common.CheckSearchResult(t, searchResPkOutput, common.DefaultNq, common.DefaultTopK)
}

// test search output fields not exist -> error
Expand All @@ -322,34 +321,34 @@ func TestSearchNotExistOutputFields(t *testing.T) {
// connect
mc := createMilvusClient(ctx, t)

for _, enableDynamic := range []bool{true, false} {
// create collection with data
collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, true, client.WithEnableDynamicSchema(enableDynamic))
// dynamic schema with unknown field will not have error
enableDynamic := false
// create collection with data
collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, true, client.WithEnableDynamicSchema(enableDynamic))

// load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)
// load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)

type notExistOutputFields []string
type notExistOutputFields []string

// search vector output fields not exist, part exist
outputFields := []notExistOutputFields{[]string{"aaa"}, []string{"fields", common.DefaultFloatFieldName},
[]string{"fields", "*"}}
for _, fields := range outputFields {
sp, _ := entity.NewIndexHNSWSearchParam(74)
_, errSearch := mc.Search(
ctx, collName,
[]string{},
"",
fields,
common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
common.DefaultFloatVecFieldName,
entity.L2,
common.DefaultTopK,
sp,
)
common.CheckErr(t, errSearch, false, "not exist")
}
// search vector output fields not exist, part exist
outputFields := []notExistOutputFields{[]string{"aaa"}, []string{"fields", common.DefaultFloatFieldName},
[]string{"fields", "*"}}
for _, fields := range outputFields {
sp, _ := entity.NewIndexHNSWSearchParam(74)
_, errSearch := mc.Search(
ctx, collName,
[]string{},
"",
fields,
common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
common.DefaultFloatVecFieldName,
entity.L2,
common.DefaultTopK,
sp,
)
common.CheckErr(t, errSearch, false, "not exist")
}
}

Expand Down

0 comments on commit 17be3e5

Please sign in to comment.