forked from airbytehq/airbyte
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move common implementation to base implementation (airbytehq#33369)
Signed-off-by: Gireesh Sreepathi <gisripa@gmail.com>
- Loading branch information
1 parent
05767a9
commit af60f8b
Showing
9 changed files
with
563 additions
and
402 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
airbyte-cdk/java/airbyte-cdk/core/src/main/resources/version.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=0.7.2 | ||
version=0.7.3 |
407 changes: 407 additions & 0 deletions
407
...n/java/io/airbyte/cdk/integrations/destination/jdbc/typing_deduping/JdbcSqlGenerator.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...irbyte/integrations/base/destination/typing_deduping/JdbcSqlGeneratorIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.base.destination.typing_deduping; | ||
|
||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_AB_EXTRACTED_AT; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_AB_ID; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_AB_LOADED_AT; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_AB_META; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_AB_RAW_ID; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_DATA; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.COLUMN_NAME_EMITTED_AT; | ||
import static io.airbyte.cdk.integrations.base.JavaBaseConstants.LEGACY_RAW_TABLE_COLUMNS; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.cdk.db.jdbc.JdbcDatabase; | ||
import io.airbyte.cdk.integrations.base.JavaBaseConstants; | ||
import java.util.List; | ||
import org.jooq.DSLContext; | ||
import org.jooq.DataType; | ||
import org.jooq.Name; | ||
import org.jooq.SQLDialect; | ||
import org.jooq.conf.ParamType; | ||
import org.jooq.impl.DSL; | ||
import org.jooq.impl.SQLDataType; | ||
|
||
public abstract class JdbcSqlGeneratorIntegrationTest<T> extends BaseSqlGeneratorIntegrationTest<T> { | ||
|
||
protected abstract JdbcDatabase getDatabase(); | ||
|
||
protected abstract DataType<?> getStructType(); | ||
|
||
protected abstract SQLDialect getSqlDialect(); | ||
|
||
private DSLContext getDslContext() { | ||
return DSL.using(getSqlDialect()); | ||
} | ||
|
||
protected abstract void insertRecords(final Name tableName, | ||
final List<String> columnNames, | ||
final List<JsonNode> records, | ||
final String... jsonColumns) | ||
throws Exception; | ||
|
||
@Override | ||
protected void createNamespace(String namespace) throws Exception { | ||
getDatabase().execute(getDslContext().createSchemaIfNotExists(namespace).getSQL(ParamType.INLINED)); | ||
} | ||
|
||
@Override | ||
protected void createRawTable(StreamId streamId) throws Exception { | ||
getDatabase().execute(getDslContext().createTable(DSL.name(streamId.rawNamespace(), streamId.rawName())) | ||
.column(COLUMN_NAME_AB_RAW_ID, SQLDataType.VARCHAR(36).nullable(false)) | ||
.column(COLUMN_NAME_AB_EXTRACTED_AT, SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) | ||
.column(COLUMN_NAME_AB_LOADED_AT, SQLDataType.TIMESTAMPWITHTIMEZONE) | ||
.column(COLUMN_NAME_DATA, getStructType().nullable(false)) | ||
.getSQL(ParamType.INLINED)); | ||
} | ||
|
||
@Override | ||
protected void createV1RawTable(StreamId v1RawTable) throws Exception { | ||
getDatabase().execute(getDslContext().createTable(DSL.name(v1RawTable.rawNamespace(), v1RawTable.rawName())) | ||
.column(COLUMN_NAME_AB_ID, SQLDataType.VARCHAR(36).nullable(false)) | ||
.column(COLUMN_NAME_EMITTED_AT, SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) | ||
.column(COLUMN_NAME_DATA, getStructType().nullable(false)) | ||
.getSQL(ParamType.INLINED)); | ||
} | ||
|
||
@Override | ||
protected void insertRawTableRecords(StreamId streamId, List<JsonNode> records) throws Exception { | ||
insertRecords( | ||
DSL.name(streamId.rawNamespace(), streamId.rawName()), | ||
JavaBaseConstants.V2_RAW_TABLE_COLUMN_NAMES, | ||
records, | ||
COLUMN_NAME_DATA); | ||
} | ||
|
||
@Override | ||
protected void insertV1RawTableRecords(StreamId streamId, List<JsonNode> records) throws Exception { | ||
insertRecords( | ||
DSL.name(streamId.rawNamespace(), streamId.rawName()), | ||
LEGACY_RAW_TABLE_COLUMNS, | ||
records, | ||
COLUMN_NAME_DATA); | ||
} | ||
|
||
@Override | ||
protected void insertFinalTableRecords(boolean includeCdcDeletedAt, StreamId streamId, String suffix, List<JsonNode> records) throws Exception { | ||
final List<String> columnNames = includeCdcDeletedAt ? FINAL_TABLE_COLUMN_NAMES_CDC : FINAL_TABLE_COLUMN_NAMES; | ||
insertRecords( | ||
DSL.name(streamId.finalNamespace(), streamId.finalName() + suffix), | ||
columnNames, | ||
records, | ||
COLUMN_NAME_AB_META, "struct", "array", "unknown"); | ||
} | ||
|
||
@Override | ||
protected List<JsonNode> dumpRawTableRecords(StreamId streamId) throws Exception { | ||
return getDatabase().queryJsons(getDslContext().selectFrom(DSL.name(streamId.rawNamespace(), streamId.rawName())).getSQL(ParamType.INLINED)); | ||
} | ||
|
||
@Override | ||
protected List<JsonNode> dumpFinalTableRecords(StreamId streamId, String suffix) throws Exception { | ||
return getDatabase() | ||
.queryJsons(getDslContext().selectFrom(DSL.name(streamId.finalNamespace(), streamId.finalName() + suffix)).getSQL(ParamType.INLINED)); | ||
} | ||
|
||
@Override | ||
protected void teardownNamespace(String namespace) throws Exception { | ||
getDatabase().execute(getDslContext().dropSchema(namespace).cascade().getSQL(ParamType.INLINED)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.