@@ -5,6 +5,7 @@ package io.airbyte.cdk.integrations.destination.jdbc.typing_deduping
5
5
6
6
import com.google.common.annotations.VisibleForTesting
7
7
import io.airbyte.cdk.integrations.base.JavaBaseConstants
8
+ import io.airbyte.cdk.integrations.base.JavaBaseConstants.DestinationColumns
8
9
import io.airbyte.cdk.integrations.destination.NamingConventionTransformer
9
10
import io.airbyte.integrations.base.destination.typing_deduping.AirbyteProtocolType
10
11
import io.airbyte.integrations.base.destination.typing_deduping.AirbyteType
@@ -23,12 +24,11 @@ import io.airbyte.integrations.base.destination.typing_deduping.UnsupportedOneOf
23
24
import io.airbyte.protocol.models.v0.DestinationSyncMode
24
25
import java.sql.Timestamp
25
26
import java.time.Instant
26
- import java.util.*
27
- import kotlin.Any
28
- import kotlin.Boolean
29
- import kotlin.IllegalArgumentException
27
+ import java.util.Locale
28
+ import java.util.Optional
30
29
import kotlin.Int
31
30
import org.jooq.Condition
31
+ import org.jooq.CreateTableColumnStep
32
32
import org.jooq.DSLContext
33
33
import org.jooq.DataType
34
34
import org.jooq.Field
@@ -37,6 +37,7 @@ import org.jooq.Name
37
37
import org.jooq.Record
38
38
import org.jooq.SQLDialect
39
39
import org.jooq.SelectConditionStep
40
+ import org.jooq.SelectFieldOrAsterisk
40
41
import org.jooq.conf.ParamType
41
42
import org.jooq.impl.DSL
42
43
import org.jooq.impl.SQLDataType
@@ -45,7 +46,9 @@ abstract class JdbcSqlGenerator
45
46
@JvmOverloads
46
47
constructor (
47
48
protected val namingTransformer: NamingConventionTransformer ,
48
- private val cascadeDrop: Boolean = false
49
+ private val cascadeDrop: Boolean = false ,
50
+ @VisibleForTesting
51
+ internal val columns: DestinationColumns = DestinationColumns .V2_WITH_GENERATION ,
49
52
) : SqlGenerator {
50
53
protected val cdcDeletedAtColumn: ColumnId = buildColumnId(" _ab_cdc_deleted_at" )
51
54
@@ -199,6 +202,9 @@ constructor(
199
202
SQLDataType .VARCHAR (36 ).nullable(false )
200
203
metaColumns[JavaBaseConstants .COLUMN_NAME_AB_EXTRACTED_AT ] =
201
204
timestampWithTimeZoneType.nullable(false )
205
+ if (columns == DestinationColumns .V2_WITH_GENERATION ) {
206
+ metaColumns[JavaBaseConstants .COLUMN_NAME_AB_GENERATION_ID ] = SQLDataType .BIGINT
207
+ }
202
208
if (includeMetaColumn)
203
209
metaColumns[JavaBaseConstants .COLUMN_NAME_AB_META ] = structType.nullable(false )
204
210
return metaColumns
@@ -332,38 +338,50 @@ constructor(
332
338
rawTableName : Name ,
333
339
namespace : String ,
334
340
tableName : String
335
- ) =
336
- dslContext
337
- .createTable(rawTableName)
338
- .column(
339
- JavaBaseConstants .COLUMN_NAME_AB_RAW_ID ,
340
- SQLDataType .VARCHAR (36 ).nullable(false ),
341
- )
342
- .column(
343
- JavaBaseConstants .COLUMN_NAME_AB_EXTRACTED_AT ,
344
- timestampWithTimeZoneType.nullable(false ),
345
- )
346
- .column(
347
- JavaBaseConstants .COLUMN_NAME_AB_LOADED_AT ,
348
- timestampWithTimeZoneType.nullable(true ),
349
- )
350
- .column(JavaBaseConstants .COLUMN_NAME_DATA , structType.nullable(false ))
351
- .column(JavaBaseConstants .COLUMN_NAME_AB_META , structType.nullable(true ))
352
- .`as `(
353
- DSL .select(
354
- DSL .field(JavaBaseConstants .COLUMN_NAME_AB_ID )
355
- .`as `(JavaBaseConstants .COLUMN_NAME_AB_RAW_ID ),
356
- DSL .field(JavaBaseConstants .COLUMN_NAME_EMITTED_AT )
357
- .`as `(JavaBaseConstants .COLUMN_NAME_AB_EXTRACTED_AT ),
358
- DSL .cast(null , timestampWithTimeZoneType)
359
- .`as `(JavaBaseConstants .COLUMN_NAME_AB_LOADED_AT ),
360
- DSL .field(JavaBaseConstants .COLUMN_NAME_DATA )
361
- .`as `(JavaBaseConstants .COLUMN_NAME_DATA ),
362
- DSL .cast(null , structType).`as `(JavaBaseConstants .COLUMN_NAME_AB_META ),
363
- )
364
- .from(DSL .table(DSL .name(namespace, tableName))),
341
+ ): String {
342
+ val hasGenerationId = columns == DestinationColumns .V2_WITH_GENERATION
343
+
344
+ val createTable: CreateTableColumnStep =
345
+ dslContext
346
+ .createTable(rawTableName)
347
+ .column(
348
+ JavaBaseConstants .COLUMN_NAME_AB_RAW_ID ,
349
+ SQLDataType .VARCHAR (36 ).nullable(false ),
350
+ )
351
+ .column(
352
+ JavaBaseConstants .COLUMN_NAME_AB_EXTRACTED_AT ,
353
+ timestampWithTimeZoneType.nullable(false ),
354
+ )
355
+ .column(
356
+ JavaBaseConstants .COLUMN_NAME_AB_LOADED_AT ,
357
+ timestampWithTimeZoneType.nullable(true ),
358
+ )
359
+ .column(JavaBaseConstants .COLUMN_NAME_DATA , structType.nullable(false ))
360
+ .column(JavaBaseConstants .COLUMN_NAME_AB_META , structType.nullable(true ))
361
+ if (hasGenerationId) {
362
+ createTable.column(JavaBaseConstants .COLUMN_NAME_AB_GENERATION_ID , SQLDataType .BIGINT )
363
+ }
364
+
365
+ val selectColumns: MutableList <SelectFieldOrAsterisk > =
366
+ mutableListOf (
367
+ DSL .field(JavaBaseConstants .COLUMN_NAME_AB_ID )
368
+ .`as `(JavaBaseConstants .COLUMN_NAME_AB_RAW_ID ),
369
+ DSL .field(JavaBaseConstants .COLUMN_NAME_EMITTED_AT )
370
+ .`as `(JavaBaseConstants .COLUMN_NAME_AB_EXTRACTED_AT ),
371
+ DSL .cast(null , timestampWithTimeZoneType)
372
+ .`as `(JavaBaseConstants .COLUMN_NAME_AB_LOADED_AT ),
373
+ DSL .field(JavaBaseConstants .COLUMN_NAME_DATA )
374
+ .`as `(JavaBaseConstants .COLUMN_NAME_DATA ),
375
+ DSL .cast(null , structType).`as `(JavaBaseConstants .COLUMN_NAME_AB_META ),
365
376
)
377
+ if (hasGenerationId) {
378
+ selectColumns + = DSL .value(0 ).`as `(JavaBaseConstants .COLUMN_NAME_AB_GENERATION_ID )
379
+ }
380
+
381
+ return createTable
382
+ .`as `(DSL .select(selectColumns).from(DSL .table(DSL .name(namespace, tableName))))
366
383
.getSQL(ParamType .INLINED )
384
+ }
367
385
368
386
override fun clearLoadedAt (streamId : StreamId ): Sql {
369
387
return of(
0 commit comments