Skip to content

Commit

Permalink
chore: cleanup/fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpgrailsdev committed Jan 17, 2025
1 parent 2b083bb commit f28f532
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import jakarta.inject.Singleton
import java.util.UUID
import javax.sql.DataSource

const val CHECK_TABLE_STATEMENT = """
CREATE TABLE ? (test int);
DROP TABLE ?;
"""

@Singleton
class MSSQLChecker(private val dataSourceFactory: MSSQLDataSourceFactory) :
DestinationChecker<MSSQLConfiguration> {
Expand All @@ -19,13 +24,10 @@ class MSSQLChecker(private val dataSourceFactory: MSSQLDataSourceFactory) :
val testTableName = "check_test_${UUID.randomUUID()}"
val fullyQualifiedTableName = "[${config.rawDataSchema}].[${testTableName}]"
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeUpdate(
"""
CREATE TABLE ${fullyQualifiedTableName} (test int);
DROP TABLE ${fullyQualifiedTableName};
""".trimIndent(),
)
connection.prepareStatement(CHECK_TABLE_STATEMENT.trimIndent()).use { statement ->
statement.setString(1, fullyQualifiedTableName)
statement.setString(2, fullyQualifiedTableName)
statement.executeUpdate()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class MSSQLQueryBuilder(
) {

companion object {
val AIRBYTE_RAW_ID = "_airbyte_raw_id"
val AIRBYTE_EXTRACTED_AT = "_airbyte_extracted_at"
val AIRBYTE_META = "_airbyte_meta"
val AIRBYTE_GENERATION_ID = "_airbyte_generation_id"
const val AIRBYTE_RAW_ID = "_airbyte_raw_id"
const val AIRBYTE_EXTRACTED_AT = "_airbyte_extracted_at"
const val AIRBYTE_META = "_airbyte_meta"
const val AIRBYTE_GENERATION_ID = "_airbyte_generation_id"
const val DEFAULT_SEPARATOR = ",\n "

val airbyteFinalTableFields =
listOf(
Expand Down Expand Up @@ -231,7 +232,7 @@ class MSSQLQueryBuilder(
BEGIN
CREATE TABLE $fqTableName
(
${airbyteTypeToSqlSchema(schema, separator = ",\n ")}
${airbyteTypeToSqlSchema(schema)}
);
END
""".trimIndent()
Expand Down Expand Up @@ -268,11 +269,12 @@ class MSSQLQueryBuilder(
else -> TODO("most likely fail hard")
}

private fun airbyteTypeToSqlSchema(schema: List<NamedField>, separator: String): String {
return schema
.map {
"${it.name} ${toMssqlType.convert(toSqlType.convert(it.type.type)).sqlString} NULL"
}
.joinToString(separator = separator)
private fun airbyteTypeToSqlSchema(
schema: List<NamedField>,
separator: String = DEFAULT_SEPARATOR
): String {
return schema.joinToString(separator = separator) {
"${it.name} ${toMssqlType.convert(toSqlType.convert(it.type.type)).sqlString} NULL"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ import org.junit.jupiter.api.Test

internal class DataSourceFactoryTest {

// @Test
// fun test() {
// val factory = DataSourceFactory()
// val dataSource = factory.dataSource()
//
// dataSource.connection.use { connection ->
// connection.createStatement().use { statement ->
// statement.execute("SELECT * FROM Inventory")
// }
// }
// }

@Test
fun `test data source base url conversion`() {
val config =
Expand Down

0 comments on commit f28f532

Please sign in to comment.