Skip to content

Commit

Permalink
enhance: Avoid panic due to nil schema (milvus-io#35063)
Browse files Browse the repository at this point in the history
/kind improvement

issue: milvus-io#25620

---------

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
  • Loading branch information
bigsheeper committed Jul 30, 2024
1 parent dd0c26c commit 39d2593
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/util/typeutil/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 39d2593

Please sign in to comment.