Skip to content

Commit

Permalink
bug fix for show collection-history --id <id> not printing value
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeri-Jose1 committed Jan 27, 2025
1 parent 43d4e81 commit b6c4257
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
44 changes: 22 additions & 22 deletions states/etcd/show/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func (rs *Collections) PrintAs(format framework.Format) string {
case framework.FormatDefault, framework.FormatPlain:
sb := &strings.Builder{}
for _, coll := range rs.collections {
printCollection(sb, coll)
printCollection( coll)
}
fmt.Fprintln(sb, "================================================================================")
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)
fmt.Printf( "================================================================================")
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)
return sb.String()
}
return ""
Expand All @@ -97,48 +97,48 @@ func (rs *Collections) Entities() any {
return rs.collections
}

func printCollection(sb *strings.Builder, collection *models.Collection) {
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)
func printCollection( collection *models.Collection) {
fmt.Printf( "================================================================================")
fmt.Printf( "DBID: %d\n", collection.DBID)
fmt.Printf( "Collection ID: %d\tCollection Name: %s\n", collection.ID, collection.Schema.Name)
t, _ := utils.ParseTS(collection.CreateTime)
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")
fmt.Printf( "Collection State: %s\tCreate Time: %s\n", collection.State.String(), t.Format("2006-01-02 15:04:05"))
fmt.Printf( "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.Fprintf(sb, " - Field ID: %d \t Field Name: %s \t Field Type: %s\n", field.FieldID, field.Name, field.DataType.String())
fmt.Printf( " - Field ID: %d \t Field Name: %s \t Field Type: %s\n", field.FieldID, field.Name, field.DataType.String())
if field.IsPrimaryKey {
fmt.Fprintf(sb, "\t - Primary Key: %t, AutoID: %t\n", field.IsPrimaryKey, field.AutoID)
fmt.Printf( "\t - Primary Key: %t, AutoID: %t\n", field.IsPrimaryKey, field.AutoID)
}
if field.IsDynamic {
fmt.Fprintf(sb, "\t - Dynamic Field\n")
fmt.Printf( "\t - Dynamic Field\n")
}
if field.IsPartitionKey {
fmt.Fprintf(sb, "\t - Partition Key\n")
fmt.Printf( "\t - Partition Key\n")
}
if field.IsClusteringKey {
fmt.Fprintf(sb, "\t - Clustering Key\n")
fmt.Printf( "\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())
fmt.Printf( "\t - Element Type: %s\n", field.ElementType.String())
}
// type params
for key, value := range field.Properties {
fmt.Fprintf(sb, "\t - Type Param %s: %s\n", key, value)
fmt.Printf( "\t - Type Param %s: %s\n", key, value)
}
}

fmt.Fprintf(sb, "Enable Dynamic Schema: %t\n", collection.Schema.EnableDynamicSchema)
fmt.Fprintf(sb, "Consistency Level: %s\n", collection.ConsistencyLevel.String())
fmt.Printf( "Enable Dynamic Schema: %t\n", collection.Schema.EnableDynamicSchema)
fmt.Printf( "Consistency Level: %s\n", collection.ConsistencyLevel.String())
for _, channel := range collection.Channels {
fmt.Fprintf(sb, "Start position for channel %s(%s): %v\n", channel.PhysicalName, channel.VirtualName, channel.StartPosition.MsgID)
fmt.Printf( "Start position for channel %s(%s): %v\n", channel.PhysicalName, channel.VirtualName, channel.StartPosition.MsgID)
}
fmt.Fprintf(sb, "Collection properties(%d):\n", len(collection.Properties))
fmt.Printf( "Collection properties(%d):\n", len(collection.Properties))
for k, v := range collection.Properties {
fmt.Fprintf(sb, "\tKey: %s: %v\n", k, v)
fmt.Printf( "\tKey: %s: %v\n", k, v)
}
}
9 changes: 4 additions & 5 deletions states/etcd/show/collection_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,15 @@ type CollectionHistory struct {
func (rs *CollectionHistory) PrintAs(format framework.Format) string {
switch format {
case framework.FormatDefault, framework.FormatPlain:
sb := &strings.Builder{}
printCollection(sb, rs.Collection)
printCollection(rs.Collection)
for _, item := range rs.HistoryItems {
t, _ := utils.ParseTS(item.Ts)
fmt.Fprintln(sb, "Snapshot at", t.Format("2006-01-02 15:04:05"))
fmt.Printf( "Snapshot at", t.Format("2006-01-02 15:04:05"))
if item.Dropped {
fmt.Fprintln(sb, "Collection Dropped")
fmt.Printf( "Collection Dropped")
continue
}
printCollection(sb, &item.Collection)
printCollection(&item.Collection)
}
default:
}
Expand Down

0 comments on commit b6c4257

Please sign in to comment.