Skip to content

Fix CLI command order and catalog not found error - #1828

Closed
iting0321 wants to merge 2 commits into
apache:mainfrom
iting0321:fix/catalog-option
Closed

iting0321 wants to merge 2 commits into
apache:mainfrom
iting0321:fix/catalog-option

Conversation

@iting0321

Copy link
Copy Markdown

Closes #1784

Rationale for this change

The command order for pyiceberg list --catalog hive would raise error; it should be pyiceberg --catalog hive list.
Now, pyiceberg list --catalog hive will return the same result as pyiceberg --catalog hive list.

Additionally, for cases where the catalog is not found:
For example, if the default catalog is not set and the command pyiceberg list is executed, it will raise an error stating:
Default catalog not found. Please provide a catalog type using --type.

Are these changes tested?

The tests test_no_catalog_error and test_list_with_catalog_option_wrong_order in tests/cli/test_console.py cover these scenarios.
Additionally, I fixed test_missing_uri. When a catalog exists but the URI is missing, it will now return an appropriate error.

Comment thread pyiceberg/cli/console.py Outdated
ctx.obj["catalog"] = load_catalog(ctx.obj["first_level_catalog"],**ctx.obj["properties"])
else:
ctx.obj["catalog"] = load_catalog(ctx.obj["second_level_catalog"],**ctx.obj["properties"])
print("cataloglll",ctx.obj["catalog"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The forgot removed print

Suggested change
print("cataloglll",ctx.obj["catalog"])

Comment thread pyiceberg/cli/console.py Outdated
Comment on lines +104 to +109
if ctx.obj["first_level_catalog"] is None and ctx.obj["second_level_catalog"] is None:
ctx.obj["catalog"] = load_catalog(None, **ctx.obj["properties"])
elif ctx.obj["first_level_catalog"] is not None and ctx.obj["second_level_catalog"] is None:
ctx.obj["catalog"] = load_catalog(ctx.obj["first_level_catalog"],**ctx.obj["properties"])
else:
ctx.obj["catalog"] = load_catalog(ctx.obj["second_level_catalog"],**ctx.obj["properties"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can refactor as:

Suggested change
if ctx.obj["first_level_catalog"] is None and ctx.obj["second_level_catalog"] is None:
ctx.obj["catalog"] = load_catalog(None, **ctx.obj["properties"])
elif ctx.obj["first_level_catalog"] is not None and ctx.obj["second_level_catalog"] is None:
ctx.obj["catalog"] = load_catalog(ctx.obj["first_level_catalog"],**ctx.obj["properties"])
else:
ctx.obj["catalog"] = load_catalog(ctx.obj["second_level_catalog"],**ctx.obj["properties"])
catalog_option = ctx.obj.get("first_level_catalog",None) or ctx.obj.get("second_level_catalog",None)
ctx.obj["catalog"] = load_catalog(catalog_option,**ctx.obj["properties"])

Comment thread pyiceberg/cli/console.py Outdated
if not isinstance(ctx.obj["catalog"], Catalog):
ctx.obj["output"].exception(
ValueError("Could not determine catalog type from uri. REST (http/https) and Hive (thrift) is supported")
ValueError("Could not determine catalog type from uri. REST (http/https) and Hive (thrift) is supported")

@jason810496 jason810496 Mar 22, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The indentation, as well as the order of imported modules, can be fixed based on the last comment.

Suggested change
ValueError("Could not determine catalog type from uri. REST (http/https) and Hive (thrift) is supported")
ValueError("Could not determine catalog type from uri. REST (http/https) and Hive (thrift) is supported")

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall looks good, thanks !
Most of the nit can be resolved by autoformatting and linting via https://py.iceberg.apache.org/contributing/#linting.

make lint

Or install the pre-commit can help run these formatting on commit.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Mar 17, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve pyiceberg CLI

2 participants