Import SQL Metadata as a Schema in Gradle Project
Each SQL database contains the metadata for all the tables. This metadata could be used for the schema generation.
NOTE: Visit this page to see how to set up all Gradle dependencies for your project.
With @file:ImportDataSchema
To generate schema for existing SQL table, you need to define a few parameters to establish JDBC connection: URL, username, and password.
Also, the tableName
parameter could be specified.
You should also specify the name of the generated Kotlin class as the first parameter of the annotation @file:ImportDataSchema
.
To generate schema for the result of an SQL query, you need to define the SQL query itself and the same parameters to establish connection with the database.
You should also specify the name of the generated Kotlin class as a first parameter of annotation @file:ImportDataSchema
.
Find full example code here.
With Gradle Task
To generate a schema for an existing SQL table, you need to define a few parameters to establish a JDBC connection: URL (passing to data
field), username, and password.
Also, the tableName
parameter should be specified to convert the data from the table with that name to the DataFrame
.
To generate a schema for the result of an SQL query, you need to define the same parameters as before together with the SQL query to establish connection.
Find full example code here.
After importing the data schema, you can start to import any data from SQL table or as a result of an SQL query you like using the generated schemas.
Now you will have a correctly typed DataFrame
!
If you experience any issues with the SQL databases support (since there are many edge-cases when converting SQL types from different databases to Kotlin types), please open an issue on the GitHub repo, specifying the database and the problem.