-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
table selection for cdc #2690
table selection for cdc #2690
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,9 @@ | |
import io.airbyte.integrations.source.jdbc.JdbcStateManager; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.protocol.models.AirbyteRecordMessage; | ||
import io.airbyte.protocol.models.AirbyteStream; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteStream; | ||
import io.debezium.engine.ChangeEvent; | ||
import io.debezium.engine.DebeziumEngine; | ||
import io.debezium.engine.format.Json; | ||
|
@@ -60,7 +62,9 @@ | |
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.codehaus.plexus.util.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -133,7 +137,7 @@ public List<AutoCloseableIterator<AirbyteMessage>> getIncrementalIterators(JsonN | |
CloseableLinkedBlockingQueue queue = new CloseableLinkedBlockingQueue(executor::shutdown); | ||
|
||
DebeziumEngine<ChangeEvent<String, String>> engine = DebeziumEngine.create(Json.class) | ||
.using(getDebeziumProperties(config)) | ||
.using(getDebeziumProperties(config, catalog)) | ||
.notifying(record -> { | ||
try { | ||
LOGGER.info("record = " + record); | ||
|
@@ -222,7 +226,7 @@ protected JsonNode computeNext() { | |
|
||
// todo: make this use catalog as well | ||
// todo: make this use the state for the files as well | ||
protected static Properties getDebeziumProperties(JsonNode config) { | ||
protected static Properties getDebeziumProperties(JsonNode config, ConfiguredAirbyteCatalog catalog) { | ||
final Properties props = new Properties(); | ||
props.setProperty("name", "engine"); | ||
props.setProperty("plugin.name", "pgoutput"); | ||
|
@@ -240,7 +244,9 @@ protected static Properties getDebeziumProperties(JsonNode config) { | |
props.setProperty("drop.tombstones", "false"); | ||
props.setProperty("transforms.unwrap.type", "io.debezium.transforms.ExtractNewRecordState"); | ||
|
||
// props.setProperty("table.include.list", "public.id_and_name"); // todo | ||
final String tableWhitelist = getTableWhitelist(catalog); | ||
System.out.println("tableWhitelist = " + tableWhitelist); | ||
props.setProperty("table.include.list", tableWhitelist); | ||
props.setProperty("database.include.list", config.get("database").asText()); | ||
props.setProperty("name", "orders-postgres-connector"); | ||
props.setProperty("include_schema_changes", "true"); | ||
|
@@ -265,6 +271,16 @@ protected static Properties getDebeziumProperties(JsonNode config) { | |
return props; | ||
} | ||
|
||
protected static String getTableWhitelist(ConfiguredAirbyteCatalog catalog) { | ||
return catalog.getStreams().stream() | ||
.map(ConfiguredAirbyteStream::getStream) | ||
.map(AirbyteStream::getName) | ||
// debezium needs commas escaped to split properly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does debezium handle quoted syntax for databases? anything special we need to do to handle it? or does it just convert to uft8 string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test case. I'll also add an issue for properly handling quoting here long term. |
||
.map(x -> StringUtils.escape(x, new char[] {','}, "\\,")) | ||
.collect(Collectors.joining(",")); | ||
|
||
} | ||
|
||
private static boolean isCdc(JsonNode config) { | ||
LOGGER.info("isCdc config: " + config); | ||
return !(config.get("replication_slot") == null); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger or remove.