| 36 | // Defines a `table_list` UDTF that returns a list of tables within the provided session. |
| 37 | |
| 38 | pub async fn table_list_udtf() -> Result<()> { |
| 39 | let ctx = SessionContext::new(); |
| 40 | ctx.register_udtf(FUNCTION_NAME, Arc::new(TableListUdtf)); |
| 41 | |
| 42 | // Register different kinds of tables. |
| 43 | ctx.sql("create view v as select 1") |
| 44 | .await? |
| 45 | .collect() |
| 46 | .await?; |
| 47 | ctx.sql("create table t(a int)").await?.collect().await?; |
| 48 | |
| 49 | // Print results. |
| 50 | ctx.sql("select * from table_list()").await?.show().await?; |
| 51 | |
| 52 | Ok(()) |
| 53 | } |
| 54 | |
| 55 | #[derive(Debug, Default)] |
| 56 | struct TableListUdtf; |