github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/test/testcases/upsert_test.go (about)

     1  //go:build L0
     2  
     3  package testcases
     4  
     5  import (
     6  	"fmt"
     7  	"strconv"
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/milvus-io/milvus-sdk-go/v2/client"
    12  	"github.com/milvus-io/milvus-sdk-go/v2/entity"
    13  	"github.com/stretchr/testify/require"
    14  
    15  	"github.com/milvus-io/milvus-sdk-go/v2/test/common"
    16  )
    17  
    18  func TestUpsert(t *testing.T) {
    19  	/*
    20  		1. prepare create -> insert -> index -> load -> query
    21  		2. upsert exist entities -> data updated -> query and verify
    22  		3. delete some pks -> query and verify
    23  		4. upsert part deleted(not exist) pk and part existed pk -> query and verify
    24  		5. upsert all not exist pk -> query and verify
    25  	*/
    26  	t.Parallel()
    27  	ctx := createContext(t, time.Second*common.DefaultTimeout)
    28  	// connect
    29  	mc := createMilvusClient(ctx, t)
    30  	for _, enableDynamic := range []bool{true, false} {
    31  
    32  		// create -> insert [0, 3000) -> flush -> index -> load
    33  		cp := CollectionParams{CollectionFieldsType: AllFields, AutoID: false, EnableDynamicField: enableDynamic,
    34  			ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
    35  		ips := GenDefaultIndexParamsForAllVectors()
    36  		collName := prepareCollection(ctx, t, mc, cp, WithIndexParams(ips), WithCreateOption(client.WithConsistencyLevel(entity.ClStrong)))
    37  
    38  		upsertNb := 10
    39  		// upsert exist entities [0, 10)
    40  		data := common.GenAllFieldsData(0, upsertNb, common.DefaultDim)
    41  		_, err := mc.Upsert(ctx, collName, "", data...)
    42  		common.CheckErr(t, err, true)
    43  
    44  		// query and verify the updated entities
    45  		resSet, err := mc.Query(ctx, collName, []string{}, "int64 < 10", []string{common.DefaultFloatVecFieldName})
    46  		common.CheckErr(t, err, true)
    47  		idx := common.ColumnIndexFunc(data, common.DefaultFloatVecFieldName)
    48  		require.ElementsMatch(t, data[idx].(*entity.ColumnFloatVector).Data()[:upsertNb],
    49  			resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
    50  
    51  		// delete some pk
    52  		mc.Delete(ctx, collName, "", "int64 < 10")
    53  		resSet, err = mc.Query(ctx, collName, []string{}, "int64 < 10", []string{})
    54  		require.Zero(t, resSet[0].Len())
    55  
    56  		// upsert part deleted(not exist) pk and part existed pk [5, 15)
    57  		data = common.GenAllFieldsData(5, upsertNb, common.DefaultDim)
    58  		_, err = mc.Upsert(ctx, collName, "", data...)
    59  		common.CheckErr(t, err, true)
    60  
    61  		// query and verify the updated entities
    62  		resSet, err = mc.Query(ctx, collName, []string{}, "5 <= int64 < 15", []string{common.DefaultFloatVecFieldName})
    63  		common.CheckErr(t, err, true)
    64  		require.ElementsMatch(t, data[idx].(*entity.ColumnFloatVector).Data()[:upsertNb],
    65  			resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
    66  
    67  		// upsert all deleted(not exist) pk [0, 5)
    68  		data = common.GenAllFieldsData(0, 5, common.DefaultDim)
    69  		_, err = mc.Upsert(ctx, collName, "", data...)
    70  		common.CheckErr(t, err, true)
    71  
    72  		// query and verify the updated entities
    73  		resSet, err = mc.Query(ctx, collName, []string{}, "0 <= int64 < 5", []string{common.DefaultFloatVecFieldName})
    74  		common.CheckErr(t, err, true)
    75  		require.ElementsMatch(t, data[idx].(*entity.ColumnFloatVector).Data()[:5],
    76  			resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
    77  	}
    78  }
    79  
    80  // test upsert autoId collection
    81  func TestUpsertAutoID(t *testing.T) {
    82  	/*
    83  		prepare autoID collection
    84  		upsert not exist pk -> error
    85  		upsert exist pk -> error ? autoID not supported upsert
    86  	*/
    87  	ctx := createContext(t, time.Second*common.DefaultTimeout)
    88  
    89  	// connect
    90  	mc := createMilvusClient(ctx, t)
    91  
    92  	// create default collection with autoID true
    93  	collName := createDefaultCollection(ctx, t, mc, true, common.DefaultShards)
    94  
    95  	// insert
    96  	_, floatColumn, vecColumn := common.GenDefaultColumnData(0, common.DefaultNb, common.DefaultDim)
    97  	ids, errInsert := mc.Insert(ctx, collName, "", floatColumn, vecColumn)
    98  	common.CheckErr(t, errInsert, true)
    99  	require.Equal(t, common.DefaultNb, ids.Len())
   100  
   101  	// flush and check row count
   102  	errFlush := mc.Flush(ctx, collName, false)
   103  	common.CheckErr(t, errFlush, true)
   104  
   105  	// index and load
   106  	idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
   107  	mc.CreateIndex(ctx, collName, "floatVec", idx, false)
   108  	errLoad := mc.LoadCollection(ctx, collName, false)
   109  	common.CheckErr(t, errLoad, true)
   110  
   111  	// upsert without pks
   112  	_, floatColumn1, vecColumn1 := common.GenDefaultColumnData(0, 100, common.DefaultDim)
   113  	_, err := mc.Upsert(ctx, collName, "", floatColumn1, vecColumn1)
   114  	common.CheckErr(t, err, false, "upsert can not assign primary field data when auto id enabled")
   115  
   116  	// upsert with pks
   117  	pkColumn := entity.NewColumnInt64(common.DefaultIntFieldName, ids.(*entity.ColumnInt64).Data()[:100])
   118  	_, err = mc.Upsert(ctx, collName, "", pkColumn, floatColumn1, vecColumn1)
   119  	common.CheckErr(t, err, false, "upsert can not assign primary field data when auto id enabled")
   120  }
   121  
   122  func TestUpsertVarcharPk(t *testing.T) {
   123  	/*
   124  		test upsert varchar pks
   125  		upsert after query
   126  		upsert "a" -> " a " -> actually new insert
   127  	*/
   128  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   129  	// connect
   130  	mc := createMilvusClient(ctx, t)
   131  
   132  	// create -> insert [0, 3000) -> flush -> index -> load
   133  	cp := CollectionParams{CollectionFieldsType: VarcharBinaryVec, AutoID: false, EnableDynamicField: true,
   134  		ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
   135  
   136  	idx, _ := entity.NewIndexBinIvfFlat(entity.JACCARD, 16)
   137  	ip := []IndexParams{{BuildIndex: true, Index: idx, FieldName: common.DefaultBinaryVecFieldName, async: false}}
   138  	collName := prepareCollection(ctx, t, mc, cp, WithIndexParams(ip), WithCreateOption(client.WithConsistencyLevel(entity.ClStrong)))
   139  
   140  	upsertNb := 10
   141  	// upsert exist entities [0, 10) varchar: ["1", ... "9"]
   142  	varcharColumn, binaryColumn := common.GenDefaultVarcharData(0, upsertNb, common.DefaultDim)
   143  	_, err := mc.Upsert(ctx, collName, "", varcharColumn, binaryColumn)
   144  	common.CheckErr(t, err, true)
   145  
   146  	// query and verify the updated entities
   147  	pkColumn := entity.NewColumnVarChar(common.DefaultVarcharFieldName, varcharColumn.(*entity.ColumnVarChar).Data()[:upsertNb])
   148  	resSet, err := mc.QueryByPks(ctx, collName, []string{}, pkColumn, []string{common.DefaultBinaryVecFieldName})
   149  	common.CheckErr(t, err, true)
   150  	require.ElementsMatch(t, binaryColumn.(*entity.ColumnBinaryVector).Data()[:upsertNb],
   151  		resSet.GetColumn(common.DefaultBinaryVecFieldName).(*entity.ColumnBinaryVector).Data())
   152  
   153  	// upsert varchar (with space): [" 1 ", ... " 9 "]
   154  	varcharValues := make([]string, 0, upsertNb)
   155  	for i := 0; i < upsertNb; i++ {
   156  		varcharValues = append(varcharValues, " "+strconv.Itoa(i)+" ")
   157  	}
   158  	varcharColumn1 := entity.NewColumnVarChar(common.DefaultVarcharFieldName, varcharValues)
   159  	_, binaryColumn1 := common.GenDefaultVarcharData(0, upsertNb, common.DefaultDim)
   160  	ids, err := mc.Upsert(ctx, collName, "", varcharColumn1, binaryColumn1)
   161  	common.CheckErr(t, err, true)
   162  	require.ElementsMatch(t, ids.(*entity.ColumnVarChar).Data(), varcharValues)
   163  
   164  	// query old varchar pk (no space): ["1", ... "9"]
   165  	resSet, err = mc.QueryByPks(ctx, collName, []string{}, pkColumn, []string{common.DefaultVarcharFieldName, common.DefaultBinaryVecFieldName})
   166  	common.CheckErr(t, err, true)
   167  	require.ElementsMatch(t, varcharColumn.(*entity.ColumnVarChar).Data()[:upsertNb], resSet.GetColumn(common.DefaultVarcharFieldName).(*entity.ColumnVarChar).Data())
   168  	require.ElementsMatch(t, binaryColumn.(*entity.ColumnBinaryVector).Data()[:upsertNb], resSet.GetColumn(common.DefaultBinaryVecFieldName).(*entity.ColumnBinaryVector).Data())
   169  
   170  	// query and verify the updated entities
   171  	pkColumn1 := entity.NewColumnVarChar(common.DefaultVarcharFieldName, varcharColumn1.Data())
   172  	resSet, err = mc.QueryByPks(ctx, collName, []string{}, pkColumn1, []string{common.DefaultVarcharFieldName, common.DefaultBinaryVecFieldName})
   173  	common.CheckErr(t, err, true)
   174  	require.ElementsMatch(t, varcharColumn1.Data(), resSet.GetColumn(common.DefaultVarcharFieldName).(*entity.ColumnVarChar).Data())
   175  	require.ElementsMatch(t, binaryColumn1.(*entity.ColumnBinaryVector).Data(), resSet.GetColumn(common.DefaultBinaryVecFieldName).(*entity.ColumnBinaryVector).Data())
   176  }
   177  
   178  // test upsert with partition
   179  func TestUpsertMultiPartitions(t *testing.T) {
   180  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   181  	// connect
   182  	mc := createMilvusClient(ctx, t)
   183  	collName := createDefaultCollection(ctx, t, mc, false, common.DefaultShards, client.WithConsistencyLevel(entity.ClStrong))
   184  
   185  	// insert [0, nb) into default, insert [nb, nb*2) into new
   186  	_, defaultPartition, newPartition := createInsertTwoPartitions(ctx, t, mc, collName, common.DefaultNb)
   187  
   188  	// create index
   189  	idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
   190  	mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
   191  
   192  	// Load collection
   193  	errLoad := mc.LoadCollection(ctx, collName, false)
   194  	common.CheckErr(t, errLoad, true)
   195  
   196  	// upsert new partition
   197  	intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, 100, common.DefaultDim)
   198  	_, err := mc.Upsert(ctx, collName, newPartition.PartitionName, intColumn, floatColumn, vecColumn)
   199  	common.CheckErr(t, err, true)
   200  
   201  	// query and verify
   202  	resSet, err := mc.QueryByPks(ctx, collName, []string{newPartition.PartitionName}, intColumn,
   203  		[]string{common.DefaultFloatVecFieldName})
   204  	common.CheckErr(t, err, true)
   205  	require.ElementsMatch(t, vecColumn.(*entity.ColumnFloatVector).Data()[:100], resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
   206  
   207  	// query and verify
   208  	resSet, err = mc.QueryByPks(ctx, collName, []string{defaultPartition.PartitionName}, intColumn,
   209  		[]string{common.DefaultFloatVecFieldName})
   210  	common.CheckErr(t, err, true)
   211  	require.ElementsMatch(t, defaultPartition.VectorColumn.(*entity.ColumnFloatVector).Data()[:100], resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
   212  }
   213  
   214  // test upsert with invalid collection / partition name
   215  func TestUpsertNotExistCollectionPartition(t *testing.T) {
   216  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   217  
   218  	// connect
   219  	mc := createMilvusClient(ctx, t)
   220  
   221  	// create default collection with autoID true
   222  	collName := createDefaultCollection(ctx, t, mc, true, common.DefaultShards)
   223  
   224  	// upsert not exist partition
   225  	_, floatColumn, vecColumn := common.GenDefaultColumnData(0, common.DefaultNb, common.DefaultDim)
   226  	_, errUpsert := mc.Upsert(ctx, collName, "aaa", floatColumn, vecColumn)
   227  	common.CheckErr(t, errUpsert, false, "can not assign primary field data when auto id enabled")
   228  
   229  	// upsert not exist collection
   230  	_, errUpsert = mc.Upsert(ctx, "aaa", "", floatColumn, vecColumn)
   231  	common.CheckErr(t, errUpsert, false, "can't find collection")
   232  }
   233  
   234  // test upsert with invalid column data
   235  func TestUpsertInvalidColumnData(t *testing.T) {
   236  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   237  	// connect
   238  	mc := createMilvusClient(ctx, t)
   239  
   240  	// create -> insert [0, 3000) -> flush -> index -> load
   241  	cp := CollectionParams{CollectionFieldsType: Int64FloatVecJSON, AutoID: false, EnableDynamicField: false,
   242  		ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
   243  
   244  	dp := DataParams{DoInsert: true, CollectionFieldsType: Int64FloatVecJSON, start: 0, nb: 200,
   245  		dim: common.DefaultDim, EnableDynamicField: false}
   246  	collName := prepareCollection(ctx, t, mc, cp, WithDataParams(dp),
   247  		WithIndexParams([]IndexParams{{BuildIndex: false}}),
   248  		WithLoadParams(LoadParams{DoLoad: false}), WithCreateOption(client.WithConsistencyLevel(entity.ClStrong)))
   249  
   250  	upsertNb := 10
   251  	// 1. upsert missing columns
   252  	intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, upsertNb, common.DefaultDim)
   253  	jsonColumn := common.GenDefaultJSONData(common.DefaultJSONFieldName, 0, upsertNb)
   254  	_, err := mc.Upsert(ctx, collName, "", intColumn, floatColumn, vecColumn)
   255  	common.CheckErr(t, err, false, fmt.Sprintf("field %s not passed", common.DefaultJSONFieldName))
   256  
   257  	// 2. upsert extra a column
   258  	varColumn := common.GenColumnData(0, upsertNb, entity.FieldTypeVarChar, common.DefaultVarcharFieldName)
   259  	_, err = mc.Upsert(ctx, collName, "", intColumn, floatColumn, vecColumn, jsonColumn, varColumn)
   260  	common.CheckErr(t, err, false, fmt.Sprintf("field %s does not exist in collection", common.DefaultVarcharFieldName))
   261  
   262  	// 3. upsert vector has different dim
   263  	dimColumn := common.GenColumnData(0, upsertNb, entity.FieldTypeFloatVector, common.DefaultFloatVecFieldName, common.WithVectorDim(64))
   264  	_, err = mc.Upsert(ctx, collName, "", intColumn, floatColumn, dimColumn, jsonColumn)
   265  	common.CheckErr(t, err, false, fmt.Sprintf("params column %s vector dim 64 not match collection definition, which has dim of %d",
   266  		common.DefaultFloatVecFieldName, common.DefaultDim))
   267  
   268  	// 4. different columns has different length
   269  	diffLenColumn := common.GenDefaultJSONData(common.DefaultJSONFieldName, 0, upsertNb*2)
   270  	_, err = mc.Upsert(ctx, collName, "", intColumn, floatColumn, vecColumn, diffLenColumn)
   271  	common.CheckErr(t, err, false, "column size not match")
   272  
   273  	// 5. column type different with schema
   274  	_, err = mc.Upsert(ctx, collName, "", intColumn, varColumn, vecColumn, jsonColumn)
   275  	common.CheckErr(t, err, false, "field varchar does not exist in collection")
   276  }
   277  
   278  func TestUpsertSamePksManyTimes(t *testing.T) {
   279  	// upsert pks [0, 1000) many times with different vector
   280  	// I mean many delete + insert
   281  	// query -> gets last upsert entities
   282  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   283  	// connect
   284  	mc := createMilvusClient(ctx, t)
   285  
   286  	// create -> insert [0, 3000) -> flush -> index -> load
   287  	cp := CollectionParams{CollectionFieldsType: AllFields, AutoID: false, EnableDynamicField: true,
   288  		ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
   289  
   290  	ips := GenDefaultIndexParamsForAllVectors()
   291  	collName := prepareCollection(ctx, t, mc, cp, WithIndexParams(ips), WithCreateOption(client.WithConsistencyLevel(entity.ClStrong)))
   292  
   293  	var data []entity.Column
   294  	upsertNb := 1000
   295  	for i := 0; i < 100; i++ {
   296  		// upsert exist entities [0, 10)
   297  		data = common.GenAllFieldsData(0, upsertNb, common.DefaultDim)
   298  		_, err := mc.Upsert(ctx, collName, "", data...)
   299  		common.CheckErr(t, err, true)
   300  	}
   301  
   302  	// query and verify the updated entities
   303  	resSet, err := mc.Query(ctx, collName, []string{}, fmt.Sprintf("%s < %d", common.DefaultIntFieldName, upsertNb), []string{common.DefaultFloatVecFieldName})
   304  	common.CheckErr(t, err, true)
   305  	idx := common.ColumnIndexFunc(data, common.DefaultFloatVecFieldName)
   306  	require.ElementsMatch(t, data[idx].(*entity.ColumnFloatVector).Data(),
   307  		resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
   308  }
   309  
   310  func TestUpsertDynamicField(t *testing.T) {
   311  	// enable dynamic field and insert dynamic column
   312  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   313  	// connect
   314  	mc := createMilvusClient(ctx, t)
   315  
   316  	// create -> insert [0, 3000) -> flush -> index -> load
   317  	cp := CollectionParams{CollectionFieldsType: Int64FloatVec, AutoID: false, EnableDynamicField: true,
   318  		ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
   319  
   320  	dp := DataParams{DoInsert: true, CollectionFieldsType: Int64FloatVec, start: 0, nb: common.DefaultNb,
   321  		dim: common.DefaultDim, EnableDynamicField: true}
   322  	collName := prepareCollection(ctx, t, mc, cp, WithDataParams(dp), WithCreateOption(client.WithConsistencyLevel(entity.ClStrong)))
   323  
   324  	// verify that dynamic field exists
   325  	upsertNb := 10
   326  	resSet, err := mc.Query(ctx, collName, []string{}, fmt.Sprintf("%s < %d", common.DefaultDynamicNumberField, upsertNb),
   327  		[]string{common.DefaultDynamicNumberField})
   328  	require.Equal(t, upsertNb, resSet[0].Len())
   329  
   330  	// 1. upsert exist pk without dynamic column
   331  	intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, upsertNb, common.DefaultDim)
   332  	_, err = mc.Upsert(ctx, collName, "", intColumn, floatColumn, vecColumn)
   333  	common.CheckErr(t, err, true)
   334  
   335  	// query and gets empty
   336  	resSet, err = mc.Query(ctx, collName, []string{}, fmt.Sprintf("%s < %d", common.DefaultDynamicNumberField, upsertNb), []string{common.DefaultDynamicNumberField})
   337  	require.Zero(t, resSet[0].Len())
   338  
   339  	// 2. upsert not exist pk with dynamic column ->  field dynamicNumber does not exist in collection
   340  	intColumn2, floatColumn2, vecColumn2 := common.GenDefaultColumnData(common.DefaultNb, upsertNb, common.DefaultDim)
   341  	dynamicData2 := common.GenDynamicFieldData(common.DefaultNb, upsertNb)
   342  	_, err = mc.Upsert(ctx, collName, "", append(dynamicData2, intColumn2, floatColumn2, vecColumn2)...)
   343  	common.CheckErr(t, err, true)
   344  
   345  	// query and gets empty dynamic field
   346  	resSet, err = mc.Query(ctx, collName, []string{}, fmt.Sprintf("%s >= %d", common.DefaultDynamicNumberField, common.DefaultNb), []string{common.QueryCountFieldName})
   347  	require.Equal(t, int64(upsertNb), resSet.GetColumn(common.QueryCountFieldName).(*entity.ColumnInt64).Data()[0])
   348  }
   349  
   350  func TestUpsertPartitionKeyCollection(t *testing.T) {
   351  	// upsert data into collection that has partition key field
   352  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   353  	// connect
   354  	mc := createMilvusClient(ctx, t)
   355  
   356  	// create partition_key field
   357  	partitionKeyFieldName := "partitionKeyField"
   358  	partitionKeyField := common.GenField(partitionKeyFieldName, entity.FieldTypeInt64,
   359  		common.WithIsPartitionKey(true), common.WithMaxLength(common.TestMaxLen))
   360  
   361  	// schema
   362  	schema := common.GenSchema(common.GenRandomString(6), false, common.GenDefaultFields(false))
   363  	schema.WithField(partitionKeyField)
   364  
   365  	// create collection and check partition key
   366  	err := mc.CreateCollection(ctx, schema, common.DefaultShards, client.WithPartitionNum(10),
   367  		client.WithConsistencyLevel(entity.ClStrong))
   368  	common.CheckErr(t, err, true)
   369  
   370  	// insert data partition key field [0, nb)
   371  	partitionKeyColumn := common.GenColumnData(0, common.DefaultNb, entity.FieldTypeInt64, partitionKeyFieldName)
   372  	pkColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, common.DefaultNb, common.DefaultDim)
   373  	ids, errInsert := mc.Insert(ctx, schema.CollectionName, "", pkColumn, floatColumn, vecColumn, partitionKeyColumn)
   374  	common.CheckErr(t, errInsert, true)
   375  	require.Equalf(t, common.DefaultNb, ids.Len(), fmt.Sprintf("Expected insert result equal to %d, actual %d", common.DefaultNb, ids.Len()))
   376  
   377  	// flush -> index and load
   378  	mc.Flush(ctx, schema.CollectionName, false)
   379  	idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
   380  	mc.CreateIndex(ctx, schema.CollectionName, common.DefaultFloatVecFieldName, idx, false)
   381  	mc.LoadCollection(ctx, schema.CollectionName, false)
   382  
   383  	// upsert data partition key field [nb, nb*2)
   384  	partitionKeyColumn2 := common.GenColumnData(common.DefaultNb, common.DefaultNb, entity.FieldTypeInt64, partitionKeyFieldName)
   385  	mc.Upsert(ctx, schema.CollectionName, "", pkColumn, floatColumn, vecColumn, partitionKeyColumn2)
   386  
   387  	// verify upsert
   388  	resSet, err := mc.Query(ctx, schema.CollectionName, []string{}, fmt.Sprintf("%s >= %d", partitionKeyFieldName, common.DefaultNb),
   389  		[]string{common.QueryCountFieldName})
   390  	require.Equal(t, int64(common.DefaultNb), resSet.GetColumn(common.QueryCountFieldName).(*entity.ColumnInt64).Data()[0])
   391  
   392  	resSet, err = mc.Query(ctx, schema.CollectionName, []string{}, fmt.Sprintf("%s < %d", partitionKeyFieldName, common.DefaultNb),
   393  		[]string{common.QueryCountFieldName})
   394  	require.Equal(t, int64(0), resSet.GetColumn(common.QueryCountFieldName).(*entity.ColumnInt64).Data()[0])
   395  }
   396  
   397  func TestUpsertWithoutLoading(t *testing.T) {
   398  	// test upsert without loading (because delete need loading)
   399  	ctx := createContext(t, time.Second*common.DefaultTimeout)
   400  	// connect
   401  	mc := createMilvusClient(ctx, t)
   402  
   403  	// create -> insert [0, 3000) -> flush -> index
   404  	cp := CollectionParams{CollectionFieldsType: Int64FloatVecJSON, AutoID: false, EnableDynamicField: true,
   405  		ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
   406  
   407  	dp := DataParams{DoInsert: true, CollectionFieldsType: Int64FloatVecJSON, start: 0, nb: 200,
   408  		dim: common.DefaultDim, EnableDynamicField: true}
   409  	collName := prepareCollection(ctx, t, mc, cp, WithDataParams(dp),
   410  		WithFlushParams(FlushParams{DoFlush: false}),
   411  		WithIndexParams([]IndexParams{{BuildIndex: false}}),
   412  		WithLoadParams(LoadParams{DoLoad: false}), WithCreateOption(client.WithConsistencyLevel(entity.ClStrong)))
   413  
   414  	// upsert
   415  	upsertNb := 10
   416  	intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, upsertNb, common.DefaultDim)
   417  	jsonColumn := common.GenDefaultJSONData(common.DefaultJSONFieldName, 0, upsertNb)
   418  	_, err := mc.Upsert(ctx, collName, "", intColumn, floatColumn, vecColumn, jsonColumn)
   419  	common.CheckErr(t, err, true)
   420  
   421  	// index -> load
   422  	idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
   423  	mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
   424  	mc.LoadCollection(ctx, collName, false)
   425  	err = mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
   426  
   427  	// query and verify
   428  	resSet, err := mc.QueryByPks(ctx, collName, []string{}, intColumn,
   429  		[]string{common.DefaultFloatVecFieldName})
   430  	common.CheckErr(t, err, true)
   431  	require.ElementsMatch(t, vecColumn.(*entity.ColumnFloatVector).Data()[:upsertNb], resSet.GetColumn(common.DefaultFloatVecFieldName).(*entity.ColumnFloatVector).Data())
   432  }