Skip to content

Commit

Permalink
Update the metadata example script
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Dec 17, 2024
1 parent 1a1440d commit b452aa5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions examples/python/remote/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,39 @@
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:
print("ID not found")
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)

0 comments on commit b452aa5

Please sign in to comment.