Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add case insert rows with autoID #859

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/testcases/groupby_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestSearchGroupByUnsupportedIndex(t *testing.T) {
_, err := mc.Search(ctx, collName, []string{}, "", []string{common.DefaultIntFieldName, common.DefaultVarcharFieldName},
queryVec, common.DefaultFloatVecFieldName, entity.MetricType(idx.Params()["metrics_type"]),
common.DefaultTopK, sp, client.WithGroupByField(common.DefaultVarcharFieldName))
common.CheckErr(t, err, false, "doesn't support search_group_by")
common.CheckErr(t, err, false, "doesn't support")
}
}

Expand Down
82 changes: 82 additions & 0 deletions test/testcases/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,88 @@ func TestInsertRows(t *testing.T) {
}
}

func TestInsertDisableAutoIDRow(t *testing.T) {
/*
autoID: false
- pass pk value -> insert success
- no pk value -> error
*/
t.Parallel()
ctx := createContext(t, time.Second*common.DefaultTimeout)
mc := createMilvusClient(ctx, t)
schema := common.GenSchema(common.GenRandomString(6), false, common.GenDefaultFields(false))
createCustomerCollection(ctx, t, mc, schema, common.DefaultShards)

// pass pk value
start := 0
rowsWithPk := common.GenDefaultRows(start, 10, common.DefaultDim, false)
idsWithPk, err := mc.InsertRows(ctx, schema.CollectionName, "", rowsWithPk)
common.CheckErr(t, err, true)
require.Contains(t, idsWithPk.(*entity.ColumnInt64).Data(), int64(start))

// no pk value -> now error
type tmpRow struct {
Float float32 `json:"float" milvus:"name:float"`
FloatVec []float32 `json:"floatVec,omitempty" milvus:"name:floatVec"`
}
rowsWithoutPk := make([]interface{}, 0, 10)

// BaseRow generate insert rows
for i := 0; i < 10; i++ {
baseRow := tmpRow{
Float: float32(i),
FloatVec: common.GenFloatVector(common.DefaultDim),
}
rowsWithoutPk = append(rowsWithoutPk, &baseRow)
}
_, err1 := mc.InsertRows(ctx, schema.CollectionName, "", rowsWithoutPk)
common.CheckErr(t, err1, false, "row 0 does not has field int64")
}

func TestInsertEnableAutoIDRow(t *testing.T) {
/*
autoID: true
- pass pk value -> ignore passed value and auto-gen pk
- no pk value -> insert success
*/
ctx := createContext(t, time.Second*common.DefaultTimeout)
mc := createMilvusClient(ctx, t)
schema := common.GenSchema(common.GenRandomString(6), true, common.GenDefaultFields(true))
createCustomerCollection(ctx, t, mc, schema, common.DefaultShards)

coll, _ := mc.DescribeCollection(ctx, schema.CollectionName)
log.Println(coll.Schema.AutoID)

// pass pk value -> ignore passed pks
start := 0
rowsWithPk := common.GenDefaultRows(start, 10, common.DefaultDim, false)
idsWithPk, err := mc.InsertRows(ctx, schema.CollectionName, "", rowsWithPk)
common.CheckErr(t, err, true)
log.Printf("origin first rowsWithPk: %v", rowsWithPk[0])
log.Println(idsWithPk.FieldData())
require.NotContains(t, idsWithPk.(*entity.ColumnInt64).Data(), int64(start))

// no pk value
rowsWithoutPk := make([]interface{}, 0, 10)
type tmpRow struct {
Float float32 `json:"float" milvus:"name:float"`
FloatVec []float32 `json:"floatVec" milvus:"name:floatVec"`
}

// BaseRow generate insert rows
for i := 0; i < 10; i++ {
baseRow := tmpRow{
Float: float32(i),
FloatVec: common.GenFloatVector(common.DefaultDim),
}
rowsWithoutPk = append(rowsWithoutPk, &baseRow)
}

idsWithoutPk, err1 := mc.InsertRows(ctx, schema.CollectionName, "", rowsWithoutPk)
common.CheckErr(t, err1, true)
require.Equal(t, 10, int(idsWithoutPk.Len()))
}

// test insert json rows field name not match
func TestInsertJsonCollectionFieldNotMatch(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
Expand Down
Loading