@@ -23,6 +23,7 @@ use crate::pg_catalog::catalog_info::CatalogInfo;
2323
2424pub mod catalog_info;
2525pub mod empty_table;
26+ pub mod format_type;
2627pub mod has_privilege_udf;
2728pub mod pg_attribute;
2829pub mod pg_class;
@@ -685,7 +686,7 @@ impl PgCatalogStaticTables {
685686 }
686687}
687688
688- pub fn create_current_schemas_udf ( name : & str ) -> ScalarUDF {
689+ pub fn create_current_schemas_udf ( ) -> ScalarUDF {
689690 // Define the function implementation
690691 let func = move |args : & [ ColumnarValue ] | {
691692 let args = ColumnarValue :: values_to_arrays ( args) ?;
@@ -708,15 +709,15 @@ pub fn create_current_schemas_udf(name: &str) -> ScalarUDF {
708709
709710 // Wrap the implementation in a scalar function
710711 create_udf (
711- name ,
712+ "current_schemas" ,
712713 vec ! [ DataType :: Boolean ] ,
713714 DataType :: List ( Arc :: new ( Field :: new ( "schema" , DataType :: Utf8 , false ) ) ) ,
714715 Volatility :: Immutable ,
715716 Arc :: new ( func) ,
716717 )
717718}
718719
719- pub fn create_current_schema_udf ( name : & str ) -> ScalarUDF {
720+ pub fn create_current_schema_udf ( ) -> ScalarUDF {
720721 // Define the function implementation
721722 let func = move |_args : & [ ColumnarValue ] | {
722723 // Create a UTF8 array with a single value
@@ -729,15 +730,15 @@ pub fn create_current_schema_udf(name: &str) -> ScalarUDF {
729730
730731 // Wrap the implementation in a scalar function
731732 create_udf (
732- name ,
733+ "current_schema" ,
733734 vec ! [ ] ,
734735 DataType :: Utf8 ,
735736 Volatility :: Immutable ,
736737 Arc :: new ( func) ,
737738 )
738739}
739740
740- pub fn create_current_database_udf ( name : & str ) -> ScalarUDF {
741+ pub fn create_current_database_udf ( ) -> ScalarUDF {
741742 // Define the function implementation
742743 let func = move |_args : & [ ColumnarValue ] | {
743744 // Create a UTF8 array with a single value
@@ -750,30 +751,7 @@ pub fn create_current_database_udf(name: &str) -> ScalarUDF {
750751
751752 // Wrap the implementation in a scalar function
752753 create_udf (
753- name,
754- vec ! [ ] ,
755- DataType :: Utf8 ,
756- Volatility :: Immutable ,
757- Arc :: new ( func) ,
758- )
759- }
760-
761- pub fn create_version_udf ( ) -> ScalarUDF {
762- // Define the function implementation
763- let func = move |_args : & [ ColumnarValue ] | {
764- // Create a UTF8 array with version information
765- let mut builder = StringBuilder :: new ( ) ;
766- // TODO: improve version string generation
767- builder
768- . append_value ( "DataFusion PostgreSQL 48.0.0 on x86_64-pc-linux-gnu, compiled by Rust" ) ;
769- let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
770-
771- Ok ( ColumnarValue :: Array ( array) )
772- } ;
773-
774- // Wrap the implementation in a scalar function
775- create_udf (
776- "version" ,
754+ "current_database" ,
777755 vec ! [ ] ,
778756 DataType :: Utf8 ,
779757 Volatility :: Immutable ,
@@ -800,15 +778,15 @@ pub fn create_pg_get_userbyid_udf() -> ScalarUDF {
800778
801779 // Wrap the implementation in a scalar function
802780 create_udf (
803- "pg_catalog. pg_get_userbyid" ,
781+ "pg_get_userbyid" ,
804782 vec ! [ DataType :: Int32 ] ,
805783 DataType :: Utf8 ,
806784 Volatility :: Stable ,
807785 Arc :: new ( func) ,
808786 )
809787}
810788
811- pub fn create_pg_table_is_visible ( name : & str ) -> ScalarUDF {
789+ pub fn create_pg_table_is_visible ( ) -> ScalarUDF {
812790 // Define the function implementation
813791 let func = move |args : & [ ColumnarValue ] | {
814792 let args = ColumnarValue :: values_to_arrays ( args) ?;
@@ -827,24 +805,42 @@ pub fn create_pg_table_is_visible(name: &str) -> ScalarUDF {
827805
828806 // Wrap the implementation in a scalar function
829807 create_udf (
830- name ,
808+ "pg_table_is_visible" ,
831809 vec ! [ DataType :: Int32 ] ,
832810 DataType :: Boolean ,
833811 Volatility :: Stable ,
834812 Arc :: new ( func) ,
835813 )
836814}
837815
838- pub fn create_format_type_udf ( ) -> ScalarUDF {
816+ pub fn create_session_user_udf ( ) -> ScalarUDF {
817+ let func = move |_args : & [ ColumnarValue ] | {
818+ let mut builder = StringBuilder :: new ( ) ;
819+ // TODO: return real user
820+ builder. append_value ( "postgres" ) ;
821+
822+ let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
823+
824+ Ok ( ColumnarValue :: Array ( array) )
825+ } ;
826+
827+ create_udf (
828+ "session_user" ,
829+ vec ! [ ] ,
830+ DataType :: Utf8 ,
831+ Volatility :: Stable ,
832+ Arc :: new ( func) ,
833+ )
834+ }
835+
836+ pub fn create_pg_get_partkeydef_udf ( ) -> ScalarUDF {
839837 let func = move |args : & [ ColumnarValue ] | {
840838 let args = ColumnarValue :: values_to_arrays ( args) ?;
841- let type_oids = & args[ 0 ] ; // Table (can be name or OID)
842- let _type_mods = & args[ 1 ] ; // Privilege type (SELECT, INSERT, etc.)
839+ let oid = & args[ 0 ] ;
843840
844- // For now, always return true (full access for current user)
845841 let mut builder = StringBuilder :: new ( ) ;
846- for _ in 0 ..type_oids . len ( ) {
847- builder. append_value ( "??? " ) ;
842+ for _ in 0 ..oid . len ( ) {
843+ builder. append_value ( "" ) ;
848844 }
849845
850846 let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
@@ -853,42 +849,46 @@ pub fn create_format_type_udf() -> ScalarUDF {
853849 } ;
854850
855851 create_udf (
856- "format_type " ,
857- vec ! [ DataType :: Int64 , DataType :: Int32 ] ,
852+ "pg_get_partkeydef " ,
853+ vec ! [ DataType :: Utf8 ] ,
858854 DataType :: Utf8 ,
859855 Volatility :: Stable ,
860856 Arc :: new ( func) ,
861857 )
862858}
863859
864- pub fn create_session_user_udf ( ) -> ScalarUDF {
865- let func = move |_args : & [ ColumnarValue ] | {
866- let mut builder = StringBuilder :: new ( ) ;
867- // TODO: return real user
868- builder. append_value ( "postgres" ) ;
860+ pub fn create_pg_relation_is_publishable_udf ( ) -> ScalarUDF {
861+ let func = move |args : & [ ColumnarValue ] | {
862+ let args = ColumnarValue :: values_to_arrays ( args) ?;
863+ let oid = & args[ 0 ] ;
864+
865+ let mut builder = BooleanBuilder :: new ( ) ;
866+ for _ in 0 ..oid. len ( ) {
867+ builder. append_value ( true ) ;
868+ }
869869
870870 let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
871871
872872 Ok ( ColumnarValue :: Array ( array) )
873873 } ;
874874
875875 create_udf (
876- "session_user " ,
877- vec ! [ ] ,
878- DataType :: Utf8 ,
876+ "pg_relation_is_publishable " ,
877+ vec ! [ DataType :: Int32 ] ,
878+ DataType :: Boolean ,
879879 Volatility :: Stable ,
880880 Arc :: new ( func) ,
881881 )
882882}
883883
884- pub fn create_pg_get_partkeydef_udf ( ) -> ScalarUDF {
884+ pub fn create_pg_get_statisticsobjdef_columns_udf ( ) -> ScalarUDF {
885885 let func = move |args : & [ ColumnarValue ] | {
886886 let args = ColumnarValue :: values_to_arrays ( args) ?;
887887 let oid = & args[ 0 ] ;
888888
889- let mut builder = StringBuilder :: new ( ) ;
889+ let mut builder = BooleanBuilder :: new ( ) ;
890890 for _ in 0 ..oid. len ( ) {
891- builder. append_value ( "" ) ;
891+ builder. append_null ( ) ;
892892 }
893893
894894 let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
@@ -897,8 +897,8 @@ pub fn create_pg_get_partkeydef_udf() -> ScalarUDF {
897897 } ;
898898
899899 create_udf (
900- "pg_catalog.pg_get_partkeydef " ,
901- vec ! [ DataType :: Utf8 ] ,
900+ "pg_get_statisticsobjdef_columns " ,
901+ vec ! [ DataType :: UInt32 ] ,
902902 DataType :: Utf8 ,
903903 Volatility :: Stable ,
904904 Arc :: new ( func) ,
@@ -924,38 +924,28 @@ pub fn setup_pg_catalog(
924924 } ) ?
925925 . register_schema ( "pg_catalog" , Arc :: new ( pg_catalog) ) ?;
926926
927- session_context. register_udf ( create_current_database_udf ( "current_database" ) ) ;
928- session_context. register_udf ( create_current_schema_udf ( "current_schema" ) ) ;
929- session_context. register_udf ( create_current_schema_udf ( "pg_catalog.current_schema" ) ) ;
930- session_context. register_udf ( create_current_schemas_udf ( "current_schemas" ) ) ;
931- session_context. register_udf ( create_current_schemas_udf ( "pg_catalog.current_schemas" ) ) ;
932- session_context. register_udf ( create_version_udf ( ) ) ;
927+ session_context. register_udf ( create_current_database_udf ( ) ) ;
928+ session_context. register_udf ( create_current_schema_udf ( ) ) ;
929+ session_context. register_udf ( create_current_schemas_udf ( ) ) ;
930+ // session_context.register_udf(create_version_udf());
933931 session_context. register_udf ( create_pg_get_userbyid_udf ( ) ) ;
934932 session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
935933 "has_table_privilege" ,
936934 ) ) ;
937- session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
938- "pg_catalog.has_table_privilege" ,
939- ) ) ;
940935 session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
941936 "has_schema_privilege" ,
942937 ) ) ;
943- session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
944- "pg_catalog.has_schema_privilege" ,
945- ) ) ;
946938 session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
947939 "has_any_column_privilege" ,
948940 ) ) ;
949- session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
950- "pg_catalog.has_any_column_privilege" ,
951- ) ) ;
952- session_context. register_udf ( create_pg_table_is_visible ( "pg_table_is_visible" ) ) ;
953- session_context. register_udf ( create_pg_table_is_visible ( "pg_catalog.pg_table_is_visible" ) ) ;
954- session_context. register_udf ( create_format_type_udf ( ) ) ;
941+ session_context. register_udf ( create_pg_table_is_visible ( ) ) ;
942+ session_context. register_udf ( format_type:: create_format_type_udf ( ) ) ;
955943 session_context. register_udf ( create_session_user_udf ( ) ) ;
956944 session_context. register_udtf ( "pg_get_keywords" , static_tables. pg_get_keywords . clone ( ) ) ;
957945 session_context. register_udf ( pg_get_expr_udf:: create_pg_get_expr_udf ( ) ) ;
958946 session_context. register_udf ( create_pg_get_partkeydef_udf ( ) ) ;
947+ session_context. register_udf ( create_pg_relation_is_publishable_udf ( ) ) ;
948+ session_context. register_udf ( create_pg_get_statisticsobjdef_columns_udf ( ) ) ;
959949
960950 Ok ( ( ) )
961951}
0 commit comments