@@ -37,7 +37,7 @@ use databend_common_expression::utils::FromData;
3737use databend_common_expression:: Constant ;
3838use databend_common_expression:: DataBlock ;
3939use databend_common_expression:: Expr ;
40- use databend_common_expression:: Scalar ;
40+ use databend_common_expression:: FunctionContext ;
4141use databend_common_expression:: TableDataType ;
4242use databend_common_expression:: TableField ;
4343use databend_common_expression:: TableSchemaRef ;
@@ -62,7 +62,7 @@ use log::warn;
6262
6363use crate :: table:: AsyncOneBlockSystemTable ;
6464use crate :: table:: AsyncSystemTable ;
65- use crate :: util:: find_eq_filter ;
65+ use crate :: util:: extract_leveled_strings ;
6666use crate :: util:: generate_catalog_meta;
6767
6868pub struct TablesTable < const WITH_HISTORY : bool , const WITHOUT_VIEW : bool > {
@@ -176,8 +176,9 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
176176 . disable_table_info_refresh ( ) ?;
177177
178178 // Optimization target: Fast path for known iceberg catalog SHOW TABLES
179+ let func_ctx = ctx. get_function_context ( ) ?;
179180 if let Some ( ( catalog_name, db_name) ) =
180- self . is_external_show_tables_query ( & push_downs, & catalog)
181+ self . is_external_show_tables_query ( & func_ctx , & push_downs, & catalog)
181182 {
182183 self . show_tables_from_external_catalog ( ctx, catalog_name, db_name)
183184 . await
@@ -1047,11 +1048,11 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
10471048
10481049 fn is_external_show_tables_query (
10491050 & self ,
1051+ func_ctx : & FunctionContext ,
10501052 push_downs : & Option < PushDownInfo > ,
10511053 catalog : & Arc < dyn Catalog > ,
10521054 ) -> Option < ( String , String ) > {
10531055 if !WITH_HISTORY && WITHOUT_VIEW {
1054- let mut database_name = None ;
10551056 // Check projection
10561057 if let Some ( push_downs) = push_downs {
10571058 if let Some ( Projection :: Columns ( projection_indices) ) = & push_downs. projection {
@@ -1074,34 +1075,26 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
10741075 return None ;
10751076 }
10761077
1077- // Check filters (catalog name)
1078- let mut catalog_name = None ;
1078+ let mut filtered_catalog_names = vec ! [ ] ;
1079+ let mut filtered_db_names = vec ! [ ] ;
10791080
10801081 if let Some ( filter) = push_downs. filters . as_ref ( ) . map ( |f| & f. filter ) {
10811082 let expr = filter. as_expr ( & BUILTIN_FUNCTIONS ) ;
1082- find_eq_filter ( & expr, & mut |col_name, scalar| {
1083- if col_name == "catalog" {
1084- if let Scalar :: String ( catalog) = scalar {
1085- catalog_name = Some ( catalog. to_string ( ) ) ;
1086- }
1087- }
1088- if col_name == "database" {
1089- if let Scalar :: String ( db) = scalar {
1090- database_name = Some ( db. to_string ( ) ) ;
1091- }
1092- }
1093- Ok ( ( ) )
1094- } ) ;
1083+ ( filtered_catalog_names, filtered_db_names) =
1084+ extract_leveled_strings ( & expr, & [ "catalog" , "database" ] , func_ctx)
1085+ . ok ( ) ?;
10951086 }
10961087
10971088 // Check iceberg catalog existence
1098- if let Some ( catalog_name) = catalog_name {
1099- if let Some ( database_name) = database_name {
1100- if catalog. name ( ) == catalog_name {
1101- if let CatalogType :: Iceberg = catalog. info ( ) . catalog_type ( ) {
1102- return Some ( ( catalog_name, database_name) ) ;
1103- }
1104- }
1089+ if filtered_catalog_names. len ( ) == 1
1090+ && filtered_db_names. len ( ) == 1
1091+ && catalog. name ( ) == filtered_catalog_names[ 0 ] . clone ( )
1092+ {
1093+ if let CatalogType :: Iceberg = catalog. info ( ) . catalog_type ( ) {
1094+ return Some ( (
1095+ filtered_catalog_names[ 0 ] . clone ( ) ,
1096+ filtered_db_names[ 0 ] . clone ( ) ,
1097+ ) ) ;
11051098 }
11061099 }
11071100 }
0 commit comments