-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Kafka Connect: Add SMTs for Debezium and AWS DMS #11936
base: main
Are you sure you want to change the base?
Changes from all commits
18fed10
801067b
7c51578
09ecf98
bf4b049
2bbd007
932fe3c
ba451e4
245c9c4
cb72c08
d17d51b
3df104d
6a0b394
703d327
f99a10e
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ awaitility = "4.2.2" | |
awssdk-bom = "2.29.43" | ||
azuresdk-bom = "1.2.30" | ||
awssdk-s3accessgrants = "2.3.0" | ||
bson-ver = "4.11.0" | ||
caffeine = "2.9.3" | ||
calcite = "1.10.0" | ||
datasketches = "6.1.1" | ||
|
@@ -100,6 +101,7 @@ avro-avro = { module = "org.apache.avro:avro", version.ref = "avro" } | |
awssdk-bom = { module = "software.amazon.awssdk:bom", version.ref = "awssdk-bom" } | ||
awssdk-s3accessgrants = { module = "software.amazon.s3.accessgrants:aws-s3-accessgrants-java-plugin", version.ref = "awssdk-s3accessgrants" } | ||
azuresdk-bom = { module = "com.azure:azure-sdk-bom", version.ref = "azuresdk-bom" } | ||
bson = { module = "org.mongodb:bson", version.ref = "bson-ver"} | ||
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine" } | ||
calcite-core = { module = "org.apache.calcite:calcite-core", version.ref = "calcite" } | ||
calcite-druid = { module = "org.apache.calcite:calcite-druid", version.ref = "calcite" } | ||
|
@@ -159,6 +161,7 @@ jaxb-runtime = { module = "org.glassfish.jaxb:jaxb-runtime", version.ref = "jaxb | |
kafka-clients = { module = "org.apache.kafka:kafka-clients", version.ref = "kafka" } | ||
kafka-connect-api = { module = "org.apache.kafka:connect-api", version.ref = "kafka" } | ||
kafka-connect-json = { module = "org.apache.kafka:connect-json", version.ref = "kafka" } | ||
kafka-connect-transforms = { module = "org.apache.kafka:connect-transforms", version.ref = "kafka" } | ||
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. We need to verify this addition is captured in LICENSE/NOTICE files (if separate from the other kafka dependencies) 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 section for kafka libs to LICENSE 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. I think we can skip that too for now, until we add the transforms to the runtime. 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. @bryanck do you mean remove all grade setting/changes from this PR and add it with separate PR? 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. I meant skip any of the runtime license changes, until we add the transforms lib to the runtime 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. in that case i have reverted all the changes done to LICENSE/NOTICE files. |
||
microprofile-openapi-api = { module = "org.eclipse.microprofile.openapi:microprofile-openapi-api", version.ref = "microprofile-openapi-api" } | ||
nessie-client = { module = "org.projectnessie.nessie:nessie-client", version.ref = "nessie" } | ||
netty-buffer = { module = "io.netty:netty-buffer", version.ref = "netty-buffer" } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.iceberg.connect.transforms; | ||
|
||
public interface CdcConstants { | ||
|
||
String OP_INSERT = "I"; | ||
String OP_UPDATE = "U"; | ||
String OP_DELETE = "D"; | ||
|
||
String COL_CDC = "_cdc"; | ||
String COL_OP = "op"; | ||
String COL_TS = "ts"; | ||
String COL_OFFSET = "offset"; | ||
String COL_SOURCE = "source"; | ||
String COL_TARGET = "target"; | ||
String COL_KEY = "key"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.iceberg.connect.transforms; | ||
|
||
import java.util.Map; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
import org.apache.kafka.common.cache.Cache; | ||
import org.apache.kafka.common.cache.LRUCache; | ||
import org.apache.kafka.common.cache.SynchronizedCache; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.connect.connector.ConnectRecord; | ||
import org.apache.kafka.connect.data.Field; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.apache.kafka.connect.transforms.Transformation; | ||
import org.apache.kafka.connect.transforms.util.Requirements; | ||
import org.apache.kafka.connect.transforms.util.SchemaUtil; | ||
import org.apache.kafka.connect.transforms.util.SimpleConfig; | ||
|
||
public class CopyValue<R extends ConnectRecord<R>> implements Transformation<R> { | ||
|
||
private static final String SOURCE_FIELD = "source.field"; | ||
private static final String TARGET_FIELD = "target.field"; | ||
|
||
public static final ConfigDef CONFIG_DEF = | ||
new ConfigDef() | ||
.define( | ||
SOURCE_FIELD, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "Source field name.") | ||
.define( | ||
TARGET_FIELD, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "Target field name."); | ||
|
||
private String sourceField; | ||
private String targetField; | ||
private Cache<Schema, Schema> schemaUpdateCache; | ||
|
||
@Override | ||
public void configure(Map<String, ?> props) { | ||
SimpleConfig config = new SimpleConfig(CONFIG_DEF, props); | ||
sourceField = config.getString(SOURCE_FIELD); | ||
targetField = config.getString(TARGET_FIELD); | ||
schemaUpdateCache = new SynchronizedCache<>(new LRUCache<>(16)); | ||
} | ||
|
||
@Override | ||
public R apply(R record) { | ||
if (record.value() == null) { | ||
return record; | ||
} else if (record.valueSchema() == null) { | ||
return applySchemaless(record); | ||
} else { | ||
return applyWithSchema(record); | ||
} | ||
} | ||
|
||
private R applySchemaless(R record) { | ||
Map<String, Object> value = Requirements.requireMap(record.value(), "copy value"); | ||
|
||
Map<String, Object> updatedValue = Maps.newHashMap(value); | ||
updatedValue.put(targetField, value.get(sourceField)); | ||
|
||
return newRecord(record, null, updatedValue); | ||
} | ||
|
||
private R applyWithSchema(R record) { | ||
Struct value = Requirements.requireStruct(record.value(), "copy value"); | ||
|
||
Schema updatedSchema = schemaUpdateCache.get(value.schema()); | ||
if (updatedSchema == null) { | ||
updatedSchema = makeUpdatedSchema(value.schema()); | ||
schemaUpdateCache.put(value.schema(), updatedSchema); | ||
} | ||
|
||
Struct updatedValue = new Struct(updatedSchema); | ||
|
||
for (Field field : value.schema().fields()) { | ||
updatedValue.put(field.name(), value.get(field)); | ||
} | ||
updatedValue.put(targetField, value.get(sourceField)); | ||
|
||
return newRecord(record, updatedSchema, updatedValue); | ||
} | ||
|
||
private Schema makeUpdatedSchema(Schema schema) { | ||
SchemaBuilder builder = SchemaUtil.copySchemaBasics(schema, SchemaBuilder.struct()); | ||
|
||
for (Field field : schema.fields()) { | ||
builder.field(field.name(), field.schema()); | ||
} | ||
builder.field(targetField, schema.field(sourceField).schema()); | ||
|
||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
schemaUpdateCache = null; | ||
} | ||
|
||
@Override | ||
public ConfigDef config() { | ||
return CONFIG_DEF; | ||
} | ||
|
||
protected R newRecord(R record, Schema updatedSchema, Object updatedValue) { | ||
return record.newRecord( | ||
record.topic(), | ||
record.kafkaPartition(), | ||
record.keySchema(), | ||
record.key(), | ||
updatedSchema, | ||
updatedValue, | ||
record.timestamp()); | ||
} | ||
} |
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.
We need to verify this addition is captured in LICENSE/NOTICE files.
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.
added section for mongodb bson libs to LICENSE
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.
I think we can remove it until we add the transform library to the runtime. When we do that, then the new license plugin can add what is needed.