File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,9 +80,12 @@ def uuid(self) -> UUID:
8080 """Return the view's UUID."""
8181 return UUID (self .metadata .view_uuid )
8282
83- def sql_for (self , dialect : str ) -> SQLViewRepresentation :
84- """Return the view representation for the sql dialect."""
85- return next (repr .root for repr in self .current_version ().representations if repr .root .dialect == dialect )
83+ def sql_for (self , dialect : str ) -> SQLViewRepresentation | None :
84+ """Return the view representation for the sql dialect, or None if no representation could be resolved."""
85+ return next (
86+ (repr .root for repr in self .current_version ().representations if repr .root .dialect .casefold () == dialect .casefold ()),
87+ None ,
88+ )
8689
8790 def __eq__ (self , other : Any ) -> bool :
8891 """Return the equality of two instances of the View class."""
Original file line number Diff line number Diff line change @@ -96,6 +96,13 @@ def test_view_sql_for_dialect(view: View) -> None:
9696 assert repr .sql == "SELECT * FROM prod.db.table"
9797
9898
99+ def test_view_sql_for_dialect_ignore_case (view : View ) -> None :
100+ repr = view .sql_for ("Spark" )
101+ assert isinstance (repr , SQLViewRepresentation )
102+ assert repr .dialect == "spark"
103+ assert repr .sql == "SELECT * FROM prod.db.table"
104+
105+
99106def test_view_schemas_multiple (example_view_metadata_v1_multiple_versions : dict [str , Any ]) -> None :
100107 view = View (("default" , "test_view" ), ViewMetadata .model_validate (example_view_metadata_v1_multiple_versions ))
101108 schemas = view .schemas ()
@@ -117,5 +124,4 @@ def test_view_version_unknown_id(view: View) -> None:
117124
118125
119126def test_view_sql_for_unknown_dialect (view : View ) -> None :
120- with pytest .raises (StopIteration ):
121- view .sql_for ("trino" )
127+ assert not view .sql_for ("trino" )
You can’t perform that action at this time.
0 commit comments