Skip to content

Commit 182d3e6

Browse files
convert #36396 to kotlin
1 parent 86517eb commit 182d3e6

File tree

6 files changed

+41
-33
lines changed

6 files changed

+41
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface JdbcCompatibleSourceOperations<SourceType> : SourceOperations<ResultSe
2323
preparedStatement: PreparedStatement,
2424
parameterIndex: Int,
2525
cursorFieldType: SourceType?,
26-
value: String
26+
value: String?
2727
)
2828

2929
/** Determine the database specific type of the input field based on its column metadata. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class JdbcSourceOperations :
6565
preparedStatement: PreparedStatement,
6666
parameterIndex: Int,
6767
cursorFieldType: JDBCType?,
68-
value: String
68+
value: String?
6969
) {
7070
when (cursorFieldType) {
7171
JDBCType.TIMESTAMP -> setTimestamp(preparedStatement, parameterIndex, value)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.28.12
1+
version=0.28.13

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

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package io.airbyte.cdk.integrations.destination.jdbc.typing_deduping
55

66
import com.fasterxml.jackson.databind.JsonNode
7+
import com.fasterxml.jackson.databind.node.ObjectNode
78
import io.airbyte.cdk.db.jdbc.JdbcDatabase
89
import io.airbyte.cdk.integrations.base.JavaBaseConstants
910
import io.airbyte.cdk.integrations.destination.jdbc.ColumnDefinition
@@ -23,16 +24,16 @@ import java.time.temporal.ChronoUnit
2324
import java.util.*
2425
import java.util.concurrent.CompletableFuture
2526
import java.util.concurrent.CompletionStage
26-
import java.util.function.Function
2727
import java.util.function.Predicate
28-
import java.util.stream.Collectors
29-
import kotlin.collections.LinkedHashMap
28+
import java.util.stream.Collectors.toMap
3029
import lombok.extern.slf4j.Slf4j
3130
import org.jooq.Condition
3231
import org.jooq.DSLContext
3332
import org.jooq.SQLDialect
3433
import org.jooq.conf.ParamType
3534
import org.jooq.impl.DSL
35+
import org.jooq.impl.DSL.field
36+
import org.jooq.impl.DSL.quotedName
3637
import org.jooq.impl.SQLDataType
3738
import org.slf4j.Logger
3839
import org.slf4j.LoggerFactory
@@ -207,60 +208,73 @@ abstract class JdbcDestinationHandler<DestinationState>(
207208
@get:Throws(SQLException::class)
208209
protected val allDestinationStates: Map<AirbyteStreamNameNamespacePair, DestinationState>
209210
get() {
211+
210212
// Guarantee the table exists.
211213
jdbcDatabase.execute(
212214
dslContext
213215
.createTableIfNotExists(
214-
DSL.quotedName(rawTableSchemaName, DESTINATION_STATE_TABLE_NAME)
215-
)
216-
.column(
217-
DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_NAME),
218-
SQLDataType.VARCHAR
216+
quotedName(rawTableSchemaName, DESTINATION_STATE_TABLE_NAME)
219217
)
218+
.column(quotedName(DESTINATION_STATE_TABLE_COLUMN_NAME), SQLDataType.VARCHAR)
220219
.column(
221-
DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_NAMESPACE),
220+
quotedName(DESTINATION_STATE_TABLE_COLUMN_NAMESPACE),
222221
SQLDataType.VARCHAR
223222
) // Just use a string type, even if the destination has a json type.
224223
// We're never going to query this column in a fancy way - all our processing
225224
// can happen
226225
// client-side.
227226
.column(
228-
DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_STATE),
227+
quotedName(DESTINATION_STATE_TABLE_COLUMN_STATE),
229228
SQLDataType.VARCHAR
230229
) // Add an updated_at field. We don't actually need it yet, but it can't hurt!
231230
.column(
232-
DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_UPDATED_AT),
231+
quotedName(DESTINATION_STATE_TABLE_COLUMN_UPDATED_AT),
233232
SQLDataType.TIMESTAMPWITHTIMEZONE
234233
)
235234
.getSQL(ParamType.INLINED)
236235
)
236+
237237
// Fetch all records from it. We _could_ filter down to just our streams... but meh.
238238
// This is small
239239
// data.
240240
return jdbcDatabase
241241
.queryJsons(
242242
dslContext
243243
.select(
244-
DSL.field(DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_NAME)),
245-
DSL.field(DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_NAMESPACE)),
246-
DSL.field(DSL.quotedName(DESTINATION_STATE_TABLE_COLUMN_STATE))
244+
field(quotedName(DESTINATION_STATE_TABLE_COLUMN_NAME)),
245+
field(quotedName(DESTINATION_STATE_TABLE_COLUMN_NAMESPACE)),
246+
field(quotedName(DESTINATION_STATE_TABLE_COLUMN_STATE))
247247
)
248-
.from(DSL.quotedName(rawTableSchemaName, DESTINATION_STATE_TABLE_NAME))
249-
.sql
248+
.from(quotedName(rawTableSchemaName, DESTINATION_STATE_TABLE_NAME))
249+
.getSQL()
250250
)
251251
.stream()
252+
.peek { recordJson: JsonNode ->
253+
// Forcibly downcase all key names.
254+
// This is to handle any destinations that upcase the column names.
255+
// For example - Snowflake with QUOTED_IDENTIFIERS_IGNORE_CASE=TRUE.
256+
val record = recordJson as ObjectNode
257+
record.fieldNames().forEachRemaining { fieldName: String ->
258+
record.set<JsonNode>(
259+
fieldName.lowercase(Locale.getDefault()),
260+
record[fieldName]
261+
)
262+
}
263+
}
252264
.collect(
253-
Collectors.toMap(
254-
Function { record: JsonNode ->
255-
val nameNode = record[DESTINATION_STATE_TABLE_COLUMN_NAME]
256-
val namespaceNode = record[DESTINATION_STATE_TABLE_COLUMN_NAMESPACE]
265+
toMap(
266+
{ record ->
267+
val nameNode: JsonNode = record.get(DESTINATION_STATE_TABLE_COLUMN_NAME)
268+
val namespaceNode: JsonNode =
269+
record.get(DESTINATION_STATE_TABLE_COLUMN_NAMESPACE)
257270
AirbyteStreamNameNamespacePair(
258-
nameNode?.asText(),
259-
namespaceNode?.asText()
271+
if (nameNode != null) nameNode.asText() else null,
272+
if (namespaceNode != null) namespaceNode.asText() else null
260273
)
261274
},
262-
Function { record: JsonNode ->
263-
val stateNode = record[DESTINATION_STATE_TABLE_COLUMN_STATE]
275+
{ record ->
276+
val stateNode: JsonNode =
277+
record.get(DESTINATION_STATE_TABLE_COLUMN_STATE)
264278
val state =
265279
if (stateNode != null) Jsons.deserialize(stateNode.asText())
266280
else Jsons.emptyObject()

airbyte-cdk/java/airbyte-cdk/db-sources/src/main/java/io/airbyte/cdk/integrations/debezium/AirbyteDebeziumHandler.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

airbyte-cdk/java/airbyte-cdk/db-sources/src/main/java/io/airbyte/cdk/integrations/debezium/CdcMetadataInjector.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)