Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mkdocs/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ hide:

Pyiceberg comes with a CLI that's available after installing the `pyiceberg` package.

You can pass the path to the Catalog using `--uri` and `--credential`. For REST catalogs that require a path prefix, you can also set `--prefix`. It is still recommended to set up a `~/.pyiceberg.yaml` config as described in the [Catalog](configuration.md) section.
You can pass the path to the Catalog using `--uri` and `--credential`. For REST catalogs, you can also set `--warehouse` to request a specific warehouse from the catalog service. It is still recommended to set up a `~/.pyiceberg.yaml` config as described in the [Catalog](configuration.md) section.

```sh
➜ pyiceberg --help
Expand All @@ -39,7 +39,7 @@ Options:
--ugi TEXT
--uri TEXT
--credential TEXT
--prefix TEXT
--warehouse TEXT
--help Show this message and exit.

Commands:
Expand Down
9 changes: 5 additions & 4 deletions pyiceberg/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from pyiceberg.catalog import URI, Catalog, load_catalog
from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError
from pyiceberg.io import WAREHOUSE
from pyiceberg.table import TableProperties
from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
from pyiceberg.utils.properties import property_as_int
Expand Down Expand Up @@ -66,7 +67,7 @@ def wrapper(*args: Any, **kwargs: Any): # type: ignore
@click.option("--ugi")
@click.option("--uri")
@click.option("--credential")
@click.option("--prefix")
@click.option("--warehouse")
@click.pass_context
def run(
ctx: Context,
Expand All @@ -77,7 +78,7 @@ def run(
ugi: str | None,
uri: str | None,
credential: str | None,
prefix: str | None,
warehouse: str | None,
) -> None:
logging.basicConfig(
level=getattr(logging, log_level.upper()),
Expand All @@ -91,8 +92,8 @@ def run(
properties[URI] = uri
if credential:
properties["credential"] = credential
if prefix:
properties["prefix"] = prefix
if warehouse:
properties[WAREHOUSE] = warehouse

ctx.ensure_object(dict)
if output == "text":
Expand Down
8 changes: 5 additions & 3 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,16 +1044,18 @@ def test_log_level_cli_overrides_env(mocker: MockFixture) -> None:
assert call_kwargs["level"] == logging.ERROR


def test_prefix_cli_option_forwarded_to_catalog(mocker: MockFixture) -> None:
def test_warehouse_cli_option_forwarded_to_catalog(mocker: MockFixture) -> None:
mock_basicConfig = mocker.patch("logging.basicConfig")
mock_catalog = MagicMock(spec=InMemoryCatalog)
mock_catalog.list_tables.return_value = []
mock_catalog.list_namespaces.return_value = []
mock_load_catalog = mocker.patch("pyiceberg.cli.console.load_catalog", return_value=mock_catalog)

runner = CliRunner()
result = runner.invoke(run, ["--catalog", "rest", "--uri", "https://example.invalid", "--prefix", "v1/ws", "list"])
result = runner.invoke(
run, ["--catalog", "rest", "--uri", "https://catalog.service", "--warehouse", "example-warehouse", "list"]
)

assert result.exit_code == 0
mock_basicConfig.assert_called_once()
mock_load_catalog.assert_called_once_with("rest", uri="https://example.invalid", prefix="v1/ws")
mock_load_catalog.assert_called_once_with("rest", uri="https://catalog.service", warehouse="example-warehouse")