Skip to content

Commit

Permalink
enhance: Print Array field element type
Browse files Browse the repository at this point in the history
Support printing array field element data type for `show collections`
command

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia committed Aug 20, 2024
1 parent 2aad825 commit 489f5fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions models/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func NewCollectionFromV2_2(info *etcdpbv2.CollectionInfo, key string, fields []*
fs.IsDynamic = fieldSchema.GetIsDynamic()
fs.IsPartitionKey = fieldSchema.GetIsPartitionKey()
fs.IsClusteringKey = fieldSchema.GetIsClusteringKey()
fs.ElementType = DataType(fieldSchema.GetElementType())
return fs
})
c.Schema.EnableDynamicSchema = info.GetSchema().GetEnableDynamicField()
Expand Down
1 change: 1 addition & 0 deletions models/collection_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type FieldSchema struct {
IsDynamic bool
IsPartitionKey bool
IsClusteringKey bool
ElementType DataType
}

func (fs *FieldSchema) GetDim() (int64, error) {
Expand Down
46 changes: 23 additions & 23 deletions states/etcd/show/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (rs *Collections) PrintAs(format framework.Format) string {
printCollection(sb, coll)
}
fmt.Fprintln(sb, "================================================================================")
fmt.Printf("--- Total collections: %d\t Matched collections: %d\n", rs.total, len(rs.collections))
fmt.Printf("--- Total channel: %d\t Healthy collections: %d\n", rs.channels, rs.healthy)
fmt.Fprintf(sb, "--- Total collections: %d\t Matched collections: %d\n", rs.total, len(rs.collections))
fmt.Fprintf(sb, "--- Total channel: %d\t Healthy collections: %d\n", rs.channels, rs.healthy)
return sb.String()
}
return ""
Expand All @@ -98,47 +98,47 @@ func (rs *Collections) Entities() any {
}

func printCollection(sb *strings.Builder, collection *models.Collection) {
fmt.Println("================================================================================")
fmt.Printf("DBID: %d\n", collection.DBID)
fmt.Printf("Collection ID: %d\tCollection Name: %s\n", collection.ID, collection.Schema.Name)
fmt.Fprintln(sb, "================================================================================")
fmt.Fprintf(sb, "DBID: %d\n", collection.DBID)
fmt.Fprintf(sb, "Collection ID: %d\tCollection Name: %s\n", collection.ID, collection.Schema.Name)
t, _ := utils.ParseTS(collection.CreateTime)
fmt.Printf("Collection State: %s\tCreate Time: %s\n", collection.State.String(), t.Format("2006-01-02 15:04:05"))
/*
fmt.Printf("Partitions:\n")
for idx, partID := range collection.GetPartitionIDs() {
fmt.Printf(" - Partition ID: %d\tPartition Name: %s\n", partID, collection.GetPartitionNames()[idx])
}*/
fmt.Printf("Fields:\n")
fmt.Fprintf(sb, "Collection State: %s\tCreate Time: %s\n", collection.State.String(), t.Format("2006-01-02 15:04:05"))
fmt.Fprintf(sb, "Fields:\n")
fields := collection.Schema.Fields
sort.Slice(fields, func(i, j int) bool {
return fields[i].FieldID < fields[j].FieldID
})
for _, field := range fields {
fmt.Printf(" - Field ID: %d \t Field Name: %s \t Field Type: %s\n", field.FieldID, field.Name, field.DataType.String())
fmt.Fprintf(sb, " - Field ID: %d \t Field Name: %s \t Field Type: %s\n", field.FieldID, field.Name, field.DataType.String())
if field.IsPrimaryKey {
fmt.Printf("\t - Primary Key: %t, AutoID: %t\n", field.IsPrimaryKey, field.AutoID)
fmt.Fprintf(sb, "\t - Primary Key: %t, AutoID: %t\n", field.IsPrimaryKey, field.AutoID)
}
if field.IsDynamic {
fmt.Printf("\t - Dynamic Field\n")
fmt.Fprintf(sb, "\t - Dynamic Field\n")
}
if field.IsPartitionKey {
fmt.Printf("\t - Partition Key\n")
fmt.Fprintf(sb, "\t - Partition Key\n")
}
if field.IsClusteringKey {
fmt.Printf("\t - Clustering Key\n")
fmt.Fprintf(sb, "\t - Clustering Key\n")
}
// print element type if field is array
if field.DataType == models.DataTypeArray {
fmt.Fprintf(sb, "\t - Element Type: %s\n", field.ElementType.String())
}
// type params
for key, value := range field.Properties {
fmt.Printf("\t - Type Param %s: %s\n", key, value)
fmt.Fprintf(sb, "\t - Type Param %s: %s\n", key, value)
}
}

fmt.Printf("Enable Dynamic Schema: %t\n", collection.Schema.EnableDynamicSchema)
fmt.Printf("Consistency Level: %s\n", collection.ConsistencyLevel.String())
fmt.Fprintf(sb, "Enable Dynamic Schema: %t\n", collection.Schema.EnableDynamicSchema)
fmt.Fprintf(sb, "Consistency Level: %s\n", collection.ConsistencyLevel.String())
for _, channel := range collection.Channels {
fmt.Printf("Start position for channel %s(%s): %v\n", channel.PhysicalName, channel.VirtualName, channel.StartPosition.MsgID)
fmt.Fprintf(sb, "Start position for channel %s(%s): %v\n", channel.PhysicalName, channel.VirtualName, channel.StartPosition.MsgID)
}
fmt.Printf("Collection properties(%d):", len(collection.Properties))
fmt.Fprintf(sb, "Collection properties(%d):\n", len(collection.Properties))
for k, v := range collection.Properties {
fmt.Printf("\tKey: %s: %v\n", k, v)
fmt.Fprintf(sb, "\tKey: %s: %v\n", k, v)
}
}

0 comments on commit 489f5fd

Please sign in to comment.