in cmd/iceberg/main.go [124:264]
func main() {
ctx := context.Background()
args, err := docopt.ParseArgs(usage, os.Args[1:], iceberg.Version())
if err != nil {
log.Fatal(err)
}
cfg := Config{}
if err := args.Bind(&cfg); err != nil {
log.Fatal(err)
}
fileCfg := config.ParseConfig(config.LoadConfig(cfg.Config), "default")
if fileCfg != nil {
mergeConf(fileCfg, &cfg)
}
var output Output
switch strings.ToLower(cfg.Output) {
case "text":
output = textOutput{}
case "json":
output = jsonOutput{}
default:
log.Fatal("unimplemented output type")
}
var cat catalog.Catalog
switch catalog.Type(cfg.Catalog) {
case catalog.REST:
opts := []rest.Option{}
if len(cfg.Cred) > 0 {
opts = append(opts, rest.WithCredential(cfg.Cred))
}
if len(cfg.Warehouse) > 0 {
opts = append(opts, rest.WithWarehouseLocation(cfg.Warehouse))
}
if cat, err = rest.NewCatalog(ctx, "rest", cfg.URI, opts...); err != nil {
log.Fatal(err)
}
case catalog.Glue:
awscfg, err := awsconfig.LoadDefaultConfig(ctx)
if err != nil {
log.Fatal(err)
}
opts := []glue.Option{
glue.WithAwsConfig(awscfg),
}
cat = glue.NewCatalog(opts...)
default:
log.Fatal("unrecognized catalog type")
}
switch {
case cfg.List:
list(ctx, output, cat, cfg.Parent)
case cfg.Describe:
entityType := "any"
if cfg.Namespace {
entityType = "ns"
} else if cfg.Table {
entityType = "tbl"
}
describe(ctx, output, cat, cfg.Ident, entityType)
case cfg.Schema:
tbl := loadTable(ctx, output, cat, cfg.TableID)
output.Schema(tbl.Schema())
case cfg.Spec:
tbl := loadTable(ctx, output, cat, cfg.TableID)
output.Spec(tbl.Spec())
case cfg.Location:
tbl := loadTable(ctx, output, cat, cfg.TableID)
output.Text(tbl.Location())
case cfg.Uuid:
tbl := loadTable(ctx, output, cat, cfg.TableID)
output.Uuid(tbl.Metadata().TableUUID())
case cfg.Props:
properties(ctx, output, cat, propCmd{
get: cfg.Get, set: cfg.Set, remove: cfg.Remove,
namespace: cfg.Namespace, table: cfg.Table,
identifier: cfg.Ident,
propname: cfg.PropName,
value: cfg.Value,
})
case cfg.Rename:
_, err := cat.RenameTable(ctx,
catalog.ToIdentifier(cfg.RenameFrom), catalog.ToIdentifier(cfg.RenameTo))
if err != nil {
output.Error(err)
os.Exit(1)
}
output.Text("Renamed table from " + cfg.RenameFrom + " to " + cfg.RenameTo)
case cfg.Drop:
switch {
case cfg.Namespace:
err := cat.DropNamespace(ctx, catalog.ToIdentifier(cfg.Ident))
if err != nil {
output.Error(err)
os.Exit(1)
}
case cfg.Table:
err := cat.DropTable(ctx, catalog.ToIdentifier(cfg.Ident))
if err != nil {
output.Error(err)
os.Exit(1)
}
}
case cfg.Create:
switch {
case cfg.Namespace:
props := iceberg.Properties{}
if cfg.Description != "" {
props["Description"] = cfg.Description
}
if cfg.LocationURI != "" {
props["Location"] = cfg.LocationURI
}
err := cat.CreateNamespace(ctx, catalog.ToIdentifier(cfg.Ident), props)
if err != nil {
output.Error(err)
os.Exit(1)
}
case cfg.Table:
output.Error(errors.New("not implemented: Create Table is WIP"))
default:
output.Error(errors.New("not implemented"))
os.Exit(1)
}
case cfg.Files:
tbl := loadTable(ctx, output, cat, cfg.TableID)
output.Files(tbl, cfg.History)
}
}