99import com .databricks .jdbc .api .internal .IDatabricksSession ;
1010import com .databricks .jdbc .common .*;
1111import com .databricks .jdbc .common .util .DriverUtil ;
12- import com .databricks .jdbc .common .util .JdbcThreadUtils ;
1312import com .databricks .jdbc .dbclient .impl .common .MetadataResultSetBuilder ;
1413import com .databricks .jdbc .dbclient .impl .common .StatementId ;
1514import com .databricks .jdbc .exception .DatabricksSQLException ;
2019import com .databricks .sdk .service .sql .StatementState ;
2120import java .sql .*;
2221import java .util .*;
23- import java .util .concurrent .ExecutorService ;
24- import java .util .concurrent .Executors ;
2522
2623public class DatabricksDatabaseMetaData implements DatabaseMetaData {
2724
@@ -40,9 +37,6 @@ public class DatabricksDatabaseMetaData implements DatabaseMetaData {
4037 public static final String SYSTEM_FUNCTIONS = "DATABASE,IFNULL,USER" ;
4138 public static final String TIME_DATE_FUNCTIONS =
4239 "CURDATE,CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP,CURTIME,DAYNAME,DAYOFMONTH,DAYOFWEEK,DAYOFYEAR,HOUR,MINUTE,MONTH,MONTHNAME,NOW,QUARTER,SECOND,TIMESTAMPADD,TIMESTAMPDIFF,WEEK,YEAR" ;
43- private static final Object THREAD_POOL_LOCK = new Object ();
44- private static ExecutorService schemasThreadPool = null ;
45- private static final int DEFAULT_MAX_THREADS = 10 ;
4640 private final IDatabricksConnectionInternal connection ;
4741 private final IDatabricksSession session ;
4842 private final MetadataResultSetBuilder metadataResultSetBuilder ;
@@ -1505,48 +1499,6 @@ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLExce
15051499 catalog , schemaPattern );
15061500 throwExceptionIfConnectionIsClosed ();
15071501
1508- if (session .getConnectionContext ().getClientType () == DatabricksClientType .SEA
1509- && (catalog == null || catalog .equals ("*" ) || catalog .equals ("%" ))) {
1510- // Fetch catalogs from the metadata client
1511- List <String > catalogList = new ArrayList <>();
1512- try (ResultSet catalogs = getCatalogs ()) {
1513- while (catalogs .next ()) {
1514- String c = catalogs .getString (1 );
1515- if (c != null && !c .isEmpty ()) {
1516- catalogList .add (c );
1517- }
1518- }
1519- }
1520-
1521- // Process catalogs in parallel, gathering schema information
1522- List <List <Object >> schemaRows =
1523- JdbcThreadUtils .parallelFlatMap (
1524- catalogList ,
1525- session .getConnectionContext (),
1526- DEFAULT_MAX_THREADS , // Not significant since the executor is provided as a parameter
1527- 90 , // 90 seconds timeout
1528- c -> {
1529- List <List <Object >> rows = new ArrayList <>();
1530- try (ResultSet catalogSchemas =
1531- session .getDatabricksMetadataClient ().listSchemas (session , c , schemaPattern )) {
1532- while (catalogSchemas .next ()) {
1533- List <Object > schemaRow = new ArrayList <>();
1534- schemaRow .add (catalogSchemas .getString (1 )); // TABLE_SCHEM
1535- schemaRow .add (catalogSchemas .getString (2 )); // TABLE_CATALOG
1536- rows .add (schemaRow );
1537- }
1538- } catch (SQLException e ) {
1539- LOGGER .warn ("Error fetching schemas for catalog %s %s" , c , e .getMessage ());
1540- }
1541- return rows ;
1542- },
1543- getOrCreateSchemasThreadPool ());
1544-
1545- // Convert combined data into a result set
1546- return metadataResultSetBuilder .getResultSetWithGivenRowsAndColumns (
1547- SCHEMA_COLUMNS , schemaRows , METADATA_STATEMENT_ID , CommandName .LIST_SCHEMAS );
1548- }
1549-
15501502 return session .getDatabricksMetadataClient ().listSchemas (session , catalog , schemaPattern );
15511503 }
15521504
@@ -1659,23 +1611,6 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException {
16591611 return iface != null && iface .isAssignableFrom (this .getClass ());
16601612 }
16611613
1662- private static ExecutorService getOrCreateSchemasThreadPool () {
1663- synchronized (THREAD_POOL_LOCK ) {
1664- if (schemasThreadPool == null || schemasThreadPool .isShutdown ()) {
1665- // Could read max threads from a configuration property
1666- schemasThreadPool =
1667- Executors .newFixedThreadPool (
1668- DEFAULT_MAX_THREADS ,
1669- r -> {
1670- Thread t = new Thread (r , "jdbc-schemas-fetcher" );
1671- t .setDaemon (true );
1672- return t ;
1673- });
1674- }
1675- return schemasThreadPool ;
1676- }
1677- }
1678-
16791614 private void throwExceptionIfConnectionIsClosed () throws SQLException {
16801615 LOGGER .debug ("private void throwExceptionIfConnectionIsClosed()" );
16811616 if (!connection .getSession ().isOpen ()) {
0 commit comments