Skip to content

Commit f703678

Browse files
fix kotlin warnings in CDK core
1 parent 5f1e4e6 commit f703678

36 files changed

+169
-225
lines changed

airbyte-cdk/java/airbyte-cdk/core/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ compileKotlin {
4242
compilerOptions {
4343
jvmTarget = JvmTarget.JVM_21
4444
languageVersion = KotlinVersion.KOTLIN_1_9
45-
allWarningsAsErrors = false
4645
freeCompilerArgs = ["-Xjvm-default=all"]
4746
}
4847
dependsOn {

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/IncrementalUtils.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package io.airbyte.cdk.db
55

66
import io.airbyte.protocol.models.JsonSchemaPrimitiveUtil
77
import io.airbyte.protocol.models.v0.ConfiguredAirbyteStream
8-
import java.lang.Boolean
98
import java.util.*
109
import kotlin.IllegalStateException
1110
import kotlin.Int
@@ -115,11 +114,11 @@ object IncrementalUtils {
115114
JsonSchemaPrimitiveUtil.JsonSchemaPrimitive.NUMBER_V1,
116115
JsonSchemaPrimitiveUtil.JsonSchemaPrimitive.INTEGER_V1 -> {
117116
// todo (cgardens) - handle big decimal. this is currently an overflow risk.
118-
java.lang.Double.compare(original.toDouble(), candidate.toDouble())
117+
original.toDouble().compareTo(candidate.toDouble())
119118
}
120119
JsonSchemaPrimitiveUtil.JsonSchemaPrimitive.BOOLEAN,
121120
JsonSchemaPrimitiveUtil.JsonSchemaPrimitive.BOOLEAN_V1 -> {
122-
Boolean.compare(original.toBoolean(), candidate.toBoolean())
121+
original.toBoolean().compareTo(candidate.toBoolean())
123122
}
124123
else ->
125124
throw IllegalStateException(

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/JdbcCompatibleSourceOperations.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ interface JdbcCompatibleSourceOperations<SourceType> : SourceOperations<ResultSe
3939
fun isCursorType(type: SourceType?): Boolean
4040

4141
@Throws(SQLException::class)
42-
abstract fun convertDatabaseRowToAirbyteRecordData(queryContext: ResultSet): AirbyteRecordData
42+
fun convertDatabaseRowToAirbyteRecordData(queryContext: ResultSet): AirbyteRecordData
4343
}

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/factory/DataSourceFactory.kt

+3-9
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,12 @@ object DataSourceFactory {
214214
}
215215

216216
fun withMaximumPoolSize(maximumPoolSize: Int): DataSourceBuilder {
217-
if (maximumPoolSize != null) {
218-
this.maximumPoolSize = maximumPoolSize
219-
}
217+
this.maximumPoolSize = maximumPoolSize
220218
return this
221219
}
222220

223221
fun withMinimumPoolSize(minimumPoolSize: Int): DataSourceBuilder {
224-
if (minimumPoolSize != null) {
225-
this.minimumPoolSize = minimumPoolSize
226-
}
222+
this.minimumPoolSize = minimumPoolSize
227223
return this
228224
}
229225

@@ -240,9 +236,7 @@ object DataSourceFactory {
240236
}
241237

242238
fun withPort(port: Int): DataSourceBuilder {
243-
if (port != null) {
244-
this.port = port
245-
}
239+
this.port = port
246240
return this
247241
}
248242

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/AbstractJdbcCompatibleSourceOperations.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ abstract class AbstractJdbcCompatibleSourceOperations<Datatype> :
6767
return AirbyteRecordData(jsonNode, AirbyteRecordMessageMeta().withChanges(metaChanges))
6868
}
6969
@Throws(SQLException::class)
70-
override fun rowToJson(queryContext: ResultSet): JsonNode {
70+
override fun rowToJson(queryResult: ResultSet): JsonNode {
7171
// the first call communicates with the database. after that the result is cached.
72-
val columnCount = queryContext.metaData.columnCount
72+
val columnCount = queryResult.metaData.columnCount
7373
val jsonNode = Jsons.jsonNode(emptyMap<Any, Any>()) as ObjectNode
7474

7575
for (i in 1..columnCount) {
@@ -78,13 +78,13 @@ abstract class AbstractJdbcCompatibleSourceOperations<Datatype> :
7878
// parsing. if it is null, we can move on. while awkward, this seems to be the agreed
7979
// upon way of
8080
// checking for null values with jdbc.
81-
queryContext.getObject(i)
82-
if (queryContext.wasNull()) {
81+
queryResult.getObject(i)
82+
if (queryResult.wasNull()) {
8383
continue
8484
}
8585

8686
// convert to java types that will convert into reasonable json.
87-
copyToJsonField(queryContext, i, jsonNode)
87+
copyToJsonField(queryResult, i, jsonNode)
8888
}
8989

9090
return jsonNode
@@ -332,8 +332,10 @@ abstract class AbstractJdbcCompatibleSourceOperations<Datatype> :
332332
}
333333
}
334334

335+
// Note: I'm guessing this is an open function, since it doesn't do anything here, and doesn't
336+
// override anything either
335337
@Throws(SQLException::class)
336-
protected fun setBit(
338+
protected open fun setBit(
337339
preparedStatement: PreparedStatement?,
338340
parameterIndex: Int,
339341
value: String?

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/DateTimeConverter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ object DateTimeConverter {
153153
date,
154154
date.format(DataTypeUtils.DATE_FORMATTER)
155155
)
156-
} else if (date is Integer) {
156+
} else if (date is Int) {
157157
// Incremental mode
158158
return LocalDate.ofEpochDay(date.toLong()).format(DataTypeUtils.DATE_FORMATTER)
159159
} else {

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/JdbcSourceOperations.kt

+18-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory
1717
/** Implementation of source operations with standard JDBC types. */
1818
open class JdbcSourceOperations :
1919
AbstractJdbcCompatibleSourceOperations<JDBCType>(), SourceOperations<ResultSet, JDBCType> {
20-
protected fun safeGetJdbcType(columnTypeInt: Int): JDBCType {
20+
private fun safeGetJdbcType(columnTypeInt: Int): JDBCType {
2121
return try {
2222
JDBCType.valueOf(columnTypeInt)
2323
} catch (e: Exception) {
@@ -33,30 +33,30 @@ open class JdbcSourceOperations :
3333

3434
when (columnType) {
3535
JDBCType.BIT,
36-
JDBCType.BOOLEAN -> putBoolean(json!!, columnName, resultSet, colIndex)
36+
JDBCType.BOOLEAN -> putBoolean(json, columnName, resultSet, colIndex)
3737
JDBCType.TINYINT,
38-
JDBCType.SMALLINT -> putShortInt(json!!, columnName, resultSet, colIndex)
39-
JDBCType.INTEGER -> putInteger(json!!, columnName, resultSet, colIndex)
40-
JDBCType.BIGINT -> putBigInt(json!!, columnName, resultSet, colIndex)
38+
JDBCType.SMALLINT -> putShortInt(json, columnName, resultSet, colIndex)
39+
JDBCType.INTEGER -> putInteger(json, columnName, resultSet, colIndex)
40+
JDBCType.BIGINT -> putBigInt(json, columnName, resultSet, colIndex)
4141
JDBCType.FLOAT,
42-
JDBCType.DOUBLE -> putDouble(json!!, columnName, resultSet, colIndex)
43-
JDBCType.REAL -> putFloat(json!!, columnName, resultSet, colIndex)
42+
JDBCType.DOUBLE -> putDouble(json, columnName, resultSet, colIndex)
43+
JDBCType.REAL -> putFloat(json, columnName, resultSet, colIndex)
4444
JDBCType.NUMERIC,
45-
JDBCType.DECIMAL -> putBigDecimal(json!!, columnName, resultSet, colIndex)
45+
JDBCType.DECIMAL -> putBigDecimal(json, columnName, resultSet, colIndex)
4646
JDBCType.CHAR,
4747
JDBCType.VARCHAR,
48-
JDBCType.LONGVARCHAR -> putString(json!!, columnName, resultSet, colIndex)
49-
JDBCType.DATE -> putDate(json!!, columnName, resultSet, colIndex)
50-
JDBCType.TIME -> putTime(json!!, columnName, resultSet, colIndex)
51-
JDBCType.TIMESTAMP -> putTimestamp(json!!, columnName, resultSet, colIndex)
48+
JDBCType.LONGVARCHAR -> putString(json, columnName, resultSet, colIndex)
49+
JDBCType.DATE -> putDate(json, columnName, resultSet, colIndex)
50+
JDBCType.TIME -> putTime(json, columnName, resultSet, colIndex)
51+
JDBCType.TIMESTAMP -> putTimestamp(json, columnName, resultSet, colIndex)
5252
JDBCType.TIMESTAMP_WITH_TIMEZONE ->
53-
putTimestampWithTimezone(json!!, columnName, resultSet, colIndex)
53+
putTimestampWithTimezone(json, columnName, resultSet, colIndex)
5454
JDBCType.BLOB,
5555
JDBCType.BINARY,
5656
JDBCType.VARBINARY,
57-
JDBCType.LONGVARBINARY -> putBinary(json!!, columnName, resultSet, colIndex)
58-
JDBCType.ARRAY -> putArray(json!!, columnName, resultSet, colIndex)
59-
else -> putDefault(json!!, columnName, resultSet, colIndex)
57+
JDBCType.LONGVARBINARY -> putBinary(json, columnName, resultSet, colIndex)
58+
JDBCType.ARRAY -> putArray(json, columnName, resultSet, colIndex)
59+
else -> putDefault(json, columnName, resultSet, colIndex)
6060
}
6161
}
6262

@@ -147,8 +147,8 @@ open class JdbcSourceOperations :
147147
return JdbcUtils.ALLOWED_CURSOR_TYPES.contains(type)
148148
}
149149

150-
override fun getAirbyteType(jdbcType: JDBCType): JsonSchemaType {
151-
return when (jdbcType) {
150+
override fun getAirbyteType(sourceType: JDBCType): JsonSchemaType {
151+
return when (sourceType) {
152152
JDBCType.BIT,
153153
JDBCType.BOOLEAN -> JsonSchemaType.BOOLEAN
154154
JDBCType.TINYINT,

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/streaming/AdaptiveStreamingQueryConfig.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ open class AdaptiveStreamingQueryConfig : JdbcStreamingQueryConfig {
1616
}
1717

1818
@Throws(SQLException::class)
19-
override fun initialize(connection: Connection, preparedStatement: Statement) {
19+
override fun initialize(connection: Connection, statement: Statement) {
2020
connection.autoCommit = false
21-
preparedStatement.fetchSize = FetchSizeConstants.INITIAL_SAMPLE_SIZE
21+
statement.fetchSize = FetchSizeConstants.INITIAL_SAMPLE_SIZE
2222
currentFetchSize = FetchSizeConstants.INITIAL_SAMPLE_SIZE
23-
LOGGER.info("Set initial fetch size: {} rows", preparedStatement.fetchSize)
23+
LOGGER.info("Set initial fetch size: {} rows", statement.fetchSize)
2424
}
2525

2626
@Throws(SQLException::class)
2727
override fun accept(resultSet: ResultSet, rowData: Any) {
2828
fetchSizeEstimator.accept(rowData)
2929
val newFetchSize = fetchSizeEstimator.fetchSize
3030

31-
if (newFetchSize!!.isPresent && currentFetchSize != newFetchSize.get()) {
31+
if (newFetchSize.isPresent && currentFetchSize != newFetchSize.get()) {
3232
LOGGER.info("Set new fetch size: {} rows", newFetchSize.get())
3333
resultSet.fetchSize = newFetchSize.get()
3434
currentFetchSize = newFetchSize.get()

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/streaming/InitialSizeEstimator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class InitialSizeEstimator(
2121
private var counter = 0
2222

2323
override fun accept(row: Any) {
24-
val byteSize: Long = BaseSizeEstimator.Companion.getEstimatedByteSize(row)
24+
val byteSize: Long = getEstimatedByteSize(row)
2525
if (maxRowByteSize < byteSize) {
2626
maxRowByteSize = byteSize.toDouble()
2727
}

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/streaming/NoOpStreamingQueryConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.sql.*
77

88
class NoOpStreamingQueryConfig : JdbcStreamingQueryConfig {
99
@Throws(SQLException::class)
10-
override fun initialize(connection: Connection, preparedStatement: Statement) {}
10+
override fun initialize(connection: Connection, statement: Statement) {}
1111

1212
@Throws(SQLException::class) override fun accept(resultSet: ResultSet, o: Any) {}
1313
}

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/jdbc/streaming/SamplingSizeEstimator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SamplingSizeEstimator(
3333
}
3434

3535
counter = 0
36-
val rowByteSize: Long = BaseSizeEstimator.Companion.getEstimatedByteSize(row)
36+
val rowByteSize: Long = getEstimatedByteSize(row)
3737
if (this.maxRowByteSize < rowByteSize) {
3838
this.maxRowByteSize = rowByteSize.toDouble()
3939
hasNewEstimation = true

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/db/util/SSLCertificateUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ object SSLCertificateUtils {
6262
@Throws(IOException::class, InterruptedException::class)
6363
private fun runProcess(cmd: String, run: Runtime) {
6464
LOGGER.debug("running [{}]", cmd)
65-
val p = run.exec(cmd)
65+
@Suppress("deprecation") val p = run.exec(cmd)
6666
if (!p.waitFor(30, TimeUnit.SECONDS)) {
6767
p.destroy()
6868
throw RuntimeException("Timeout while executing: $cmd")

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/base/AirbyteMessageConsumer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interface AirbyteMessageConsumer : CheckedConsumer<AirbyteMessage, Exception>, A
4949
fun appendOnClose(
5050
consumer: AirbyteMessageConsumer?,
5151
voidCallable: VoidCallable
52-
): AirbyteMessageConsumer? {
52+
): AirbyteMessageConsumer {
5353
return object : AirbyteMessageConsumer {
5454
@Throws(Exception::class)
5555
override fun start() {

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/base/AirbyteTraceMessageUtility.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ object AirbyteTraceMessageUtility {
8585
// Not sure why defaultOutputRecordCollector is under Destination specifically,
8686
// but this matches usage elsewhere in base-java
8787
val outputRecordCollector =
88-
Consumer<AirbyteMessage> { message: AirbyteMessage? ->
89-
Destination.Companion.defaultOutputRecordCollector(message)
88+
Consumer<AirbyteMessage> { m: AirbyteMessage? ->
89+
Destination.Companion.defaultOutputRecordCollector(m)
9090
}
9191
outputRecordCollector.accept(message)
9292
}

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/base/Destination.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ interface Destination : Integration {
7979
* message, processing is halted. Otherwise, the invalid message is logged and execution
8080
* continues.
8181
*
82-
* @param inputString JSON representation of an [AirbyteMessage].
82+
* @param message JSON representation of an [AirbyteMessage].
8383
* @throws Exception if an invalid state message is provided or the consumer is unable to
8484
* accept the provided message.
8585
*/
8686
@Throws(Exception::class)
87-
override fun accept(inputString: String, sizeInBytes: Int) {
88-
consumeMessage(consumer, inputString)
87+
override fun accept(message: String, sizeInBytes: Int) {
88+
consumeMessage(consumer, message)
8989
}
9090

9191
@Throws(Exception::class)

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/base/FailureTrackingAirbyteMessageConsumer.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ abstract class FailureTrackingAirbyteMessageConsumer : AirbyteMessageConsumer {
5454
@Throws(Exception::class) protected abstract fun acceptTracked(msg: AirbyteMessage)
5555

5656
@Throws(Exception::class)
57-
override fun accept(msg: AirbyteMessage) {
57+
override fun accept(message: AirbyteMessage) {
5858
try {
59-
acceptTracked(msg)
59+
acceptTracked(message)
6060
} catch (e: Exception) {
6161
LOGGER.error("Exception while accepting message", e)
6262
hasFailed = true

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/base/IntegrationCliParser.kt

-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ class IntegrationCliParser {
134134
.build()
135135
)
136136
}
137-
else -> throw IllegalStateException("Unexpected value: $command")
138137
}
139138
val parsed =
140139
Clis.parse(args, options, command.toString().lowercase(Locale.getDefault()))
@@ -174,7 +173,6 @@ class IntegrationCliParser {
174173
Path.of(argsMap[JavaBaseConstants.ARGS_CATALOG_KEY])
175174
)
176175
}
177-
else -> throw IllegalStateException("Unexpected value: $command")
178176
}
179177
}
180178
}

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/base/IntegrationConfig.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ private constructor(
4545
'}'
4646
}
4747

48-
override fun equals(o: Any?): Boolean {
49-
if (this === o) {
48+
override fun equals(other: Any?): Boolean {
49+
if (this === other) {
5050
return true
5151
}
52-
if (o == null || javaClass != o.javaClass) {
52+
if (other == null || javaClass != other.javaClass) {
5353
return false
5454
}
55-
val that = o as IntegrationConfig
55+
val that = other as IntegrationConfig
5656
return command == that.command &&
5757
configPath == that.configPath &&
5858
catalogPath == that.catalogPath &&

0 commit comments

Comments
 (0)