enhance: Avoid panic due to nil schema (#35063) (#35064)

/kind improvement

issue: https://github.com/milvus-io/milvus/discussions/25620

pr: https://github.com/milvus-io/milvus/pull/35063

---------

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2024-07-29 20:07:49 +08:00 committed by GitHub
parent 4138a9f87d
commit cc188fb322
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1033,7 +1033,7 @@ func MergeFieldData(dst []*schemapb.FieldData, src []*schemapb.FieldData) error
// GetVectorFieldSchema get vector field schema from collection schema.
func GetVectorFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSchema, error) {
for _, fieldSchema := range schema.Fields {
for _, fieldSchema := range schema.GetFields() {
if IsVectorType(fieldSchema.DataType) {
return fieldSchema, nil
}
@ -1044,7 +1044,7 @@ func GetVectorFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSch
// GetVectorFieldSchemas get vector fields schema from collection schema.
func GetVectorFieldSchemas(schema *schemapb.CollectionSchema) []*schemapb.FieldSchema {
ret := make([]*schemapb.FieldSchema, 0)
for _, fieldSchema := range schema.Fields {
for _, fieldSchema := range schema.GetFields() {
if IsVectorType(fieldSchema.DataType) {
ret = append(ret, fieldSchema)
}
@ -1055,7 +1055,7 @@ func GetVectorFieldSchemas(schema *schemapb.CollectionSchema) []*schemapb.FieldS
// GetPrimaryFieldSchema get primary field schema from collection schema
func GetPrimaryFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSchema, error) {
for _, fieldSchema := range schema.Fields {
for _, fieldSchema := range schema.GetFields() {
if fieldSchema.IsPrimaryKey {
return fieldSchema, nil
}
@ -1066,7 +1066,7 @@ func GetPrimaryFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSc
// GetPartitionKeyFieldSchema get partition field schema from collection schema
func GetPartitionKeyFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSchema, error) {
for _, fieldSchema := range schema.Fields {
for _, fieldSchema := range schema.GetFields() {
if fieldSchema.IsPartitionKey {
return fieldSchema, nil
}