You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "MonkeyCanCode (via GitHub)" <gi...@apache.org> on 2026/08/09 05:35:22 UTC
[PR] Add views and generic-tables support in CLI [polaris]
MonkeyCanCode opened a new pull request, #5260:
URL: https://github.com/apache/polaris/pull/5260
<!--
๐ Describe what changes you're proposing, especially breaking or user-facing changes.
๐ See https://github.com/apache/polaris/blob/main/CONTRIBUTING.md for more.
-->
Similar to https://github.com/apache/polaris/pull/4075, this PR adds the support for views and generic-tables that doesn't required FileIO as agreed on the original [ML](https://lists.apache.org/thread/35zzzh2jgorhx7q2xksp7rwxnt6gl2zx).
Sample outputs for `views`:
Sample outputs for `generic-tables`:
```
# List
(.venv) โ polaris git:(main) โ polaris --client-id root --client-secret s3cr3t generic-tables list --catalog polaris_demo --namespace DELTA_NS.PUBLIC
{"namespace": ["DELTA_NS", "PUBLIC"], "name": "PEOPLE"}
# Get
(.venv) โ polaris git:(main) โ polaris --client-id root --client-secret s3cr3t generic-tables get --catalog polaris_demo --namespace DELTA_NS.PUBLIC PEOPLE | jq
{
"table": {
"name": "PEOPLE",
"format": "delta",
"base-location": "file:/tmp/delta_tables/people",
"properties": {
"owner": "",
"external": "true",
"location": "file:/tmp/delta_tables/people",
"provider": "delta"
}
},
"storage-access-configs": []
}
(.venv) โ polaris git:(main) โ polaris --client-id root --client-secret s3cr3t generic-tables delete --catalog polaris_demo --namespace DELTA_NS.PUBLIC PEOPLE
Dropping generic table DELTA_NS.PUBLIC.PEOPLE...
Dropping generic table DELTA_NS.PUBLIC.PEOPLE completed
```
## Checklist
- [ ] ๐ก๏ธ Don't disclose security issues! (contact security@apache.org)
- [ ] ๐ Clearly explained why the changes are needed, or linked related issues: Fixes #
- [ ] ๐งช Added/updated tests with good coverage, or manually tested (and explained how)
- [ ] ๐ก Added comments for complex logic
- [ ] ๐งพ Updated `CHANGELOG.md` (if needed)
- [ ] ๐ Updated documentation in `site/content/in-dev/unreleased` (if needed)
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add views and generic-tables support in CLI [polaris]
Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #5260:
URL: https://github.com/apache/polaris/pull/5260#discussion_r3762910645
##########
client/python/apache_polaris/cli/command/views.py:
##########
@@ -0,0 +1,175 @@
+#
+# 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.
+#
+from dataclasses import dataclass, field
+from typing import List, Optional, cast
+
+from apache_polaris.cli.command import Command
+from apache_polaris.cli.command.utils import get_catalog_api_client
+from apache_polaris.cli.exceptions import CliError
+from apache_polaris.cli.constants import Subcommands, Arguments, UNIT_SEPARATOR
+from apache_polaris.cli.options.option_tree import Argument
+from apache_polaris.sdk.catalog import IcebergCatalogAPI
+from apache_polaris.sdk.management import PolarisDefaultApi
+from apache_polaris.cli.command.utils import (
+ handle_api_exception,
+ format_timestamp,
+ format_iceberg_type,
+)
+from prettytable import PrettyTable
+
+
+@dataclass
+class ViewCommand(Command):
+ """
+ A Command implementation to represent `polaris views`. It manages Iceberg views within a Polaris Catalog.
+
+ Example commands:
+ * polaris views list --catalog my_catalog --namespace ns1
+ * polaris views get my_view --catalog my_catalog --namespace ns1
+ * polaris views summarize my_view --catalog my_catalog --namespace ns1
+ * polaris views delete my_view --catalog my_catalog --namespace ns1
+ """
+
+ views_subcommand: str
+ catalog_name: Optional[str] = None
+ namespace: Optional[List[str]] = field(default_factory=list)
+ view_name: Optional[str] = None
+
+ def validate(self) -> None:
+ if not self.catalog_name:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.CATALOG)}"
+ )
+ if not self.namespace:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.NAMESPACE)}"
+ )
+ if (
+ self.views_subcommand == Subcommands.GET
+ or self.views_subcommand == Subcommands.SUMMARIZE
+ or self.views_subcommand == Subcommands.DELETE
+ ):
+ if not self.view_name or not self.view_name.strip():
+ raise CliError("The view name cannot be empty.")
+
+ def execute(self, api: PolarisDefaultApi) -> None:
+ catalog_api = IcebergCatalogAPI(get_catalog_api_client(api))
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+ ns_str = UNIT_SEPARATOR.join(namespace_list)
+
+ if self.views_subcommand == Subcommands.LIST:
+ result = catalog_api.list_views(prefix=catalog_name, namespace=ns_str)
+ for view_identifier in result.identifiers:
+ print(view_identifier.to_json())
+ elif self.views_subcommand == Subcommands.GET:
+ print(
+ catalog_api.load_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ ).to_json()
+ )
+ elif self.views_subcommand == Subcommands.DELETE:
+ namespace_dot = ".".join(namespace_list)
+ print(f"Dropping view {namespace_dot}.{view_name}...")
+ catalog_api.drop_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ )
+ print(f"Dropping view {namespace_dot}.{view_name} completed")
+ elif self.views_subcommand == Subcommands.SUMMARIZE:
+ self._generate_summary(api, catalog_api, ns_str)
+
+ def _generate_summary(
+ self, api: PolarisDefaultApi, catalog_api: IcebergCatalogAPI, ns_str: str
+ ) -> None:
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+
+ namespace_dot = ".".join(namespace_list)
+ print(f"View: {namespace_dot}.{view_name}")
+ print("-" * 80)
+ try:
+ resp = catalog_api.load_view(
+ prefix=catalog_name, namespace=ns_str, view=view_name
+ )
+ # Metadata
+ metadata = resp.metadata
+ current_version = next(
Review Comment:
If the view's `current_version_id` doesn't match any entry in `versions`, this bare `next()` raises `StopIteration`, which the broad `except` at the bottom catches and hands to `handle_api_exception`. `StopIteration` has an empty string representation, so what the user actually sees is `[x] View Metadata Error:` with nothing after it โ no indication of what went wrong.
`tables.py:130-136` handles the same lookup with `next((...), None)` plus an explicit fallback line (`"Table is empty (no snapshots found)"`). Worth matching that here so a malformed-metadata response says something useful.
##########
site/content/in-dev/unreleased/command-line-interface.md:
##########
@@ -1815,6 +1819,193 @@ Command Options:
polaris tables delete my_table --catalog my_catalog --namespace ns1
```
+### Views
+
+The `views` command is used to manage Iceberg views within a Polaris Catalog.
+
+`views` supports the following subcommands:
+
+1. list
+2. get
+3. summarize
+4. delete
+
+#### list
+
+The `list` subcommand is used to list views within a namesace from a given catalog.
Review Comment:
`namesace` โ `namespace`. Copied from the tables section, which has the same typo at :1731 โ feel free to sweep all three.
##########
client/python/tests/test_views_command.py:
##########
@@ -0,0 +1,154 @@
+#
+# 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.
+#
+
+from unittest.mock import patch, MagicMock
+from cli_test_utils import CLITestBase
+from apache_polaris.cli.constants import UNIT_SEPARATOR
+from apache_polaris.cli.exceptions import CLI_ERROR_EXIT_CODE
+from apache_polaris.cli.polaris_cli import PolarisCli
+from apache_polaris.sdk.catalog.exceptions import ApiException
+
+
+class TestViewsCommand(CLITestBase):
+ def test_view_validation(self) -> None:
+ mock_client = self.build_mock_client()
+ # Missing catalog/namespace
+ self.check_exception(
+ lambda: self.mock_execute(mock_client, ["views", "list"]),
+ "Missing required argument",
+ )
+ # Empty view name
+ self.check_exception(
+ lambda: self.mock_execute(
+ mock_client,
+ ["views", "get", " ", "--catalog", "my-catalog", "--namespace", "ns1"],
+ ),
+ "The view name cannot be empty",
+ )
+
+ @patch("apache_polaris.cli.command.views.IcebergCatalogAPI")
+ def test_view_list(self, mock_iceberg_api_class: MagicMock) -> None:
+ mock_client = self.build_mock_client()
+ mock_iceberg_api = mock_iceberg_api_class.return_value
+ mock_iceberg_api.list_views.return_value.identifiers = []
+ self.mock_execute(
+ mock_client,
+ ["views", "list", "--catalog", "my-catalog", "--namespace", "ns1.ns2"],
+ )
+ mock_iceberg_api.list_views.assert_called_once_with(
+ prefix="my-catalog", namespace=UNIT_SEPARATOR.join(["ns1", "ns2"])
+ )
+
+ @patch("apache_polaris.cli.command.views.IcebergCatalogAPI")
+ def test_view_get(self, mock_iceberg_api_class: MagicMock) -> None:
+ mock_client = self.build_mock_client()
+ mock_iceberg_api = mock_iceberg_api_class.return_value
+ mock_iceberg_api.load_view.return_value.to_json.return_value = "{}"
+ self.mock_execute(
+ mock_client,
+ [
+ "views",
+ "get",
+ "my_view",
+ "--catalog",
+ "my-catalog",
+ "--namespace",
+ "ns1",
+ ],
+ )
+ mock_iceberg_api.load_view.assert_called_once_with(
+ prefix="my-catalog", namespace="ns1", view="my_view"
+ )
+
+ @patch("apache_polaris.cli.command.views.IcebergCatalogAPI")
+ def test_view_delete(self, mock_iceberg_api_class: MagicMock) -> None:
+ mock_client = self.build_mock_client()
+ mock_iceberg_api = mock_iceberg_api_class.return_value
+ self.mock_execute(
+ mock_client,
+ [
+ "views",
+ "delete",
+ "my_view",
+ "--catalog",
+ "my-catalog",
+ "--namespace",
+ "ns1",
+ ],
+ )
+ mock_iceberg_api.drop_view.assert_called_once_with(
+ prefix="my-catalog",
+ namespace="ns1",
+ view="my_view",
+ )
+
+ @patch("apache_polaris.cli.polaris_cli.PolarisCli.print_api_exception")
+ @patch("apache_polaris.cli.command.views.IcebergCatalogAPI")
+ @patch("apache_polaris.cli.polaris_cli.PolarisDefaultApi")
+ @patch("apache_polaris.cli.polaris_cli.ApiClientBuilder.get_api_client")
+ def test_view_api_errors_exit_with_runtime_failure(
+ self,
+ _mock_get_api_client: MagicMock,
+ mock_default_api: MagicMock,
+ mock_iceberg_api_class: MagicMock,
+ mock_print_api_exception: MagicMock,
+ ) -> None:
+ mock_default_api.return_value = self.build_mock_client()
+ mock_iceberg_api = mock_iceberg_api_class.return_value
+ cases = [
+ ("list_views", ["views", "list"]),
+ ("load_view", ["views", "get", "my_view"]),
+ ("drop_view", ["views", "delete", "my_view"]),
+ ]
+
+ for api_method, args in cases:
+ with self.subTest(api_method=api_method):
+ method = getattr(mock_iceberg_api, api_method)
+ method.side_effect = ApiException(status=404, reason="Not Found")
+
+ with self.assertRaises(SystemExit) as cm:
+ PolarisCli.execute(
+ [*args, "--catalog", "my-catalog", "--namespace", "ns1"]
+ )
+
+ self.assertEqual(cm.exception.code, CLI_ERROR_EXIT_CODE)
+ mock_print_api_exception.assert_called_once()
+ method.side_effect = None
+ mock_print_api_exception.reset_mock()
+
+ @patch("apache_polaris.cli.command.views.IcebergCatalogAPI")
+ def test_view_summarize(self, mock_iceberg_api_class: MagicMock) -> None:
+ mock_client = self.build_mock_client()
+ mock_iceberg_api = mock_iceberg_api_class.return_value
+
+ self.mock_execute(
+ mock_client,
+ [
+ "views",
+ "summarize",
+ "my_view",
+ "--catalog",
+ "my-catalog",
+ "--namespace",
+ "ns1",
+ ],
+ )
+ mock_iceberg_api.load_view.assert_called_with(
Review Comment:
This test doesn't actually exercise the summary. `mock_iceberg_api` is a plain `MagicMock`, and MagicMock's default `__iter__` yields an *empty* iterator โ so `metadata.versions` iterates over nothing, the first `next()` in `_generate_summary` raises, and the broad `except` swallows it. The assert below still passes because `load_view` was called before any of that.
Net effect: the ~55 lines that format metadata, representations, the schema table and the version log have no coverage at all, and the failure is invisible because it only prints to stderr and still exits 0.
Can you populate a realistic `LoadViewResult` (a version whose `version_id` matches `current_version_id`, a schema matching that version's `schema_id`, and a `version_log` entry) and assert on the printed output? That's also what would catch a regression in the two lookups above.
##########
site/content/in-dev/unreleased/command-line-interface.md:
##########
@@ -1815,6 +1819,193 @@ Command Options:
polaris tables delete my_table --catalog my_catalog --namespace ns1
```
+### Views
+
+The `views` command is used to manage Iceberg views within a Polaris Catalog.
+
+`views` supports the following subcommands:
+
+1. list
+2. get
+3. summarize
+4. delete
+
+#### list
+
+The `list` subcommand is used to list views within a namesace from a given catalog.
+
+```
+usage: polaris views list [-h] [options]
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views list
+```
+
+#### get
+
+The `get` subcommand retrieves the view metadata for a specific view.
+
+```
+usage: polaris views get [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views get my_view --catalog my_catalog --namespace ns1
+```
+
+#### summarize
+
+The `summarize` subcommand provides a detail overview of a view.
+
+```
+usage: polaris views summarize [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris view summarize my_view --catalog my_catalog --namespace ns1
+```
+
+#### delete
+
+The `delete` subcommand drop a view from catalog.
+
+```
+usage: polaris views delete [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views delete my_view --catalog my_catalog --namespace ns1
+```
+
+
Review Comment:
Four extra blank lines before the Generic Tables heading โ collapse to one.
##########
client/python/apache_polaris/cli/command/views.py:
##########
@@ -0,0 +1,175 @@
+#
+# 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.
+#
+from dataclasses import dataclass, field
+from typing import List, Optional, cast
+
+from apache_polaris.cli.command import Command
+from apache_polaris.cli.command.utils import get_catalog_api_client
+from apache_polaris.cli.exceptions import CliError
+from apache_polaris.cli.constants import Subcommands, Arguments, UNIT_SEPARATOR
+from apache_polaris.cli.options.option_tree import Argument
+from apache_polaris.sdk.catalog import IcebergCatalogAPI
+from apache_polaris.sdk.management import PolarisDefaultApi
+from apache_polaris.cli.command.utils import (
+ handle_api_exception,
+ format_timestamp,
+ format_iceberg_type,
+)
+from prettytable import PrettyTable
+
+
+@dataclass
+class ViewCommand(Command):
+ """
+ A Command implementation to represent `polaris views`. It manages Iceberg views within a Polaris Catalog.
+
+ Example commands:
+ * polaris views list --catalog my_catalog --namespace ns1
+ * polaris views get my_view --catalog my_catalog --namespace ns1
+ * polaris views summarize my_view --catalog my_catalog --namespace ns1
+ * polaris views delete my_view --catalog my_catalog --namespace ns1
+ """
+
+ views_subcommand: str
+ catalog_name: Optional[str] = None
+ namespace: Optional[List[str]] = field(default_factory=list)
+ view_name: Optional[str] = None
+
+ def validate(self) -> None:
+ if not self.catalog_name:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.CATALOG)}"
+ )
+ if not self.namespace:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.NAMESPACE)}"
+ )
+ if (
+ self.views_subcommand == Subcommands.GET
+ or self.views_subcommand == Subcommands.SUMMARIZE
+ or self.views_subcommand == Subcommands.DELETE
+ ):
+ if not self.view_name or not self.view_name.strip():
+ raise CliError("The view name cannot be empty.")
+
+ def execute(self, api: PolarisDefaultApi) -> None:
+ catalog_api = IcebergCatalogAPI(get_catalog_api_client(api))
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+ ns_str = UNIT_SEPARATOR.join(namespace_list)
+
+ if self.views_subcommand == Subcommands.LIST:
+ result = catalog_api.list_views(prefix=catalog_name, namespace=ns_str)
+ for view_identifier in result.identifiers:
+ print(view_identifier.to_json())
+ elif self.views_subcommand == Subcommands.GET:
+ print(
+ catalog_api.load_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ ).to_json()
+ )
+ elif self.views_subcommand == Subcommands.DELETE:
+ namespace_dot = ".".join(namespace_list)
+ print(f"Dropping view {namespace_dot}.{view_name}...")
+ catalog_api.drop_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ )
+ print(f"Dropping view {namespace_dot}.{view_name} completed")
+ elif self.views_subcommand == Subcommands.SUMMARIZE:
+ self._generate_summary(api, catalog_api, ns_str)
+
+ def _generate_summary(
+ self, api: PolarisDefaultApi, catalog_api: IcebergCatalogAPI, ns_str: str
Review Comment:
`api` isn't used anywhere in this method โ `tables.py:104` is just `_generate_summary(self, catalog_api, ns_str)`. Worth dropping to keep the two files aligned.
##########
site/content/in-dev/unreleased/command-line-interface.md:
##########
@@ -1815,6 +1819,193 @@ Command Options:
polaris tables delete my_table --catalog my_catalog --namespace ns1
```
+### Views
+
+The `views` command is used to manage Iceberg views within a Polaris Catalog.
+
+`views` supports the following subcommands:
+
+1. list
+2. get
+3. summarize
+4. delete
+
+#### list
+
+The `list` subcommand is used to list views within a namesace from a given catalog.
+
+```
+usage: polaris views list [-h] [options]
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views list
+```
+
+#### get
+
+The `get` subcommand retrieves the view metadata for a specific view.
+
+```
+usage: polaris views get [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views get my_view --catalog my_catalog --namespace ns1
+```
+
+#### summarize
+
+The `summarize` subcommand provides a detail overview of a view.
+
+```
+usage: polaris views summarize [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris view summarize my_view --catalog my_catalog --namespace ns1
+```
+
+#### delete
+
+The `delete` subcommand drop a view from catalog.
+
+```
+usage: polaris views delete [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views delete my_view --catalog my_catalog --namespace ns1
+```
+
+
+
+
+
+### Generic Tables
+
+The `generic-tables` command is used to manage generic tables within a Polaris Catalog.
+
+`generic-tables` supports the following subcommands:
+
+1. list
+2. get
+3. delete
+
+#### list
+
+The `list` subcommand is used to list generic tables within a namesace from a given catalog.
Review Comment:
Same `namesace` typo here.
##########
site/content/in-dev/unreleased/command-line-interface.md:
##########
@@ -1815,6 +1819,193 @@ Command Options:
polaris tables delete my_table --catalog my_catalog --namespace ns1
```
+### Views
+
+The `views` command is used to manage Iceberg views within a Polaris Catalog.
+
+`views` supports the following subcommands:
+
+1. list
+2. get
+3. summarize
+4. delete
+
+#### list
+
+The `list` subcommand is used to list views within a namesace from a given catalog.
+
+```
+usage: polaris views list [-h] [options]
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views list
+```
+
+#### get
+
+The `get` subcommand retrieves the view metadata for a specific view.
+
+```
+usage: polaris views get [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris views get my_view --catalog my_catalog --namespace ns1
+```
+
+#### summarize
+
+The `summarize` subcommand provides a detail overview of a view.
+
+```
+usage: polaris views summarize [-h] [options] VIEW_NAME
+
+positional arguments:
+ VIEW_NAME view
+
+options:
+ -h, --help show this help message and exit
+
+Command Options:
+ --catalog CATALOG The name of a catalog
+ --namespace NAMESPACE A period-delimited namespace
+```
+
+##### Examples
+
+```
+polaris view summarize my_view --catalog my_catalog --namespace ns1
Review Comment:
`polaris view summarize` โ `polaris views summarize` (the command is plural).
##########
client/python/apache_polaris/cli/command/views.py:
##########
@@ -0,0 +1,175 @@
+#
+# 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.
+#
+from dataclasses import dataclass, field
+from typing import List, Optional, cast
+
+from apache_polaris.cli.command import Command
+from apache_polaris.cli.command.utils import get_catalog_api_client
+from apache_polaris.cli.exceptions import CliError
+from apache_polaris.cli.constants import Subcommands, Arguments, UNIT_SEPARATOR
+from apache_polaris.cli.options.option_tree import Argument
+from apache_polaris.sdk.catalog import IcebergCatalogAPI
+from apache_polaris.sdk.management import PolarisDefaultApi
+from apache_polaris.cli.command.utils import (
+ handle_api_exception,
+ format_timestamp,
+ format_iceberg_type,
+)
+from prettytable import PrettyTable
+
+
+@dataclass
+class ViewCommand(Command):
+ """
+ A Command implementation to represent `polaris views`. It manages Iceberg views within a Polaris Catalog.
+
+ Example commands:
+ * polaris views list --catalog my_catalog --namespace ns1
+ * polaris views get my_view --catalog my_catalog --namespace ns1
+ * polaris views summarize my_view --catalog my_catalog --namespace ns1
+ * polaris views delete my_view --catalog my_catalog --namespace ns1
+ """
+
+ views_subcommand: str
+ catalog_name: Optional[str] = None
+ namespace: Optional[List[str]] = field(default_factory=list)
+ view_name: Optional[str] = None
+
+ def validate(self) -> None:
+ if not self.catalog_name:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.CATALOG)}"
+ )
+ if not self.namespace:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.NAMESPACE)}"
+ )
+ if (
+ self.views_subcommand == Subcommands.GET
+ or self.views_subcommand == Subcommands.SUMMARIZE
+ or self.views_subcommand == Subcommands.DELETE
+ ):
+ if not self.view_name or not self.view_name.strip():
+ raise CliError("The view name cannot be empty.")
+
+ def execute(self, api: PolarisDefaultApi) -> None:
+ catalog_api = IcebergCatalogAPI(get_catalog_api_client(api))
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+ ns_str = UNIT_SEPARATOR.join(namespace_list)
+
+ if self.views_subcommand == Subcommands.LIST:
+ result = catalog_api.list_views(prefix=catalog_name, namespace=ns_str)
+ for view_identifier in result.identifiers:
+ print(view_identifier.to_json())
+ elif self.views_subcommand == Subcommands.GET:
+ print(
+ catalog_api.load_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ ).to_json()
+ )
+ elif self.views_subcommand == Subcommands.DELETE:
+ namespace_dot = ".".join(namespace_list)
+ print(f"Dropping view {namespace_dot}.{view_name}...")
+ catalog_api.drop_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ )
+ print(f"Dropping view {namespace_dot}.{view_name} completed")
+ elif self.views_subcommand == Subcommands.SUMMARIZE:
+ self._generate_summary(api, catalog_api, ns_str)
+
+ def _generate_summary(
+ self, api: PolarisDefaultApi, catalog_api: IcebergCatalogAPI, ns_str: str
+ ) -> None:
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+
+ namespace_dot = ".".join(namespace_list)
+ print(f"View: {namespace_dot}.{view_name}")
+ print("-" * 80)
+ try:
+ resp = catalog_api.load_view(
+ prefix=catalog_name, namespace=ns_str, view=view_name
+ )
+ # Metadata
+ metadata = resp.metadata
+ current_version = next(
+ v
+ for v in metadata.versions
+ if v.version_id == metadata.current_version_id
+ )
+ print("Metadata")
+ print(f" {'Location:':<30} {metadata.location}")
+ print(f" {'Format Version:':<30} {metadata.format_version}")
+ print(f" {'Current Version ID:':<30} {metadata.current_version_id}")
+ print(
+ f" {'Last Updated:':<30} {format_timestamp(current_version.timestamp_ms)}"
+ )
+
+ # SQL representations
+ print("\nRepresentations")
+ for representation in current_version.representations:
+ unwrapped = representation.actual_instance
+ if unwrapped is None:
+ continue
+ print(f" {'Dialect:':<30} {unwrapped.dialect}")
+ indented_sql = "\n".join(
+ " " * 4 + line for line in unwrapped.sql.splitlines()
+ )
+ print(" SQL:")
+ print(indented_sql)
+
+ # Schema
+ print("\nSchema")
+ current_schema = next(
Review Comment:
Same here for the schema lookup โ `tables.py:153-160` uses `next((...), None)` and falls back to `"No schema information available"`.
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add views and generic-tables support in CLI [polaris]
Posted by "MonkeyCanCode (via GitHub)" <gi...@apache.org>.
MonkeyCanCode merged PR #5260:
URL: https://github.com/apache/polaris/pull/5260
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add views and generic-tables support in CLI [polaris]
Posted by "MonkeyCanCode (via GitHub)" <gi...@apache.org>.
MonkeyCanCode commented on code in PR #5260:
URL: https://github.com/apache/polaris/pull/5260#discussion_r3781464508
##########
client/python/apache_polaris/cli/command/views.py:
##########
@@ -0,0 +1,175 @@
+#
+# 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.
+#
+from dataclasses import dataclass, field
+from typing import List, Optional, cast
+
+from apache_polaris.cli.command import Command
+from apache_polaris.cli.command.utils import get_catalog_api_client
+from apache_polaris.cli.exceptions import CliError
+from apache_polaris.cli.constants import Subcommands, Arguments, UNIT_SEPARATOR
+from apache_polaris.cli.options.option_tree import Argument
+from apache_polaris.sdk.catalog import IcebergCatalogAPI
+from apache_polaris.sdk.management import PolarisDefaultApi
+from apache_polaris.cli.command.utils import (
+ handle_api_exception,
+ format_timestamp,
+ format_iceberg_type,
+)
+from prettytable import PrettyTable
+
+
+@dataclass
+class ViewCommand(Command):
+ """
+ A Command implementation to represent `polaris views`. It manages Iceberg views within a Polaris Catalog.
+
+ Example commands:
+ * polaris views list --catalog my_catalog --namespace ns1
+ * polaris views get my_view --catalog my_catalog --namespace ns1
+ * polaris views summarize my_view --catalog my_catalog --namespace ns1
+ * polaris views delete my_view --catalog my_catalog --namespace ns1
+ """
+
+ views_subcommand: str
+ catalog_name: Optional[str] = None
+ namespace: Optional[List[str]] = field(default_factory=list)
+ view_name: Optional[str] = None
+
+ def validate(self) -> None:
+ if not self.catalog_name:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.CATALOG)}"
+ )
+ if not self.namespace:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.NAMESPACE)}"
+ )
+ if (
+ self.views_subcommand == Subcommands.GET
+ or self.views_subcommand == Subcommands.SUMMARIZE
+ or self.views_subcommand == Subcommands.DELETE
+ ):
+ if not self.view_name or not self.view_name.strip():
+ raise CliError("The view name cannot be empty.")
+
+ def execute(self, api: PolarisDefaultApi) -> None:
+ catalog_api = IcebergCatalogAPI(get_catalog_api_client(api))
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+ ns_str = UNIT_SEPARATOR.join(namespace_list)
+
+ if self.views_subcommand == Subcommands.LIST:
+ result = catalog_api.list_views(prefix=catalog_name, namespace=ns_str)
+ for view_identifier in result.identifiers:
+ print(view_identifier.to_json())
+ elif self.views_subcommand == Subcommands.GET:
+ print(
+ catalog_api.load_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ ).to_json()
+ )
+ elif self.views_subcommand == Subcommands.DELETE:
+ namespace_dot = ".".join(namespace_list)
+ print(f"Dropping view {namespace_dot}.{view_name}...")
+ catalog_api.drop_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ )
+ print(f"Dropping view {namespace_dot}.{view_name} completed")
+ elif self.views_subcommand == Subcommands.SUMMARIZE:
+ self._generate_summary(api, catalog_api, ns_str)
+
+ def _generate_summary(
+ self, api: PolarisDefaultApi, catalog_api: IcebergCatalogAPI, ns_str: str
Review Comment:
Yes. Copy paste from other ones. Let me fix this.
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add views and generic-tables support in CLI [polaris]
Posted by "MonkeyCanCode (via GitHub)" <gi...@apache.org>.
MonkeyCanCode commented on code in PR #5260:
URL: https://github.com/apache/polaris/pull/5260#discussion_r3781459023
##########
client/python/apache_polaris/cli/command/views.py:
##########
@@ -0,0 +1,175 @@
+#
+# 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.
+#
+from dataclasses import dataclass, field
+from typing import List, Optional, cast
+
+from apache_polaris.cli.command import Command
+from apache_polaris.cli.command.utils import get_catalog_api_client
+from apache_polaris.cli.exceptions import CliError
+from apache_polaris.cli.constants import Subcommands, Arguments, UNIT_SEPARATOR
+from apache_polaris.cli.options.option_tree import Argument
+from apache_polaris.sdk.catalog import IcebergCatalogAPI
+from apache_polaris.sdk.management import PolarisDefaultApi
+from apache_polaris.cli.command.utils import (
+ handle_api_exception,
+ format_timestamp,
+ format_iceberg_type,
+)
+from prettytable import PrettyTable
+
+
+@dataclass
+class ViewCommand(Command):
+ """
+ A Command implementation to represent `polaris views`. It manages Iceberg views within a Polaris Catalog.
+
+ Example commands:
+ * polaris views list --catalog my_catalog --namespace ns1
+ * polaris views get my_view --catalog my_catalog --namespace ns1
+ * polaris views summarize my_view --catalog my_catalog --namespace ns1
+ * polaris views delete my_view --catalog my_catalog --namespace ns1
+ """
+
+ views_subcommand: str
+ catalog_name: Optional[str] = None
+ namespace: Optional[List[str]] = field(default_factory=list)
+ view_name: Optional[str] = None
+
+ def validate(self) -> None:
+ if not self.catalog_name:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.CATALOG)}"
+ )
+ if not self.namespace:
+ raise CliError(
+ f"Missing required argument: {Argument.to_flag_name(Arguments.NAMESPACE)}"
+ )
+ if (
+ self.views_subcommand == Subcommands.GET
+ or self.views_subcommand == Subcommands.SUMMARIZE
+ or self.views_subcommand == Subcommands.DELETE
+ ):
+ if not self.view_name or not self.view_name.strip():
+ raise CliError("The view name cannot be empty.")
+
+ def execute(self, api: PolarisDefaultApi) -> None:
+ catalog_api = IcebergCatalogAPI(get_catalog_api_client(api))
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+ ns_str = UNIT_SEPARATOR.join(namespace_list)
+
+ if self.views_subcommand == Subcommands.LIST:
+ result = catalog_api.list_views(prefix=catalog_name, namespace=ns_str)
+ for view_identifier in result.identifiers:
+ print(view_identifier.to_json())
+ elif self.views_subcommand == Subcommands.GET:
+ print(
+ catalog_api.load_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ ).to_json()
+ )
+ elif self.views_subcommand == Subcommands.DELETE:
+ namespace_dot = ".".join(namespace_list)
+ print(f"Dropping view {namespace_dot}.{view_name}...")
+ catalog_api.drop_view(
+ prefix=catalog_name,
+ namespace=ns_str,
+ view=view_name,
+ )
+ print(f"Dropping view {namespace_dot}.{view_name} completed")
+ elif self.views_subcommand == Subcommands.SUMMARIZE:
+ self._generate_summary(api, catalog_api, ns_str)
+
+ def _generate_summary(
+ self, api: PolarisDefaultApi, catalog_api: IcebergCatalogAPI, ns_str: str
+ ) -> None:
+ catalog_name = cast(str, self.catalog_name)
+ namespace_list = cast(List[str], self.namespace)
+ view_name = cast(str, self.view_name)
+
+ namespace_dot = ".".join(namespace_list)
+ print(f"View: {namespace_dot}.{view_name}")
+ print("-" * 80)
+ try:
+ resp = catalog_api.load_view(
+ prefix=catalog_name, namespace=ns_str, view=view_name
+ )
+ # Metadata
+ metadata = resp.metadata
+ current_version = next(
Review Comment:
Hi @flyrain , sorry for merged too early. For this specific one, I did started with with `next((...), None)` but later decided to change to this as I am not sure if we can have a view without version (however, from the spec, it is optional field). Should we match it or update Table to this as well?
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add views and generic-tables support in CLI [polaris]
Posted by "MonkeyCanCode (via GitHub)" <gi...@apache.org>.
MonkeyCanCode commented on PR #5260:
URL: https://github.com/apache/polaris/pull/5260#issuecomment-5290048710
thanks for the review @flyrain . Sorry for merged this too early. Let me fix those in a follow up PR.
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org