github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/insert_test.go (about) 1 // Copyright (C) 2019-2021 Zilliz. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance 4 // with the License. You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software distributed under the License 9 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 10 // or implied. See the License for the specific language governing permissions and limitations under the License. 11 12 package client 13 14 import ( 15 "context" 16 "testing" 17 18 "github.com/cockroachdb/errors" 19 "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" 20 "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" 21 "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" 22 "github.com/milvus-io/milvus-sdk-go/v2/entity" 23 "github.com/stretchr/testify/mock" 24 "github.com/stretchr/testify/suite" 25 ) 26 27 type InsertSuite struct { 28 MockSuiteBase 29 } 30 31 func (s *InsertSuite) TestInsertFail() { 32 c := s.client 33 ctx, cancel := context.WithCancel(context.Background()) 34 defer cancel() 35 36 s.Run("collection_not_exist", func() { 37 defer s.resetMock() 38 s.setupDescribeCollectionError(commonpb.ErrorCode_UnexpectedError, errors.New("mocked")) 39 _, err := c.Insert(ctx, testCollectionName, "") 40 s.Error(err) 41 }) 42 43 s.Run("field_not_exist", func() { 44 defer s.resetMock() 45 s.setupHasCollection(testCollectionName) 46 s.setupHasPartition(testCollectionName, "partition_1") 47 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 48 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 49 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 50 ) 51 52 _, err := c.Insert(ctx, testCollectionName, "partition_1", 53 entity.NewColumnInt64("extra", []int64{1}), 54 ) 55 s.Error(err) 56 }) 57 58 s.Run("missing_field_without_default_value", func() { 59 defer s.resetMock() 60 s.setupHasCollection(testCollectionName) 61 s.setupHasPartition(testCollectionName, "partition_1") 62 63 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 64 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 65 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 66 ) 67 68 _, err := c.Insert(ctx, testCollectionName, "partition_1", 69 entity.NewColumnInt64("ID", []int64{1}), 70 ) 71 s.Error(err) 72 }) 73 74 s.Run("column_len_not_match", func() { 75 defer s.resetMock() 76 s.setupHasCollection(testCollectionName) 77 s.setupHasPartition(testCollectionName, "partition_1") 78 79 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 80 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 81 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 82 ) 83 84 _, err := c.Insert(ctx, testCollectionName, "partition_1", 85 entity.NewColumnInt64("ID", []int64{1, 2}), 86 entity.NewColumnFloatVector("vector", 128, [][]float32{}), 87 ) 88 s.Error(err) 89 }) 90 91 s.Run("duplicated column", func() { 92 defer s.resetMock() 93 s.setupHasCollection(testCollectionName) 94 s.setupHasPartition(testCollectionName, "partition_1") 95 96 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 97 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 98 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 99 ) 100 101 s.mock.EXPECT().Insert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")). 102 Run(func(ctx context.Context, req *milvuspb.InsertRequest) { 103 s.Equal(1, len(req.GetFieldsData())) 104 }).Return(&milvuspb.MutationResult{ 105 Status: &commonpb.Status{}, 106 IDs: &schemapb.IDs{ 107 IdField: &schemapb.IDs_IntId{ 108 IntId: &schemapb.LongArray{ 109 Data: []int64{1}, 110 }, 111 }, 112 }, 113 }, nil) 114 115 _, err := c.Insert(ctx, testCollectionName, "partition_1", 116 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 117 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 118 ) 119 120 s.Error(err) 121 }) 122 123 s.Run("dim_not_match", func() { 124 defer s.resetMock() 125 s.setupHasCollection(testCollectionName) 126 s.setupHasPartition(testCollectionName, "partition_1") 127 128 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 129 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 130 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 131 ) 132 133 _, err := c.Insert(ctx, testCollectionName, "partition_1", 134 entity.NewColumnInt64("ID", []int64{1}), 135 entity.NewColumnFloatVector("vector", 8, [][]float32{{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}}), 136 ) 137 s.Error(err) 138 }) 139 140 s.Run("server_insert_fail", func() { 141 defer s.resetMock() 142 s.setupHasCollection(testCollectionName) 143 s.setupHasPartition(testCollectionName, "partition_1") 144 145 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 146 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 147 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 148 ) 149 150 s.mock.EXPECT().Insert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")).Return( 151 &milvuspb.MutationResult{Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError}}, nil, 152 ) 153 154 _, err := c.Insert(ctx, testCollectionName, "partition_1", 155 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 156 ) 157 158 s.Error(err) 159 }) 160 161 s.Run("server_connection_error", func() { 162 defer s.resetMock() 163 s.setupHasCollection(testCollectionName) 164 s.setupHasPartition(testCollectionName, "partition_1") 165 166 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 167 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 168 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 169 ) 170 171 s.mock.EXPECT().Insert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")).Return( 172 nil, errors.New("mocked error"), 173 ) 174 175 _, err := c.Insert(ctx, testCollectionName, "partition_1", 176 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 177 ) 178 179 s.Error(err) 180 }) 181 } 182 183 func (s *InsertSuite) TestInsertSuccess() { 184 c := s.client 185 ctx, cancel := context.WithCancel(context.Background()) 186 defer cancel() 187 188 s.Run("non_dynamic_schema", func() { 189 defer s.resetMock() 190 s.setupHasCollection(testCollectionName) 191 s.setupHasPartition(testCollectionName, "partition_1") 192 193 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 194 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 195 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 196 ) 197 198 s.mock.EXPECT().Insert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")). 199 Run(func(ctx context.Context, req *milvuspb.InsertRequest) { 200 s.Equal(1, len(req.GetFieldsData())) 201 }).Return(&milvuspb.MutationResult{ 202 Status: &commonpb.Status{}, 203 IDs: &schemapb.IDs{ 204 IdField: &schemapb.IDs_IntId{ 205 IntId: &schemapb.LongArray{ 206 Data: []int64{1}, 207 }, 208 }, 209 }, 210 }, nil) 211 212 r, err := c.Insert(ctx, testCollectionName, "partition_1", 213 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 214 ) 215 216 s.NoError(err) 217 s.Equal(1, r.Len()) 218 }) 219 220 s.Run("dynamic_field_schema", func() { 221 defer s.resetMock() 222 s.setupHasCollection(testCollectionName) 223 s.setupHasPartition(testCollectionName, "partition_1") 224 225 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 226 WithDynamicFieldEnabled(true). 227 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 228 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 229 ) 230 231 s.mock.EXPECT().Insert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")). 232 Run(func(ctx context.Context, req *milvuspb.InsertRequest) { 233 s.Equal(2, len(req.GetFieldsData())) 234 var found bool 235 for _, fd := range req.GetFieldsData() { 236 if fd.GetFieldName() == "" && fd.GetIsDynamic() { 237 found = true 238 break 239 } 240 } 241 s.True(found) 242 }).Return(&milvuspb.MutationResult{ 243 Status: &commonpb.Status{}, 244 IDs: &schemapb.IDs{ 245 IdField: &schemapb.IDs_IntId{ 246 IntId: &schemapb.LongArray{ 247 Data: []int64{1}, 248 }, 249 }, 250 }, 251 }, nil) 252 253 r, err := c.Insert(ctx, testCollectionName, "partition_1", 254 entity.NewColumnInt64("extra", []int64{1}), 255 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 256 ) 257 258 s.NoError(err) 259 s.Equal(1, r.Len()) 260 }) 261 262 s.Run("missing_field_with_default_value", func() { 263 s.T().Skip("skip for default value test") 264 defer s.resetMock() 265 s.setupHasCollection(testCollectionName) 266 s.setupHasPartition(testCollectionName, "partition_1") 267 268 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 269 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 270 WithField(entity.NewField().WithName("default_value").WithDataType(entity.FieldTypeInt64)). 271 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 272 ) 273 274 s.mock.EXPECT().Insert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")). 275 Run(func(ctx context.Context, req *milvuspb.InsertRequest) { 276 s.Equal(2, len(req.GetFieldsData())) 277 }).Return(&milvuspb.MutationResult{ 278 Status: &commonpb.Status{}, 279 IDs: &schemapb.IDs{ 280 IdField: &schemapb.IDs_IntId{ 281 IntId: &schemapb.LongArray{ 282 Data: []int64{1}, 283 }, 284 }, 285 }, 286 }, nil) 287 288 r, err := c.Insert(ctx, testCollectionName, "partition_1", 289 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 290 ) 291 s.NoError(err) 292 s.Equal(1, r.Len()) 293 }) 294 } 295 296 type UpsertSuite struct { 297 MockSuiteBase 298 } 299 300 func (s *UpsertSuite) TestUpsertFail() { 301 c := s.client 302 ctx, cancel := context.WithCancel(context.Background()) 303 defer cancel() 304 305 s.Run("collection_not_exist", func() { 306 defer s.resetMock() 307 s.setupDescribeCollectionError(commonpb.ErrorCode_UnexpectedError, errors.New("mocked")) 308 _, err := c.Upsert(ctx, testCollectionName, "") 309 s.Error(err) 310 }) 311 312 s.Run("field_not_exist", func() { 313 defer s.resetMock() 314 s.setupHasCollection(testCollectionName) 315 s.setupHasPartition(testCollectionName, "partition_1") 316 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 317 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 318 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 319 ) 320 321 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 322 entity.NewColumnInt64("extra", []int64{1}), 323 ) 324 s.Error(err) 325 }) 326 327 s.Run("missing_field_without_default_value", func() { 328 defer s.resetMock() 329 s.setupHasCollection(testCollectionName) 330 s.setupHasPartition(testCollectionName, "partition_1") 331 332 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 333 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 334 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 335 ) 336 337 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 338 entity.NewColumnInt64("ID", []int64{1}), 339 ) 340 s.Error(err) 341 }) 342 343 s.Run("column_len_not_match", func() { 344 defer s.resetMock() 345 s.setupHasCollection(testCollectionName) 346 s.setupHasPartition(testCollectionName, "partition_1") 347 348 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 349 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 350 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 351 ) 352 353 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 354 entity.NewColumnInt64("ID", []int64{1, 2}), 355 entity.NewColumnFloatVector("vector", 128, [][]float32{}), 356 ) 357 s.Error(err) 358 }) 359 360 s.Run("duplicated column", func() { 361 defer s.resetMock() 362 s.setupHasCollection(testCollectionName) 363 s.setupHasPartition(testCollectionName, "partition_1") 364 365 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 366 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 367 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 368 ) 369 370 s.mock.EXPECT().Upsert(mock.Anything, mock.AnythingOfType("*milvuspb.InsertRequest")). 371 Run(func(ctx context.Context, req *milvuspb.UpsertRequest) { 372 s.Equal(1, len(req.GetFieldsData())) 373 }).Return(&milvuspb.MutationResult{ 374 Status: &commonpb.Status{}, 375 IDs: &schemapb.IDs{ 376 IdField: &schemapb.IDs_IntId{ 377 IntId: &schemapb.LongArray{ 378 Data: []int64{1}, 379 }, 380 }, 381 }, 382 }, nil) 383 384 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 385 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 386 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 387 ) 388 389 s.Error(err) 390 }) 391 392 s.Run("dim_not_match", func() { 393 defer s.resetMock() 394 s.setupHasCollection(testCollectionName) 395 s.setupHasPartition(testCollectionName, "partition_1") 396 397 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 398 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 399 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 400 ) 401 402 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 403 entity.NewColumnInt64("ID", []int64{1}), 404 entity.NewColumnFloatVector("vector", 8, [][]float32{{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}}), 405 ) 406 s.Error(err) 407 }) 408 409 s.Run("server_insert_fail", func() { 410 defer s.resetMock() 411 s.setupHasCollection(testCollectionName) 412 s.setupHasPartition(testCollectionName, "partition_1") 413 414 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 415 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 416 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 417 ) 418 419 s.mock.EXPECT().Upsert(mock.Anything, mock.AnythingOfType("*milvuspb.UpsertRequest")).Return( 420 &milvuspb.MutationResult{Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError}}, nil, 421 ) 422 423 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 424 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 425 ) 426 427 s.Error(err) 428 }) 429 430 s.Run("server_connection_error", func() { 431 defer s.resetMock() 432 s.setupHasCollection(testCollectionName) 433 s.setupHasPartition(testCollectionName, "partition_1") 434 435 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 436 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 437 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 438 ) 439 440 s.mock.EXPECT().Upsert(mock.Anything, mock.AnythingOfType("*milvuspb.UpsertRequest")).Return( 441 nil, errors.New("mocked error"), 442 ) 443 444 _, err := c.Upsert(ctx, testCollectionName, "partition_1", 445 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 446 ) 447 448 s.Error(err) 449 }) 450 } 451 452 func (s *UpsertSuite) TestUpsertSuccess() { 453 c := s.client 454 ctx, cancel := context.WithCancel(context.Background()) 455 defer cancel() 456 457 s.Run("non_dynamic_schema", func() { 458 defer s.resetMock() 459 s.setupHasCollection(testCollectionName) 460 s.setupHasPartition(testCollectionName, "partition_1") 461 462 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 463 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 464 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 465 ) 466 467 s.mock.EXPECT().Upsert(mock.Anything, mock.AnythingOfType("*milvuspb.UpsertRequest")). 468 Run(func(ctx context.Context, req *milvuspb.UpsertRequest) { 469 s.Equal(1, len(req.GetFieldsData())) 470 }).Return(&milvuspb.MutationResult{ 471 Status: &commonpb.Status{}, 472 IDs: &schemapb.IDs{ 473 IdField: &schemapb.IDs_IntId{ 474 IntId: &schemapb.LongArray{ 475 Data: []int64{1}, 476 }, 477 }, 478 }, 479 }, nil) 480 481 r, err := c.Upsert(ctx, testCollectionName, "partition_1", 482 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 483 ) 484 485 s.NoError(err) 486 s.Equal(1, r.Len()) 487 }) 488 489 s.Run("dynamic_field_schema", func() { 490 defer s.resetMock() 491 s.setupHasCollection(testCollectionName) 492 s.setupHasPartition(testCollectionName, "partition_1") 493 494 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 495 WithDynamicFieldEnabled(true). 496 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 497 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 498 ) 499 500 s.mock.EXPECT().Upsert(mock.Anything, mock.AnythingOfType("*milvuspb.UpsertRequest")). 501 Run(func(ctx context.Context, req *milvuspb.UpsertRequest) { 502 s.Equal(2, len(req.GetFieldsData())) 503 var found bool 504 for _, fd := range req.GetFieldsData() { 505 if fd.GetFieldName() == "" && fd.GetIsDynamic() { 506 found = true 507 break 508 } 509 } 510 s.True(found) 511 }).Return(&milvuspb.MutationResult{ 512 Status: &commonpb.Status{}, 513 IDs: &schemapb.IDs{ 514 IdField: &schemapb.IDs_IntId{ 515 IntId: &schemapb.LongArray{ 516 Data: []int64{1}, 517 }, 518 }, 519 }, 520 }, nil) 521 522 r, err := c.Upsert(ctx, testCollectionName, "partition_1", 523 entity.NewColumnInt64("extra", []int64{1}), 524 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 525 ) 526 527 s.NoError(err) 528 s.Equal(1, r.Len()) 529 }) 530 531 s.Run("missing_field_with_default_value", func() { 532 s.T().Skip("skip for default value test") 533 defer s.resetMock() 534 s.setupHasCollection(testCollectionName) 535 s.setupHasPartition(testCollectionName, "partition_1") 536 537 s.setupDescribeCollection(testCollectionName, entity.NewSchema(). 538 WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)). 539 WithField(entity.NewField().WithName("default_value").WithDataType(entity.FieldTypeInt64)). 540 WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")), 541 ) 542 543 s.mock.EXPECT().Upsert(mock.Anything, mock.AnythingOfType("*milvuspb.UpsertRequest")). 544 Run(func(ctx context.Context, req *milvuspb.UpsertRequest) { 545 s.Equal(2, len(req.GetFieldsData())) 546 }).Return(&milvuspb.MutationResult{ 547 Status: &commonpb.Status{}, 548 IDs: &schemapb.IDs{ 549 IdField: &schemapb.IDs_IntId{ 550 IntId: &schemapb.LongArray{ 551 Data: []int64{1}, 552 }, 553 }, 554 }, 555 }, nil) 556 557 r, err := c.Upsert(ctx, testCollectionName, "partition_1", 558 entity.NewColumnFloatVector("vector", 128, generateFloatVector(1, 128)), 559 ) 560 s.NoError(err) 561 s.Equal(1, r.Len()) 562 }) 563 } 564 565 func TestWrite(t *testing.T) { 566 suite.Run(t, new(InsertSuite)) 567 suite.Run(t, new(UpsertSuite)) 568 }