Skip to content

Commit 765cf5b

Browse files
committed
wow
1 parent 47b9096 commit 765cf5b

File tree

1 file changed

+29
-0
lines changed
  • airbyte-cdk/bulk/core/load/src/main/kotlin/io/airbyte/cdk/load/data

1 file changed

+29
-0
lines changed

airbyte-cdk/bulk/core/load/src/main/kotlin/io/airbyte/cdk/load/data/AirbyteType.kt

+29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package io.airbyte.cdk.load.data
66

77
import com.fasterxml.jackson.databind.JsonNode
8+
import io.github.oshai.kotlinlogging.KotlinLogging
9+
10+
private val logger = KotlinLogging.logger {}
811

912
sealed interface AirbyteType {
1013
/**
@@ -64,6 +67,32 @@ data object ObjectTypeWithoutSchema : AirbyteType {
6467
}
6568

6669
data class UnionType(val options: Set<AirbyteType>) : AirbyteType {
70+
/**
71+
* This is a hack to handle weird schemas like {type: [object, string]}. If a stream's top-level
72+
* schema looks like this, we still want to be able to extract the object properties (i.e. treat
73+
* it as though the string option didn't exist).
74+
*
75+
* @throws IllegalArgumentException if we cannot extract columns from this schema
76+
*/
77+
override fun asColumns(): LinkedHashMap<String, FieldType> {
78+
logger.warn { "asColumns options=$options" }
79+
val numObjectOptions = options.count { it.isObject }
80+
if (numObjectOptions > 1) {
81+
logger.error { "Can't extract columns from a schema with multiple object options" }
82+
return LinkedHashMap()
83+
}
84+
85+
var retVal: LinkedHashMap<String, FieldType>
86+
try {
87+
retVal = options.first { it.isObject }.asColumns()
88+
} catch (_: NoSuchElementException) {
89+
logger.error { "Can't extract columns from a schema with no object options" }
90+
retVal = LinkedHashMap()
91+
}
92+
logger.warn { "Union.asColumns retVal=$retVal" }
93+
return retVal
94+
}
95+
6796
companion object {
6897
fun of(options: Set<AirbyteType>): AirbyteType {
6998
if (options.size == 1) {

0 commit comments

Comments
 (0)