1use std::collections::HashMap;
2use std::sync::atomic::AtomicU32;
3use std::sync::Arc;
4
5use async_trait::async_trait;
6use datafusion::arrow::array::{
7 as_boolean_array, ArrayRef, AsArray, BooleanBuilder, Int32Builder, RecordBatch, StringArray,
8 StringBuilder,
9};
10use datafusion::arrow::datatypes::{DataType, Field, Int32Type, SchemaRef};
11use datafusion::arrow::ipc::reader::FileReader;
12use datafusion::catalog::streaming::StreamingTable;
13use datafusion::catalog::{MemTable, SchemaProvider, TableFunctionImpl};
14use datafusion::common::utils::SingleRowListArrayBuilder;
15use datafusion::datasource::TableProvider;
16use datafusion::error::{DataFusionError, Result};
17use datafusion::logical_expr::{
18 ColumnarValue, ScalarUDF, ScalarUDFImpl, Signature, TypeSignature, Volatility,
19};
20use datafusion::physical_plan::streaming::PartitionStream;
21use datafusion::prelude::{create_udf, Expr, SessionContext};
22use postgres_types::Oid;
23use tokio::sync::RwLock;
24
25use crate::pg_catalog::catalog_info::CatalogInfo;
26use crate::pg_catalog::context::PgCatalogContextProvider;
27use crate::pg_catalog::empty_table::EmptyTable;
28
29pub mod catalog_info;
30pub mod context;
31pub mod empty_table;
32pub mod format_type;
33pub mod has_privilege_udf;
34pub mod pg_attribute;
35pub mod pg_class;
36pub mod pg_database;
37pub mod pg_get_expr_udf;
38pub mod pg_namespace;
39pub mod pg_replication_slot;
40pub mod pg_roles;
41pub mod pg_settings;
42pub mod pg_stat_gssapi;
43pub mod pg_tables;
44pub mod pg_views;
45pub mod quote_ident_udf;
46
47const PG_CATALOG_TABLE_PG_AGGREGATE: &str = "pg_aggregate";
48const PG_CATALOG_TABLE_PG_AM: &str = "pg_am";
49const PG_CATALOG_TABLE_PG_AMOP: &str = "pg_amop";
50const PG_CATALOG_TABLE_PG_AMPROC: &str = "pg_amproc";
51const PG_CATALOG_TABLE_PG_CAST: &str = "pg_cast";
52const PG_CATALOG_TABLE_PG_COLLATION: &str = "pg_collation";
53const PG_CATALOG_TABLE_PG_CONVERSION: &str = "pg_conversion";
54const PG_CATALOG_TABLE_PG_LANGUAGE: &str = "pg_language";
55const PG_CATALOG_TABLE_PG_OPCLASS: &str = "pg_opclass";
56const PG_CATALOG_TABLE_PG_OPERATOR: &str = "pg_operator";
57const PG_CATALOG_TABLE_PG_OPFAMILY: &str = "pg_opfamily";
58const PG_CATALOG_TABLE_PG_PROC: &str = "pg_proc";
59const PG_CATALOG_TABLE_PG_RANGE: &str = "pg_range";
60const PG_CATALOG_TABLE_PG_TS_CONFIG: &str = "pg_ts_config";
61const PG_CATALOG_TABLE_PG_TS_DICT: &str = "pg_ts_dict";
62const PG_CATALOG_TABLE_PG_TS_PARSER: &str = "pg_ts_parser";
63const PG_CATALOG_TABLE_PG_TS_TEMPLATE: &str = "pg_ts_template";
64const PG_CATALOG_TABLE_PG_TYPE: &str = "pg_type";
65const PG_CATALOG_TABLE_PG_ATTRIBUTE: &str = "pg_attribute";
66const PG_CATALOG_TABLE_PG_ATTRDEF: &str = "pg_attrdef";
67const PG_CATALOG_TABLE_PG_AUTH_MEMBERS: &str = "pg_auth_members";
68const PG_CATALOG_TABLE_PG_AUTHID: &str = "pg_authid";
69const PG_CATALOG_TABLE_PG_CLASS: &str = "pg_class";
70const PG_CATALOG_TABLE_PG_CONSTRAINT: &str = "pg_constraint";
71const PG_CATALOG_TABLE_PG_DATABASE: &str = "pg_database";
72const PG_CATALOG_TABLE_PG_DB_ROLE_SETTING: &str = "pg_db_role_setting";
73const PG_CATALOG_TABLE_PG_DEFAULT_ACL: &str = "pg_default_acl";
74const PG_CATALOG_TABLE_PG_DEPEND: &str = "pg_depend";
75const PG_CATALOG_TABLE_PG_DESCRIPTION: &str = "pg_description";
76const PG_CATALOG_TABLE_PG_ENUM: &str = "pg_enum";
77const PG_CATALOG_TABLE_PG_EVENT_TRIGGER: &str = "pg_event_trigger";
78const PG_CATALOG_TABLE_PG_EXTENSION: &str = "pg_extension";
79const PG_CATALOG_TABLE_PG_FOREIGN_DATA_WRAPPER: &str = "pg_foreign_data_wrapper";
80const PG_CATALOG_TABLE_PG_FOREIGN_SERVER: &str = "pg_foreign_server";
81const PG_CATALOG_TABLE_PG_FOREIGN_TABLE: &str = "pg_foreign_table";
82const PG_CATALOG_TABLE_PG_INDEX: &str = "pg_index";
83const PG_CATALOG_TABLE_PG_INHERITS: &str = "pg_inherits";
84const PG_CATALOG_TABLE_PG_INIT_PRIVS: &str = "pg_init_privs";
85const PG_CATALOG_TABLE_PG_LARGEOBJECT: &str = "pg_largeobject";
86const PG_CATALOG_TABLE_PG_LARGEOBJECT_METADATA: &str = "pg_largeobject_metadata";
87const PG_CATALOG_TABLE_PG_NAMESPACE: &str = "pg_namespace";
88const PG_CATALOG_TABLE_PG_PARTITIONED_TABLE: &str = "pg_partitioned_table";
89const PG_CATALOG_TABLE_PG_POLICY: &str = "pg_policy";
90const PG_CATALOG_TABLE_PG_PUBLICATION: &str = "pg_publication";
91const PG_CATALOG_TABLE_PG_PUBLICATION_NAMESPACE: &str = "pg_publication_namespace";
92const PG_CATALOG_TABLE_PG_PUBLICATION_REL: &str = "pg_publication_rel";
93const PG_CATALOG_TABLE_PG_REPLICATION_ORIGIN: &str = "pg_replication_origin";
94const PG_CATALOG_TABLE_PG_REWRITE: &str = "pg_rewrite";
95const PG_CATALOG_TABLE_PG_SECLABEL: &str = "pg_seclabel";
96const PG_CATALOG_TABLE_PG_SEQUENCE: &str = "pg_sequence";
97const PG_CATALOG_TABLE_PG_SHDEPEND: &str = "pg_shdepend";
98const PG_CATALOG_TABLE_PG_SHDESCRIPTION: &str = "pg_shdescription";
99const PG_CATALOG_TABLE_PG_SHSECLABEL: &str = "pg_shseclabel";
100const PG_CATALOG_TABLE_PG_STATISTIC: &str = "pg_statistic";
101const PG_CATALOG_TABLE_PG_STATISTIC_EXT: &str = "pg_statistic_ext";
102const PG_CATALOG_TABLE_PG_STATISTIC_EXT_DATA: &str = "pg_statistic_ext_data";
103const PG_CATALOG_TABLE_PG_SUBSCRIPTION: &str = "pg_subscription";
104const PG_CATALOG_TABLE_PG_SUBSCRIPTION_REL: &str = "pg_subscription_rel";
105const PG_CATALOG_TABLE_PG_TABLESPACE: &str = "pg_tablespace";
106const PG_CATALOG_TABLE_PG_TRIGGER: &str = "pg_trigger";
107const PG_CATALOG_TABLE_PG_USER_MAPPING: &str = "pg_user_mapping";
108const PG_CATALOG_VIEW_PG_SETTINGS: &str = "pg_settings";
109const PG_CATALOG_VIEW_PG_VIEWS: &str = "pg_views";
110const PG_CATALOG_VIEW_PG_MATVIEWS: &str = "pg_matviews";
111const PG_CATALOG_VIEW_PG_ROLES: &str = "pg_roles";
112const PG_CATALOG_VIEW_PG_TABLES: &str = "pg_tables";
113const PG_CATALOG_VIEW_PG_STAT_GSSAPI: &str = "pg_stat_gssapi";
114const PG_CATALOG_VIEW_PG_STAT_USER_TABLES: &str = "pg_stat_user_tables";
115const PG_CATALOG_VIEW_PG_REPLICATION_SLOTS: &str = "pg_replication_slots";
116
117pub const PG_CATALOG_TABLES: &[&str] = &[
118 PG_CATALOG_TABLE_PG_AGGREGATE,
119 PG_CATALOG_TABLE_PG_AM,
120 PG_CATALOG_TABLE_PG_AMOP,
121 PG_CATALOG_TABLE_PG_AMPROC,
122 PG_CATALOG_TABLE_PG_CAST,
123 PG_CATALOG_TABLE_PG_COLLATION,
124 PG_CATALOG_TABLE_PG_CONVERSION,
125 PG_CATALOG_TABLE_PG_LANGUAGE,
126 PG_CATALOG_TABLE_PG_OPCLASS,
127 PG_CATALOG_TABLE_PG_OPERATOR,
128 PG_CATALOG_TABLE_PG_OPFAMILY,
129 PG_CATALOG_TABLE_PG_PROC,
130 PG_CATALOG_TABLE_PG_RANGE,
131 PG_CATALOG_TABLE_PG_TS_CONFIG,
132 PG_CATALOG_TABLE_PG_TS_DICT,
133 PG_CATALOG_TABLE_PG_TS_PARSER,
134 PG_CATALOG_TABLE_PG_TS_TEMPLATE,
135 PG_CATALOG_TABLE_PG_TYPE,
136 PG_CATALOG_TABLE_PG_ATTRIBUTE,
137 PG_CATALOG_TABLE_PG_ATTRDEF,
138 PG_CATALOG_TABLE_PG_AUTH_MEMBERS,
139 PG_CATALOG_TABLE_PG_AUTHID,
140 PG_CATALOG_TABLE_PG_CLASS,
141 PG_CATALOG_TABLE_PG_CONSTRAINT,
142 PG_CATALOG_TABLE_PG_DATABASE,
143 PG_CATALOG_TABLE_PG_DB_ROLE_SETTING,
144 PG_CATALOG_TABLE_PG_DEFAULT_ACL,
145 PG_CATALOG_TABLE_PG_DEPEND,
146 PG_CATALOG_TABLE_PG_DESCRIPTION,
147 PG_CATALOG_TABLE_PG_ENUM,
148 PG_CATALOG_TABLE_PG_EVENT_TRIGGER,
149 PG_CATALOG_TABLE_PG_EXTENSION,
150 PG_CATALOG_TABLE_PG_FOREIGN_DATA_WRAPPER,
151 PG_CATALOG_TABLE_PG_FOREIGN_SERVER,
152 PG_CATALOG_TABLE_PG_FOREIGN_TABLE,
153 PG_CATALOG_TABLE_PG_INDEX,
154 PG_CATALOG_TABLE_PG_INHERITS,
155 PG_CATALOG_TABLE_PG_INIT_PRIVS,
156 PG_CATALOG_TABLE_PG_LARGEOBJECT,
157 PG_CATALOG_TABLE_PG_LARGEOBJECT_METADATA,
158 PG_CATALOG_TABLE_PG_NAMESPACE,
159 PG_CATALOG_TABLE_PG_PARTITIONED_TABLE,
160 PG_CATALOG_TABLE_PG_POLICY,
161 PG_CATALOG_TABLE_PG_PUBLICATION,
162 PG_CATALOG_TABLE_PG_PUBLICATION_NAMESPACE,
163 PG_CATALOG_TABLE_PG_PUBLICATION_REL,
164 PG_CATALOG_TABLE_PG_REPLICATION_ORIGIN,
165 PG_CATALOG_TABLE_PG_REWRITE,
166 PG_CATALOG_TABLE_PG_SECLABEL,
167 PG_CATALOG_TABLE_PG_SEQUENCE,
168 PG_CATALOG_TABLE_PG_SHDEPEND,
169 PG_CATALOG_TABLE_PG_SHDESCRIPTION,
170 PG_CATALOG_TABLE_PG_SHSECLABEL,
171 PG_CATALOG_TABLE_PG_STATISTIC,
172 PG_CATALOG_TABLE_PG_STATISTIC_EXT,
173 PG_CATALOG_TABLE_PG_STATISTIC_EXT_DATA,
174 PG_CATALOG_TABLE_PG_SUBSCRIPTION,
175 PG_CATALOG_TABLE_PG_SUBSCRIPTION_REL,
176 PG_CATALOG_TABLE_PG_TABLESPACE,
177 PG_CATALOG_TABLE_PG_TRIGGER,
178 PG_CATALOG_TABLE_PG_USER_MAPPING,
179 PG_CATALOG_VIEW_PG_ROLES,
180 PG_CATALOG_VIEW_PG_SETTINGS,
181 PG_CATALOG_VIEW_PG_STAT_GSSAPI,
182 PG_CATALOG_VIEW_PG_TABLES,
183 PG_CATALOG_VIEW_PG_VIEWS,
184 PG_CATALOG_VIEW_PG_MATVIEWS,
185 PG_CATALOG_VIEW_PG_STAT_USER_TABLES,
186 PG_CATALOG_VIEW_PG_REPLICATION_SLOTS,
187];
188
189#[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord)]
190pub(crate) enum OidCacheKey {
191 Catalog(String),
192 Schema(String, String),
193 Table(String, String, String),
195}
196
197#[derive(Debug)]
199pub struct PgCatalogSchemaProvider<C, P> {
200 catalog_list: C,
201 oid_counter: Arc<AtomicU32>,
202 oid_cache: Arc<RwLock<HashMap<OidCacheKey, Oid>>>,
203 static_tables: Arc<PgCatalogStaticTables>,
204 context_provider: P,
205}
206
207#[async_trait]
208impl<C: CatalogInfo, P: PgCatalogContextProvider> SchemaProvider for PgCatalogSchemaProvider<C, P> {
209 fn as_any(&self) -> &dyn std::any::Any {
210 self
211 }
212
213 fn table_names(&self) -> Vec<String> {
214 PG_CATALOG_TABLES.iter().map(ToString::to_string).collect()
215 }
216
217 async fn table(&self, name: &str) -> Result<Option<Arc<dyn TableProvider>>> {
218 if let Some(table) = self.build_table_by_name(name)? {
219 let table_provider = table.try_into_table_provider()?;
220 Ok(Some(table_provider))
221 } else {
222 Ok(None)
223 }
224 }
225
226 fn table_exist(&self, name: &str) -> bool {
227 PG_CATALOG_TABLES.contains(&name.to_ascii_lowercase().as_str())
228 }
229}
230
231impl<C: CatalogInfo, P: PgCatalogContextProvider> PgCatalogSchemaProvider<C, P> {
232 pub fn try_new(
233 catalog_list: C,
234 static_tables: Arc<PgCatalogStaticTables>,
235 context_provider: P,
236 ) -> Result<PgCatalogSchemaProvider<C, P>> {
237 Ok(Self {
238 catalog_list,
239 oid_counter: Arc::new(AtomicU32::new(16384)),
240 oid_cache: Arc::new(RwLock::new(HashMap::new())),
241 static_tables,
242 context_provider,
243 })
244 }
245
246 pub fn build_table_by_name(&self, name: &str) -> Result<Option<PgCatalogTable>> {
247 match name.to_ascii_lowercase().as_str() {
248 PG_CATALOG_TABLE_PG_AGGREGATE => {
249 Ok(Some(self.static_tables.pg_aggregate.clone().into()))
250 }
251 PG_CATALOG_TABLE_PG_AM => Ok(Some(self.static_tables.pg_am.clone().into())),
252 PG_CATALOG_TABLE_PG_AMOP => Ok(Some(self.static_tables.pg_amop.clone().into())),
253 PG_CATALOG_TABLE_PG_AMPROC => Ok(Some(self.static_tables.pg_amproc.clone().into())),
254 PG_CATALOG_TABLE_PG_CAST => Ok(Some(self.static_tables.pg_cast.clone().into())),
255 PG_CATALOG_TABLE_PG_COLLATION => {
256 Ok(Some(self.static_tables.pg_collation.clone().into()))
257 }
258 PG_CATALOG_TABLE_PG_CONVERSION => {
259 Ok(Some(self.static_tables.pg_conversion.clone().into()))
260 }
261 PG_CATALOG_TABLE_PG_LANGUAGE => Ok(Some(self.static_tables.pg_language.clone().into())),
262 PG_CATALOG_TABLE_PG_OPCLASS => Ok(Some(self.static_tables.pg_opclass.clone().into())),
263 PG_CATALOG_TABLE_PG_OPERATOR => Ok(Some(self.static_tables.pg_operator.clone().into())),
264 PG_CATALOG_TABLE_PG_OPFAMILY => Ok(Some(self.static_tables.pg_opfamily.clone().into())),
265 PG_CATALOG_TABLE_PG_PROC => Ok(Some(self.static_tables.pg_proc.clone().into())),
266 PG_CATALOG_TABLE_PG_RANGE => Ok(Some(self.static_tables.pg_range.clone().into())),
267 PG_CATALOG_TABLE_PG_TS_CONFIG => {
268 Ok(Some(self.static_tables.pg_ts_config.clone().into()))
269 }
270 PG_CATALOG_TABLE_PG_TS_DICT => Ok(Some(self.static_tables.pg_ts_dict.clone().into())),
271 PG_CATALOG_TABLE_PG_TS_PARSER => {
272 Ok(Some(self.static_tables.pg_ts_parser.clone().into()))
273 }
274 PG_CATALOG_TABLE_PG_TS_TEMPLATE => {
275 Ok(Some(self.static_tables.pg_ts_template.clone().into()))
276 }
277 PG_CATALOG_TABLE_PG_TYPE => Ok(Some(self.static_tables.pg_type.clone().into())),
278 PG_CATALOG_TABLE_PG_ATTRDEF => Ok(Some(self.static_tables.pg_attrdef.clone().into())),
279 PG_CATALOG_TABLE_PG_AUTH_MEMBERS => {
280 Ok(Some(self.static_tables.pg_auth_members.clone().into()))
281 }
282 PG_CATALOG_TABLE_PG_AUTHID => Ok(Some(self.static_tables.pg_authid.clone().into())),
283
284 PG_CATALOG_TABLE_PG_CONSTRAINT => {
285 Ok(Some(self.static_tables.pg_constraint.clone().into()))
286 }
287
288 PG_CATALOG_TABLE_PG_DB_ROLE_SETTING => {
289 Ok(Some(self.static_tables.pg_db_role_setting.clone().into()))
290 }
291 PG_CATALOG_TABLE_PG_DEFAULT_ACL => {
292 Ok(Some(self.static_tables.pg_default_acl.clone().into()))
293 }
294 PG_CATALOG_TABLE_PG_DEPEND => Ok(Some(self.static_tables.pg_depend.clone().into())),
295 PG_CATALOG_TABLE_PG_DESCRIPTION => {
296 Ok(Some(self.static_tables.pg_description.clone().into()))
297 }
298 PG_CATALOG_TABLE_PG_ENUM => Ok(Some(self.static_tables.pg_enum.clone().into())),
299 PG_CATALOG_TABLE_PG_EVENT_TRIGGER => {
300 Ok(Some(self.static_tables.pg_event_trigger.clone().into()))
301 }
302 PG_CATALOG_TABLE_PG_EXTENSION => {
303 Ok(Some(self.static_tables.pg_extension.clone().into()))
304 }
305 PG_CATALOG_TABLE_PG_FOREIGN_DATA_WRAPPER => Ok(Some(
306 self.static_tables.pg_foreign_data_wrapper.clone().into(),
307 )),
308 PG_CATALOG_TABLE_PG_FOREIGN_SERVER => {
309 Ok(Some(self.static_tables.pg_foreign_server.clone().into()))
310 }
311 PG_CATALOG_TABLE_PG_FOREIGN_TABLE => {
312 Ok(Some(self.static_tables.pg_foreign_table.clone().into()))
313 }
314 PG_CATALOG_TABLE_PG_INDEX => Ok(Some(self.static_tables.pg_index.clone().into())),
315 PG_CATALOG_TABLE_PG_INHERITS => Ok(Some(self.static_tables.pg_inherits.clone().into())),
316 PG_CATALOG_TABLE_PG_INIT_PRIVS => {
317 Ok(Some(self.static_tables.pg_init_privs.clone().into()))
318 }
319 PG_CATALOG_TABLE_PG_LARGEOBJECT => {
320 Ok(Some(self.static_tables.pg_largeobject.clone().into()))
321 }
322 PG_CATALOG_TABLE_PG_LARGEOBJECT_METADATA => Ok(Some(
323 self.static_tables.pg_largeobject_metadata.clone().into(),
324 )),
325 PG_CATALOG_TABLE_PG_PARTITIONED_TABLE => {
326 Ok(Some(self.static_tables.pg_partitioned_table.clone().into()))
327 }
328 PG_CATALOG_TABLE_PG_POLICY => Ok(Some(self.static_tables.pg_policy.clone().into())),
329 PG_CATALOG_TABLE_PG_PUBLICATION => {
330 Ok(Some(self.static_tables.pg_publication.clone().into()))
331 }
332 PG_CATALOG_TABLE_PG_PUBLICATION_NAMESPACE => Ok(Some(
333 self.static_tables.pg_publication_namespace.clone().into(),
334 )),
335 PG_CATALOG_TABLE_PG_PUBLICATION_REL => {
336 Ok(Some(self.static_tables.pg_publication_rel.clone().into()))
337 }
338 PG_CATALOG_TABLE_PG_REPLICATION_ORIGIN => Ok(Some(
339 self.static_tables.pg_replication_origin.clone().into(),
340 )),
341 PG_CATALOG_TABLE_PG_REWRITE => Ok(Some(self.static_tables.pg_rewrite.clone().into())),
342 PG_CATALOG_TABLE_PG_SECLABEL => Ok(Some(self.static_tables.pg_seclabel.clone().into())),
343 PG_CATALOG_TABLE_PG_SEQUENCE => Ok(Some(self.static_tables.pg_sequence.clone().into())),
344 PG_CATALOG_TABLE_PG_SHDEPEND => Ok(Some(self.static_tables.pg_shdepend.clone().into())),
345 PG_CATALOG_TABLE_PG_SHDESCRIPTION => {
346 Ok(Some(self.static_tables.pg_shdescription.clone().into()))
347 }
348 PG_CATALOG_TABLE_PG_SHSECLABEL => {
349 Ok(Some(self.static_tables.pg_shseclabel.clone().into()))
350 }
351 PG_CATALOG_TABLE_PG_STATISTIC => {
352 Ok(Some(self.static_tables.pg_statistic.clone().into()))
353 }
354 PG_CATALOG_TABLE_PG_STATISTIC_EXT => {
355 Ok(Some(self.static_tables.pg_statistic_ext.clone().into()))
356 }
357 PG_CATALOG_TABLE_PG_STATISTIC_EXT_DATA => Ok(Some(
358 self.static_tables.pg_statistic_ext_data.clone().into(),
359 )),
360 PG_CATALOG_TABLE_PG_SUBSCRIPTION => {
361 Ok(Some(self.static_tables.pg_subscription.clone().into()))
362 }
363 PG_CATALOG_TABLE_PG_SUBSCRIPTION_REL => {
364 Ok(Some(self.static_tables.pg_subscription_rel.clone().into()))
365 }
366 PG_CATALOG_TABLE_PG_TABLESPACE => {
367 Ok(Some(self.static_tables.pg_tablespace.clone().into()))
368 }
369 PG_CATALOG_TABLE_PG_TRIGGER => Ok(Some(self.static_tables.pg_trigger.clone().into())),
370 PG_CATALOG_TABLE_PG_USER_MAPPING => {
371 Ok(Some(self.static_tables.pg_user_mapping.clone().into()))
372 }
373
374 PG_CATALOG_TABLE_PG_ATTRIBUTE => {
375 let table = Arc::new(pg_attribute::PgAttributeTable::new(
376 self.catalog_list.clone(),
377 self.oid_counter.clone(),
378 self.oid_cache.clone(),
379 ));
380 Ok(Some(PgCatalogTable::Dynamic(table)))
381 }
382 PG_CATALOG_TABLE_PG_CLASS => {
383 let table = Arc::new(pg_class::PgClassTable::new(
384 self.catalog_list.clone(),
385 self.oid_counter.clone(),
386 self.oid_cache.clone(),
387 ));
388 Ok(Some(PgCatalogTable::Dynamic(table)))
389 }
390 PG_CATALOG_TABLE_PG_DATABASE => {
391 let table = Arc::new(pg_database::PgDatabaseTable::new(
392 self.catalog_list.clone(),
393 self.oid_counter.clone(),
394 self.oid_cache.clone(),
395 ));
396 Ok(Some(PgCatalogTable::Dynamic(table)))
397 }
398 PG_CATALOG_TABLE_PG_NAMESPACE => {
399 let table = Arc::new(pg_namespace::PgNamespaceTable::new(
400 self.catalog_list.clone(),
401 self.oid_counter.clone(),
402 self.oid_cache.clone(),
403 ));
404 Ok(Some(PgCatalogTable::Dynamic(table)))
405 }
406 PG_CATALOG_VIEW_PG_TABLES => {
407 let table = Arc::new(pg_tables::PgTablesTable::new(self.catalog_list.clone()));
408 Ok(Some(PgCatalogTable::Dynamic(table)))
409 }
410 PG_CATALOG_VIEW_PG_SETTINGS => {
411 let table = Arc::new(pg_settings::PgSettingsView::new());
412 Ok(Some(PgCatalogTable::Dynamic(table)))
413 }
414
415 PG_CATALOG_VIEW_PG_STAT_GSSAPI => {
416 let table = Arc::new(pg_stat_gssapi::PgStatGssApiTable::new());
417 Ok(Some(PgCatalogTable::Dynamic(table)))
418 }
419 PG_CATALOG_VIEW_PG_ROLES => {
420 let table = Arc::new(pg_roles::PgRolesTable::new(self.context_provider.clone()));
421 Ok(Some(PgCatalogTable::Dynamic(table)))
422 }
423
424 PG_CATALOG_VIEW_PG_VIEWS => Ok(Some(pg_views::pg_views().into())),
425 PG_CATALOG_VIEW_PG_MATVIEWS => Ok(Some(pg_views::pg_matviews().into())),
426 PG_CATALOG_VIEW_PG_STAT_USER_TABLES => Ok(Some(pg_views::pg_stat_user_tables().into())),
427 PG_CATALOG_VIEW_PG_REPLICATION_SLOTS => {
428 Ok(Some(pg_replication_slot::pg_replication_slots().into()))
429 }
430
431 _ => Ok(None),
432 }
433 }
434}
435
436#[derive(Debug, Clone)]
438pub struct ArrowTable {
439 schema: SchemaRef,
440 data: Vec<RecordBatch>,
441}
442
443impl ArrowTable {
444 pub fn from_ipc_data(data: Vec<u8>) -> Result<Self> {
446 let cursor = std::io::Cursor::new(data);
447 let reader = FileReader::try_new(cursor, None)?;
448
449 let schema = reader.schema();
450 let mut batches = Vec::new();
451
452 for batch in reader {
454 batches.push(batch?);
455 }
456
457 Ok(Self {
458 schema,
459 data: batches,
460 })
461 }
462
463 pub fn try_into_memtable(&self) -> Result<Arc<MemTable>> {
465 let mem_table = MemTable::try_new(self.schema.clone(), vec![self.data.clone()])?;
466 Ok(Arc::new(mem_table))
467 }
468
469 pub fn data(&self) -> &[RecordBatch] {
470 &self.data
471 }
472
473 pub fn schema(&self) -> SchemaRef {
474 self.schema.clone()
475 }
476}
477
478impl TableFunctionImpl for ArrowTable {
479 fn call(&self, _args: &[Expr]) -> Result<Arc<dyn TableProvider>> {
480 let table = self.try_into_memtable()?;
481 Ok(table)
482 }
483}
484
485pub enum PgCatalogTable {
487 Static(Arc<ArrowTable>),
488 Dynamic(Arc<dyn PartitionStream>),
489 Empty(EmptyTable),
490}
491
492impl From<Arc<ArrowTable>> for PgCatalogTable {
493 fn from(t: Arc<ArrowTable>) -> PgCatalogTable {
494 PgCatalogTable::Static(t)
495 }
496}
497
498impl From<EmptyTable> for PgCatalogTable {
499 fn from(t: EmptyTable) -> PgCatalogTable {
500 Self::Empty(t)
501 }
502}
503
504impl PgCatalogTable {
505 pub fn try_into_table_provider(&self) -> Result<Arc<dyn TableProvider>> {
506 match self {
507 Self::Static(t) => {
508 let memtable = t.try_into_memtable()?;
509 Ok(memtable)
510 }
511 Self::Dynamic(t) => {
512 let streaming_table =
513 StreamingTable::try_new(Arc::clone(t.schema()), vec![t.clone()])?;
514 Ok(Arc::new(streaming_table))
515 }
516 Self::Empty(t) => {
517 let memtable = t.try_into_memtable()?;
518 Ok(memtable)
519 }
520 }
521 }
522
523 pub fn schema(&self) -> SchemaRef {
524 match self {
525 Self::Static(t) => t.schema(),
526 Self::Dynamic(t) => t.schema().clone(),
527 Self::Empty(t) => t.schema(),
528 }
529 }
530}
531
532#[derive(Debug, Clone)]
536pub struct PgCatalogStaticTables {
537 pub pg_aggregate: Arc<ArrowTable>,
538 pub pg_am: Arc<ArrowTable>,
539 pub pg_amop: Arc<ArrowTable>,
540 pub pg_amproc: Arc<ArrowTable>,
541 pub pg_cast: Arc<ArrowTable>,
542 pub pg_collation: Arc<ArrowTable>,
543 pub pg_conversion: Arc<ArrowTable>,
544 pub pg_language: Arc<ArrowTable>,
545 pub pg_opclass: Arc<ArrowTable>,
546 pub pg_operator: Arc<ArrowTable>,
547 pub pg_opfamily: Arc<ArrowTable>,
548 pub pg_proc: Arc<ArrowTable>,
549 pub pg_range: Arc<ArrowTable>,
550 pub pg_ts_config: Arc<ArrowTable>,
551 pub pg_ts_dict: Arc<ArrowTable>,
552 pub pg_ts_parser: Arc<ArrowTable>,
553 pub pg_ts_template: Arc<ArrowTable>,
554 pub pg_type: Arc<ArrowTable>,
555 pub pg_attrdef: Arc<ArrowTable>,
556 pub pg_auth_members: Arc<ArrowTable>,
557 pub pg_authid: Arc<ArrowTable>,
558 pub pg_constraint: Arc<ArrowTable>,
559 pub pg_db_role_setting: Arc<ArrowTable>,
560 pub pg_default_acl: Arc<ArrowTable>,
561 pub pg_depend: Arc<ArrowTable>,
562 pub pg_description: Arc<ArrowTable>,
563 pub pg_enum: Arc<ArrowTable>,
564 pub pg_event_trigger: Arc<ArrowTable>,
565 pub pg_extension: Arc<ArrowTable>,
566 pub pg_foreign_data_wrapper: Arc<ArrowTable>,
567 pub pg_foreign_server: Arc<ArrowTable>,
568 pub pg_foreign_table: Arc<ArrowTable>,
569 pub pg_index: Arc<ArrowTable>,
570 pub pg_inherits: Arc<ArrowTable>,
571 pub pg_init_privs: Arc<ArrowTable>,
572 pub pg_largeobject: Arc<ArrowTable>,
573 pub pg_largeobject_metadata: Arc<ArrowTable>,
574 pub pg_partitioned_table: Arc<ArrowTable>,
575 pub pg_policy: Arc<ArrowTable>,
576 pub pg_publication: Arc<ArrowTable>,
577 pub pg_publication_namespace: Arc<ArrowTable>,
578 pub pg_publication_rel: Arc<ArrowTable>,
579 pub pg_replication_origin: Arc<ArrowTable>,
580 pub pg_rewrite: Arc<ArrowTable>,
581 pub pg_seclabel: Arc<ArrowTable>,
582 pub pg_sequence: Arc<ArrowTable>,
583 pub pg_shdepend: Arc<ArrowTable>,
584 pub pg_shdescription: Arc<ArrowTable>,
585 pub pg_shseclabel: Arc<ArrowTable>,
586 pub pg_statistic: Arc<ArrowTable>,
587 pub pg_statistic_ext: Arc<ArrowTable>,
588 pub pg_statistic_ext_data: Arc<ArrowTable>,
589 pub pg_subscription: Arc<ArrowTable>,
590 pub pg_subscription_rel: Arc<ArrowTable>,
591 pub pg_tablespace: Arc<ArrowTable>,
592 pub pg_trigger: Arc<ArrowTable>,
593 pub pg_user_mapping: Arc<ArrowTable>,
594
595 pub pg_get_keywords: Arc<ArrowTable>,
596}
597
598impl PgCatalogStaticTables {
599 pub fn try_new() -> Result<Self> {
600 Ok(Self {
601 pg_aggregate: Self::create_arrow_table(
602 include_bytes!(concat!(
603 env!("CARGO_MANIFEST_DIR"),
604 "/pg_catalog_arrow_exports/pg_aggregate.feather"
605 ))
606 .to_vec(),
607 )?,
608 pg_am: Self::create_arrow_table(
609 include_bytes!(concat!(
610 env!("CARGO_MANIFEST_DIR"),
611 "/pg_catalog_arrow_exports/pg_am.feather"
612 ))
613 .to_vec(),
614 )?,
615 pg_amop: Self::create_arrow_table(
616 include_bytes!(concat!(
617 env!("CARGO_MANIFEST_DIR"),
618 "/pg_catalog_arrow_exports/pg_amop.feather"
619 ))
620 .to_vec(),
621 )?,
622 pg_amproc: Self::create_arrow_table(
623 include_bytes!(concat!(
624 env!("CARGO_MANIFEST_DIR"),
625 "/pg_catalog_arrow_exports/pg_amproc.feather"
626 ))
627 .to_vec(),
628 )?,
629 pg_cast: Self::create_arrow_table(
630 include_bytes!(concat!(
631 env!("CARGO_MANIFEST_DIR"),
632 "/pg_catalog_arrow_exports/pg_cast.feather"
633 ))
634 .to_vec(),
635 )?,
636 pg_collation: Self::create_arrow_table(
637 include_bytes!(concat!(
638 env!("CARGO_MANIFEST_DIR"),
639 "/pg_catalog_arrow_exports/pg_collation.feather"
640 ))
641 .to_vec(),
642 )?,
643 pg_conversion: Self::create_arrow_table(
644 include_bytes!(concat!(
645 env!("CARGO_MANIFEST_DIR"),
646 "/pg_catalog_arrow_exports/pg_conversion.feather"
647 ))
648 .to_vec(),
649 )?,
650 pg_language: Self::create_arrow_table(
651 include_bytes!(concat!(
652 env!("CARGO_MANIFEST_DIR"),
653 "/pg_catalog_arrow_exports/pg_language.feather"
654 ))
655 .to_vec(),
656 )?,
657 pg_opclass: Self::create_arrow_table(
658 include_bytes!(concat!(
659 env!("CARGO_MANIFEST_DIR"),
660 "/pg_catalog_arrow_exports/pg_opclass.feather"
661 ))
662 .to_vec(),
663 )?,
664 pg_operator: Self::create_arrow_table(
665 include_bytes!(concat!(
666 env!("CARGO_MANIFEST_DIR"),
667 "/pg_catalog_arrow_exports/pg_operator.feather"
668 ))
669 .to_vec(),
670 )?,
671 pg_opfamily: Self::create_arrow_table(
672 include_bytes!(concat!(
673 env!("CARGO_MANIFEST_DIR"),
674 "/pg_catalog_arrow_exports/pg_opfamily.feather"
675 ))
676 .to_vec(),
677 )?,
678 pg_proc: Self::create_arrow_table(
679 include_bytes!(concat!(
680 env!("CARGO_MANIFEST_DIR"),
681 "/pg_catalog_arrow_exports/pg_proc.feather"
682 ))
683 .to_vec(),
684 )?,
685 pg_range: Self::create_arrow_table(
686 include_bytes!(concat!(
687 env!("CARGO_MANIFEST_DIR"),
688 "/pg_catalog_arrow_exports/pg_range.feather"
689 ))
690 .to_vec(),
691 )?,
692 pg_ts_config: Self::create_arrow_table(
693 include_bytes!(concat!(
694 env!("CARGO_MANIFEST_DIR"),
695 "/pg_catalog_arrow_exports/pg_ts_config.feather"
696 ))
697 .to_vec(),
698 )?,
699 pg_ts_dict: Self::create_arrow_table(
700 include_bytes!(concat!(
701 env!("CARGO_MANIFEST_DIR"),
702 "/pg_catalog_arrow_exports/pg_ts_dict.feather"
703 ))
704 .to_vec(),
705 )?,
706 pg_ts_parser: Self::create_arrow_table(
707 include_bytes!(concat!(
708 env!("CARGO_MANIFEST_DIR"),
709 "/pg_catalog_arrow_exports/pg_ts_parser.feather"
710 ))
711 .to_vec(),
712 )?,
713 pg_ts_template: Self::create_arrow_table(
714 include_bytes!(concat!(
715 env!("CARGO_MANIFEST_DIR"),
716 "/pg_catalog_arrow_exports/pg_ts_template.feather"
717 ))
718 .to_vec(),
719 )?,
720 pg_type: Self::create_arrow_table(
721 include_bytes!(concat!(
722 env!("CARGO_MANIFEST_DIR"),
723 "/pg_catalog_arrow_exports/pg_type.feather"
724 ))
725 .to_vec(),
726 )?,
727 pg_attrdef: Self::create_arrow_table(
728 include_bytes!(concat!(
729 env!("CARGO_MANIFEST_DIR"),
730 "/pg_catalog_arrow_exports/pg_attrdef.feather"
731 ))
732 .to_vec(),
733 )?,
734 pg_auth_members: Self::create_arrow_table(
735 include_bytes!(concat!(
736 env!("CARGO_MANIFEST_DIR"),
737 "/pg_catalog_arrow_exports/pg_auth_members.feather"
738 ))
739 .to_vec(),
740 )?,
741 pg_authid: Self::create_arrow_table(
742 include_bytes!(concat!(
743 env!("CARGO_MANIFEST_DIR"),
744 "/pg_catalog_arrow_exports/pg_authid.feather"
745 ))
746 .to_vec(),
747 )?,
748 pg_constraint: Self::create_arrow_table(
749 include_bytes!(concat!(
750 env!("CARGO_MANIFEST_DIR"),
751 "/pg_catalog_arrow_exports/pg_constraint.feather"
752 ))
753 .to_vec(),
754 )?,
755 pg_db_role_setting: Self::create_arrow_table(
756 include_bytes!(concat!(
757 env!("CARGO_MANIFEST_DIR"),
758 "/pg_catalog_arrow_exports/pg_db_role_setting.feather"
759 ))
760 .to_vec(),
761 )?,
762 pg_default_acl: Self::create_arrow_table(
763 include_bytes!(concat!(
764 env!("CARGO_MANIFEST_DIR"),
765 "/pg_catalog_arrow_exports/pg_default_acl.feather"
766 ))
767 .to_vec(),
768 )?,
769 pg_depend: Self::create_arrow_table(
770 include_bytes!(concat!(
771 env!("CARGO_MANIFEST_DIR"),
772 "/pg_catalog_arrow_exports/pg_depend.feather"
773 ))
774 .to_vec(),
775 )?,
776 pg_description: Self::create_arrow_table(
777 include_bytes!(concat!(
778 env!("CARGO_MANIFEST_DIR"),
779 "/pg_catalog_arrow_exports/pg_description.feather"
780 ))
781 .to_vec(),
782 )?,
783 pg_enum: Self::create_arrow_table(
784 include_bytes!(concat!(
785 env!("CARGO_MANIFEST_DIR"),
786 "/pg_catalog_arrow_exports/pg_enum.feather"
787 ))
788 .to_vec(),
789 )?,
790 pg_event_trigger: Self::create_arrow_table(
791 include_bytes!(concat!(
792 env!("CARGO_MANIFEST_DIR"),
793 "/pg_catalog_arrow_exports/pg_event_trigger.feather"
794 ))
795 .to_vec(),
796 )?,
797 pg_extension: Self::create_arrow_table(
798 include_bytes!(concat!(
799 env!("CARGO_MANIFEST_DIR"),
800 "/pg_catalog_arrow_exports/pg_extension.feather"
801 ))
802 .to_vec(),
803 )?,
804 pg_foreign_data_wrapper: Self::create_arrow_table(
805 include_bytes!(concat!(
806 env!("CARGO_MANIFEST_DIR"),
807 "/pg_catalog_arrow_exports/pg_foreign_data_wrapper.feather"
808 ))
809 .to_vec(),
810 )?,
811 pg_foreign_server: Self::create_arrow_table(
812 include_bytes!(concat!(
813 env!("CARGO_MANIFEST_DIR"),
814 "/pg_catalog_arrow_exports/pg_foreign_server.feather"
815 ))
816 .to_vec(),
817 )?,
818 pg_foreign_table: Self::create_arrow_table(
819 include_bytes!(concat!(
820 env!("CARGO_MANIFEST_DIR"),
821 "/pg_catalog_arrow_exports/pg_foreign_table.feather"
822 ))
823 .to_vec(),
824 )?,
825 pg_index: Self::create_arrow_table(
826 include_bytes!(concat!(
827 env!("CARGO_MANIFEST_DIR"),
828 "/pg_catalog_arrow_exports/pg_index.feather"
829 ))
830 .to_vec(),
831 )?,
832 pg_inherits: Self::create_arrow_table(
833 include_bytes!(concat!(
834 env!("CARGO_MANIFEST_DIR"),
835 "/pg_catalog_arrow_exports/pg_inherits.feather"
836 ))
837 .to_vec(),
838 )?,
839 pg_init_privs: Self::create_arrow_table(
840 include_bytes!(concat!(
841 env!("CARGO_MANIFEST_DIR"),
842 "/pg_catalog_arrow_exports/pg_init_privs.feather"
843 ))
844 .to_vec(),
845 )?,
846 pg_largeobject: Self::create_arrow_table(
847 include_bytes!(concat!(
848 env!("CARGO_MANIFEST_DIR"),
849 "/pg_catalog_arrow_exports/pg_largeobject.feather"
850 ))
851 .to_vec(),
852 )?,
853 pg_largeobject_metadata: Self::create_arrow_table(
854 include_bytes!(concat!(
855 env!("CARGO_MANIFEST_DIR"),
856 "/pg_catalog_arrow_exports/pg_largeobject_metadata.feather"
857 ))
858 .to_vec(),
859 )?,
860
861 pg_partitioned_table: Self::create_arrow_table(
862 include_bytes!(concat!(
863 env!("CARGO_MANIFEST_DIR"),
864 "/pg_catalog_arrow_exports/pg_partitioned_table.feather"
865 ))
866 .to_vec(),
867 )?,
868 pg_policy: Self::create_arrow_table(
869 include_bytes!(concat!(
870 env!("CARGO_MANIFEST_DIR"),
871 "/pg_catalog_arrow_exports/pg_policy.feather"
872 ))
873 .to_vec(),
874 )?,
875 pg_publication: Self::create_arrow_table(
876 include_bytes!(concat!(
877 env!("CARGO_MANIFEST_DIR"),
878 "/pg_catalog_arrow_exports/pg_publication.feather"
879 ))
880 .to_vec(),
881 )?,
882 pg_publication_namespace: Self::create_arrow_table(
883 include_bytes!(concat!(
884 env!("CARGO_MANIFEST_DIR"),
885 "/pg_catalog_arrow_exports/pg_publication_namespace.feather"
886 ))
887 .to_vec(),
888 )?,
889 pg_publication_rel: Self::create_arrow_table(
890 include_bytes!(concat!(
891 env!("CARGO_MANIFEST_DIR"),
892 "/pg_catalog_arrow_exports/pg_publication_rel.feather"
893 ))
894 .to_vec(),
895 )?,
896 pg_replication_origin: Self::create_arrow_table(
897 include_bytes!(concat!(
898 env!("CARGO_MANIFEST_DIR"),
899 "/pg_catalog_arrow_exports/pg_replication_origin.feather"
900 ))
901 .to_vec(),
902 )?,
903 pg_rewrite: Self::create_arrow_table(
904 include_bytes!(concat!(
905 env!("CARGO_MANIFEST_DIR"),
906 "/pg_catalog_arrow_exports/pg_rewrite.feather"
907 ))
908 .to_vec(),
909 )?,
910 pg_seclabel: Self::create_arrow_table(
911 include_bytes!(concat!(
912 env!("CARGO_MANIFEST_DIR"),
913 "/pg_catalog_arrow_exports/pg_seclabel.feather"
914 ))
915 .to_vec(),
916 )?,
917 pg_sequence: Self::create_arrow_table(
918 include_bytes!(concat!(
919 env!("CARGO_MANIFEST_DIR"),
920 "/pg_catalog_arrow_exports/pg_sequence.feather"
921 ))
922 .to_vec(),
923 )?,
924 pg_shdepend: Self::create_arrow_table(
925 include_bytes!(concat!(
926 env!("CARGO_MANIFEST_DIR"),
927 "/pg_catalog_arrow_exports/pg_shdepend.feather"
928 ))
929 .to_vec(),
930 )?,
931 pg_shdescription: Self::create_arrow_table(
932 include_bytes!(concat!(
933 env!("CARGO_MANIFEST_DIR"),
934 "/pg_catalog_arrow_exports/pg_shdescription.feather"
935 ))
936 .to_vec(),
937 )?,
938 pg_shseclabel: Self::create_arrow_table(
939 include_bytes!(concat!(
940 env!("CARGO_MANIFEST_DIR"),
941 "/pg_catalog_arrow_exports/pg_shseclabel.feather"
942 ))
943 .to_vec(),
944 )?,
945 pg_statistic: Self::create_arrow_table(
946 include_bytes!(concat!(
947 env!("CARGO_MANIFEST_DIR"),
948 "/pg_catalog_arrow_exports/pg_statistic.feather"
949 ))
950 .to_vec(),
951 )?,
952 pg_statistic_ext: Self::create_arrow_table(
953 include_bytes!(concat!(
954 env!("CARGO_MANIFEST_DIR"),
955 "/pg_catalog_arrow_exports/pg_statistic_ext.feather"
956 ))
957 .to_vec(),
958 )?,
959 pg_statistic_ext_data: Self::create_arrow_table(
960 include_bytes!(concat!(
961 env!("CARGO_MANIFEST_DIR"),
962 "/pg_catalog_arrow_exports/pg_statistic_ext_data.feather"
963 ))
964 .to_vec(),
965 )?,
966 pg_subscription: Self::create_arrow_table(
967 include_bytes!(concat!(
968 env!("CARGO_MANIFEST_DIR"),
969 "/pg_catalog_arrow_exports/pg_subscription.feather"
970 ))
971 .to_vec(),
972 )?,
973 pg_subscription_rel: Self::create_arrow_table(
974 include_bytes!(concat!(
975 env!("CARGO_MANIFEST_DIR"),
976 "/pg_catalog_arrow_exports/pg_subscription_rel.feather"
977 ))
978 .to_vec(),
979 )?,
980 pg_tablespace: Self::create_arrow_table(
981 include_bytes!(concat!(
982 env!("CARGO_MANIFEST_DIR"),
983 "/pg_catalog_arrow_exports/pg_tablespace.feather"
984 ))
985 .to_vec(),
986 )?,
987 pg_trigger: Self::create_arrow_table(
988 include_bytes!(concat!(
989 env!("CARGO_MANIFEST_DIR"),
990 "/pg_catalog_arrow_exports/pg_trigger.feather"
991 ))
992 .to_vec(),
993 )?,
994 pg_user_mapping: Self::create_arrow_table(
995 include_bytes!(concat!(
996 env!("CARGO_MANIFEST_DIR"),
997 "/pg_catalog_arrow_exports/pg_user_mapping.feather"
998 ))
999 .to_vec(),
1000 )?,
1001
1002 pg_get_keywords: Self::create_arrow_table(
1003 include_bytes!(concat!(
1004 env!("CARGO_MANIFEST_DIR"),
1005 "/pg_catalog_arrow_exports/pg_get_keywords.feather"
1006 ))
1007 .to_vec(),
1008 )?,
1009 })
1010 }
1011
1012 fn create_arrow_table(data_bytes: Vec<u8>) -> Result<Arc<ArrowTable>> {
1014 ArrowTable::from_ipc_data(data_bytes).map(Arc::new)
1015 }
1016}
1017
1018pub fn create_current_schemas_udf() -> ScalarUDF {
1019 let func = move |args: &[ColumnarValue]| {
1021 let args = ColumnarValue::values_to_arrays(args)?;
1022 let input = as_boolean_array(&args[0]);
1023
1024 let mut values = vec!["public"];
1026 if input.value(0) {
1028 values.push("information_schema");
1029 values.push("pg_catalog");
1030 }
1031
1032 let list_array = SingleRowListArrayBuilder::new(Arc::new(StringArray::from(values)));
1033
1034 let array: ArrayRef = Arc::new(list_array.build_list_array());
1035
1036 Ok(ColumnarValue::Array(array))
1037 };
1038
1039 create_udf(
1041 "current_schemas",
1042 vec![DataType::Boolean],
1043 DataType::List(Arc::new(Field::new("item", DataType::Utf8, true))),
1044 Volatility::Immutable,
1045 Arc::new(func),
1046 )
1047}
1048
1049pub fn create_current_schema_udf() -> ScalarUDF {
1050 let func = move |_args: &[ColumnarValue]| {
1052 let mut builder = StringBuilder::new();
1054 builder.append_value("public");
1055 let array: ArrayRef = Arc::new(builder.finish());
1056
1057 Ok(ColumnarValue::Array(array))
1058 };
1059
1060 create_udf(
1062 "current_schema",
1063 vec![],
1064 DataType::Utf8,
1065 Volatility::Immutable,
1066 Arc::new(func),
1067 )
1068}
1069
1070pub fn create_current_database_udf() -> ScalarUDF {
1071 let func = move |_args: &[ColumnarValue]| {
1073 let mut builder = StringBuilder::new();
1075 builder.append_value("datafusion");
1076 let array: ArrayRef = Arc::new(builder.finish());
1077
1078 Ok(ColumnarValue::Array(array))
1079 };
1080
1081 create_udf(
1083 "current_database",
1084 vec![],
1085 DataType::Utf8,
1086 Volatility::Immutable,
1087 Arc::new(func),
1088 )
1089}
1090
1091pub fn create_pg_get_userbyid_udf() -> ScalarUDF {
1092 let func = move |args: &[ColumnarValue]| {
1094 let args = ColumnarValue::values_to_arrays(args)?;
1095 let input = &args[0]; let mut builder = StringBuilder::new();
1099 for _ in 0..input.len() {
1100 builder.append_value("postgres");
1101 }
1102
1103 let array: ArrayRef = Arc::new(builder.finish());
1104
1105 Ok(ColumnarValue::Array(array))
1106 };
1107
1108 create_udf(
1110 "pg_get_userbyid",
1111 vec![DataType::Int32],
1112 DataType::Utf8,
1113 Volatility::Stable,
1114 Arc::new(func),
1115 )
1116}
1117
1118pub fn create_pg_table_is_visible() -> ScalarUDF {
1119 let func = move |args: &[ColumnarValue]| {
1121 let args = ColumnarValue::values_to_arrays(args)?;
1122 let input = &args[0]; let mut builder = BooleanBuilder::new();
1126 for _ in 0..input.len() {
1127 builder.append_value(true);
1128 }
1129
1130 let array: ArrayRef = Arc::new(builder.finish());
1131
1132 Ok(ColumnarValue::Array(array))
1133 };
1134
1135 create_udf(
1137 "pg_table_is_visible",
1138 vec![DataType::Int32],
1139 DataType::Boolean,
1140 Volatility::Stable,
1141 Arc::new(func),
1142 )
1143}
1144
1145pub fn create_session_user_udf() -> ScalarUDF {
1146 let func = move |_args: &[ColumnarValue]| {
1147 let mut builder = StringBuilder::new();
1148 builder.append_value("postgres");
1150
1151 let array: ArrayRef = Arc::new(builder.finish());
1152
1153 Ok(ColumnarValue::Array(array))
1154 };
1155
1156 create_udf(
1157 "session_user",
1158 vec![],
1159 DataType::Utf8,
1160 Volatility::Stable,
1161 Arc::new(func),
1162 )
1163}
1164
1165pub fn create_pg_get_partkeydef_udf() -> ScalarUDF {
1166 let func = move |args: &[ColumnarValue]| {
1167 let args = ColumnarValue::values_to_arrays(args)?;
1168 let oid = &args[0];
1169
1170 let mut builder = StringBuilder::new();
1171 for _ in 0..oid.len() {
1172 builder.append_value("");
1173 }
1174
1175 let array: ArrayRef = Arc::new(builder.finish());
1176
1177 Ok(ColumnarValue::Array(array))
1178 };
1179
1180 create_udf(
1181 "pg_get_partkeydef",
1182 vec![DataType::Utf8],
1183 DataType::Utf8,
1184 Volatility::Stable,
1185 Arc::new(func),
1186 )
1187}
1188
1189pub fn create_pg_relation_is_publishable_udf() -> ScalarUDF {
1190 let func = move |args: &[ColumnarValue]| {
1191 let args = ColumnarValue::values_to_arrays(args)?;
1192 let oid = &args[0];
1193
1194 let mut builder = BooleanBuilder::new();
1195 for _ in 0..oid.len() {
1196 builder.append_value(true);
1197 }
1198
1199 let array: ArrayRef = Arc::new(builder.finish());
1200
1201 Ok(ColumnarValue::Array(array))
1202 };
1203
1204 create_udf(
1205 "pg_relation_is_publishable",
1206 vec![DataType::Int32],
1207 DataType::Boolean,
1208 Volatility::Stable,
1209 Arc::new(func),
1210 )
1211}
1212
1213pub fn create_pg_get_statisticsobjdef_columns_udf() -> ScalarUDF {
1214 let func = move |args: &[ColumnarValue]| {
1215 let args = ColumnarValue::values_to_arrays(args)?;
1216 let oid = &args[0];
1217
1218 let mut builder = StringBuilder::new();
1219 for _ in 0..oid.len() {
1220 builder.append_null();
1221 }
1222
1223 let array: ArrayRef = Arc::new(builder.finish());
1224
1225 Ok(ColumnarValue::Array(array))
1226 };
1227
1228 create_udf(
1229 "pg_get_statisticsobjdef_columns",
1230 vec![DataType::Int32],
1231 DataType::Utf8,
1232 Volatility::Stable,
1233 Arc::new(func),
1234 )
1235}
1236
1237pub fn create_pg_encoding_to_char_udf() -> ScalarUDF {
1238 let func = move |args: &[ColumnarValue]| {
1239 let args = ColumnarValue::values_to_arrays(args)?;
1240 let encoding = &args[0].as_primitive::<Int32Type>();
1241
1242 let mut builder = StringBuilder::new();
1243 for i in 0..encoding.len() {
1244 if encoding.value(i) == 6 {
1245 builder.append_value("UTF-8");
1246 } else {
1247 builder.append_null();
1248 }
1249 }
1250
1251 let array: ArrayRef = Arc::new(builder.finish());
1252
1253 Ok(ColumnarValue::Array(array))
1254 };
1255
1256 create_udf(
1257 "pg_encoding_to_char",
1258 vec![DataType::Int32],
1259 DataType::Utf8,
1260 Volatility::Stable,
1261 Arc::new(func),
1262 )
1263}
1264
1265const BACKEND_PID: i32 = 1;
1266
1267pub fn create_pg_backend_pid_udf() -> ScalarUDF {
1268 let func = move |_args: &[ColumnarValue]| {
1269 let mut builder = Int32Builder::new();
1270 builder.append_value(BACKEND_PID);
1271 let array: ArrayRef = Arc::new(builder.finish());
1272 Ok(ColumnarValue::Array(array))
1273 };
1274
1275 create_udf(
1276 "pg_backend_pid",
1277 vec![],
1278 DataType::Int32,
1279 Volatility::Stable,
1280 Arc::new(func),
1281 )
1282}
1283
1284pub fn create_pg_relation_size_udf() -> ScalarUDF {
1285 let func = move |args: &[ColumnarValue]| {
1286 let args = ColumnarValue::values_to_arrays(args)?;
1287 let oids = &args[0].as_primitive::<Int32Type>();
1288
1289 let mut builder = Int32Builder::new();
1290 for _ in 0..oids.len() {
1291 builder.append_value(0);
1292 }
1293
1294 let array: ArrayRef = Arc::new(builder.finish());
1295 Ok(ColumnarValue::Array(array))
1296 };
1297
1298 create_udf(
1299 "pg_relation_size",
1300 vec![DataType::Int32],
1301 DataType::Int32,
1302 Volatility::Stable,
1303 Arc::new(func),
1304 )
1305}
1306
1307pub fn create_pg_total_relation_size_udf() -> ScalarUDF {
1308 let func = move |args: &[ColumnarValue]| {
1309 let args = ColumnarValue::values_to_arrays(args)?;
1310 let oids = &args[0].as_primitive::<Int32Type>();
1311
1312 let mut builder = Int32Builder::new();
1313 for _ in 0..oids.len() {
1314 builder.append_value(0);
1315 }
1316
1317 let array: ArrayRef = Arc::new(builder.finish());
1318 Ok(ColumnarValue::Array(array))
1319 };
1320
1321 create_udf(
1322 "pg_total_relation_size",
1323 vec![DataType::Int32],
1324 DataType::Int32,
1325 Volatility::Stable,
1326 Arc::new(func),
1327 )
1328}
1329
1330pub fn create_pg_stat_get_numscans() -> ScalarUDF {
1331 let func = move |args: &[ColumnarValue]| {
1332 let args = ColumnarValue::values_to_arrays(args)?;
1333 let index_rel_id = &args[0].as_primitive::<Int32Type>();
1334
1335 let mut builder = Int32Builder::new();
1336 for _ in 0..index_rel_id.len() {
1337 builder.append_value(0);
1338 }
1339
1340 let array: ArrayRef = Arc::new(builder.finish());
1341 Ok(ColumnarValue::Array(array))
1342 };
1343
1344 create_udf(
1345 "pg_stat_get_numscans",
1346 vec![DataType::Int32],
1347 DataType::Int32,
1348 Volatility::Stable,
1349 Arc::new(func),
1350 )
1351}
1352
1353pub fn create_pg_get_constraintdef() -> ScalarUDF {
1354 #[derive(Debug, PartialEq, Eq, Hash)]
1355 struct GetConstraintDefUDF {
1356 signature: Signature,
1357 }
1358
1359 impl GetConstraintDefUDF {
1360 fn new() -> Self {
1361 let type_signature = TypeSignature::OneOf(vec![
1362 TypeSignature::Exact(vec![DataType::Int32]),
1363 TypeSignature::Exact(vec![DataType::Int32, DataType::Boolean]),
1364 ]);
1365
1366 let signature = Signature::new(type_signature, Volatility::Stable);
1367 GetConstraintDefUDF { signature }
1368 }
1369 }
1370
1371 impl ScalarUDFImpl for GetConstraintDefUDF {
1372 fn as_any(&self) -> &dyn std::any::Any {
1373 self
1374 }
1375
1376 fn name(&self) -> &str {
1377 "pg_get_constraintdef"
1378 }
1379
1380 fn signature(&self) -> &Signature {
1381 &self.signature
1382 }
1383
1384 fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
1385 Ok(DataType::Utf8)
1386 }
1387
1388 fn invoke_with_args(
1389 &self,
1390 args: datafusion::logical_expr::ScalarFunctionArgs,
1391 ) -> Result<ColumnarValue> {
1392 let args = ColumnarValue::values_to_arrays(&args.args)?;
1393 let oids = &args[0].as_primitive::<Int32Type>();
1394
1395 let mut builder = StringBuilder::new();
1396 for _ in 0..oids.len() {
1397 builder.append_value("");
1398 }
1399
1400 let array: ArrayRef = Arc::new(builder.finish());
1401 Ok(ColumnarValue::Array(array))
1402 }
1403 }
1404
1405 GetConstraintDefUDF::new().into()
1406}
1407
1408pub fn create_pg_get_partition_ancestors_udf() -> ScalarUDF {
1409 let func = move |args: &[ColumnarValue]| {
1410 let args = ColumnarValue::values_to_arrays(args)?;
1411 let string_array = args[0].as_string::<i32>();
1412
1413 let mut builder = StringBuilder::new();
1414 string_array.iter().for_each(|i| builder.append_option(i));
1415 let array: ArrayRef = Arc::new(builder.finish());
1416
1417 Ok(ColumnarValue::Array(array))
1418 };
1419
1420 create_udf(
1421 "pg_partition_ancestors",
1422 vec![DataType::Utf8],
1423 DataType::Utf8,
1424 Volatility::Stable,
1425 Arc::new(func),
1426 )
1427}
1428
1429pub fn setup_pg_catalog<P>(
1431 session_context: &SessionContext,
1432 catalog_name: &str,
1433 context_provider: P,
1434) -> Result<(), Box<DataFusionError>>
1435where
1436 P: PgCatalogContextProvider,
1437{
1438 let static_tables = Arc::new(PgCatalogStaticTables::try_new()?);
1439 let pg_catalog = PgCatalogSchemaProvider::try_new(
1440 session_context.state().catalog_list().clone(),
1441 static_tables.clone(),
1442 context_provider,
1443 )?;
1444 session_context
1445 .catalog(catalog_name)
1446 .ok_or_else(|| {
1447 DataFusionError::Configuration(format!(
1448 "Catalog not found when registering pg_catalog: {catalog_name}"
1449 ))
1450 })?
1451 .register_schema("pg_catalog", Arc::new(pg_catalog))?;
1452
1453 session_context.register_udf(create_current_database_udf());
1454 session_context.register_udf(create_current_schema_udf());
1455 session_context.register_udf(create_current_schemas_udf());
1456 session_context.register_udf(create_pg_get_userbyid_udf());
1458 session_context.register_udf(has_privilege_udf::create_has_privilege_udf(
1459 "has_table_privilege",
1460 ));
1461 session_context.register_udf(has_privilege_udf::create_has_privilege_udf(
1462 "has_schema_privilege",
1463 ));
1464 session_context.register_udf(has_privilege_udf::create_has_privilege_udf(
1465 "has_database_privilege",
1466 ));
1467 session_context.register_udf(has_privilege_udf::create_has_privilege_udf(
1468 "has_any_column_privilege",
1469 ));
1470 session_context.register_udf(create_pg_table_is_visible());
1471 session_context.register_udf(format_type::create_format_type_udf());
1472 session_context.register_udf(create_session_user_udf());
1473 session_context.register_udtf("pg_get_keywords", static_tables.pg_get_keywords.clone());
1474 session_context.register_udf(pg_get_expr_udf::create_pg_get_expr_udf());
1475 session_context.register_udf(create_pg_get_partkeydef_udf());
1476 session_context.register_udf(create_pg_relation_is_publishable_udf());
1477 session_context.register_udf(create_pg_get_statisticsobjdef_columns_udf());
1478 session_context.register_udf(create_pg_encoding_to_char_udf());
1479 session_context.register_udf(create_pg_backend_pid_udf());
1480 session_context.register_udf(create_pg_relation_size_udf());
1481 session_context.register_udf(create_pg_total_relation_size_udf());
1482 session_context.register_udf(create_pg_stat_get_numscans());
1483 session_context.register_udf(create_pg_get_constraintdef());
1484 session_context.register_udf(create_pg_get_partition_ancestors_udf());
1485 session_context.register_udf(quote_ident_udf::create_quote_ident_udf());
1486 session_context.register_udf(quote_ident_udf::create_parse_ident_udf());
1487
1488 Ok(())
1489}
1490
1491#[cfg(test)]
1492mod test {
1493 use super::*;
1494
1495 #[test]
1496 fn test_load_arrow_data() {
1497 let table = ArrowTable::from_ipc_data(
1498 include_bytes!(concat!(
1499 env!("CARGO_MANIFEST_DIR"),
1500 "/pg_catalog_arrow_exports/pg_aggregate.feather"
1501 ))
1502 .to_vec(),
1503 )
1504 .expect("Failed to load ipc data");
1505
1506 assert_eq!(table.schema.fields.len(), 22);
1507 assert_eq!(table.data.len(), 1);
1508
1509 let _ = ArrowTable::from_ipc_data(
1510 include_bytes!(concat!(
1511 env!("CARGO_MANIFEST_DIR"),
1512 "/pg_catalog_arrow_exports/pg_aggregate.feather"
1513 ))
1514 .to_vec(),
1515 )
1516 .expect("Failed to load ipc data");
1517 let _ = ArrowTable::from_ipc_data(
1518 include_bytes!(concat!(
1519 env!("CARGO_MANIFEST_DIR"),
1520 "/pg_catalog_arrow_exports/pg_am.feather"
1521 ))
1522 .to_vec(),
1523 )
1524 .expect("Failed to load ipc data");
1525 let _ = ArrowTable::from_ipc_data(
1526 include_bytes!(concat!(
1527 env!("CARGO_MANIFEST_DIR"),
1528 "/pg_catalog_arrow_exports/pg_amop.feather"
1529 ))
1530 .to_vec(),
1531 )
1532 .expect("Failed to load ipc data");
1533 let _ = ArrowTable::from_ipc_data(
1534 include_bytes!(concat!(
1535 env!("CARGO_MANIFEST_DIR"),
1536 "/pg_catalog_arrow_exports/pg_amproc.feather"
1537 ))
1538 .to_vec(),
1539 )
1540 .expect("Failed to load ipc data");
1541 let _ = ArrowTable::from_ipc_data(
1542 include_bytes!(concat!(
1543 env!("CARGO_MANIFEST_DIR"),
1544 "/pg_catalog_arrow_exports/pg_cast.feather"
1545 ))
1546 .to_vec(),
1547 )
1548 .expect("Failed to load ipc data");
1549 let _ = ArrowTable::from_ipc_data(
1550 include_bytes!(concat!(
1551 env!("CARGO_MANIFEST_DIR"),
1552 "/pg_catalog_arrow_exports/pg_collation.feather"
1553 ))
1554 .to_vec(),
1555 )
1556 .expect("Failed to load ipc data");
1557 let _ = ArrowTable::from_ipc_data(
1558 include_bytes!(concat!(
1559 env!("CARGO_MANIFEST_DIR"),
1560 "/pg_catalog_arrow_exports/pg_conversion.feather"
1561 ))
1562 .to_vec(),
1563 )
1564 .expect("Failed to load ipc data");
1565 let _ = ArrowTable::from_ipc_data(
1566 include_bytes!(concat!(
1567 env!("CARGO_MANIFEST_DIR"),
1568 "/pg_catalog_arrow_exports/pg_language.feather"
1569 ))
1570 .to_vec(),
1571 )
1572 .expect("Failed to load ipc data");
1573 let _ = ArrowTable::from_ipc_data(
1574 include_bytes!(concat!(
1575 env!("CARGO_MANIFEST_DIR"),
1576 "/pg_catalog_arrow_exports/pg_opclass.feather"
1577 ))
1578 .to_vec(),
1579 )
1580 .expect("Failed to load ipc data");
1581 let _ = ArrowTable::from_ipc_data(
1582 include_bytes!(concat!(
1583 env!("CARGO_MANIFEST_DIR"),
1584 "/pg_catalog_arrow_exports/pg_operator.feather"
1585 ))
1586 .to_vec(),
1587 )
1588 .expect("Failed to load ipc data");
1589 let _ = ArrowTable::from_ipc_data(
1590 include_bytes!(concat!(
1591 env!("CARGO_MANIFEST_DIR"),
1592 "/pg_catalog_arrow_exports/pg_opfamily.feather"
1593 ))
1594 .to_vec(),
1595 )
1596 .expect("Failed to load ipc data");
1597 let _ = ArrowTable::from_ipc_data(
1598 include_bytes!(concat!(
1599 env!("CARGO_MANIFEST_DIR"),
1600 "/pg_catalog_arrow_exports/pg_proc.feather"
1601 ))
1602 .to_vec(),
1603 )
1604 .expect("Failed to load ipc data");
1605 let _ = ArrowTable::from_ipc_data(
1606 include_bytes!(concat!(
1607 env!("CARGO_MANIFEST_DIR"),
1608 "/pg_catalog_arrow_exports/pg_range.feather"
1609 ))
1610 .to_vec(),
1611 )
1612 .expect("Failed to load ipc data");
1613 let _ = ArrowTable::from_ipc_data(
1614 include_bytes!(concat!(
1615 env!("CARGO_MANIFEST_DIR"),
1616 "/pg_catalog_arrow_exports/pg_ts_config.feather"
1617 ))
1618 .to_vec(),
1619 )
1620 .expect("Failed to load ipc data");
1621 let _ = ArrowTable::from_ipc_data(
1622 include_bytes!(concat!(
1623 env!("CARGO_MANIFEST_DIR"),
1624 "/pg_catalog_arrow_exports/pg_ts_dict.feather"
1625 ))
1626 .to_vec(),
1627 )
1628 .expect("Failed to load ipc data");
1629 let _ = ArrowTable::from_ipc_data(
1630 include_bytes!(concat!(
1631 env!("CARGO_MANIFEST_DIR"),
1632 "/pg_catalog_arrow_exports/pg_ts_parser.feather"
1633 ))
1634 .to_vec(),
1635 )
1636 .expect("Failed to load ipc data");
1637 let _ = ArrowTable::from_ipc_data(
1638 include_bytes!(concat!(
1639 env!("CARGO_MANIFEST_DIR"),
1640 "/pg_catalog_arrow_exports/pg_ts_template.feather"
1641 ))
1642 .to_vec(),
1643 )
1644 .expect("Failed to load ipc data");
1645 let _ = ArrowTable::from_ipc_data(
1646 include_bytes!(concat!(
1647 env!("CARGO_MANIFEST_DIR"),
1648 "/pg_catalog_arrow_exports/pg_type.feather"
1649 ))
1650 .to_vec(),
1651 )
1652 .expect("Failed to load ipc data");
1653
1654 let _ = ArrowTable::from_ipc_data(
1655 include_bytes!(concat!(
1656 env!("CARGO_MANIFEST_DIR"),
1657 "/pg_catalog_arrow_exports/pg_attrdef.feather"
1658 ))
1659 .to_vec(),
1660 )
1661 .expect("Failed to load ipc data");
1662 let _ = ArrowTable::from_ipc_data(
1663 include_bytes!(concat!(
1664 env!("CARGO_MANIFEST_DIR"),
1665 "/pg_catalog_arrow_exports/pg_auth_members.feather"
1666 ))
1667 .to_vec(),
1668 )
1669 .expect("Failed to load ipc data");
1670 let _ = ArrowTable::from_ipc_data(
1671 include_bytes!(concat!(
1672 env!("CARGO_MANIFEST_DIR"),
1673 "/pg_catalog_arrow_exports/pg_authid.feather"
1674 ))
1675 .to_vec(),
1676 )
1677 .expect("Failed to load ipc data");
1678
1679 let _ = ArrowTable::from_ipc_data(
1680 include_bytes!(concat!(
1681 env!("CARGO_MANIFEST_DIR"),
1682 "/pg_catalog_arrow_exports/pg_constraint.feather"
1683 ))
1684 .to_vec(),
1685 )
1686 .expect("Failed to load ipc data");
1687
1688 let _ = ArrowTable::from_ipc_data(
1689 include_bytes!(concat!(
1690 env!("CARGO_MANIFEST_DIR"),
1691 "/pg_catalog_arrow_exports/pg_db_role_setting.feather"
1692 ))
1693 .to_vec(),
1694 )
1695 .expect("Failed to load ipc data");
1696 let _ = ArrowTable::from_ipc_data(
1697 include_bytes!(concat!(
1698 env!("CARGO_MANIFEST_DIR"),
1699 "/pg_catalog_arrow_exports/pg_default_acl.feather"
1700 ))
1701 .to_vec(),
1702 )
1703 .expect("Failed to load ipc data");
1704 let _ = ArrowTable::from_ipc_data(
1705 include_bytes!(concat!(
1706 env!("CARGO_MANIFEST_DIR"),
1707 "/pg_catalog_arrow_exports/pg_depend.feather"
1708 ))
1709 .to_vec(),
1710 )
1711 .expect("Failed to load ipc data");
1712 let _ = ArrowTable::from_ipc_data(
1713 include_bytes!(concat!(
1714 env!("CARGO_MANIFEST_DIR"),
1715 "/pg_catalog_arrow_exports/pg_description.feather"
1716 ))
1717 .to_vec(),
1718 )
1719 .expect("Failed to load ipc data");
1720 let _ = ArrowTable::from_ipc_data(
1721 include_bytes!(concat!(
1722 env!("CARGO_MANIFEST_DIR"),
1723 "/pg_catalog_arrow_exports/pg_enum.feather"
1724 ))
1725 .to_vec(),
1726 )
1727 .expect("Failed to load ipc data");
1728 let _ = ArrowTable::from_ipc_data(
1729 include_bytes!(concat!(
1730 env!("CARGO_MANIFEST_DIR"),
1731 "/pg_catalog_arrow_exports/pg_event_trigger.feather"
1732 ))
1733 .to_vec(),
1734 )
1735 .expect("Failed to load ipc data");
1736 let _ = ArrowTable::from_ipc_data(
1737 include_bytes!(concat!(
1738 env!("CARGO_MANIFEST_DIR"),
1739 "/pg_catalog_arrow_exports/pg_extension.feather"
1740 ))
1741 .to_vec(),
1742 )
1743 .expect("Failed to load ipc data");
1744 let _ = ArrowTable::from_ipc_data(
1745 include_bytes!(concat!(
1746 env!("CARGO_MANIFEST_DIR"),
1747 "/pg_catalog_arrow_exports/pg_foreign_data_wrapper.feather"
1748 ))
1749 .to_vec(),
1750 )
1751 .expect("Failed to load ipc data");
1752 let _ = ArrowTable::from_ipc_data(
1753 include_bytes!(concat!(
1754 env!("CARGO_MANIFEST_DIR"),
1755 "/pg_catalog_arrow_exports/pg_foreign_server.feather"
1756 ))
1757 .to_vec(),
1758 )
1759 .expect("Failed to load ipc data");
1760 let _ = ArrowTable::from_ipc_data(
1761 include_bytes!(concat!(
1762 env!("CARGO_MANIFEST_DIR"),
1763 "/pg_catalog_arrow_exports/pg_foreign_table.feather"
1764 ))
1765 .to_vec(),
1766 )
1767 .expect("Failed to load ipc data");
1768 let _ = ArrowTable::from_ipc_data(
1769 include_bytes!(concat!(
1770 env!("CARGO_MANIFEST_DIR"),
1771 "/pg_catalog_arrow_exports/pg_index.feather"
1772 ))
1773 .to_vec(),
1774 )
1775 .expect("Failed to load ipc data");
1776 let _ = ArrowTable::from_ipc_data(
1777 include_bytes!(concat!(
1778 env!("CARGO_MANIFEST_DIR"),
1779 "/pg_catalog_arrow_exports/pg_inherits.feather"
1780 ))
1781 .to_vec(),
1782 )
1783 .expect("Failed to load ipc data");
1784 let _ = ArrowTable::from_ipc_data(
1785 include_bytes!(concat!(
1786 env!("CARGO_MANIFEST_DIR"),
1787 "/pg_catalog_arrow_exports/pg_init_privs.feather"
1788 ))
1789 .to_vec(),
1790 )
1791 .expect("Failed to load ipc data");
1792 let _ = ArrowTable::from_ipc_data(
1793 include_bytes!(concat!(
1794 env!("CARGO_MANIFEST_DIR"),
1795 "/pg_catalog_arrow_exports/pg_largeobject.feather"
1796 ))
1797 .to_vec(),
1798 )
1799 .expect("Failed to load ipc data");
1800 let _ = ArrowTable::from_ipc_data(
1801 include_bytes!(concat!(
1802 env!("CARGO_MANIFEST_DIR"),
1803 "/pg_catalog_arrow_exports/pg_largeobject_metadata.feather"
1804 ))
1805 .to_vec(),
1806 )
1807 .expect("Failed to load ipc data");
1808
1809 let _ = ArrowTable::from_ipc_data(
1810 include_bytes!(concat!(
1811 env!("CARGO_MANIFEST_DIR"),
1812 "/pg_catalog_arrow_exports/pg_partitioned_table.feather"
1813 ))
1814 .to_vec(),
1815 )
1816 .expect("Failed to load ipc data");
1817 let _ = ArrowTable::from_ipc_data(
1818 include_bytes!(concat!(
1819 env!("CARGO_MANIFEST_DIR"),
1820 "/pg_catalog_arrow_exports/pg_policy.feather"
1821 ))
1822 .to_vec(),
1823 )
1824 .expect("Failed to load ipc data");
1825 let _ = ArrowTable::from_ipc_data(
1826 include_bytes!(concat!(
1827 env!("CARGO_MANIFEST_DIR"),
1828 "/pg_catalog_arrow_exports/pg_publication.feather"
1829 ))
1830 .to_vec(),
1831 )
1832 .expect("Failed to load ipc data");
1833 let _ = ArrowTable::from_ipc_data(
1834 include_bytes!(concat!(
1835 env!("CARGO_MANIFEST_DIR"),
1836 "/pg_catalog_arrow_exports/pg_publication_namespace.feather"
1837 ))
1838 .to_vec(),
1839 )
1840 .expect("Failed to load ipc data");
1841 let _ = ArrowTable::from_ipc_data(
1842 include_bytes!(concat!(
1843 env!("CARGO_MANIFEST_DIR"),
1844 "/pg_catalog_arrow_exports/pg_publication_rel.feather"
1845 ))
1846 .to_vec(),
1847 )
1848 .expect("Failed to load ipc data");
1849 let _ = ArrowTable::from_ipc_data(
1850 include_bytes!(concat!(
1851 env!("CARGO_MANIFEST_DIR"),
1852 "/pg_catalog_arrow_exports/pg_replication_origin.feather"
1853 ))
1854 .to_vec(),
1855 )
1856 .expect("Failed to load ipc data");
1857 let _ = ArrowTable::from_ipc_data(
1858 include_bytes!(concat!(
1859 env!("CARGO_MANIFEST_DIR"),
1860 "/pg_catalog_arrow_exports/pg_rewrite.feather"
1861 ))
1862 .to_vec(),
1863 )
1864 .expect("Failed to load ipc data");
1865 let _ = ArrowTable::from_ipc_data(
1866 include_bytes!(concat!(
1867 env!("CARGO_MANIFEST_DIR"),
1868 "/pg_catalog_arrow_exports/pg_seclabel.feather"
1869 ))
1870 .to_vec(),
1871 )
1872 .expect("Failed to load ipc data");
1873 let _ = ArrowTable::from_ipc_data(
1874 include_bytes!(concat!(
1875 env!("CARGO_MANIFEST_DIR"),
1876 "/pg_catalog_arrow_exports/pg_sequence.feather"
1877 ))
1878 .to_vec(),
1879 )
1880 .expect("Failed to load ipc data");
1881 let _ = ArrowTable::from_ipc_data(
1882 include_bytes!(concat!(
1883 env!("CARGO_MANIFEST_DIR"),
1884 "/pg_catalog_arrow_exports/pg_shdepend.feather"
1885 ))
1886 .to_vec(),
1887 )
1888 .expect("Failed to load ipc data");
1889 let _ = ArrowTable::from_ipc_data(
1890 include_bytes!(concat!(
1891 env!("CARGO_MANIFEST_DIR"),
1892 "/pg_catalog_arrow_exports/pg_shdescription.feather"
1893 ))
1894 .to_vec(),
1895 )
1896 .expect("Failed to load ipc data");
1897 let _ = ArrowTable::from_ipc_data(
1898 include_bytes!(concat!(
1899 env!("CARGO_MANIFEST_DIR"),
1900 "/pg_catalog_arrow_exports/pg_shseclabel.feather"
1901 ))
1902 .to_vec(),
1903 )
1904 .expect("Failed to load ipc data");
1905 let _ = ArrowTable::from_ipc_data(
1906 include_bytes!(concat!(
1907 env!("CARGO_MANIFEST_DIR"),
1908 "/pg_catalog_arrow_exports/pg_statistic.feather"
1909 ))
1910 .to_vec(),
1911 )
1912 .expect("Failed to load ipc data");
1913 let _ = ArrowTable::from_ipc_data(
1914 include_bytes!(concat!(
1915 env!("CARGO_MANIFEST_DIR"),
1916 "/pg_catalog_arrow_exports/pg_statistic_ext.feather"
1917 ))
1918 .to_vec(),
1919 )
1920 .expect("Failed to load ipc data");
1921 let _ = ArrowTable::from_ipc_data(
1922 include_bytes!(concat!(
1923 env!("CARGO_MANIFEST_DIR"),
1924 "/pg_catalog_arrow_exports/pg_statistic_ext_data.feather"
1925 ))
1926 .to_vec(),
1927 )
1928 .expect("Failed to load ipc data");
1929 let _ = ArrowTable::from_ipc_data(
1930 include_bytes!(concat!(
1931 env!("CARGO_MANIFEST_DIR"),
1932 "/pg_catalog_arrow_exports/pg_subscription.feather"
1933 ))
1934 .to_vec(),
1935 )
1936 .expect("Failed to load ipc data");
1937 let _ = ArrowTable::from_ipc_data(
1938 include_bytes!(concat!(
1939 env!("CARGO_MANIFEST_DIR"),
1940 "/pg_catalog_arrow_exports/pg_subscription_rel.feather"
1941 ))
1942 .to_vec(),
1943 )
1944 .expect("Failed to load ipc data");
1945 let _ = ArrowTable::from_ipc_data(
1946 include_bytes!(concat!(
1947 env!("CARGO_MANIFEST_DIR"),
1948 "/pg_catalog_arrow_exports/pg_tablespace.feather"
1949 ))
1950 .to_vec(),
1951 )
1952 .expect("Failed to load ipc data");
1953 let _ = ArrowTable::from_ipc_data(
1954 include_bytes!(concat!(
1955 env!("CARGO_MANIFEST_DIR"),
1956 "/pg_catalog_arrow_exports/pg_trigger.feather"
1957 ))
1958 .to_vec(),
1959 )
1960 .expect("Failed to load ipc data");
1961 let _ = ArrowTable::from_ipc_data(
1962 include_bytes!(concat!(
1963 env!("CARGO_MANIFEST_DIR"),
1964 "/pg_catalog_arrow_exports/pg_user_mapping.feather"
1965 ))
1966 .to_vec(),
1967 )
1968 .expect("Failed to load ipc data");
1969 let _ = ArrowTable::from_ipc_data(
1970 include_bytes!(concat!(
1971 env!("CARGO_MANIFEST_DIR"),
1972 "/pg_catalog_arrow_exports/pg_get_keywords.feather"
1973 ))
1974 .to_vec(),
1975 )
1976 .expect("Failed to load ipc data");
1977 }
1978}