in cmd/iceberg/main.go [346:417]
func properties(ctx context.Context, output Output, cat catalog.Catalog, args propCmd) {
ident := catalog.ToIdentifier(args.identifier)
switch {
case args.get:
var props iceberg.Properties
switch {
case args.namespace:
var err error
props, err = cat.LoadNamespaceProperties(ctx, ident)
if err != nil {
output.Error(err)
os.Exit(1)
}
case args.table:
tbl := loadTable(ctx, output, cat, args.identifier)
props = tbl.Metadata().Properties()
}
if args.propname == "" {
output.DescribeProperties(props)
return
}
if val, ok := props[args.propname]; ok {
output.Text(val)
} else {
output.Error(errors.New("could not find property " + args.propname + " on namespace " + args.identifier))
os.Exit(1)
}
case args.set:
switch {
case args.namespace:
_, err := cat.UpdateNamespaceProperties(ctx, ident,
nil, iceberg.Properties{args.propname: args.value})
if err != nil {
output.Error(err)
os.Exit(1)
}
output.Text("updated " + args.propname + " on " + args.identifier)
case args.table:
tbl := loadTable(ctx, output, cat, args.identifier)
output.Text("Setting " + args.propname + "=" + args.value + " on " + args.identifier)
// TODO: handle other Update operations
_, _, err := cat.CommitTable(ctx, tbl, nil,
[]table.Update{table.NewSetPropertiesUpdate(iceberg.Properties{args.propname: args.value})})
if err != nil {
output.Error(err)
os.Exit(1)
}
}
case args.remove:
switch {
case args.namespace:
_, err := cat.UpdateNamespaceProperties(ctx, ident,
[]string{args.propname}, nil)
if err != nil {
output.Error(err)
os.Exit(1)
}
output.Text("removing " + args.propname + " from " + args.identifier)
case args.table:
loadTable(ctx, output, cat, args.identifier)
output.Text("Setting " + args.propname + "=" + args.value + " on " + args.identifier)
output.Error(errors.New("not implemented: Writing is WIP"))
}
}
}