mirror of https://github.com/milvus-io/milvus.git
enhance: Add rules and fix for go_client e2e code style (#34033)
See also #31293 --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>pull/34043/head
parent
4e414fb7fc
commit
35ea775c14
6
Makefile
6
Makefile
|
@ -144,6 +144,7 @@ lint-fix: getdeps
|
|||
@$(INSTALL_PATH)/gofumpt -l -w cmd/
|
||||
@$(INSTALL_PATH)/gofumpt -l -w pkg/
|
||||
@$(INSTALL_PATH)/gofumpt -l -w client/
|
||||
@$(INSTALL_PATH)/gofumpt -l -w tests/go_client/
|
||||
@$(INSTALL_PATH)/gofumpt -l -w tests/integration/
|
||||
@echo "Running gci fix"
|
||||
@$(INSTALL_PATH)/gci write cmd/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order
|
||||
|
@ -159,9 +160,14 @@ lint-fix: getdeps
|
|||
#TODO: Check code specifications by golangci-lint
|
||||
static-check: getdeps
|
||||
@echo "Running $@ check"
|
||||
@echo "Start check core packages"
|
||||
@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --build-tags dynamic,test --timeout=30m --config $(PWD)/.golangci.yml
|
||||
@echo "Start check pkg package"
|
||||
@source $(PWD)/scripts/setenv.sh && cd pkg && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --build-tags dynamic,test --timeout=30m --config $(PWD)/.golangci.yml
|
||||
@echo "Start check client package"
|
||||
@source $(PWD)/scripts/setenv.sh && cd client && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config $(PWD)/client/.golangci.yml
|
||||
@echo "Start check go_client e2e package"
|
||||
@source $(PWD)/scripts/setenv.sh && cd tests/go_client && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config $(PWD)/client/.golangci.yml
|
||||
|
||||
verifiers: build-cpp getdeps cppcheck fmt static-check
|
||||
|
||||
|
|
|
@ -451,8 +451,8 @@ func (c *ColumnInt64) Slice(start, end int) Column {
|
|||
}
|
||||
return &ColumnInt64{
|
||||
ColumnBase: c.ColumnBase,
|
||||
name: c.name,
|
||||
values: c.values[start: end],
|
||||
name: c.name,
|
||||
values: c.values[start:end],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ func (c *ColumnBinaryVector) Slice(start, end int) Column {
|
|||
return &ColumnBinaryVector{
|
||||
ColumnBase: c.ColumnBase,
|
||||
name: c.name,
|
||||
dim: c.dim,
|
||||
dim: c.dim,
|
||||
values: c.values[start:end],
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ func (c *ColumnFloatVector) Slice(start, end int) Column {
|
|||
return &ColumnFloatVector{
|
||||
ColumnBase: c.ColumnBase,
|
||||
name: c.name,
|
||||
dim: c.dim,
|
||||
dim: c.dim,
|
||||
values: c.values[start:end],
|
||||
}
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ func (c *ColumnFloat16Vector) Slice(start, end int) Column {
|
|||
return &ColumnFloat16Vector{
|
||||
ColumnBase: c.ColumnBase,
|
||||
name: c.name,
|
||||
dim: c.dim,
|
||||
dim: c.dim,
|
||||
values: c.values[start:end],
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ func (c *ColumnBFloat16Vector) Slice(start, end int) Column {
|
|||
return &ColumnBFloat16Vector{
|
||||
ColumnBase: c.ColumnBase,
|
||||
name: c.name,
|
||||
dim: c.dim,
|
||||
dim: c.dim,
|
||||
values: c.values[start:end],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
include:
|
||||
- "../../.golangci.yml"
|
||||
|
||||
linters-settings:
|
||||
gocritic:
|
||||
enabled-checks:
|
||||
- ruleguard
|
||||
settings:
|
||||
ruleguard:
|
||||
failOnError: true
|
||||
rules: "ruleguard/rules.go"
|
|
@ -6,15 +6,13 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/client/v2/index"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
)
|
||||
|
||||
func LoggingUnaryInterceptor() grpc.UnaryClientInterceptor {
|
||||
|
@ -116,7 +114,7 @@ func (mc *MilvusClient) ListCollections(ctx context.Context, option clientv2.Lis
|
|||
return collectionNames, err
|
||||
}
|
||||
|
||||
//DescribeCollection Describe collection
|
||||
// DescribeCollection Describe collection
|
||||
func (mc *MilvusClient) DescribeCollection(ctx context.Context, option clientv2.DescribeCollectionOption, callOptions ...grpc.CallOption) (*entity.Collection, error) {
|
||||
collection, err := mc.mClient.DescribeCollection(ctx, option, callOptions...)
|
||||
return collection, err
|
||||
|
@ -197,7 +195,7 @@ func (mc *MilvusClient) DropIndex(ctx context.Context, option clientv2.DropIndex
|
|||
// Insert insert data
|
||||
func (mc *MilvusClient) Insert(ctx context.Context, option clientv2.InsertOption, callOptions ...grpc.CallOption) (clientv2.InsertResult, error) {
|
||||
insertRes, err := mc.mClient.Insert(ctx, option, callOptions...)
|
||||
if err == nil{
|
||||
if err == nil {
|
||||
log.Info("Insert", zap.Any("result", insertRes))
|
||||
}
|
||||
return insertRes, err
|
||||
|
|
|
@ -5,14 +5,13 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/column"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/column"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
)
|
||||
|
||||
func CheckErr(t *testing.T, actualErr error, expErrNil bool, expErrorMsg ...string) {
|
||||
|
@ -71,10 +70,12 @@ func EqualColumn(t *testing.T, columnA column.Column, columnB column.Column) {
|
|||
case entity.FieldTypeArray:
|
||||
log.Info("TODO support column element type")
|
||||
default:
|
||||
log.Info("Support column type is:", zap.Any("FieldType", []entity.FieldType{entity.FieldTypeBool,
|
||||
log.Info("Support column type is:", zap.Any("FieldType", []entity.FieldType{
|
||||
entity.FieldTypeBool,
|
||||
entity.FieldTypeInt8, entity.FieldTypeInt16, entity.FieldTypeInt32, entity.FieldTypeInt64,
|
||||
entity.FieldTypeFloat, entity.FieldTypeDouble, entity.FieldTypeString, entity.FieldTypeVarChar,
|
||||
entity.FieldTypeArray, entity.FieldTypeFloatVector, entity.FieldTypeBinaryVector}))
|
||||
entity.FieldTypeArray, entity.FieldTypeFloatVector, entity.FieldTypeBinaryVector,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,14 +8,17 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/x448/float16"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
)
|
||||
|
||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
var r *rand.Rand
|
||||
var (
|
||||
letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
r *rand.Rand
|
||||
)
|
||||
|
||||
func init() {
|
||||
r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
@ -70,7 +73,7 @@ func GenInvalidNames() []string {
|
|||
|
||||
func GenFloatVector(dim int) []float32 {
|
||||
vector := make([]float32, 0, dim)
|
||||
for j := 0; j < int(dim); j++ {
|
||||
for j := 0; j < dim; j++ {
|
||||
vector = append(vector, rand.Float32())
|
||||
}
|
||||
return vector
|
||||
|
@ -78,7 +81,7 @@ func GenFloatVector(dim int) []float32 {
|
|||
|
||||
func GenFloat16Vector(dim int) []byte {
|
||||
ret := make([]byte, dim*2)
|
||||
for i := 0; i < int(dim); i++ {
|
||||
for i := 0; i < dim; i++ {
|
||||
v := float16.Fromfloat32(rand.Float32()).Bits()
|
||||
binary.LittleEndian.PutUint16(ret[i*2:], v)
|
||||
}
|
||||
|
@ -87,7 +90,7 @@ func GenFloat16Vector(dim int) []byte {
|
|||
|
||||
func GenBFloat16Vector(dim int) []byte {
|
||||
ret16 := make([]uint16, 0, dim)
|
||||
for i := 0; i < int(dim); i++ {
|
||||
for i := 0; i < dim; i++ {
|
||||
f := rand.Float32()
|
||||
bits := math.Float32bits(f)
|
||||
bits >>= 16
|
||||
|
@ -151,5 +154,5 @@ var InvalidExpressions = []InvalidExprStruct{
|
|||
{Expr: fmt.Sprintf("json_contains_aby (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression: json_contains_aby"},
|
||||
{Expr: fmt.Sprintf("json_contains_aby (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression: json_contains_aby"},
|
||||
{Expr: fmt.Sprintf("%s[-1] > %d", DefaultInt8ArrayField, TestCapacity), ErrNil: false, ErrMsg: "cannot parse expression"}, // array[-1] >
|
||||
{Expr: fmt.Sprintf(fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName)), ErrNil: false, ErrMsg: "invalid expression"}, // json[-1] >
|
||||
}
|
||||
{Expr: fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression"}, // json[-1] >
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ require (
|
|||
github.com/prometheus/client_model v0.3.0 // indirect
|
||||
github.com/prometheus/common v0.42.0 // indirect
|
||||
github.com/prometheus/procfs v0.9.0 // indirect
|
||||
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
|
||||
github.com/rogpeppe/go-internal v1.10.0 // indirect
|
||||
github.com/samber/lo v1.27.0 // indirect
|
||||
github.com/shirou/gopsutil/v3 v3.22.9 // indirect
|
||||
|
|
|
@ -490,6 +490,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
|
|||
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
|
||||
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/quasilyte/go-ruleguard/dsl v0.3.22 h1:wd8zkOhSNr+I+8Qeciml08ivDt1pSXe60+5DqOpCjPE=
|
||||
github.com/quasilyte/go-ruleguard/dsl v0.3.22/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
|
|
|
@ -0,0 +1,409 @@
|
|||
// Licensed to the LF AI & Data foundation under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package gorules
|
||||
|
||||
import (
|
||||
"github.com/quasilyte/go-ruleguard/dsl"
|
||||
)
|
||||
|
||||
// This is a collection of rules for ruleguard: https://github.com/quasilyte/go-ruleguard
|
||||
|
||||
// Remove extra conversions: mdempsky/unconvert
|
||||
func unconvert(m dsl.Matcher) {
|
||||
m.Match("int($x)").Where(m["x"].Type.Is("int") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
|
||||
m.Match("float32($x)").Where(m["x"].Type.Is("float32") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("float64($x)").Where(m["x"].Type.Is("float64") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
|
||||
// m.Match("byte($x)").Where(m["x"].Type.Is("byte")).Report("unnecessary conversion").Suggest("$x")
|
||||
// m.Match("rune($x)").Where(m["x"].Type.Is("rune")).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("bool($x)").Where(m["x"].Type.Is("bool") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
|
||||
m.Match("int8($x)").Where(m["x"].Type.Is("int8") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("int16($x)").Where(m["x"].Type.Is("int16") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("int32($x)").Where(m["x"].Type.Is("int32") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("int64($x)").Where(m["x"].Type.Is("int64") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
|
||||
m.Match("uint8($x)").Where(m["x"].Type.Is("uint8") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("uint16($x)").Where(m["x"].Type.Is("uint16") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("uint32($x)").Where(m["x"].Type.Is("uint32") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
m.Match("uint64($x)").Where(m["x"].Type.Is("uint64") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x")
|
||||
|
||||
m.Match("time.Duration($x)").Where(m["x"].Type.Is("time.Duration") && !m["x"].Text.Matches("^[0-9]*$")).Report("unnecessary conversion").Suggest("$x")
|
||||
}
|
||||
|
||||
// Don't use == or != with time.Time
|
||||
// https://github.com/dominikh/go-tools/issues/47 : Wontfix
|
||||
func timeeq(m dsl.Matcher) {
|
||||
m.Match("$t0 == $t1").Where(m["t0"].Type.Is("time.Time")).Report("using == with time.Time")
|
||||
m.Match("$t0 != $t1").Where(m["t0"].Type.Is("time.Time")).Report("using != with time.Time")
|
||||
m.Match(`map[$k]$v`).Where(m["k"].Type.Is("time.Time")).Report("map with time.Time keys are easy to misuse")
|
||||
}
|
||||
|
||||
// err but no an error
|
||||
func errnoterror(m dsl.Matcher) {
|
||||
// Would be easier to check for all err identifiers instead, but then how do we get the type from m[] ?
|
||||
|
||||
m.Match(
|
||||
"if $*_, err := $x; $err != nil { $*_ } else if $_ { $*_ }",
|
||||
"if $*_, err := $x; $err != nil { $*_ } else { $*_ }",
|
||||
"if $*_, err := $x; $err != nil { $*_ }",
|
||||
|
||||
"if $*_, err = $x; $err != nil { $*_ } else if $_ { $*_ }",
|
||||
"if $*_, err = $x; $err != nil { $*_ } else { $*_ }",
|
||||
"if $*_, err = $x; $err != nil { $*_ }",
|
||||
|
||||
"$*_, err := $x; if $err != nil { $*_ } else if $_ { $*_ }",
|
||||
"$*_, err := $x; if $err != nil { $*_ } else { $*_ }",
|
||||
"$*_, err := $x; if $err != nil { $*_ }",
|
||||
|
||||
"$*_, err = $x; if $err != nil { $*_ } else if $_ { $*_ }",
|
||||
"$*_, err = $x; if $err != nil { $*_ } else { $*_ }",
|
||||
"$*_, err = $x; if $err != nil { $*_ }",
|
||||
).
|
||||
Where(m["err"].Text == "err" && !m["err"].Type.Is("error") && m["x"].Text != "recover()").
|
||||
Report("err variable not error type")
|
||||
}
|
||||
|
||||
// Identical if and else bodies
|
||||
func ifbodythenbody(m dsl.Matcher) {
|
||||
m.Match("if $*_ { $body } else { $body }").
|
||||
Report("identical if and else bodies")
|
||||
|
||||
// Lots of false positives.
|
||||
// m.Match("if $*_ { $body } else if $*_ { $body }").
|
||||
// Report("identical if and else bodies")
|
||||
}
|
||||
|
||||
// Odd inequality: A - B < 0 instead of !=
|
||||
// Too many false positives.
|
||||
/*
|
||||
func subtractnoteq(m dsl.Matcher) {
|
||||
m.Match("$a - $b < 0").Report("consider $a != $b")
|
||||
m.Match("$a - $b > 0").Report("consider $a != $b")
|
||||
m.Match("0 < $a - $b").Report("consider $a != $b")
|
||||
m.Match("0 > $a - $b").Report("consider $a != $b")
|
||||
}
|
||||
*/
|
||||
|
||||
// Self-assignment
|
||||
func selfassign(m dsl.Matcher) {
|
||||
m.Match("$x = $x").Report("useless self-assignment")
|
||||
}
|
||||
|
||||
// Odd nested ifs
|
||||
func oddnestedif(m dsl.Matcher) {
|
||||
m.Match("if $x { if $x { $*_ }; $*_ }",
|
||||
"if $x == $y { if $x != $y {$*_ }; $*_ }",
|
||||
"if $x != $y { if $x == $y {$*_ }; $*_ }",
|
||||
"if $x { if !$x { $*_ }; $*_ }",
|
||||
"if !$x { if $x { $*_ }; $*_ }").
|
||||
Report("odd nested ifs")
|
||||
|
||||
m.Match("for $x { if $x { $*_ }; $*_ }",
|
||||
"for $x == $y { if $x != $y {$*_ }; $*_ }",
|
||||
"for $x != $y { if $x == $y {$*_ }; $*_ }",
|
||||
"for $x { if !$x { $*_ }; $*_ }",
|
||||
"for !$x { if $x { $*_ }; $*_ }").
|
||||
Report("odd nested for/ifs")
|
||||
}
|
||||
|
||||
// odd bitwise expressions
|
||||
func oddbitwise(m dsl.Matcher) {
|
||||
m.Match("$x | $x",
|
||||
"$x | ^$x",
|
||||
"^$x | $x").
|
||||
Report("odd bitwise OR")
|
||||
|
||||
m.Match("$x & $x",
|
||||
"$x & ^$x",
|
||||
"^$x & $x").
|
||||
Report("odd bitwise AND")
|
||||
|
||||
m.Match("$x &^ $x").
|
||||
Report("odd bitwise AND-NOT")
|
||||
}
|
||||
|
||||
// odd sequence of if tests with return
|
||||
func ifreturn(m dsl.Matcher) {
|
||||
m.Match("if $x { return $*_ }; if $x {$*_ }").Report("odd sequence of if test")
|
||||
m.Match("if $x { return $*_ }; if !$x {$*_ }").Report("odd sequence of if test")
|
||||
m.Match("if !$x { return $*_ }; if $x {$*_ }").Report("odd sequence of if test")
|
||||
m.Match("if $x == $y { return $*_ }; if $x != $y {$*_ }").Report("odd sequence of if test")
|
||||
m.Match("if $x != $y { return $*_ }; if $x == $y {$*_ }").Report("odd sequence of if test")
|
||||
}
|
||||
|
||||
func oddifsequence(m dsl.Matcher) {
|
||||
/*
|
||||
m.Match("if $x { $*_ }; if $x {$*_ }").Report("odd sequence of if test")
|
||||
|
||||
m.Match("if $x == $y { $*_ }; if $y == $x {$*_ }").Report("odd sequence of if tests")
|
||||
m.Match("if $x != $y { $*_ }; if $y != $x {$*_ }").Report("odd sequence of if tests")
|
||||
|
||||
m.Match("if $x < $y { $*_ }; if $y > $x {$*_ }").Report("odd sequence of if tests")
|
||||
m.Match("if $x <= $y { $*_ }; if $y >= $x {$*_ }").Report("odd sequence of if tests")
|
||||
|
||||
m.Match("if $x > $y { $*_ }; if $y < $x {$*_ }").Report("odd sequence of if tests")
|
||||
m.Match("if $x >= $y { $*_ }; if $y <= $x {$*_ }").Report("odd sequence of if tests")
|
||||
*/
|
||||
}
|
||||
|
||||
// odd sequence of nested if tests
|
||||
func nestedifsequence(m dsl.Matcher) {
|
||||
/*
|
||||
m.Match("if $x < $y { if $x >= $y {$*_ }; $*_ }").Report("odd sequence of nested if tests")
|
||||
m.Match("if $x <= $y { if $x > $y {$*_ }; $*_ }").Report("odd sequence of nested if tests")
|
||||
m.Match("if $x > $y { if $x <= $y {$*_ }; $*_ }").Report("odd sequence of nested if tests")
|
||||
m.Match("if $x >= $y { if $x < $y {$*_ }; $*_ }").Report("odd sequence of nested if tests")
|
||||
*/
|
||||
}
|
||||
|
||||
// odd sequence of assignments
|
||||
func identicalassignments(m dsl.Matcher) {
|
||||
m.Match("$x = $y; $y = $x").Report("odd sequence of assignments")
|
||||
}
|
||||
|
||||
func oddcompoundop(m dsl.Matcher) {
|
||||
m.Match("$x += $x + $_",
|
||||
"$x += $x - $_").
|
||||
Report("odd += expression")
|
||||
|
||||
m.Match("$x -= $x + $_",
|
||||
"$x -= $x - $_").
|
||||
Report("odd -= expression")
|
||||
}
|
||||
|
||||
func constswitch(m dsl.Matcher) {
|
||||
m.Match("switch $x { $*_ }", "switch $*_; $x { $*_ }").
|
||||
Where(m["x"].Const && !m["x"].Text.Matches(`^runtime\.`)).
|
||||
Report("constant switch")
|
||||
}
|
||||
|
||||
func oddcomparisons(m dsl.Matcher) {
|
||||
m.Match(
|
||||
"$x - $y == 0",
|
||||
"$x - $y != 0",
|
||||
"$x - $y < 0",
|
||||
"$x - $y <= 0",
|
||||
"$x - $y > 0",
|
||||
"$x - $y >= 0",
|
||||
"$x ^ $y == 0",
|
||||
"$x ^ $y != 0",
|
||||
).Report("odd comparison")
|
||||
}
|
||||
|
||||
func oddmathbits(m dsl.Matcher) {
|
||||
m.Match(
|
||||
"64 - bits.LeadingZeros64($x)",
|
||||
"32 - bits.LeadingZeros32($x)",
|
||||
"16 - bits.LeadingZeros16($x)",
|
||||
"8 - bits.LeadingZeros8($x)",
|
||||
).Report("odd math/bits expression: use bits.Len*() instead?")
|
||||
}
|
||||
|
||||
// func floateq(m dsl.Matcher) {
|
||||
// m.Match(
|
||||
// "$x == $y",
|
||||
// "$x != $y",
|
||||
// ).
|
||||
// Where(m["x"].Type.Is("float32") && !m["x"].Const && !m["y"].Text.Matches("0(.0+)?") && !m.File().Name.Matches("floating_comparision.go")).
|
||||
// Report("floating point tested for equality")
|
||||
|
||||
// m.Match(
|
||||
// "$x == $y",
|
||||
// "$x != $y",
|
||||
// ).
|
||||
// Where(m["x"].Type.Is("float64") && !m["x"].Const && !m["y"].Text.Matches("0(.0+)?") && !m.File().Name.Matches("floating_comparision.go")).
|
||||
// Report("floating point tested for equality")
|
||||
|
||||
// m.Match("switch $x { $*_ }", "switch $*_; $x { $*_ }").
|
||||
// Where(m["x"].Type.Is("float32")).
|
||||
// Report("floating point as switch expression")
|
||||
|
||||
// m.Match("switch $x { $*_ }", "switch $*_; $x { $*_ }").
|
||||
// Where(m["x"].Type.Is("float64")).
|
||||
// Report("floating point as switch expression")
|
||||
|
||||
// }
|
||||
|
||||
func badexponent(m dsl.Matcher) {
|
||||
m.Match(
|
||||
"2 ^ $x",
|
||||
"10 ^ $x",
|
||||
).
|
||||
Report("caret (^) is not exponentiation")
|
||||
}
|
||||
|
||||
func floatloop(m dsl.Matcher) {
|
||||
m.Match(
|
||||
"for $i := $x; $i < $y; $i += $z { $*_ }",
|
||||
"for $i = $x; $i < $y; $i += $z { $*_ }",
|
||||
).
|
||||
Where(m["i"].Type.Is("float64")).
|
||||
Report("floating point for loop counter")
|
||||
|
||||
m.Match(
|
||||
"for $i := $x; $i < $y; $i += $z { $*_ }",
|
||||
"for $i = $x; $i < $y; $i += $z { $*_ }",
|
||||
).
|
||||
Where(m["i"].Type.Is("float32")).
|
||||
Report("floating point for loop counter")
|
||||
}
|
||||
|
||||
func urlredacted(m dsl.Matcher) {
|
||||
m.Match(
|
||||
"log.Println($x, $*_)",
|
||||
"log.Println($*_, $x, $*_)",
|
||||
"log.Println($*_, $x)",
|
||||
"log.Printf($*_, $x, $*_)",
|
||||
"log.Printf($*_, $x)",
|
||||
|
||||
"log.Println($x, $*_)",
|
||||
"log.Println($*_, $x, $*_)",
|
||||
"log.Println($*_, $x)",
|
||||
"log.Printf($*_, $x, $*_)",
|
||||
"log.Printf($*_, $x)",
|
||||
).
|
||||
Where(m["x"].Type.Is("*url.URL")).
|
||||
Report("consider $x.Redacted() when outputting URLs")
|
||||
}
|
||||
|
||||
func sprinterr(m dsl.Matcher) {
|
||||
m.Match(`fmt.Sprint($err)`,
|
||||
`fmt.Sprintf("%s", $err)`,
|
||||
`fmt.Sprintf("%v", $err)`,
|
||||
).
|
||||
Where(m["err"].Type.Is("error")).
|
||||
Report("maybe call $err.Error() instead of fmt.Sprint()?")
|
||||
}
|
||||
|
||||
// disable this check, because it can not apply to generic type
|
||||
// func largeloopcopy(m dsl.Matcher) {
|
||||
// m.Match(
|
||||
// `for $_, $v := range $_ { $*_ }`,
|
||||
// ).
|
||||
// Where(m["v"].Type.Size > 1024).
|
||||
// Report(`loop copies large value each iteration`)
|
||||
//}
|
||||
|
||||
func joinpath(m dsl.Matcher) {
|
||||
m.Match(
|
||||
`strings.Join($_, "/")`,
|
||||
`strings.Join($_, "\\")`,
|
||||
"strings.Join($_, `\\`)",
|
||||
).
|
||||
Report(`did you mean path.Join() or filepath.Join() ?`)
|
||||
}
|
||||
|
||||
func readfull(m dsl.Matcher) {
|
||||
m.Match(`$n, $err := io.ReadFull($_, $slice)
|
||||
if $err != nil || $n != len($slice) {
|
||||
$*_
|
||||
}`,
|
||||
`$n, $err := io.ReadFull($_, $slice)
|
||||
if $n != len($slice) || $err != nil {
|
||||
$*_
|
||||
}`,
|
||||
`$n, $err = io.ReadFull($_, $slice)
|
||||
if $err != nil || $n != len($slice) {
|
||||
$*_
|
||||
}`,
|
||||
`$n, $err = io.ReadFull($_, $slice)
|
||||
if $n != len($slice) || $err != nil {
|
||||
$*_
|
||||
}`,
|
||||
`if $n, $err := io.ReadFull($_, $slice); $n != len($slice) || $err != nil {
|
||||
$*_
|
||||
}`,
|
||||
`if $n, $err := io.ReadFull($_, $slice); $err != nil || $n != len($slice) {
|
||||
$*_
|
||||
}`,
|
||||
`if $n, $err = io.ReadFull($_, $slice); $n != len($slice) || $err != nil {
|
||||
$*_
|
||||
}`,
|
||||
`if $n, $err = io.ReadFull($_, $slice); $err != nil || $n != len($slice) {
|
||||
$*_
|
||||
}`,
|
||||
).Report("io.ReadFull() returns err == nil iff n == len(slice)")
|
||||
}
|
||||
|
||||
func nilerr(m dsl.Matcher) {
|
||||
m.Match(
|
||||
`if err == nil { return err }`,
|
||||
`if err == nil { return $*_, err }`,
|
||||
).
|
||||
Report(`return nil error instead of nil value`)
|
||||
}
|
||||
|
||||
func mailaddress(m dsl.Matcher) {
|
||||
m.Match(
|
||||
"fmt.Sprintf(`\"%s\" <%s>`, $NAME, $EMAIL)",
|
||||
"fmt.Sprintf(`\"%s\"<%s>`, $NAME, $EMAIL)",
|
||||
"fmt.Sprintf(`%s <%s>`, $NAME, $EMAIL)",
|
||||
"fmt.Sprintf(`%s<%s>`, $NAME, $EMAIL)",
|
||||
`fmt.Sprintf("\"%s\"<%s>", $NAME, $EMAIL)`,
|
||||
`fmt.Sprintf("\"%s\" <%s>", $NAME, $EMAIL)`,
|
||||
`fmt.Sprintf("%s<%s>", $NAME, $EMAIL)`,
|
||||
`fmt.Sprintf("%s <%s>", $NAME, $EMAIL)`,
|
||||
).
|
||||
Report("use net/mail Address.String() instead of fmt.Sprintf()").
|
||||
Suggest("(&mail.Address{Name:$NAME, Address:$EMAIL}).String()")
|
||||
}
|
||||
|
||||
func errnetclosed(m dsl.Matcher) {
|
||||
m.Match(
|
||||
`strings.Contains($err.Error(), $text)`,
|
||||
).
|
||||
Where(m["text"].Text.Matches("\".*closed network connection.*\"")).
|
||||
Report(`String matching against error texts is fragile; use net.ErrClosed instead`).
|
||||
Suggest(`errors.Is($err, net.ErrClosed)`)
|
||||
}
|
||||
|
||||
func httpheaderadd(m dsl.Matcher) {
|
||||
m.Match(
|
||||
`$H.Add($KEY, $VALUE)`,
|
||||
).
|
||||
Where(m["H"].Type.Is("http.Header")).
|
||||
Report("use http.Header.Set method instead of Add to overwrite all existing header values").
|
||||
Suggest(`$H.Set($KEY, $VALUE)`)
|
||||
}
|
||||
|
||||
func hmacnew(m dsl.Matcher) {
|
||||
m.Match("hmac.New(func() hash.Hash { return $x }, $_)",
|
||||
`$f := func() hash.Hash { return $x }
|
||||
$*_
|
||||
hmac.New($f, $_)`,
|
||||
).Where(m["x"].Pure).
|
||||
Report("invalid hash passed to hmac.New()")
|
||||
}
|
||||
|
||||
func writestring(m dsl.Matcher) {
|
||||
m.Match(`io.WriteString($w, string($b))`).
|
||||
Where(m["b"].Type.Is("[]byte")).
|
||||
Suggest("$w.Write($b)")
|
||||
}
|
||||
|
||||
func badlock(m dsl.Matcher) {
|
||||
// Shouldn't give many false positives without type filter
|
||||
// as Lock+Unlock pairs in combination with defer gives us pretty
|
||||
// a good chance to guess correctly. If we constrain the type to sync.Mutex
|
||||
// then it'll be harder to match embedded locks and custom methods
|
||||
// that may forward the call to the sync.Mutex (or other synchronization primitive).
|
||||
|
||||
m.Match(`$mu.Lock(); defer $mu.RUnlock()`).Report(`maybe $mu.RLock() was intended?`)
|
||||
m.Match(`$mu.RLock(); defer $mu.Unlock()`).Report(`maybe $mu.Lock() was intended?`)
|
||||
}
|
|
@ -7,11 +7,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/tests/go_client/base"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
"github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
)
|
||||
|
||||
// test connect and close, connect again
|
||||
|
@ -56,7 +55,8 @@ func TestConnectInvalidAddr(t *testing.T) {
|
|||
// connect
|
||||
ctx := helper.CreateContext(t, time.Second*5)
|
||||
for _, invalidCfg := range genInvalidClientConfig() {
|
||||
_, errConnect := base.NewMilvusClient(ctx, &invalidCfg)
|
||||
cfg := invalidCfg
|
||||
_, errConnect := base.NewMilvusClient(ctx, &cfg)
|
||||
common.CheckErr(t, errConnect, false, "context deadline exceeded")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,14 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"go.uber.org/zap"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
)
|
||||
|
||||
var prefix = "collection"
|
||||
|
@ -42,7 +40,7 @@ func TestCreateCollection(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//func TestCreateCollection(t *testing.T) {}
|
||||
// func TestCreateCollection(t *testing.T) {}
|
||||
func TestCreateAutoIdCollectionField(t *testing.T) {
|
||||
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout)
|
||||
mc := createDefaultMilvusClient(ctx, t)
|
||||
|
@ -229,6 +227,7 @@ func TestCreateCollectionPartitionKey(t *testing.T) {
|
|||
// verify partitions
|
||||
partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName))
|
||||
require.Len(t, partitions, common.DefaultPartitionNum)
|
||||
common.CheckErr(t, err, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,6 +252,7 @@ func TestCreateCollectionPartitionKeyNumPartition(t *testing.T) {
|
|||
// verify partitions num
|
||||
partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName))
|
||||
require.Len(t, partitions, int(numPartition))
|
||||
common.CheckErr(t, err, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,6 +275,7 @@ func TestCreateCollectionDynamicSchema(t *testing.T) {
|
|||
require.True(t, has)
|
||||
|
||||
coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName))
|
||||
common.CheckErr(t, err, true)
|
||||
require.True(t, coll.Schema.EnableDynamicField)
|
||||
|
||||
// insert dynamic
|
||||
|
@ -307,7 +308,8 @@ func TestCreateCollectionDynamic(t *testing.T) {
|
|||
|
||||
coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName))
|
||||
log.Info("collection dynamic", zap.Bool("collectionSchema", coll.Schema.EnableDynamicField))
|
||||
//require.True(t, coll.Schema.Fields[0].IsDynamic)
|
||||
common.CheckErr(t, err, true)
|
||||
// require.True(t, coll.Schema.Fields[0].IsDynamic)
|
||||
|
||||
// insert dynamic
|
||||
columnOption := *hp.TNewDataOption()
|
||||
|
@ -627,7 +629,6 @@ func TestPartitionKeyInvalidNumPartition(t *testing.T) {
|
|||
{-1, "the specified partitions should be greater than 0 if partition key is used"},
|
||||
}
|
||||
for _, npStruct := range invalidNumPartitionStruct {
|
||||
|
||||
// create collection with num partitions
|
||||
err := mc.CreateCollection(ctx, clientv2.NewCreateCollectionOption(collName, schema))
|
||||
common.CheckErr(t, err, false, npStruct.errMsg)
|
||||
|
@ -910,7 +911,7 @@ func TestCreateMultiVectorExceed(t *testing.T) {
|
|||
common.CheckErr(t, err, false, fmt.Sprintf("maximum vector field's number should be limited to %d", common.MaxVectorFieldNum))
|
||||
}
|
||||
|
||||
//func TestCreateCollection(t *testing.T) {}
|
||||
// func TestCreateCollection(t *testing.T) {}
|
||||
func TestCreateCollectionInvalidShards(t *testing.T) {
|
||||
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout)
|
||||
mc := createDefaultMilvusClient(ctx, t)
|
||||
|
@ -938,7 +939,7 @@ func TestCreateCollectionInvalid(t *testing.T) {
|
|||
vecField := entity.NewField().WithName("vec").WithDataType(entity.FieldTypeFloatVector).WithDim(8)
|
||||
mSchemaErrs := []mSchemaErr{
|
||||
{schema: nil, errMsg: "duplicated field name"},
|
||||
{schema: entity.NewSchema().WithField(vecField), errMsg: "collection name should not be empty"}, // no collection name
|
||||
{schema: entity.NewSchema().WithField(vecField), errMsg: "collection name should not be empty"}, // no collection name
|
||||
{schema: entity.NewSchema().WithName("aaa").WithField(vecField), errMsg: "primary key is not specified"}, // no pk field
|
||||
{schema: entity.NewSchema().WithName("aaa").WithField(vecField).WithField(entity.NewField()), errMsg: "primary key is not specified"},
|
||||
{schema: entity.NewSchema().WithName("aaa").WithField(vecField).WithField(entity.NewField().WithIsPrimaryKey(true)), errMsg: "the data type of primary key should be Int64 or VarChar"},
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
|
@ -408,6 +408,7 @@ func TestDeletePartitionName(t *testing.T) {
|
|||
// query and verify
|
||||
resQuery, err := mc.Query(ctx, clientv2.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithOutputFields([]string{common.QueryCountFieldName}).
|
||||
WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
count, _ := resQuery.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, int64(common.DefaultNb*2), count)
|
||||
|
||||
|
@ -443,7 +444,7 @@ func TestDeleteComplexExpr(t *testing.T) {
|
|||
exprLimits := []exprCount{
|
||||
{expr: fmt.Sprintf("%s >= 1000 || %s > 2000", common.DefaultInt64FieldName, common.DefaultInt64FieldName), count: 2000},
|
||||
|
||||
//json and dynamic field filter expr: == < in bool/ list/ int
|
||||
// json and dynamic field filter expr: == < in bool/ list/ int
|
||||
{expr: fmt.Sprintf("%s['number'] < 100 and %s['number'] != 0", common.DefaultJSONFieldName, common.DefaultJSONFieldName), count: 50},
|
||||
{expr: fmt.Sprintf("%s < 100", common.DefaultDynamicNumberField), count: 100},
|
||||
{expr: fmt.Sprintf("%s == false", common.DefaultDynamicBoolField), count: 2000},
|
||||
|
@ -496,7 +497,7 @@ func TestDeleteComplexExpr(t *testing.T) {
|
|||
resDe, err := mc.Delete(ctx, clientv2.NewDeleteOption(schema.CollectionName).WithExpr(exprLimit.expr))
|
||||
common.CheckErr(t, err, true)
|
||||
log.Debug("delete count", zap.Bool("equal", int64(exprLimit.count) == resDe.DeleteCount))
|
||||
//require.Equal(t, int64(exprLimit.count), resDe.DeleteCount)
|
||||
// require.Equal(t, int64(exprLimit.count), resDe.DeleteCount)
|
||||
|
||||
resQuery, err := mc.Query(ctx, clientv2.NewQueryOption(schema.CollectionName).WithFilter(exprLimit.expr).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
|
@ -555,4 +556,3 @@ func TestDeleteDuplicatedPks(t *testing.T) {
|
|||
common.CheckErr(t, errQuery, true)
|
||||
require.Equal(t, common.DefaultNb-1, resQuery.ResultCount)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/column"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// insert params
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type GetFieldNameOpt func(opt *getFieldNameOpt)
|
||||
|
@ -73,7 +74,7 @@ func GetFieldNameByFieldType(t entity.FieldType, opts ...GetFieldNameOpt) string
|
|||
case entity.FieldTypeVarChar:
|
||||
return common.DefaultVarcharFieldName
|
||||
case entity.FieldTypeJSON:
|
||||
if opt.isDynamic{
|
||||
if opt.isDynamic {
|
||||
return common.DefaultDynamicFieldName
|
||||
}
|
||||
return common.DefaultJSONFieldName
|
||||
|
@ -288,7 +289,6 @@ func (cf FieldsAllFields) GenFields(option GenFieldsOption) []*entity.Field {
|
|||
scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType)
|
||||
fields = append(fields, scalarField)
|
||||
}
|
||||
|
||||
}
|
||||
for _, fieldType := range GetAllVectorFieldType() {
|
||||
if fieldType == entity.FieldTypeSparseVector {
|
||||
|
@ -329,7 +329,6 @@ func (cf FieldsInt64VecAllScalar) GenFields(option GenFieldsOption) []*entity.Fi
|
|||
scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType)
|
||||
fields = append(fields, scalarField)
|
||||
}
|
||||
|
||||
}
|
||||
vecField := entity.NewField().WithName(GetFieldNameByFieldType(entity.FieldTypeFloatVector)).WithDataType(entity.FieldTypeFloatVector).WithDim(option.Dim)
|
||||
fields = append(fields, vecField)
|
||||
|
|
|
@ -5,13 +5,13 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/base"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
)
|
||||
|
||||
func CreateContext(t *testing.T, timeout time.Duration) context.Context {
|
||||
|
@ -22,8 +22,7 @@ func CreateContext(t *testing.T, timeout time.Duration) context.Context {
|
|||
return ctx
|
||||
}
|
||||
|
||||
//var ArrayFieldType =
|
||||
|
||||
// var ArrayFieldType =
|
||||
func GetAllArrayElementType() []entity.FieldType {
|
||||
return []entity.FieldType{
|
||||
entity.FieldTypeBool,
|
||||
|
@ -68,7 +67,7 @@ func GetAllFieldsType() []entity.FieldType {
|
|||
entity.FieldTypeFloatVector,
|
||||
entity.FieldTypeFloat16Vector,
|
||||
entity.FieldTypeBFloat16Vector,
|
||||
//entity.FieldTypeSparseVector, max vector fields num is 4
|
||||
// entity.FieldTypeSparseVector, max vector fields num is 4
|
||||
)
|
||||
return allFieldType
|
||||
}
|
||||
|
@ -107,12 +106,14 @@ func GetInvalidPartitionKeyFieldType() []entity.FieldType {
|
|||
// ----------------- prepare data --------------------------
|
||||
type CollectionPrepare struct{}
|
||||
|
||||
var CollPrepare CollectionPrepare
|
||||
var FieldsFact FieldsFactory
|
||||
var (
|
||||
CollPrepare CollectionPrepare
|
||||
FieldsFact FieldsFactory
|
||||
)
|
||||
|
||||
func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *testing.T, mc *base.MilvusClient,
|
||||
cp *CreateCollectionParams, fieldOpt *GenFieldsOption, schemaOpt *GenSchemaOption) (*CollectionPrepare, *entity.Schema) {
|
||||
|
||||
cp *CreateCollectionParams, fieldOpt *GenFieldsOption, schemaOpt *GenSchemaOption,
|
||||
) (*CollectionPrepare, *entity.Schema) {
|
||||
fields := FieldsFact.GenFieldsForCollection(cp.CollectionFieldsType, fieldOpt)
|
||||
schemaOpt.Fields = fields
|
||||
schema := GenSchema(schemaOpt)
|
||||
|
@ -128,7 +129,8 @@ func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *tes
|
|||
}
|
||||
|
||||
func (chainTask *CollectionPrepare) InsertData(ctx context.Context, t *testing.T, mc *base.MilvusClient,
|
||||
ip *InsertParams, option *GenDataOption) (*CollectionPrepare, clientv2.InsertResult) {
|
||||
ip *InsertParams, option *GenDataOption,
|
||||
) (*CollectionPrepare, clientv2.InsertResult) {
|
||||
if nil == ip.Schema || ip.Schema.CollectionName == "" {
|
||||
log.Fatal("[InsertData] Nil Schema is not expected")
|
||||
}
|
||||
|
@ -138,7 +140,7 @@ func (chainTask *CollectionPrepare) InsertData(ctx context.Context, t *testing.T
|
|||
if field.IsDynamic {
|
||||
insertOpt.WithColumns(GenDynamicColumnData(option.start, ip.Nb)...)
|
||||
} else {
|
||||
if field.DataType == entity.FieldTypeArray{
|
||||
if field.DataType == entity.FieldTypeArray {
|
||||
option.TWithElementType(field.ElementType)
|
||||
}
|
||||
column := GenColumnData(ip.Nb, field.DataType, *option)
|
||||
|
|
|
@ -14,7 +14,7 @@ func GetDefaultVectorIndex(fieldType entity.FieldType) index.Index {
|
|||
return index.NewGenericIndex(common.DefaultBinaryVecFieldName, map[string]string{"nlist": "64", index.MetricTypeKey: "JACCARD", index.IndexTypeKey: "BIN_IVF_FLAT"})
|
||||
// return binary index
|
||||
case entity.FieldTypeSparseVector:
|
||||
return index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.1", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"})
|
||||
return index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.1", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"})
|
||||
default:
|
||||
return nil
|
||||
// return auto index
|
||||
|
|
|
@ -79,7 +79,7 @@ func GenDynamicRow(index int) Dynamic {
|
|||
return dynamic
|
||||
}
|
||||
|
||||
func GenJsonRow(index int) *JSONStruct {
|
||||
func GenJSONRow(index int) *JSONStruct {
|
||||
var jsonStruct JSONStruct
|
||||
_bool := &BoolStruct{
|
||||
Bool: index%2 == 0,
|
||||
|
@ -130,7 +130,7 @@ func GenInt64VarcharSparseRows(nb int, enableDynamicField bool, autoID bool, opt
|
|||
// BaseRow generate insert rows
|
||||
for i := start; i < start+nb; i++ {
|
||||
vec := common.GenSparseVector(2)
|
||||
//log.Info("", zap.Any("SparseVec", vec))
|
||||
// log.Info("", zap.Any("SparseVec", vec))
|
||||
baseRow := BaseRow{
|
||||
Varchar: strconv.Itoa(i + 1),
|
||||
SparseVec: vec,
|
||||
|
@ -166,7 +166,7 @@ func GenAllFieldsRows(nb int, enableDynamicField bool, option GenDataOption) []i
|
|||
Float: float32(i + 1),
|
||||
Double: float64(i + 1),
|
||||
Varchar: strconv.Itoa(i + 1),
|
||||
JSON: GenJsonRow(i + 1),
|
||||
JSON: GenJSONRow(i + 1),
|
||||
FloatVec: common.GenFloatVector(dim),
|
||||
Fp16Vec: common.GenFloat16Vector(dim),
|
||||
Bf16Vec: common.GenBFloat16Vector(dim),
|
||||
|
|
|
@ -5,15 +5,14 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/index"
|
||||
|
||||
"github.com/milvus-io/milvus/client/v2/column"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/column"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/client/v2/index"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
)
|
||||
|
@ -475,13 +474,13 @@ func TestInsertSparseVectorSamePosition(t *testing.T) {
|
|||
cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec)
|
||||
_, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption())
|
||||
|
||||
//insert data column
|
||||
// insert data column
|
||||
columnOpt := hp.TNewDataOption()
|
||||
data := []column.Column{
|
||||
hp.GenColumnData(1, entity.FieldTypeInt64, *columnOpt),
|
||||
hp.GenColumnData(1, entity.FieldTypeVarChar, *columnOpt),
|
||||
}
|
||||
//invalid sparse vector: position > (maximum of uint32 - 1)
|
||||
// invalid sparse vector: position > (maximum of uint32 - 1)
|
||||
sparseVec, err := entity.NewSliceSparseEmbedding([]uint32{2, 10, 2}, []float32{0.4, 0.5, 0.6})
|
||||
common.CheckErr(t, err, true)
|
||||
data = append(data, column.NewColumnSparseVectors(common.DefaultSparseVecFieldName, []entity.SparseEmbedding{sparseVec}))
|
||||
|
@ -607,7 +606,7 @@ func TestInsertSparseRows(t *testing.T) {
|
|||
// BaseRow generate insert rows
|
||||
for i := 0; i < common.DefaultNb; i++ {
|
||||
vec := common.GenSparseVector(500)
|
||||
//log.Info("", zap.Any("SparseVec", vec))
|
||||
// log.Info("", zap.Any("SparseVec", vec))
|
||||
baseRow := hp.BaseRow{
|
||||
Int64: int64(i + 1),
|
||||
SparseVec: vec,
|
||||
|
@ -657,7 +656,7 @@ func TestInsertRowMismatchFields(t *testing.T) {
|
|||
cp := hp.NewCreateCollectionParams(hp.Int64Vec)
|
||||
_, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithDim(8), hp.TNewSchemaOption())
|
||||
|
||||
//rows fields < schema fields
|
||||
// rows fields < schema fields
|
||||
rowsLess := make([]interface{}, 0, 10)
|
||||
for i := 1; i < 11; i++ {
|
||||
row := hp.BaseRow{
|
||||
|
|
|
@ -10,14 +10,15 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/base"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
)
|
||||
|
||||
var addr = flag.String("addr", "localhost:19530", "server host and port")
|
||||
var defaultCfg clientv2.ClientConfig
|
||||
var (
|
||||
addr = flag.String("addr", "localhost:19530", "server host and port")
|
||||
defaultCfg clientv2.ClientConfig
|
||||
)
|
||||
|
||||
// teardown
|
||||
func teardown() {
|
||||
|
|
|
@ -4,12 +4,13 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||
"github.com/milvus-io/milvus/client/v2/entity"
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue