|
20 | 20 | //! [Information Schema]: https://en.wikipedia.org/wiki/Information_schema |
21 | 21 |
|
22 | 22 | use crate::streaming::StreamingTable; |
| 23 | +use crate::table::TableFunction; |
23 | 24 | use crate::{CatalogProviderList, SchemaProvider, TableProvider}; |
24 | 25 | use arrow::array::builder::{BooleanBuilder, UInt8Builder}; |
25 | 26 | use arrow::{ |
@@ -81,14 +82,28 @@ impl InformationSchemaProvider { |
81 | 82 | /// Creates a new [`InformationSchemaProvider`] for the provided `catalog_list` |
82 | 83 | pub fn new(catalog_list: Arc<dyn CatalogProviderList>) -> Self { |
83 | 84 | Self { |
84 | | - config: InformationSchemaConfig { catalog_list }, |
| 85 | + config: InformationSchemaConfig { |
| 86 | + catalog_list, |
| 87 | + table_functions: HashMap::new(), |
| 88 | + }, |
85 | 89 | } |
86 | 90 | } |
| 91 | + |
| 92 | + /// Attach the session's table (UDTF) functions so that they appear in |
| 93 | + /// `information_schema.routines` / `SHOW FUNCTIONS`. |
| 94 | + pub fn with_table_functions( |
| 95 | + mut self, |
| 96 | + table_functions: HashMap<String, Arc<TableFunction>>, |
| 97 | + ) -> Self { |
| 98 | + self.config.table_functions = table_functions; |
| 99 | + self |
| 100 | + } |
87 | 101 | } |
88 | 102 |
|
89 | 103 | #[derive(Clone, Debug)] |
90 | 104 | struct InformationSchemaConfig { |
91 | 105 | catalog_list: Arc<dyn CatalogProviderList>, |
| 106 | + table_functions: HashMap<String, Arc<TableFunction>>, |
92 | 107 | } |
93 | 108 |
|
94 | 109 | impl InformationSchemaConfig { |
@@ -301,6 +316,26 @@ impl InformationSchemaConfig { |
301 | 316 | ) |
302 | 317 | } |
303 | 318 | } |
| 319 | + |
| 320 | + // Table functions (UDTFs) don't have scalar signatures; their return |
| 321 | + // type is always a table, so emit a single row per UDTF with |
| 322 | + // routine_type = "FUNCTION", function_type = "TABLE" and |
| 323 | + // data_type = "TABLE". |
| 324 | + for name in self.table_functions.keys() { |
| 325 | + builder.add_routine( |
| 326 | + catalog_name, |
| 327 | + schema_name, |
| 328 | + name, |
| 329 | + "FUNCTION", |
| 330 | + // No signature is available for UDTFs; report deterministic |
| 331 | + // = false to stay conservative. |
| 332 | + false, |
| 333 | + Some(&"TABLE"), |
| 334 | + "TABLE", |
| 335 | + None::<String>, |
| 336 | + None::<String>, |
| 337 | + ) |
| 338 | + } |
304 | 339 | Ok(()) |
305 | 340 | } |
306 | 341 |
|
@@ -400,6 +435,14 @@ impl InformationSchemaConfig { |
400 | 435 | } |
401 | 436 | } |
402 | 437 |
|
| 438 | + // UDTFs deliberately do NOT appear in `information_schema.parameters`. |
| 439 | + // A same-named scalar UDF (e.g. `generate_series` exists as both a |
| 440 | + // scalar UDF in functions-nested and a UDTF in functions-table) would |
| 441 | + // cross-join with a UDTF row keyed only by (name, rid) and produce |
| 442 | + // spurious `TABLE`-typed variants of every scalar signature in |
| 443 | + // SHOW FUNCTIONS. `show_functions_to_plan` sources UDTFs directly |
| 444 | + // from `information_schema.routines` via a UNION branch instead. |
| 445 | + |
403 | 446 | Ok(()) |
404 | 447 | } |
405 | 448 |
|
@@ -1522,6 +1565,7 @@ mod tests { |
1522 | 1565 | async fn make_tables_uses_table_type() { |
1523 | 1566 | let config = InformationSchemaConfig { |
1524 | 1567 | catalog_list: Arc::new(Fixture), |
| 1568 | + table_functions: HashMap::new(), |
1525 | 1569 | }; |
1526 | 1570 | let mut builder = InformationSchemaTablesBuilder { |
1527 | 1571 | catalog_names: StringBuilder::new(), |
|
0 commit comments