Skip to content

Commit a363461

Browse files
committed
Add UDF for pg_table_is_visible
Add a UDF for the pg_table_is_visible function. This is another step towards improved pg_catalog support.
1 parent 12a6d2e commit a363461

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

datafusion-postgres/src/pg_catalog.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::sync::Arc;
22

33
use async_trait::async_trait;
44
use datafusion::arrow::array::{
5-
as_boolean_array, ArrayRef, BooleanArray, Float32Array, Float64Array, Int16Array, Int32Array,
6-
RecordBatch, StringArray, StringBuilder,
5+
as_boolean_array, ArrayRef, BooleanArray, BooleanBuilder, Float32Array, Float64Array,
6+
Int16Array, Int32Array, RecordBatch, StringArray, StringBuilder,
77
};
88
use datafusion::arrow::datatypes::{DataType, Field, Schema, SchemaRef};
99
use datafusion::catalog::streaming::StreamingTable;
@@ -1807,6 +1807,30 @@ pub fn create_pg_get_userbyid_udf() -> ScalarUDF {
18071807
)
18081808
}
18091809

1810+
pub fn create_pg_table_is_visible() -> ScalarUDF {
1811+
// Define the function implementation
1812+
let func = move |args: &[ColumnarValue]| {
1813+
let args = ColumnarValue::values_to_arrays(args)?;
1814+
let _input = &args[0]; // Table OID
1815+
1816+
// Always return true
1817+
let mut builder = BooleanBuilder::new();
1818+
builder.append_value(true);
1819+
let array: ArrayRef = Arc::new(builder.finish());
1820+
1821+
Ok(ColumnarValue::Array(array))
1822+
};
1823+
1824+
// Wrap the implementation in a scalar function
1825+
create_udf(
1826+
"pg_table_is_visible",
1827+
vec![DataType::Int32],
1828+
DataType::Boolean,
1829+
Volatility::Stable,
1830+
Arc::new(func),
1831+
)
1832+
}
1833+
18101834
pub fn create_has_table_privilege_3param_udf() -> ScalarUDF {
18111835
// Define the function implementation for 3-parameter version
18121836
let func = move |args: &[ColumnarValue]| {
@@ -1878,6 +1902,7 @@ pub fn setup_pg_catalog(
18781902
session_context.register_udf(create_version_udf());
18791903
session_context.register_udf(create_pg_get_userbyid_udf());
18801904
session_context.register_udf(create_has_table_privilege_2param_udf());
1905+
session_context.register_udf(create_pg_table_is_visible());
18811906

18821907
Ok(())
18831908
}

0 commit comments

Comments
 (0)