@@ -686,7 +686,7 @@ impl PgCatalogStaticTables {
686686 }
687687}
688688
689- pub fn create_current_schemas_udf ( name : & str ) -> ScalarUDF {
689+ pub fn create_current_schemas_udf ( ) -> ScalarUDF {
690690 // Define the function implementation
691691 let func = move |args : & [ ColumnarValue ] | {
692692 let args = ColumnarValue :: values_to_arrays ( args) ?;
@@ -709,15 +709,15 @@ pub fn create_current_schemas_udf(name: &str) -> ScalarUDF {
709709
710710 // Wrap the implementation in a scalar function
711711 create_udf (
712- name ,
712+ "current_schemas" ,
713713 vec ! [ DataType :: Boolean ] ,
714714 DataType :: List ( Arc :: new ( Field :: new ( "schema" , DataType :: Utf8 , false ) ) ) ,
715715 Volatility :: Immutable ,
716716 Arc :: new ( func) ,
717717 )
718718}
719719
720- pub fn create_current_schema_udf ( name : & str ) -> ScalarUDF {
720+ pub fn create_current_schema_udf ( ) -> ScalarUDF {
721721 // Define the function implementation
722722 let func = move |_args : & [ ColumnarValue ] | {
723723 // Create a UTF8 array with a single value
@@ -730,15 +730,15 @@ pub fn create_current_schema_udf(name: &str) -> ScalarUDF {
730730
731731 // Wrap the implementation in a scalar function
732732 create_udf (
733- name ,
733+ "current_schema" ,
734734 vec ! [ ] ,
735735 DataType :: Utf8 ,
736736 Volatility :: Immutable ,
737737 Arc :: new ( func) ,
738738 )
739739}
740740
741- pub fn create_current_database_udf ( name : & str ) -> ScalarUDF {
741+ pub fn create_current_database_udf ( ) -> ScalarUDF {
742742 // Define the function implementation
743743 let func = move |_args : & [ ColumnarValue ] | {
744744 // Create a UTF8 array with a single value
@@ -751,30 +751,7 @@ pub fn create_current_database_udf(name: &str) -> ScalarUDF {
751751
752752 // Wrap the implementation in a scalar function
753753 create_udf (
754- name,
755- vec ! [ ] ,
756- DataType :: Utf8 ,
757- Volatility :: Immutable ,
758- Arc :: new ( func) ,
759- )
760- }
761-
762- pub fn create_version_udf ( ) -> ScalarUDF {
763- // Define the function implementation
764- let func = move |_args : & [ ColumnarValue ] | {
765- // Create a UTF8 array with version information
766- let mut builder = StringBuilder :: new ( ) ;
767- // TODO: improve version string generation
768- builder
769- . append_value ( "DataFusion PostgreSQL 48.0.0 on x86_64-pc-linux-gnu, compiled by Rust" ) ;
770- let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
771-
772- Ok ( ColumnarValue :: Array ( array) )
773- } ;
774-
775- // Wrap the implementation in a scalar function
776- create_udf (
777- "version" ,
754+ "current_database" ,
778755 vec ! [ ] ,
779756 DataType :: Utf8 ,
780757 Volatility :: Immutable ,
@@ -801,15 +778,15 @@ pub fn create_pg_get_userbyid_udf() -> ScalarUDF {
801778
802779 // Wrap the implementation in a scalar function
803780 create_udf (
804- "pg_catalog. pg_get_userbyid" ,
781+ "pg_get_userbyid" ,
805782 vec ! [ DataType :: Int32 ] ,
806783 DataType :: Utf8 ,
807784 Volatility :: Stable ,
808785 Arc :: new ( func) ,
809786 )
810787}
811788
812- pub fn create_pg_table_is_visible ( name : & str ) -> ScalarUDF {
789+ pub fn create_pg_table_is_visible ( ) -> ScalarUDF {
813790 // Define the function implementation
814791 let func = move |args : & [ ColumnarValue ] | {
815792 let args = ColumnarValue :: values_to_arrays ( args) ?;
@@ -828,17 +805,17 @@ pub fn create_pg_table_is_visible(name: &str) -> ScalarUDF {
828805
829806 // Wrap the implementation in a scalar function
830807 create_udf (
831- name ,
808+ "pg_table_is_visible" ,
832809 vec ! [ DataType :: Int32 ] ,
833810 DataType :: Boolean ,
834811 Volatility :: Stable ,
835812 Arc :: new ( func) ,
836813 )
837814}
838815
839- pub fn create_format_type_udf ( name : & str ) -> ScalarUDF {
816+ pub fn create_format_type_udf ( ) -> ScalarUDF {
840817 create_udf (
841- name ,
818+ "format_type" ,
842819 vec ! [ DataType :: Int64 , DataType :: Int32 ] ,
843820 DataType :: Utf8 ,
844821 Volatility :: Stable ,
@@ -882,15 +859,15 @@ pub fn create_pg_get_partkeydef_udf() -> ScalarUDF {
882859 } ;
883860
884861 create_udf (
885- "pg_catalog. pg_get_partkeydef" ,
862+ "pg_get_partkeydef" ,
886863 vec ! [ DataType :: Utf8 ] ,
887864 DataType :: Utf8 ,
888865 Volatility :: Stable ,
889866 Arc :: new ( func) ,
890867 )
891868}
892869
893- pub fn create_pg_relation_is_publishable_udf ( name : & str ) -> ScalarUDF {
870+ pub fn create_pg_relation_is_publishable_udf ( ) -> ScalarUDF {
894871 let func = move |args : & [ ColumnarValue ] | {
895872 let args = ColumnarValue :: values_to_arrays ( args) ?;
896873 let oid = & args[ 0 ] ;
@@ -906,14 +883,38 @@ pub fn create_pg_relation_is_publishable_udf(name: &str) -> ScalarUDF {
906883 } ;
907884
908885 create_udf (
909- name ,
886+ "pg_relation_is_publishable" ,
910887 vec ! [ DataType :: Int32 ] ,
911888 DataType :: Boolean ,
912889 Volatility :: Stable ,
913890 Arc :: new ( func) ,
914891 )
915892}
916893
894+ pub fn create_pg_get_statisticsobjdef_columns_udf ( ) -> ScalarUDF {
895+ let func = move |args : & [ ColumnarValue ] | {
896+ let args = ColumnarValue :: values_to_arrays ( args) ?;
897+ let oid = & args[ 0 ] ;
898+
899+ let mut builder = BooleanBuilder :: new ( ) ;
900+ for _ in 0 ..oid. len ( ) {
901+ builder. append_null ( ) ;
902+ }
903+
904+ let array: ArrayRef = Arc :: new ( builder. finish ( ) ) ;
905+
906+ Ok ( ColumnarValue :: Array ( array) )
907+ } ;
908+
909+ create_udf (
910+ "pg_get_statisticsobjdef_columns" ,
911+ vec ! [ DataType :: UInt32 ] ,
912+ DataType :: Utf8 ,
913+ Volatility :: Stable ,
914+ Arc :: new ( func) ,
915+ )
916+ }
917+
917918/// Install pg_catalog and postgres UDFs to current `SessionContext`
918919pub fn setup_pg_catalog (
919920 session_context : & SessionContext ,
@@ -933,42 +934,28 @@ pub fn setup_pg_catalog(
933934 } ) ?
934935 . register_schema ( "pg_catalog" , Arc :: new ( pg_catalog) ) ?;
935936
936- session_context. register_udf ( create_current_database_udf ( "current_database" ) ) ;
937- session_context. register_udf ( create_current_schema_udf ( "current_schema" ) ) ;
938- session_context. register_udf ( create_current_schema_udf ( "pg_catalog.current_schema" ) ) ;
939- session_context. register_udf ( create_current_schemas_udf ( "current_schemas" ) ) ;
940- session_context. register_udf ( create_current_schemas_udf ( "pg_catalog.current_schemas" ) ) ;
941- session_context. register_udf ( create_version_udf ( ) ) ;
937+ session_context. register_udf ( create_current_database_udf ( ) ) ;
938+ session_context. register_udf ( create_current_schema_udf ( ) ) ;
939+ session_context. register_udf ( create_current_schemas_udf ( ) ) ;
940+ // session_context.register_udf(create_version_udf());
942941 session_context. register_udf ( create_pg_get_userbyid_udf ( ) ) ;
943942 session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
944943 "has_table_privilege" ,
945944 ) ) ;
946- session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
947- "pg_catalog.has_table_privilege" ,
948- ) ) ;
949945 session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
950946 "has_schema_privilege" ,
951947 ) ) ;
952- session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
953- "pg_catalog.has_schema_privilege" ,
954- ) ) ;
955948 session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
956949 "has_any_column_privilege" ,
957950 ) ) ;
958- session_context. register_udf ( has_privilege_udf:: create_has_privilege_udf (
959- "pg_catalog.has_any_column_privilege" ,
960- ) ) ;
961- session_context. register_udf ( create_pg_table_is_visible ( "pg_table_is_visible" ) ) ;
962- session_context. register_udf ( create_pg_table_is_visible ( "pg_catalog.pg_table_is_visible" ) ) ;
963- session_context. register_udf ( create_format_type_udf ( "format_type" ) ) ;
964- session_context. register_udf ( create_format_type_udf ( "pg_catalog.format_type" ) ) ;
951+ session_context. register_udf ( create_pg_table_is_visible ( ) ) ;
952+ session_context. register_udf ( create_format_type_udf ( ) ) ;
965953 session_context. register_udf ( create_session_user_udf ( ) ) ;
966954 session_context. register_udtf ( "pg_get_keywords" , static_tables. pg_get_keywords . clone ( ) ) ;
967955 session_context. register_udf ( pg_get_expr_udf:: create_pg_get_expr_udf ( ) ) ;
968956 session_context. register_udf ( create_pg_get_partkeydef_udf ( ) ) ;
969- session_context. register_udf ( create_pg_relation_is_publishable_udf (
970- "pg_catalog.pg_relation_is_publishable" ,
971- ) ) ;
957+ session_context. register_udf ( create_pg_relation_is_publishable_udf ( ) ) ;
958+ session_context. register_udf ( create_pg_get_statisticsobjdef_columns_udf ( ) ) ;
972959
973960 Ok ( ( ) )
974961}
0 commit comments