Skip to content

Fix CLI command order and catalog not found error #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iting0321
Copy link

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.

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
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 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
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"])

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")
Copy link
Member

@jason810496 jason810496 Mar 22, 2025

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")

Copy link
Member

@jason810496 jason810496 left a comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

improve pyiceberg CLI
2 participants