-
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.
Improve conversion of debezium schema to iceberg schema (#347)
* Improve conversion of debezium schema to iceberg schema * Improve conversion of debezium schema to iceberg schema
- Loading branch information
1 parent
0997cae
commit ab211b3
Showing
3 changed files
with
85 additions
and
41 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
28 changes: 28 additions & 0 deletions
28
...r-iceberg-sink/src/main/java/io/debezium/server/iceberg/IcebergChangeEventSchemaData.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,28 @@ | ||
package io.debezium.server.iceberg; | ||
|
||
import org.apache.iceberg.types.Types; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
record IcebergChangeEventSchemaData(List<Types.NestedField> fields, Set<Integer> identifierFieldIds, | ||
AtomicInteger nextFieldId) { | ||
|
||
|
||
public IcebergChangeEventSchemaData(Integer nextFieldId) { | ||
this(new ArrayList<>(), new HashSet<>(), new AtomicInteger(nextFieldId)); | ||
} | ||
|
||
public IcebergChangeEventSchemaData() { | ||
this(new ArrayList<>(), new HashSet<>(), new AtomicInteger(1)); | ||
} | ||
|
||
public IcebergChangeEventSchemaData copyKeepNextFieldId() { | ||
return new IcebergChangeEventSchemaData(new ArrayList<>(), new HashSet<>(), this.nextFieldId); | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...eberg-sink/src/test/java/io/debezium/server/iceberg/IcebergChangeEventSchemaDataTest.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,21 @@ | ||
package io.debezium.server.iceberg; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class IcebergChangeEventSchemaDataTest { | ||
|
||
@Test | ||
void nextFieldId() { | ||
|
||
IcebergChangeEventSchemaData test = new IcebergChangeEventSchemaData(5); | ||
test.identifierFieldIds().add(1); | ||
assertEquals(6, test.nextFieldId().incrementAndGet()); | ||
|
||
IcebergChangeEventSchemaData testSubschemaField = test.copyKeepNextFieldId(); | ||
testSubschemaField.nextFieldId().incrementAndGet(); | ||
assertEquals(7, test.nextFieldId().get()); | ||
} | ||
|
||
} |