Skip to content

Commit 88c9030

Browse files
fix kotlin warnings in azure-destination, datastore-{bigquery,mongo,postgres} CDK submodules (#37479)
cleaning kotlin warnings in some CDK submodules
1 parent 978142e commit 88c9030

File tree

12 files changed

+60
-97
lines changed

12 files changed

+60
-97
lines changed

airbyte-cdk/java/airbyte-cdk/azure-destinations/build.gradle

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
compileKotlin {
2-
compilerOptions {
3-
allWarningsAsErrors = false
4-
}
5-
}
6-
71
dependencies {
82
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies')
93
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-core')

airbyte-cdk/java/airbyte-cdk/azure-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/copy/azure/AzureBlobStorageStreamCopier.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ abstract class AzureBlobStorageStreamCopier(
4747
)
4848
protected val azureStagingFiles: MutableSet<String> = HashSet()
4949

50-
@get:VisibleForTesting val tmpTableName: String = nameTransformer.getTmpTableName(streamName)
50+
@Suppress("DEPRECATION")
51+
@get:VisibleForTesting
52+
val tmpTableName: String = nameTransformer.getTmpTableName(streamName)
5153
protected val activeStagingWriterFileNames: MutableSet<String?> = HashSet()
5254
private val csvPrinters = HashMap<String?, CSVPrinter>()
5355
private val blobClients = HashMap<String?, AppendBlobClient>()
5456
override var currentFile: String? = null
5557

5658
@Throws(Exception::class)
57-
override fun write(id: UUID?, recordMessage: AirbyteRecordMessage?, azureFileName: String?) {
58-
if (csvPrinters.containsKey(azureFileName)) {
59-
csvPrinters[azureFileName]!!.printRecord(
59+
override fun write(id: UUID?, recordMessage: AirbyteRecordMessage?, fileName: String?) {
60+
if (csvPrinters.containsKey(fileName)) {
61+
csvPrinters[fileName]!!.printRecord(
6062
id,
6163
Jsons.serialize(recordMessage!!.data),
6264
Timestamp.from(Instant.ofEpochMilli(recordMessage.emittedAt))
@@ -163,7 +165,7 @@ abstract class AzureBlobStorageStreamCopier(
163165

164166
@Throws(Exception::class)
165167
override fun createDestinationTable(): String? {
166-
val destTableName = nameTransformer.getRawTableName(streamName)
168+
@Suppress("DEPRECATION") val destTableName = nameTransformer.getRawTableName(streamName)
167169
LOGGER.info("Preparing table {} in destination.", destTableName)
168170
sqlOperations.createTableIfNotExists(db, schemaName, destTableName)
169171
LOGGER.info("Table {} in destination prepared.", tmpTableName)

airbyte-cdk/java/airbyte-cdk/azure-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/copy/azure/AzureBlobStorageStreamCopierFactory.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import io.airbyte.protocol.models.v0.DestinationSyncMode
1616
abstract class AzureBlobStorageStreamCopierFactory : StreamCopierFactory<AzureBlobStorageConfig> {
1717
override fun create(
1818
configuredSchema: String?,
19-
azureBlobConfig: AzureBlobStorageConfig,
19+
config: AzureBlobStorageConfig,
2020
stagingFolder: String?,
2121
configuredStream: ConfiguredAirbyteStream?,
2222
nameTransformer: StandardNameTransformer?,
@@ -31,9 +31,9 @@ abstract class AzureBlobStorageStreamCopierFactory : StreamCopierFactory<AzureBl
3131

3232
val specializedBlobClientBuilder =
3333
SpecializedBlobClientBuilder()
34-
.endpoint(azureBlobConfig.endpointUrl)
35-
.sasToken(azureBlobConfig.sasToken)
36-
.containerName(azureBlobConfig.containerName)
34+
.endpoint(config.endpointUrl)
35+
.sasToken(config.sasToken)
36+
.containerName(config.containerName)
3737

3838
return create(
3939
stagingFolder,
@@ -42,7 +42,7 @@ abstract class AzureBlobStorageStreamCopierFactory : StreamCopierFactory<AzureBl
4242
streamName,
4343
specializedBlobClientBuilder,
4444
db,
45-
azureBlobConfig,
45+
config,
4646
nameTransformer,
4747
sqlOperations
4848
)

airbyte-cdk/java/airbyte-cdk/datastore-bigquery/build.gradle

-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ compileTestKotlin {
1313
}
1414
}
1515

16-
compileKotlin {
17-
compilerOptions {
18-
allWarningsAsErrors = false
19-
}
20-
}
21-
2216
dependencies {
2317
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies')
2418
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-core')

airbyte-cdk/java/airbyte-cdk/datastore-bigquery/src/main/kotlin/io/airbyte/cdk/db/bigquery/BigQueryDatabase.kt

+16-20
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,20 @@ constructor(
9393

9494
@Throws(Exception::class)
9595
fun query(sql: String?, vararg params: QueryParameterValue): Stream<JsonNode> {
96-
return query(sql, (if (params == null) emptyList() else Arrays.asList(*params).toList()))
96+
return query(sql, listOf(*params))
9797
}
9898

9999
@Throws(Exception::class)
100100
override fun unsafeQuery(sql: String?, vararg params: String?): Stream<JsonNode> {
101101
val parameterValueList =
102-
if (params == null) emptyList()
103-
else
104-
Arrays.stream(params)
105-
.map { param: String? ->
106-
QueryParameterValue.newBuilder()
107-
.setValue(param)
108-
.setType(StandardSQLTypeName.STRING)
109-
.build()
110-
}
111-
.collect(Collectors.toList())
102+
Arrays.stream(params)
103+
.map { param: String? ->
104+
QueryParameterValue.newBuilder()
105+
.setValue(param)
106+
.setType(StandardSQLTypeName.STRING)
107+
.build()
108+
}
109+
.collect(Collectors.toList())
112110

113111
return query(sql, parameterValueList)
114112
}
@@ -158,17 +156,17 @@ constructor(
158156
*/
159157
fun getProjectTables(projectId: String?): List<Table> {
160158
val tableList: MutableList<Table> = ArrayList()
161-
bigQuery!!
159+
bigQuery
162160
.listDatasets(projectId)
163161
.iterateAll()
164162
.forEach(
165163
Consumer { dataset: Dataset ->
166-
bigQuery!!
164+
bigQuery
167165
.listTables(dataset.datasetId)
168166
.iterateAll()
169167
.forEach(
170168
Consumer { table: Table ->
171-
tableList.add(bigQuery!!.getTable(table.tableId))
169+
tableList.add(bigQuery.getTable(table.tableId))
172170
}
173171
)
174172
}
@@ -184,18 +182,18 @@ constructor(
184182
*/
185183
fun getDatasetTables(datasetId: String?): List<Table> {
186184
val tableList: MutableList<Table> = ArrayList()
187-
bigQuery!!
185+
bigQuery
188186
.listTables(datasetId)
189187
.iterateAll()
190-
.forEach(Consumer { table: Table -> tableList.add(bigQuery!!.getTable(table.tableId)) })
188+
.forEach(Consumer { table: Table -> tableList.add(bigQuery.getTable(table.tableId)) })
191189
return tableList
192190
}
193191

194192
fun cleanDataSet(dataSetId: String) {
195193
// allows deletion of a dataset that has contents
196194
val option = BigQuery.DatasetDeleteOption.deleteContents()
197195

198-
val success = bigQuery!!.delete(dataSetId, option)
196+
val success = bigQuery.delete(dataSetId, option)
199197
if (success) {
200198
LOGGER.info("BQ Dataset $dataSetId deleted...")
201199
} else {
@@ -205,9 +203,7 @@ constructor(
205203

206204
private fun executeQuery(queryJob: Job): ImmutablePair<Job?, String?> {
207205
val completedJob = waitForQuery(queryJob)
208-
if (completedJob == null) {
209-
throw RuntimeException("Job no longer exists")
210-
} else if (completedJob.status.error != null) {
206+
if (completedJob.status.error != null) {
211207
// You can also look at queryJob.getStatus().getExecutionErrors() for all
212208
// errors, not just the latest one.
213209
return ImmutablePair.of(null, (completedJob.status.error.toString()))

airbyte-cdk/java/airbyte-cdk/datastore-bigquery/src/main/kotlin/io/airbyte/cdk/db/bigquery/BigQuerySourceOperations.kt

+8-10
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ class BigQuerySourceOperations : SourceOperations<BigQueryResultSet, StandardSQL
3737
private val BIG_QUERY_TIMESTAMP_FORMAT: DateFormat =
3838
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS z")
3939

40-
override fun rowToJson(bigQueryResultSet: BigQueryResultSet): JsonNode {
40+
override fun rowToJson(queryResult: BigQueryResultSet): JsonNode {
4141
val jsonNode = Jsons.jsonNode(emptyMap<Any, Any>()) as ObjectNode
42-
bigQueryResultSet!!
43-
.fieldList
44-
.forEach(
45-
Consumer { field: Field ->
46-
setJsonField(field, bigQueryResultSet.rowValues[field.name], jsonNode)
47-
}
48-
)
42+
queryResult.fieldList.forEach(
43+
Consumer { field: Field ->
44+
setJsonField(field, queryResult.rowValues[field.name], jsonNode)
45+
}
46+
)
4947
return jsonNode
5048
}
5149

@@ -154,8 +152,8 @@ class BigQuerySourceOperations : SourceOperations<BigQueryResultSet, StandardSQL
154152
return parsedValue
155153
}
156154

157-
override fun getAirbyteType(bigQueryType: StandardSQLTypeName?): JsonSchemaType {
158-
return when (bigQueryType) {
155+
override fun getAirbyteType(sourceType: StandardSQLTypeName?): JsonSchemaType {
156+
return when (sourceType) {
159157
StandardSQLTypeName.BOOL -> JsonSchemaType.BOOLEAN
160158
StandardSQLTypeName.INT64 -> JsonSchemaType.INTEGER
161159
StandardSQLTypeName.FLOAT64,

airbyte-cdk/java/airbyte-cdk/datastore-mongo/build.gradle

-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ compileTestKotlin {
2020
}
2121
}
2222

23-
compileKotlin {
24-
compilerOptions {
25-
allWarningsAsErrors = false
26-
}
27-
}
28-
2923
dependencies {
3024
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies')
3125
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-core')

airbyte-cdk/java/airbyte-cdk/datastore-mongo/src/main/kotlin/io/airbyte/cdk/db/mongodb/MongoDatabase.kt

+20-23
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import org.bson.conversions.Bson
2525
import org.slf4j.Logger
2626
import org.slf4j.LoggerFactory
2727

28-
class MongoDatabase(connectionString: String?, databaseName: String?) :
28+
class MongoDatabase(connectionString: String, databaseName: String) :
2929
AbstractDatabase(), AutoCloseable {
30-
private var connectionString: ConnectionString? = null
31-
var database: com.mongodb.client.MongoDatabase? = null
30+
private val connectionString: ConnectionString
31+
private val database: com.mongodb.client.MongoDatabase
3232
private val mongoClient: MongoClient
3333

3434
init {
@@ -47,59 +47,56 @@ class MongoDatabase(connectionString: String?, databaseName: String?) :
4747

4848
@Throws(Exception::class)
4949
override fun close() {
50-
mongoClient!!.close()
50+
mongoClient.close()
5151
}
5252

5353
val databaseNames: MongoIterable<String>
54-
get() = mongoClient!!.listDatabaseNames()
54+
get() = mongoClient.listDatabaseNames()
5555

5656
val collectionNames: Set<String?>
5757
get() {
58-
val collectionNames = database!!.listCollectionNames() ?: return Collections.emptySet()
59-
return MoreIterators.toSet(database!!.listCollectionNames().iterator())
58+
val collectionNames = database.listCollectionNames() ?: return Collections.emptySet()
59+
return MoreIterators.toSet(collectionNames.iterator())
6060
.stream()
6161
.filter { c: String -> !c.startsWith(MONGO_RESERVED_COLLECTION_PREFIX) }
6262
.collect(Collectors.toSet())
6363
}
6464

6565
fun getCollection(collectionName: String): MongoCollection<Document> {
66-
return database!!.getCollection(collectionName).withReadConcern(ReadConcern.MAJORITY)
66+
return database.getCollection(collectionName).withReadConcern(ReadConcern.MAJORITY)
6767
}
6868

6969
fun getOrCreateNewCollection(collectionName: String): MongoCollection<Document> {
70-
val collectionNames = MoreIterators.toSet(database!!.listCollectionNames().iterator())
70+
val collectionNames = MoreIterators.toSet(database.listCollectionNames().iterator())
7171
if (!collectionNames.contains(collectionName)) {
72-
database!!.createCollection(collectionName)
72+
database.createCollection(collectionName)
7373
}
74-
return database!!.getCollection(collectionName)
74+
return database.getCollection(collectionName)
7575
}
7676

7777
@VisibleForTesting
7878
fun createCollection(name: String): MongoCollection<Document> {
79-
database!!.createCollection(name)
80-
return database!!.getCollection(name)
79+
database.createCollection(name)
80+
return database.getCollection(name)
8181
}
8282

8383
@get:VisibleForTesting
8484
val name: String
85-
get() = database!!.name
85+
get() = database.name
8686

8787
fun read(
88-
collectionName: String?,
88+
collectionName: String,
8989
columnNames: List<String>,
90-
filter: Optional<Bson?>
90+
filter: Optional<Bson>
9191
): Stream<JsonNode> {
9292
try {
93-
val collection = database!!.getCollection(collectionName)
93+
val collection = database.getCollection(collectionName)
9494
val cursor =
9595
collection.find(filter.orElse(BsonDocument())).batchSize(BATCH_SIZE).cursor()
9696

97-
return getStream(
98-
cursor,
99-
CheckedFunction { document: Document ->
100-
MongoUtils.toJsonNode(document, columnNames)
101-
}
102-
)
97+
return getStream(cursor) { document: Document ->
98+
MongoUtils.toJsonNode(document, columnNames)
99+
}
103100
.onClose {
104101
try {
105102
cursor.close()

airbyte-cdk/java/airbyte-cdk/datastore-mongo/src/main/kotlin/io/airbyte/cdk/db/mongodb/MongoUtils.kt

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ object MongoUtils {
365365
)
366366
)
367367
return if (output.cursor().hasNext()) {
368+
@Suppress("unchecked_cast")
368369
output.cursor().next()["allkeys"] as List<String>?
369370
} else {
370371
emptyList()

airbyte-cdk/java/airbyte-cdk/datastore-postgres/build.gradle

-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
java {
2-
// TODO: rewrite code to avoid javac wornings in the first place
3-
compileJava {
4-
options.compilerArgs += "-Xlint:-deprecation,-this-escape"
5-
}
6-
}
7-
8-
compileKotlin {
9-
compilerOptions {
10-
allWarningsAsErrors = false
11-
}
12-
}
13-
141
dependencies {
152
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies')
163
implementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-core')

airbyte-cdk/java/airbyte-cdk/datastore-postgres/src/main/kotlin/io/airbyte/cdk/db/PgLsn.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class PgLsn private constructor(private val lsn: Long) : Comparable<PgLsn> {
2121
return longToLsn(lsn)
2222
}
2323

24-
override fun compareTo(o: PgLsn): Int {
25-
return java.lang.Long.compare(lsn, o.asLong())
24+
override fun compareTo(other: PgLsn): Int {
25+
return java.lang.Long.compare(lsn, other.asLong())
2626
}
2727

2828
override fun toString(): String {

airbyte-cdk/java/airbyte-cdk/datastore-postgres/src/main/kotlin/io/airbyte/cdk/integrations/util/PostgresSslConnectionUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ object PostgresSslConnectionUtils {
215215

216216
@Throws(IOException::class, InterruptedException::class)
217217
private fun runProcess(cmd: String, run: Runtime) {
218-
val pr = run.exec(cmd)
218+
@Suppress("deprecation") val pr = run.exec(cmd)
219219
if (!pr.waitFor(30, TimeUnit.SECONDS)) {
220220
pr.destroy()
221221
throw RuntimeException("Timeout while executing: $cmd")

0 commit comments

Comments
 (0)