-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][transforms-v2] Support append only stream from cdc source (#…
- Loading branch information
Showing
13 changed files
with
912 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# RowKindExtractor | ||
|
||
> RowKindExtractor transform plugin | ||
## Description | ||
|
||
transform cdc row to append only row that contains the cdc RowKind. <br /> | ||
Example: <br /> | ||
CDC row: -D 1, test1, test2 <br /> | ||
transformed Row: +I 1,test1,test2,DELETE | ||
|
||
## Options | ||
|
||
| name | type | required | default value | | ||
|-------------------|--------|----------|---------------| | ||
| custom_field_name | string | yes | row_kind | | ||
| transform_type | enum | yes | SHORT | | ||
|
||
### custom_field_name [string] | ||
|
||
Custom field name of the RowKind field | ||
|
||
### transform_type [enum] | ||
|
||
the RowKind field value formatting , the option can be `SHORT` or `FULL` | ||
|
||
`SHORT` : +I, -U , +U, -D | ||
`FULL` : INSERT, UPDATE_BEFORE, UPDATE_AFTER , DELETE | ||
|
||
## Examples | ||
|
||
|
||
```yaml | ||
|
||
env { | ||
parallelism = 1 | ||
job.mode = "BATCH" | ||
} | ||
|
||
source { | ||
FakeSource { | ||
schema = { | ||
fields { | ||
pk_id = bigint | ||
name = string | ||
score = int | ||
} | ||
primaryKey { | ||
name = "pk_id" | ||
columnNames = [pk_id] | ||
} | ||
} | ||
rows = [ | ||
{ | ||
kind = INSERT | ||
fields = [1, "A", 100] | ||
}, | ||
{ | ||
kind = INSERT | ||
fields = [2, "B", 100] | ||
}, | ||
{ | ||
kind = INSERT | ||
fields = [3, "C", 100] | ||
}, | ||
{ | ||
kind = INSERT | ||
fields = [4, "D", 100] | ||
}, | ||
{ | ||
kind = UPDATE_BEFORE | ||
fields = [1, "A", 100] | ||
}, | ||
{ | ||
kind = UPDATE_AFTER | ||
fields = [1, "F", 100] | ||
} | ||
{ | ||
kind = UPDATE_BEFORE | ||
fields = [2, "B", 100] | ||
}, | ||
{ | ||
kind = UPDATE_AFTER | ||
fields = [2, "G", 100] | ||
}, | ||
{ | ||
kind = DELETE | ||
fields = [3, "C", 100] | ||
}, | ||
{ | ||
kind = DELETE | ||
fields = [4, "D", 100] | ||
} | ||
] | ||
} | ||
} | ||
|
||
transform { | ||
RowKindExtractor { | ||
custom_field_name = "custom_name" | ||
transform_type = FULL | ||
result_table_name = "trans_result" | ||
} | ||
} | ||
|
||
sink { | ||
Console { | ||
source_table_name = "custom_name" | ||
} | ||
} | ||
|
||
``` | ||
|
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,112 @@ | ||
# RowKindExtractor | ||
|
||
> RowKindExtractor transform plugin | ||
## Description | ||
|
||
将CDC Row 转换为 Append only Row, 转换后的行扩展了RowKind字段 <br /> | ||
Example: <br /> | ||
CDC row: -D 1, test1, test2 <br /> | ||
transformed Row: +I 1,test1,test2,DELETE | ||
|
||
## Options | ||
|
||
| name | type | required | default value | | ||
|-------------------|--------|----------|---------------| | ||
| custom_field_name | string | yes | row_kind | | ||
| transform_type | enum | yes | SHORT | | ||
|
||
### custom_field_name [string] | ||
|
||
RowKind列的自定义名 | ||
|
||
### transform_type [enum] | ||
|
||
格式化RowKind值 , 配置为 `SHORT` 或 `FULL` | ||
|
||
`SHORT` : +I, -U , +U, -D | ||
`FULL` : INSERT, UPDATE_BEFORE, UPDATE_AFTER , DELETE | ||
|
||
## Examples | ||
|
||
```yaml | ||
|
||
env { | ||
parallelism = 1 | ||
job.mode = "BATCH" | ||
} | ||
|
||
source { | ||
FakeSource { | ||
schema = { | ||
fields { | ||
pk_id = bigint | ||
name = string | ||
score = int | ||
} | ||
primaryKey { | ||
name = "pk_id" | ||
columnNames = [pk_id] | ||
} | ||
} | ||
rows = [ | ||
{ | ||
kind = INSERT | ||
fields = [1, "A", 100] | ||
}, | ||
{ | ||
kind = INSERT | ||
fields = [2, "B", 100] | ||
}, | ||
{ | ||
kind = INSERT | ||
fields = [3, "C", 100] | ||
}, | ||
{ | ||
kind = INSERT | ||
fields = [4, "D", 100] | ||
}, | ||
{ | ||
kind = UPDATE_BEFORE | ||
fields = [1, "A", 100] | ||
}, | ||
{ | ||
kind = UPDATE_AFTER | ||
fields = [1, "F", 100] | ||
} | ||
{ | ||
kind = UPDATE_BEFORE | ||
fields = [2, "B", 100] | ||
}, | ||
{ | ||
kind = UPDATE_AFTER | ||
fields = [2, "G", 100] | ||
}, | ||
{ | ||
kind = DELETE | ||
fields = [3, "C", 100] | ||
}, | ||
{ | ||
kind = DELETE | ||
fields = [4, "D", 100] | ||
} | ||
] | ||
} | ||
} | ||
|
||
transform { | ||
RowKindExtractor { | ||
custom_field_name = "custom_name" | ||
transform_type = FULL | ||
result_table_name = "trans_result" | ||
} | ||
} | ||
|
||
sink { | ||
Console { | ||
source_table_name = "custom_name" | ||
} | ||
} | ||
|
||
``` | ||
|
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
40 changes: 40 additions & 0 deletions
40
...t-1/src/test/java/org/apache/seatunnel/e2e/transform/TestRowKindExtractorTransformIT.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,40 @@ | ||
/* | ||
* 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.seatunnel.e2e.transform; | ||
|
||
import org.apache.seatunnel.e2e.common.container.TestContainer; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.testcontainers.containers.Container; | ||
|
||
import java.io.IOException; | ||
|
||
public class TestRowKindExtractorTransformIT extends TestSuiteBase { | ||
|
||
@TestTemplate | ||
public void testRowKindExtractorTransform(TestContainer container) | ||
throws IOException, InterruptedException { | ||
Container.ExecResult execResult1 = | ||
container.executeJob("/rowkind_extractor_transform_case1.conf"); | ||
Assertions.assertEquals(0, execResult1.getExitCode()); | ||
Container.ExecResult execResult2 = | ||
container.executeJob("/rowkind_extractor_transform_case2.conf"); | ||
Assertions.assertEquals(0, execResult2.getExitCode()); | ||
} | ||
} |
Oops, something went wrong.