readSqlTable

Retrieves the schema for an SQL table using the provided database configuration.

Default Behavior:

If DbConnectionConfig.readOnly is true (which is the default), the connection will be:

  • explicitly set as read-only via Connection.setReadOnly(true)

  • used with autoCommit = false

  • automatically rolled back after reading, ensuring no changes to the database

Even if DbConnectionConfig.readOnly is set to false, the library still prevents data-modifying queries and only permits safe SELECT operations internally.

Return

the DataFrameSchema object representing the schema of the SQL table

Parameters

dbConfig

the database configuration to connect to the database, including URL, user, and password.

tableName

the name of the SQL table for which to retrieve the schema.

dbType

the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the dbConfig.


fun DataFrameSchema.Companion.readSqlTable(dataSource: DataSource, tableName: String, dbType: DbType? = null): DataFrameSchema

Retrieves the schema for an SQL table using the provided DataSource.

Example with HikariCP:

import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource

val config = HikariConfig().apply {
jdbcUrl = "jdbc:postgresql://localhost:5432/mydb"
username = "user"
password = "password"
}
val dataSource = HikariDataSource(config)

// Get the schema for a specific table
val customersSchema = DataFrame.getSchemaForSqlTable(dataSource, "customers")

// Inspect the schema
println(customersSchema.columns)

Return

the schema of the SQL table as a DataFrameSchema object.

Parameters

dataSource

the DataSource to get a database connection from.

tableName

the name of the SQL table for which to retrieve the schema.

dbType

the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the dataSource.

See also


fun DataFrameSchema.Companion.readSqlTable(connection: Connection, tableName: String, dbType: DbType? = null): DataFrameSchema

Retrieves the schema for an SQL table using the provided database connection.

Return

the schema of the SQL table as a DataFrameSchema object.

Parameters

connection

the database connection.

tableName

the name of the SQL table for which to retrieve the schema.

dbType

the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the connection.

See also


fun DataFrame.Companion.readSqlTable(dbConfig: DbConnectionConfig, tableName: String, limit: Int? = null, inferNullability: Boolean = true, dbType: DbType? = null, configureStatement: (PreparedStatement) -> Unit = {}): AnyFrame

Reads data from an SQL table and converts it into a DataFrame.

Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.

Default Behavior:

If DbConnectionConfig.readOnly is true (which is the default), the connection will be:

  • explicitly set as read-only via Connection.setReadOnly(true)

  • used with autoCommit = false

  • automatically rolled back after reading, ensuring no changes to the database

Even if DbConnectionConfig.readOnly is set to false, the library still prevents data-modifying queries and only permits safe SELECT operations internally.

Return

the DataFrame containing the data from the SQL table.

Parameters

dbConfig

the configuration for the database, including URL, user, and password.

tableName

the name of the table to read data from.

limit

the maximum number of rows to retrieve from the table. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows

inferNullability

indicates how the column nullability should be inferred.

dbType

the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the dbConfig.

configureStatement

optional lambda to configure the PreparedStatement before execution. This allows for custom tuning of fetch size, query timeout, and other JDBC parameters.


fun DataFrame.Companion.readSqlTable(dataSource: DataSource, tableName: String, limit: Int? = null, inferNullability: Boolean = true, dbType: DbType? = null, configureStatement: (PreparedStatement) -> Unit = {}): AnyFrame

Reads data from an SQL table and converts it into a DataFrame.

Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.

Return

the DataFrame containing the data from the SQL table.

Parameters

dataSource

the DataSource to get a database connection from.

tableName

the name of the table to read data from.

limit

the maximum number of rows to retrieve from the table. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows

inferNullability

indicates how the column nullability should be inferred.

dbType

the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the dataSource.

configureStatement

optional lambda to configure the PreparedStatement before execution. This allows for custom tuning of fetch size, query timeout, and other JDBC parameters.

See also


fun DataFrame.Companion.readSqlTable(connection: Connection, tableName: String, limit: Int? = null, inferNullability: Boolean = true, dbType: DbType? = null, configureStatement: (PreparedStatement) -> Unit = {}): AnyFrame

Reads data from an SQL table and converts it into a DataFrame.

Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.

Return

the DataFrame containing the data from the SQL table.

Parameters

connection

the database connection to read tables from.

tableName

the name of the table to read data from.

limit

the maximum number of rows to retrieve from the table. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows

inferNullability

indicates how the column nullability should be inferred.

dbType

the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the connection.

configureStatement

optional lambda to configure the PreparedStatement before execution. This allows for custom tuning of fetch size, query timeout, and other JDBC parameters.

See also