@@ -290,33 +290,35 @@ public fun DataFrame.Companion.readResultSet(
290290}
291291
292292/* *
293- * Reads all tables from the given database using the provided database configuration and limit.
293+ * Reads all non-system tables from a database and returns them
294+ * as a map of SQL tables and corresponding dataframes using the provided database configuration and limit.
294295 *
295296 * @param [dbConfig] the database configuration to connect to the database, including URL, user, and password.
296297 * @param [limit] the maximum number of rows to read from each table.
297298 * @param [catalogue] a name of the catalog from which tables will be retrieved. A null value retrieves tables from all catalogs.
298299 * @param [inferNullability] indicates how the column nullability should be inferred.
299- * @return a list of [AnyFrame] objects representing the non-system tables from the database.
300+ * @return a map of [String] to [AnyFrame] objects representing the non-system tables from the database.
300301 */
301302public fun DataFrame.Companion.readAllSqlTables (
302303 dbConfig : DatabaseConfiguration ,
303304 catalogue : String? = null,
304305 limit : Int = DEFAULT_LIMIT ,
305306 inferNullability : Boolean = true,
306- ): List < AnyFrame > {
307+ ): Map < String , AnyFrame > {
307308 DriverManager .getConnection(dbConfig.url, dbConfig.user, dbConfig.password).use { connection ->
308309 return readAllSqlTables(connection, catalogue, limit, inferNullability)
309310 }
310311}
311312
312313/* *
313- * Reads all non-system tables from a database and returns them as a list of data frames.
314+ * Reads all non-system tables from a database and returns them
315+ * as a map of SQL tables and corresponding dataframes.
314316 *
315317 * @param [connection] the database connection to read tables from.
316318 * @param [limit] the maximum number of rows to read from each table.
317319 * @param [catalogue] a name of the catalog from which tables will be retrieved. A null value retrieves tables from all catalogs.
318320 * @param [inferNullability] indicates how the column nullability should be inferred.
319- * @return a list of [AnyFrame] objects representing the non-system tables from the database.
321+ * @return a map of [String] to [AnyFrame] objects representing the non-system tables from the database.
320322 *
321323 * @see DriverManager.getConnection
322324 */
@@ -325,20 +327,20 @@ public fun DataFrame.Companion.readAllSqlTables(
325327 catalogue : String? = null,
326328 limit : Int = DEFAULT_LIMIT ,
327329 inferNullability : Boolean = true,
328- ): List < AnyFrame > {
330+ ): Map < String , AnyFrame > {
329331 val metaData = connection.metaData
330332 val url = connection.metaData.url
331333 val dbType = extractDBTypeFromUrl(url)
332334
333- // exclude a system and other tables without data, but it looks like it supported badly for many databases
335+ // exclude a system and other tables without data, but it looks like it is supported badly for many databases
334336 val tables = metaData.getTables(catalogue, null , null , arrayOf(" TABLE" ))
335337
336- val dataFrames = mutableListOf< AnyFrame >()
338+ val dataFrames = mutableMapOf< String , AnyFrame >()
337339
338340 while (tables.next()) {
339341 val table = dbType.buildTableMetadata(tables)
340342 if (! dbType.isSystemTable(table)) {
341- // we filter her second time because of specific logic with SQLite and possible issues with future databases
343+ // we filter here a second time because of specific logic with SQLite and possible issues with future databases
342344 val tableName = when {
343345 catalogue != null && table.schemaName != null -> " $catalogue .${table.schemaName} .${table.name} "
344346 catalogue != null && table.schemaName == null -> " $catalogue .${table.name} "
@@ -351,7 +353,7 @@ public fun DataFrame.Companion.readAllSqlTables(
351353 logger.debug { " Reading table: $tableName " }
352354
353355 val dataFrame = readSqlTable(connection, tableName, limit, inferNullability)
354- dataFrames + = dataFrame
356+ dataFrames + = tableName to dataFrame
355357 logger.debug { " Finished reading table: $tableName " }
356358 }
357359 }
@@ -474,24 +476,24 @@ public fun DataFrame.Companion.getSchemaForResultSet(resultSet: ResultSet, conne
474476}
475477
476478/* *
477- * Retrieves the schema of all non-system tables in the database using the provided database configuration.
479+ * Retrieves the schemas of all non-system tables in the database using the provided database configuration.
478480 *
479481 * @param [dbConfig] the database configuration to connect to the database, including URL, user, and password.
480- * @return a list of [DataFrameSchema] objects representing the schema of each non-system table.
482+ * @return a map of [String, DataFrameSchema] objects representing the table name and its schema for each non-system table.
481483 */
482- public fun DataFrame.Companion.getSchemaForAllSqlTables (dbConfig : DatabaseConfiguration ): List < DataFrameSchema > {
484+ public fun DataFrame.Companion.getSchemaForAllSqlTables (dbConfig : DatabaseConfiguration ): Map < String , DataFrameSchema > {
483485 DriverManager .getConnection(dbConfig.url, dbConfig.user, dbConfig.password).use { connection ->
484486 return getSchemaForAllSqlTables(connection)
485487 }
486488}
487489
488490/* *
489- * Retrieves the schema of all non-system tables in the database using the provided database connection.
491+ * Retrieves the schemas of all non-system tables in the database using the provided database connection.
490492 *
491493 * @param [connection] the database connection.
492- * @return a list of [DataFrameSchema] objects representing the schema of each non-system table.
494+ * @return a map of [String, DataFrameSchema] objects representing the table name and its schema for each non-system table.
493495 */
494- public fun DataFrame.Companion.getSchemaForAllSqlTables (connection : Connection ): List < DataFrameSchema > {
496+ public fun DataFrame.Companion.getSchemaForAllSqlTables (connection : Connection ): Map < String , DataFrameSchema > {
495497 val metaData = connection.metaData
496498 val url = connection.metaData.url
497499 val dbType = extractDBTypeFromUrl(url)
@@ -500,14 +502,15 @@ public fun DataFrame.Companion.getSchemaForAllSqlTables(connection: Connection):
500502 // exclude a system and other tables without data
501503 val tables = metaData.getTables(null , null , null , tableTypes)
502504
503- val dataFrameSchemas = mutableListOf< DataFrameSchema >()
505+ val dataFrameSchemas = mutableMapOf< String , DataFrameSchema >()
504506
505507 while (tables.next()) {
506508 val jdbcTable = dbType.buildTableMetadata(tables)
507509 if (! dbType.isSystemTable(jdbcTable)) {
508- // we filter her second time because of specific logic with SQLite and possible issues with future databases
509- val dataFrameSchema = getSchemaForSqlTable(connection, jdbcTable.name)
510- dataFrameSchemas + = dataFrameSchema
510+ // we filter her a second time because of specific logic with SQLite and possible issues with future databases
511+ val tableName = jdbcTable.name
512+ val dataFrameSchema = getSchemaForSqlTable(connection, tableName)
513+ dataFrameSchemas + = tableName to dataFrameSchema
511514 }
512515 }
513516
0 commit comments