Fokko commented on code in PR #5417: URL: https://github.com/apache/iceberg/pull/5417#discussion_r941012574
########## python/pyiceberg/cli/console.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import os + +import click +from rich.console import Console +from rich.table import Table +from rich.tree import Tree + +from pyiceberg.catalog.rest import RestCatalog +from pyiceberg.exceptions import NamespaceNotEmptyError, NoSuchNamespaceError, NoSuchTableError + + [email protected]() [email protected]("--catalog", type=click.Choice(["rest"], case_sensitive=False), default="rest") [email protected]("--uri", default=lambda: os.environ.get("PYICEBERG_URI")) [email protected]("--credentials", default=lambda: os.environ.get("PYICEBERG_CREDENTIALS")) [email protected]_context +def run(ctx, catalog, uri, credentials): + if catalog == "rest": + ctx.ensure_object(dict) + ctx.obj["catalog"] = RestCatalog(name="catalog", properties={}, uri=uri, credentials=credentials) + + [email protected]() [email protected]_context +def list_namespace(ctx): + # Add parent namespaces + catalog: RestCatalog = ctx.obj["catalog"] + identifiers = catalog.list_namespaces() + + table = Table(title="Namespaces") + + table.add_column("Namespace") + + for identifier in identifiers: + table.add_row(".".join(identifier)) + + console = Console() + console.print(table) + + [email protected]() [email protected]("namespace") [email protected]_context +def load_namespace(ctx, namespace: str): + catalog: RestCatalog = ctx.obj["catalog"] + console = Console() + + try: + properties = catalog.load_namespace_properties(namespace) + + if properties: + table = Table(title=f"{namespace} properties", show_header=False) + for key, value in properties.items(): + table.add_row(key, value) + console.print(table) + else: + console.print("No properties...") + except NoSuchNamespaceError: + console.print(f"Namespace does not exists: {namespace}") + + [email protected]() [email protected]("namespace") [email protected]_context +def drop_namespace(ctx, namespace: str): + catalog: RestCatalog = ctx.obj["catalog"] + console = Console() + + try: + catalog.drop_namespace(namespace) + console.print(f"Namespace {namespace} has been dropped") + except NoSuchNamespaceError: + console.print(f"Namespace does not exists: {namespace}") Review Comment: Thanks 👍🏻 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
