Skip to content

Commit 52ed312

Browse files
convert #36466 to kotlin
1 parent 7b8b981 commit 52ed312

File tree

1 file changed

+23
-14
lines changed
  • airbyte-cdk/java/airbyte-cdk/db-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/typing_deduping

1 file changed

+23
-14
lines changed

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ import io.airbyte.commons.json.Jsons
1717
import io.airbyte.integrations.base.destination.typing_deduping.*
1818
import io.airbyte.integrations.base.destination.typing_deduping.Struct
1919
import io.airbyte.protocol.models.v0.AirbyteStreamNameNamespacePair
20-
import java.sql.*
21-
import java.time.Instant
22-
import java.time.OffsetDateTime
23-
import java.time.temporal.ChronoUnit
24-
import java.util.*
25-
import java.util.concurrent.CompletableFuture
26-
import java.util.concurrent.CompletionStage
27-
import java.util.function.Predicate
28-
import java.util.stream.Collectors.toMap
2920
import lombok.extern.slf4j.Slf4j
3021
import org.jooq.Condition
3122
import org.jooq.DSLContext
@@ -37,6 +28,17 @@ import org.jooq.impl.DSL.quotedName
3728
import org.jooq.impl.SQLDataType
3829
import org.slf4j.Logger
3930
import org.slf4j.LoggerFactory
31+
import java.sql.*
32+
import java.time.Instant
33+
import java.time.OffsetDateTime
34+
import java.time.temporal.ChronoUnit
35+
import java.util.*
36+
import java.util.concurrent.CompletableFuture
37+
import java.util.concurrent.CompletionStage
38+
import java.util.function.Predicate
39+
import java.util.stream.Collectors.toMap
40+
import java.util.HashMap
41+
4042

4143
@Slf4j
4244
abstract class JdbcDestinationHandler<DestinationState>(
@@ -254,12 +256,19 @@ abstract class JdbcDestinationHandler<DestinationState>(
254256
// This is to handle any destinations that upcase the column names.
255257
// For example - Snowflake with QUOTED_IDENTIFIERS_IGNORE_CASE=TRUE.
256258
val record = recordJson as ObjectNode
257-
record.fieldNames().forEachRemaining { fieldName: String ->
258-
record.set<JsonNode>(
259-
fieldName.lowercase(Locale.getDefault()),
260-
record[fieldName]
261-
)
259+
val newFields: HashMap<String, JsonNode> = HashMap()
260+
261+
val it = record.fieldNames()
262+
while (it.hasNext()) {
263+
val fieldName = it.next()
264+
// We can't directly call record.set here, because that will raise a
265+
// ConcurrentModificationException on the fieldnames iterator.
266+
// Instead, build up a map of new fields and set them all at once.
267+
newFields.put(fieldName.lowercase(Locale.getDefault()), record[fieldName])
262268
}
269+
270+
271+
record.setAll<JsonNode>(newFields)
263272
}
264273
.collect(
265274
toMap(

0 commit comments

Comments
 (0)