66
77import pyarrow as pa
88
9- from vgi .catalog import FunctionInfo , FunctionType , TableInfo , ViewInfo
9+ from vgi .catalog import (
10+ AttachId ,
11+ FunctionInfo ,
12+ FunctionType ,
13+ SchemaObjectType ,
14+ TableInfo ,
15+ ViewInfo ,
16+ )
1017from vgi .client import Client
1118from vgi .examples .worker import ExampleWorker
1219
@@ -30,6 +37,26 @@ def _get_functions(
3037 return [item for item in contents if isinstance (item , FunctionInfo )]
3138
3239
40+ def _get_all_functions (client : Client , attach_id : AttachId ) -> list [FunctionInfo ]:
41+ """Get both table and scalar functions from the catalog."""
42+ table_funcs = list (
43+ client .schema_contents (
44+ attach_id = attach_id ,
45+ name = "main" ,
46+ type = SchemaObjectType .TABLE_FUNCTION ,
47+ )
48+ )
49+ scalar_funcs = list (
50+ client .schema_contents (
51+ attach_id = attach_id ,
52+ name = "main" ,
53+ type = SchemaObjectType .SCALAR_FUNCTION ,
54+ )
55+ )
56+ # Combine to list - the overloads guarantee FunctionInfo for function types
57+ return list (table_funcs ) + list (scalar_funcs )
58+
59+
3360class TestExampleWorkerCatalog :
3461 """Test ExampleWorker's catalog interface."""
3562
@@ -49,15 +76,19 @@ def test_catalog_attach_works(self) -> None:
4976 assert result .catalog_version_frozen is True
5077
5178 def test_schema_contents_returns_functions (self ) -> None :
52- """schema_contents() returns FunctionInfo for all example functions."""
79+ """schema_contents() returns FunctionInfo for table functions."""
5380 client = Client (EXAMPLE_WORKER )
5481
5582 # Attach to catalog
5683 attach_result = client .catalog_attach (name = "example" , options = {})
5784 attach_id = attach_result .attach_id
5885
59- # Get schema contents
60- contents = list (client .schema_contents (attach_id = attach_id , name = "main" ))
86+ # Get table functions
87+ contents = list (
88+ client .schema_contents (
89+ attach_id = attach_id , name = "main" , type = SchemaObjectType .TABLE_FUNCTION
90+ )
91+ )
6192
6293 # Should have functions
6394 assert len (contents ) > 0
@@ -70,12 +101,30 @@ def test_all_example_functions_listed(self) -> None:
70101 """All example functions are listed in the catalog."""
71102 client = Client (EXAMPLE_WORKER )
72103
73- # Attach and get contents
104+ # Attach and get both table and scalar functions
74105 attach_result = client .catalog_attach (name = "example" , options = {})
75- contents = list (
76- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
106+
107+ # Get table functions
108+ table_funcs = list (
109+ client .schema_contents (
110+ attach_id = attach_result .attach_id ,
111+ name = "main" ,
112+ type = SchemaObjectType .TABLE_FUNCTION ,
113+ )
77114 )
78115
116+ # Get scalar functions
117+ scalar_funcs = list (
118+ client .schema_contents (
119+ attach_id = attach_result .attach_id ,
120+ name = "main" ,
121+ type = SchemaObjectType .SCALAR_FUNCTION ,
122+ )
123+ )
124+
125+ # Combine all functions
126+ contents = table_funcs + scalar_funcs
127+
79128 # Get function names
80129 function_names = {item .name for item in contents }
81130
@@ -95,10 +144,7 @@ def test_function_info_has_correct_types(self) -> None:
95144 client = Client (EXAMPLE_WORKER )
96145
97146 attach_result = client .catalog_attach (name = "example" , options = {})
98- contents = list (
99- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
100- )
101- functions = _get_functions (contents )
147+ functions = _get_all_functions (client , attach_result .attach_id )
102148
103149 # Create lookup by name
104150 by_name = {fn .name : fn for fn in functions }
@@ -117,10 +163,7 @@ def test_function_info_has_arguments(self) -> None:
117163 client = Client (EXAMPLE_WORKER )
118164
119165 attach_result = client .catalog_attach (name = "example" , options = {})
120- contents = list (
121- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
122- )
123- functions = _get_functions (contents )
166+ functions = _get_all_functions (client , attach_result .attach_id )
124167
125168 # Create lookup by name
126169 by_name = {fn .name : fn for fn in functions }
@@ -142,10 +185,13 @@ def test_function_info_has_description(self) -> None:
142185 client = Client (EXAMPLE_WORKER )
143186
144187 attach_result = client .catalog_attach (name = "example" , options = {})
145- contents = list (
146- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
188+ functions = list (
189+ client .schema_contents (
190+ attach_id = attach_result .attach_id ,
191+ name = "main" ,
192+ type = SchemaObjectType .TABLE_FUNCTION ,
193+ )
147194 )
148- functions = _get_functions (contents )
149195
150196 # Create lookup by name
151197 by_name = {fn .name : fn for fn in functions }
@@ -160,23 +206,24 @@ def test_function_info_schema_name(self) -> None:
160206 client = Client (EXAMPLE_WORKER )
161207
162208 attach_result = client .catalog_attach (name = "example" , options = {})
163- contents = list (
164- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
165- )
209+ functions = _get_all_functions (client , attach_result .attach_id )
166210
167211 # All functions should be in 'main' schema
168- for item in contents :
212+ for item in functions :
169213 assert item .schema_name == "main"
170214
171215 def test_scalar_function_has_output_schema (self ) -> None :
172216 """Scalar functions with static output types have output_schema populated."""
173217 client = Client (EXAMPLE_WORKER )
174218
175219 attach_result = client .catalog_attach (name = "example" , options = {})
176- contents = list (
177- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
220+ functions = list (
221+ client .schema_contents (
222+ attach_id = attach_result .attach_id ,
223+ name = "main" ,
224+ type = SchemaObjectType .SCALAR_FUNCTION ,
225+ )
178226 )
179- functions = _get_functions (contents )
180227
181228 # Create lookup by name
182229 by_name = {fn .name : fn for fn in functions }
@@ -195,10 +242,13 @@ def test_scalar_function_with_dynamic_output_has_any_type(self) -> None:
195242 client = Client (EXAMPLE_WORKER )
196243
197244 attach_result = client .catalog_attach (name = "example" , options = {})
198- contents = list (
199- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
245+ functions = list (
246+ client .schema_contents (
247+ attach_id = attach_result .attach_id ,
248+ name = "main" ,
249+ type = SchemaObjectType .SCALAR_FUNCTION ,
250+ )
200251 )
201- functions = _get_functions (contents )
202252
203253 # Create lookup by name
204254 by_name = {fn .name : fn for fn in functions }
@@ -218,10 +268,13 @@ def test_table_function_has_empty_output_schema(self) -> None:
218268 client = Client (EXAMPLE_WORKER )
219269
220270 attach_result = client .catalog_attach (name = "example" , options = {})
221- contents = list (
222- client .schema_contents (attach_id = attach_result .attach_id , name = "main" )
271+ functions = list (
272+ client .schema_contents (
273+ attach_id = attach_result .attach_id ,
274+ name = "main" ,
275+ type = SchemaObjectType .TABLE_FUNCTION ,
276+ )
223277 )
224- functions = _get_functions (contents )
225278
226279 # Create lookup by name
227280 by_name = {fn .name : fn for fn in functions }
0 commit comments