readDataFrameSchema
Retrieves the schema of an SQL query result or the 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 = falseautomatically 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 schema of the SQL query as a DataFrameSchema object.
Parameters
the SQL query to execute and retrieve the schema from.
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 DbConnectionConfig.
Retrieves the schema of an SQL query result or the 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 schema for a table
val tableSchema = dataSource.getDataFrameSchema("customers")
// Or get schema for a query
val querySchema = dataSource.getDataFrameSchema("SELECT name, age FROM customers WHERE age > 25")
// Inspect the schema
println(tableSchema.columns)Return
the schema of the SQL query as a DataFrameSchema object.
Parameters
the SQL query to execute or name of the SQL table. It should be a name of one of the existing SQL tables, or the SQL query should start from SELECT and contain one query for reading data without any manipulation. It should not contain ; symbol.
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
Retrieves the schema of an SQL query result or the SQL table using the provided database configuration.
Return
the schema of the SQL query as a DataFrameSchema object.
Parameters
the SQL query to execute and retrieve the schema from.
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.
Retrieves the schema from ResultSet.
NOTE: This function will not close connection and result set and not retrieve data from the result set.
Return
the schema of the ResultSet as a DataFrameSchema object.
Parameters
the type of database that the ResultSet belongs to, could be a custom object, provided by user.