-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if configuration has isUnwrapped
- Loading branch information
1 parent
a299f51
commit c7ac14c
Showing
7 changed files
with
157 additions
and
34 deletions.
There are no files selected for viewing
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
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
75 changes: 75 additions & 0 deletions
75
...ceberg-sink/src/test/java/io/debezium/server/iceberg/IcebergChangeEventTestUnwrapped.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,75 @@ | ||
/* | ||
* | ||
* * Copyright memiiso Authors. | ||
* * | ||
* * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*/ | ||
|
||
package io.debezium.server.iceberg; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.debezium.serde.DebeziumSerdes; | ||
import io.debezium.server.iceberg.testresources.IcebergChangeEventBuilder; | ||
import io.debezium.server.iceberg.testresources.S3Minio; | ||
import io.debezium.server.iceberg.testresources.SourceMysqlDB; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import jakarta.inject.Inject; | ||
import org.apache.iceberg.Schema; | ||
import org.apache.iceberg.data.GenericRecord; | ||
import org.apache.iceberg.types.Types; | ||
import org.apache.kafka.common.serialization.Serde; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@QuarkusTest | ||
@TestProfile(IcebergChangeEventTestUnwrapped.TestProfile.class) | ||
class IcebergChangeEventTestUnwrapped { | ||
|
||
@Test | ||
public void testIcebergChangeEventSchemaWithNestedKey() throws IOException { | ||
|
||
assertFalse(IcebergUtil.configIncludesUnwrapSmt()); | ||
|
||
String key = Files.readString(Path.of("src/test/resources/json/serde-unnested-order-key-withschema.json")); | ||
String val = Files.readString(Path.of("src/test/resources/json/serde-unnested-order-val-withschema.json")); | ||
TestChangeEvent<String, String> dbzEvent = new TestChangeEvent<>(key, val, "test"); | ||
Schema schema = dbzEvent.toIcebergChangeEvent().icebergSchema(); | ||
assertEquals(""" | ||
table { | ||
1: before: optional struct<2: order_number: optional int, 3: order_date: optional int, 4: purchaser: optional int, 5: quantity: optional int, 6: product_id: optional int> | ||
7: after: required struct<8: order_number: required int, 9: order_date: optional int, 10: purchaser: optional int, 11: quantity: optional int, 12: product_id: optional int> | ||
13: source: optional struct<14: version: optional string, 15: connector: optional string, 16: name: optional string, 17: ts_ms: optional long, 18: snapshot: optional string, 19: db: optional string, 20: sequence: optional string, 21: ts_us: optional long, 22: ts_ns: optional long, 23: table: optional string, 24: server_id: optional long, 25: gtid: optional string, 26: file: optional string, 27: pos: optional long, 28: row: optional int, 29: thread: optional long, 30: query: optional string> | ||
31: transaction: optional struct<32: id: optional string, 33: total_order: optional long, 34: data_collection_order: optional long> | ||
35: op: optional string | ||
36: ts_ms: optional long | ||
37: ts_us: optional long | ||
38: ts_ns: optional long | ||
}""", schema.toString()); | ||
assertEquals(Set.of(8), schema.identifierFieldIds()); | ||
} | ||
public static class TestProfile implements QuarkusTestProfile { | ||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
Map<String, String> config = new HashMap<>(); | ||
config.put("debezium.transforms", ","); | ||
config.put("debezium.transforms.unwrap.type", "null"); | ||
|
||
return config; | ||
} | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
debezium-server-iceberg-sink/src/test/java/io/debezium/server/iceberg/IcebergUtilTest.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,42 @@ | ||
package io.debezium.server.iceberg; | ||
|
||
import io.smallrye.config.SmallRyeConfig; | ||
import io.smallrye.config.SmallRyeConfigBuilder; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class IcebergUtilTest { | ||
|
||
|
||
@Test | ||
void configIncludesUnwrapSmt() { | ||
// mongodb transforms | ||
String mongoConfVal = "io.debezium.connector.mongodb.transforms.ExtractNewDocumentState"; | ||
SmallRyeConfig mongodbConf = new SmallRyeConfigBuilder(). | ||
withProfile("mongodb"). | ||
withDefaultValue("debezium.transforms", "unwrap,someothersmt"). | ||
withDefaultValue("%mongodb.debezium.transforms.unwrap.type", mongoConfVal). | ||
build(); | ||
assertEquals(mongodbConf.getConfigValue("debezium.transforms.unwrap.type").getValue(), mongoConfVal); | ||
assertTrue(IcebergUtil.configIncludesUnwrapSmt(mongodbConf)); | ||
|
||
String defaultConfVal = "io.debezium.transforms.ExtractNewRecordState"; | ||
SmallRyeConfig defaultConf = new SmallRyeConfigBuilder(). | ||
withProfile("mysql"). | ||
withDefaultValue("%mysql.debezium.transforms", "unwrapdata,someothersmt"). | ||
withDefaultValue("%mysql.debezium.transforms.unwrapdata.type", defaultConfVal). | ||
build(); | ||
assertEquals(defaultConf.getConfigValue("debezium.transforms.unwrapdata.type").getValue(), defaultConfVal); | ||
assertTrue(IcebergUtil.configIncludesUnwrapSmt(defaultConf)); | ||
|
||
|
||
SmallRyeConfig testConf = new SmallRyeConfigBuilder(). | ||
withProfile("testing"). | ||
withDefaultValue("%testing.test.property", "test-Value"). | ||
build(); | ||
assertEquals(testConf.getConfigValue("test.property").getValue(), "test-Value"); | ||
assertFalse(IcebergUtil.configIncludesUnwrapSmt(testConf)); | ||
} | ||
|
||
} |
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