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

/kind improvement

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

---------

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2024-07-30 20:18:32 +08:00 committed by GitHub
parent dd0c26cf58
commit 39d25938c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1038,7 +1038,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
}
@ -1049,7 +1049,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)
}
@ -1060,7 +1060,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
}
@ -1071,7 +1071,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
}