-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MS SQL support for the dataframe-jdbc module (#689)
* Add support for MS SQL database type and associated tests Added support for MS SQL database type in the util.kt file and created a new file for MS SQL configuration. Additionally, implemented test cases for new support in mssqlTest.kt. * Add sqlQueryLimitOne method to DbType and update test cases Implemented sqlQueryLimitOne method in DbType companion object. This method generates a SQL query that selects one record from a given table. Also, updated the unit tests to accommodate these modifications. * Refactor SQL query limit implementation across databases The SQL query limit behavior has been updated to use a unified method, `sqlQueryLimit`, on different database types, instead of hardcoding this limitation. This ensures a consistent application of these limits across different databases. Also added `TODO` comments to address the nullability issues and points to be checked like filtering system tables and special behavior with catalogues in MSSQL in the future. * Refactored and improved SQL query limit and nullability handling * Ignore MSSQLTest class in test execution * Add MSSQL support and clean up code This commit adds Microsoft SQL Server (MSSQL) library to the dataframe-jdbc project's dependencies. Also, system table filtering has been specifically implemented for MSSQL by adjusting the isSystemTable method. This is a significant improvement over the previous assumption that all DBMS are similar to MySql. * Ignore MSSQLTest class in unit tests * Refactor indentation in Kotlin files * Update comments and fix formatting in MsSql.kt and build.gradle.kts * Refactor code to simplify SQL query construction
- Loading branch information
Showing
8 changed files
with
500 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/db/MsSql.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.jetbrains.kotlinx.dataframe.io.db | ||
|
||
import org.jetbrains.kotlinx.dataframe.io.TableColumnMetadata | ||
import org.jetbrains.kotlinx.dataframe.io.TableMetadata | ||
import org.jetbrains.kotlinx.dataframe.schema.ColumnSchema | ||
import java.sql.ResultSet | ||
import java.util.* | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.full.createType | ||
|
||
/** | ||
* Represents the MSSQL database type. | ||
* | ||
* This class provides methods to convert data from a ResultSet to the appropriate type for MSSQL, | ||
* and to generate the corresponding column schema. | ||
*/ | ||
public object MsSql : DbType("sqlserver") { | ||
override val driverClassName: String | ||
get() = "com.microsoft.sqlserver.jdbc.SQLServerDriver" | ||
|
||
override fun convertSqlTypeToColumnSchemaValue(tableColumnMetadata: TableColumnMetadata): ColumnSchema? { | ||
return null | ||
} | ||
|
||
override fun isSystemTable(tableMetadata: TableMetadata): Boolean { | ||
val locale = Locale.getDefault() | ||
|
||
fun String?.containsWithLowercase(substr: String) = this?.lowercase(locale)?.contains(substr) == true | ||
|
||
val schemaName = tableMetadata.schemaName | ||
val tableName = tableMetadata.name | ||
val catalogName = tableMetadata.catalogue | ||
|
||
return schemaName.containsWithLowercase("sys") || | ||
schemaName.containsWithLowercase("information_schema") || | ||
tableName.startsWith("sys") || | ||
tableName.startsWith("dt") || | ||
tableName.containsWithLowercase("sys_config") || | ||
catalogName.containsWithLowercase("system") || | ||
catalogName.containsWithLowercase("master") || | ||
catalogName.containsWithLowercase("model") || | ||
catalogName.containsWithLowercase("msdb") || | ||
catalogName.containsWithLowercase("tempdb") | ||
} | ||
|
||
override fun buildTableMetadata(tables: ResultSet): TableMetadata { | ||
return TableMetadata( | ||
tables.getString("table_name"), | ||
tables.getString("table_schem"), | ||
tables.getString("table_cat") | ||
) | ||
} | ||
|
||
override fun convertSqlTypeToKType(tableColumnMetadata: TableColumnMetadata): KType? { | ||
return null | ||
} | ||
|
||
public override fun sqlQueryLimit(sqlQuery: String, limit: Int): String { | ||
sqlQuery.replace("SELECT", "SELECT TOP $limit", ignoreCase = true) | ||
return sqlQuery | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.