Skip to content

Commit a2115ec

Browse files
enable spotbugs for cdk typing_and_deduping submodule (#36701)
1 parent cd286a6 commit a2115ec

File tree

11 files changed

+94
-135
lines changed

11 files changed

+94
-135
lines changed

airbyte-cdk/java/airbyte-cdk/db-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/typing_deduping/JdbcSqlGenerator.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ abstract class JdbcSqlGenerator(protected val namingTransformer: NamingConventio
286286

287287
override fun updateTable(
288288
streamConfig: StreamConfig,
289-
finalSuffix: String?,
289+
finalSuffix: String,
290290
minRawTimestamp: Optional<Instant>,
291291
useExpensiveSaferCasting: Boolean
292292
): Sql {
@@ -300,7 +300,7 @@ abstract class JdbcSqlGenerator(protected val namingTransformer: NamingConventio
300300
)
301301
}
302302

303-
override fun overwriteFinalTable(stream: StreamId, finalSuffix: String?): Sql {
303+
override fun overwriteFinalTable(stream: StreamId, finalSuffix: String): Sql {
304304
return transactionally(
305305
DSL.dropTableIfExists(DSL.name(stream.finalNamespace, stream.finalName))
306306
.getSQL(ParamType.INLINED),

airbyte-cdk/java/airbyte-cdk/db-destinations/src/testFixtures/kotlin/io/airbyte/cdk/integrations/standardtest/destination/typing_deduping/JdbcSqlGeneratorIntegrationTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class JdbcSqlGeneratorIntegrationTest<DestinationState : MinimumDestina
3838
// TODO - can we move this class into db_destinations/testFixtures?
3939
get() = sqlGenerator!!.toDialectType(AirbyteProtocolType.TIMESTAMP_WITH_TIMEZONE)
4040

41-
abstract override val sqlGenerator: JdbcSqlGenerator?
41+
abstract override val sqlGenerator: JdbcSqlGenerator
4242
get
4343

4444
protected abstract val sqlDialect: SQLDialect?

airbyte-cdk/java/airbyte-cdk/typing-deduping/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ compileTestFixturesKotlin {
2626
}
2727
}
2828

29-
spotbugsTest.enabled = false
30-
spotbugsTestFixtures.enabled = false
31-
32-
3329
dependencies {
3430
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies')
3531
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-core')

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/main/kotlin/io/airbyte/integrations/base/destination/typing_deduping/SqlGenerator.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ interface SqlGenerator {
6565
*/
6666
fun updateTable(
6767
stream: StreamConfig,
68-
finalSuffix: String?,
68+
finalSuffix: String,
6969
minRawTimestamp: Optional<Instant>,
7070
useExpensiveSaferCasting: Boolean
7171
): Sql
@@ -76,7 +76,7 @@ interface SqlGenerator {
7676
* This method may assume that the stream is an OVERWRITE stream, and that the final suffix is
7777
* non-empty. Callers are responsible for verifying those are true.
7878
*/
79-
fun overwriteFinalTable(stream: StreamId, finalSuffix: String?): Sql
79+
fun overwriteFinalTable(stream: StreamId, finalSuffix: String): Sql
8080

8181
/**
8282
* Creates a sql query which will create a v2 raw table from the v1 raw table, then performs a

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/main/kotlin/io/airbyte/integrations/base/destination/typing_deduping/TypeAndDedupeTransaction.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object TypeAndDedupeTransaction {
3131
destinationHandler: DestinationHandler<*>,
3232
streamConfig: StreamConfig?,
3333
minExtractedAt: Optional<Instant>,
34-
suffix: String?
34+
suffix: String
3535
) {
3636
try {
3737
LOGGER.info(

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/test/kotlin/io/airbyte/integrations/base/destination/typing_deduping/AirbyteTypeTest.kt

+2-14
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,7 @@ class AirbyteTypeTest {
396396
Union(
397397
List.of(
398398
AirbyteProtocolType.STRING,
399-
Struct(
400-
object : LinkedHashMap<String, AirbyteType>() {
401-
init {
402-
put("foo", AirbyteProtocolType.STRING)
403-
}
404-
}
405-
),
399+
Struct(linkedMapOf("foo" to AirbyteProtocolType.STRING)),
406400
Array(AirbyteProtocolType.STRING)
407401
)
408402
)
@@ -533,13 +527,7 @@ class AirbyteTypeTest {
533527
Union(
534528
List.of(
535529
AirbyteProtocolType.STRING,
536-
Struct(
537-
object : LinkedHashMap<String, AirbyteType>() {
538-
init {
539-
put("foo", AirbyteProtocolType.STRING)
540-
}
541-
}
542-
),
530+
Struct(linkedMapOf("foo" to AirbyteProtocolType.STRING)),
543531
Array(
544532
AirbyteProtocolType.STRING
545533
), // This is bad behavior, but it matches current behavior so we'll test it.

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/test/kotlin/io/airbyte/integrations/base/destination/typing_deduping/CollectionUtilsTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import org.junit.jupiter.params.provider.CsvSource
1212
class CollectionUtilsTest {
1313
@ParameterizedTest
1414
@CsvSource("foo,foo", "bar,BAR", "fIzZ,fizz", "ZIP_zop,zip_ZOP", "nope,")
15-
fun testMatchingKey(input: String?, output: String?) {
15+
fun testMatchingKey(input: String, output: String?) {
1616
val expected = Optional.ofNullable(output)
17-
Assertions.assertEquals(matchingKey(TEST_COLLECTION, input!!), expected)
17+
Assertions.assertEquals(matchingKey(TEST_COLLECTION, input), expected)
1818
}
1919

2020
companion object {

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/test/kotlin/io/airbyte/integrations/base/destination/typing_deduping/DefaultTyperDeduperTest.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ class DefaultTyperDeduperTest {
137137
}
138138
)
139139

140-
updatedStates = HashMap()
140+
val updatedStates: MutableMap<StreamId, MockState> = HashMap()
141141
updatedStates[OVERWRITE_STREAM_CONFIG.id] = MockState(false, false, true)
142142
updatedStates[APPEND_STREAM_CONFIG.id] = MockState(false, false, true)
143143
updatedStates[DEDUPE_STREAM_CONFIG.id] = MockState(false, false, true)
144+
this.updatedStates = updatedStates
144145

145146
migrator = NoOpDestinationV1V2Migrator()
146147

@@ -579,7 +580,7 @@ class DefaultTyperDeduperTest {
579580
@Test
580581
@Throws(Exception::class)
581582
fun multipleSoftResets() {
582-
typerDeduper =
583+
val typerDeduper =
583584
DefaultTyperDeduper(
584585
sqlGenerator!!,
585586
destinationHandler,
@@ -588,6 +589,7 @@ class DefaultTyperDeduperTest {
588589
java.util.List.of(MIGRATION_REQUIRING_SOFT_RESET)
589590
)
590591

592+
this.typerDeduper = typerDeduper
591593
// Notably: isSchemaMismatch = true,
592594
// and the MockStates have needsSoftReset = false and isMigrated = false.
593595
Mockito.`when`(destinationHandler!!.gatherInitialState(ArgumentMatchers.anyList()))
@@ -698,7 +700,7 @@ class DefaultTyperDeduperTest {
698700
@Test
699701
@Throws(Exception::class)
700702
fun migrationsMixedResults() {
701-
typerDeduper =
703+
val typerDeduper =
702704
DefaultTyperDeduper(
703705
sqlGenerator!!,
704706
destinationHandler,
@@ -709,6 +711,7 @@ class DefaultTyperDeduperTest {
709711
MIGRATION_NOT_REQUIRING_SOFT_RESET
710712
)
711713
)
714+
this.typerDeduper = typerDeduper
712715

713716
Mockito.`when`(destinationHandler!!.gatherInitialState(ArgumentMatchers.anyList()))
714717
.thenReturn(

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/test/kotlin/io/airbyte/integrations/base/destination/typing_deduping/DestinationV1V2MigratorTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ class DestinationV1V2MigratorTest {
7474
@ArgumentsSource(ShouldMigrateTestArgumentProvider::class)
7575
@Throws(Exception::class)
7676
fun testShouldMigrate(
77-
destinationSyncMode: DestinationSyncMode?,
77+
destinationSyncMode: DestinationSyncMode,
7878
migrator: BaseDestinationV1V2Migrator<*>,
7979
expected: Boolean
8080
) {
81-
val config = StreamConfig(STREAM_ID, null, destinationSyncMode!!, null, null, null)
81+
val config = StreamConfig(STREAM_ID, null, destinationSyncMode, null, null, null)
8282
val actual = migrator.shouldMigrate(config)
8383
Assertions.assertEquals(expected, actual)
8484
}

airbyte-cdk/java/airbyte-cdk/typing-deduping/src/test/kotlin/io/airbyte/integrations/base/destination/typing_deduping/MockSqlGenerator.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class MockSqlGenerator : SqlGenerator {
3232

3333
override fun updateTable(
3434
stream: StreamConfig,
35-
finalSuffix: String?,
35+
finalSuffix: String,
3636
minRawTimestamp: Optional<Instant>,
3737
useExpensiveSaferCasting: Boolean
3838
): Sql {
@@ -42,18 +42,18 @@ internal class MockSqlGenerator : SqlGenerator {
4242
.orElse("")
4343
val casting = if (useExpensiveSaferCasting) " WITH" else " WITHOUT" + " SAFER CASTING"
4444
return of(
45-
("UPDATE TABLE " + stream!!.id.finalTableId("", finalSuffix!!)).toString() +
45+
("UPDATE TABLE " + stream.id.finalTableId("", finalSuffix)).toString() +
4646
casting +
4747
timestampFilter
4848
)
4949
}
5050

51-
override fun overwriteFinalTable(stream: StreamId, finalSuffix: String?): Sql {
51+
override fun overwriteFinalTable(stream: StreamId, finalSuffix: String): Sql {
5252
return of(
5353
"OVERWRITE TABLE " +
54-
stream!!.finalTableId("") +
54+
stream.finalTableId("") +
5555
" FROM " +
56-
stream.finalTableId("", finalSuffix!!)
56+
stream.finalTableId("", finalSuffix)
5757
)
5858
}
5959

0 commit comments

Comments
 (0)