diff --git a/examples/python/remote/metadata.py b/examples/python/remote/metadata.py index e199499d8f2a..31371bfac2d3 100644 --- a/examples/python/remote/metadata.py +++ b/examples/python/remote/metadata.py @@ -14,23 +14,31 @@ subparsers = parser.add_subparsers(dest="subcommand") print_cmd = subparsers.add_parser("print", help="Print everything") + register_cmd = subparsers.add_parser("register", help="Register a new recording") update_cmd = subparsers.add_parser("update", help="Update metadata for a recording") update_cmd.add_argument("id", help="ID of the recording to update") update_cmd.add_argument("key", help="Key of the metadata to update") update_cmd.add_argument("value", help="Value of the metadata to update") + register_cmd.add_argument("storage_url", help="Storage URL to register") + args = parser.parse_args() # Register the new rrd conn = rr.remote.connect("http://0.0.0.0:51234") - catalog = pl.from_arrow(conn.query_catalog()) + catalog = pl.from_arrow(conn.query_catalog().read_all()) if args.subcommand == "print": print(catalog) - if args.subcommand == "update": + elif args.subcommand == "register": + extra_metadata = pa.Table.from_pydict({"extra": [42]}) + id = conn.register(args.storage_url, extra_metadata) + print(f"Registered new recording with ID: {id}") + + elif args.subcommand == "update": id = catalog.filter(catalog["id"].str.starts_with(args.id)).select(pl.first("id")).item() if id is None: @@ -38,4 +46,7 @@ exit(1) print(f"Updating metadata for {id}") - conn.update_catalog(id, {args.key: pa.array([args.value])}) + new_metadata = pa.Table.from_pydict({"id": [id], args.key: [args.value]}) + print(new_metadata) + + conn.update_catalog(new_metadata)