This is an automated email from the ASF dual-hosted git repository.
kevinjqliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new 1adff267a Make `View.sql_for` case-insensitive and return None for
unknown dialect (#3407)
1adff267a is described below
commit 1adff267a44038c8ae98ebbbc538cd521312c20c
Author: Yuya Ebihara <[email protected]>
AuthorDate: Sun May 24 11:58:13 2026 +0900
Make `View.sql_for` case-insensitive and return None for unknown dialect
(#3407)
# Rationale for this change
Iceberg Java compares the dialect in a case-insensitive manner, and
returns null if the dialect is unknown.
https://github.com/apache/iceberg/blob/29ba0a14dc6667db0683fdfcd520639b3da77774/core/src/main/java/org/apache/iceberg/view/BaseView.java#L113-L130
## Are these changes tested?
Yes
## Are there any user-facing changes?
No - the method isn't released yet
<!-- In the case of user-facing changes, please add the changelog label.
-->
---
pyiceberg/view/__init__.py | 9 ++++++---
tests/test_view.py | 10 ++++++++--
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/pyiceberg/view/__init__.py b/pyiceberg/view/__init__.py
index a0bcefa85..7f9343218 100644
--- a/pyiceberg/view/__init__.py
+++ b/pyiceberg/view/__init__.py
@@ -80,9 +80,12 @@ class View:
"""Return the view's UUID."""
return UUID(self.metadata.view_uuid)
- def sql_for(self, dialect: str) -> SQLViewRepresentation:
- """Return the view representation for the sql dialect."""
- return next(repr.root for repr in
self.current_version().representations if repr.root.dialect == dialect)
+ def sql_for(self, dialect: str) -> SQLViewRepresentation | None:
+ """Return the view representation for the sql dialect, or None if no
representation could be resolved."""
+ return next(
+ (repr.root for repr in self.current_version().representations if
repr.root.dialect.casefold() == dialect.casefold()),
+ None,
+ )
def __eq__(self, other: Any) -> bool:
"""Return the equality of two instances of the View class."""
diff --git a/tests/test_view.py b/tests/test_view.py
index 3919e1ab8..2c4f00192 100644
--- a/tests/test_view.py
+++ b/tests/test_view.py
@@ -96,6 +96,13 @@ def test_view_sql_for_dialect(view: View) -> None:
assert repr.sql == "SELECT * FROM prod.db.table"
+def test_view_sql_for_dialect_ignore_case(view: View) -> None:
+ repr = view.sql_for("Spark")
+ assert isinstance(repr, SQLViewRepresentation)
+ assert repr.dialect == "spark"
+ assert repr.sql == "SELECT * FROM prod.db.table"
+
+
def test_view_schemas_multiple(example_view_metadata_v1_multiple_versions:
dict[str, Any]) -> None:
view = View(("default", "test_view"),
ViewMetadata.model_validate(example_view_metadata_v1_multiple_versions))
schemas = view.schemas()
@@ -117,5 +124,4 @@ def test_view_version_unknown_id(view: View) -> None:
def test_view_sql_for_unknown_dialect(view: View) -> None:
- with pytest.raises(StopIteration):
- view.sql_for("trino")
+ assert not view.sql_for("trino")