@@ -290,33 +290,35 @@ public fun DataFrame.Companion.readResultSet(
290
290
}
291
291
292
292
/* *
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.
294
295
*
295
296
* @param [dbConfig] the database configuration to connect to the database, including URL, user, and password.
296
297
* @param [limit] the maximum number of rows to read from each table.
297
298
* @param [catalogue] a name of the catalog from which tables will be retrieved. A null value retrieves tables from all catalogs.
298
299
* @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.
300
301
*/
301
302
public fun DataFrame.Companion.readAllSqlTables (
302
303
dbConfig : DatabaseConfiguration ,
303
304
catalogue : String? = null,
304
305
limit : Int = DEFAULT_LIMIT ,
305
306
inferNullability : Boolean = true,
306
- ): List < AnyFrame > {
307
+ ): Map < String , AnyFrame > {
307
308
DriverManager .getConnection(dbConfig.url, dbConfig.user, dbConfig.password).use { connection ->
308
309
return readAllSqlTables(connection, catalogue, limit, inferNullability)
309
310
}
310
311
}
311
312
312
313
/* *
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.
314
316
*
315
317
* @param [connection] the database connection to read tables from.
316
318
* @param [limit] the maximum number of rows to read from each table.
317
319
* @param [catalogue] a name of the catalog from which tables will be retrieved. A null value retrieves tables from all catalogs.
318
320
* @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.
320
322
*
321
323
* @see DriverManager.getConnection
322
324
*/
@@ -325,20 +327,20 @@ public fun DataFrame.Companion.readAllSqlTables(
325
327
catalogue : String? = null,
326
328
limit : Int = DEFAULT_LIMIT ,
327
329
inferNullability : Boolean = true,
328
- ): List < AnyFrame > {
330
+ ): Map < String , AnyFrame > {
329
331
val metaData = connection.metaData
330
332
val url = connection.metaData.url
331
333
val dbType = extractDBTypeFromUrl(url)
332
334
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
334
336
val tables = metaData.getTables(catalogue, null , null , arrayOf(" TABLE" ))
335
337
336
- val dataFrames = mutableListOf< AnyFrame >()
338
+ val dataFrames = mutableMapOf< String , AnyFrame >()
337
339
338
340
while (tables.next()) {
339
341
val table = dbType.buildTableMetadata(tables)
340
342
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
342
344
val tableName = when {
343
345
catalogue != null && table.schemaName != null -> " $catalogue .${table.schemaName} .${table.name} "
344
346
catalogue != null && table.schemaName == null -> " $catalogue .${table.name} "
@@ -351,7 +353,7 @@ public fun DataFrame.Companion.readAllSqlTables(
351
353
logger.debug { " Reading table: $tableName " }
352
354
353
355
val dataFrame = readSqlTable(connection, tableName, limit, inferNullability)
354
- dataFrames + = dataFrame
356
+ dataFrames + = tableName to dataFrame
355
357
logger.debug { " Finished reading table: $tableName " }
356
358
}
357
359
}
@@ -474,24 +476,24 @@ public fun DataFrame.Companion.getSchemaForResultSet(resultSet: ResultSet, conne
474
476
}
475
477
476
478
/* *
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.
478
480
*
479
481
* @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.
481
483
*/
482
- public fun DataFrame.Companion.getSchemaForAllSqlTables (dbConfig : DatabaseConfiguration ): List < DataFrameSchema > {
484
+ public fun DataFrame.Companion.getSchemaForAllSqlTables (dbConfig : DatabaseConfiguration ): Map < String , DataFrameSchema > {
483
485
DriverManager .getConnection(dbConfig.url, dbConfig.user, dbConfig.password).use { connection ->
484
486
return getSchemaForAllSqlTables(connection)
485
487
}
486
488
}
487
489
488
490
/* *
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.
490
492
*
491
493
* @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.
493
495
*/
494
- public fun DataFrame.Companion.getSchemaForAllSqlTables (connection : Connection ): List < DataFrameSchema > {
496
+ public fun DataFrame.Companion.getSchemaForAllSqlTables (connection : Connection ): Map < String , DataFrameSchema > {
495
497
val metaData = connection.metaData
496
498
val url = connection.metaData.url
497
499
val dbType = extractDBTypeFromUrl(url)
@@ -500,14 +502,15 @@ public fun DataFrame.Companion.getSchemaForAllSqlTables(connection: Connection):
500
502
// exclude a system and other tables without data
501
503
val tables = metaData.getTables(null , null , null , tableTypes)
502
504
503
- val dataFrameSchemas = mutableListOf< DataFrameSchema >()
505
+ val dataFrameSchemas = mutableMapOf< String , DataFrameSchema >()
504
506
505
507
while (tables.next()) {
506
508
val jdbcTable = dbType.buildTableMetadata(tables)
507
509
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
511
514
}
512
515
}
513
516
0 commit comments