-
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][Transform-v2] Add metadata transform
- Loading branch information
Showing
15 changed files
with
651 additions
and
6 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
84 changes: 84 additions & 0 deletions
84
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/type/MetadataUtil.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,84 @@ | ||
/* | ||
* 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.api.table.type; | ||
|
||
import org.apache.seatunnel.api.table.catalog.TablePath; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class MetadataUtil { | ||
|
||
public static final String DATABASE = "database"; | ||
public static final String TABLE = "table"; | ||
public static final String PARTITION = "partition"; | ||
public static final String ROW_KIND = "rowKind"; | ||
public static final String EVENT_TIME = "ts_ms"; | ||
public static final String DELAY = "delay"; | ||
|
||
public static final List<String> METADATA_FIELDS = | ||
Arrays.asList(DELAY, PARTITION, DATABASE, TABLE, ROW_KIND, EVENT_TIME); | ||
|
||
public static void setDelay(SeaTunnelRow row, Long delay) { | ||
row.getMetadata().put(DELAY, delay); | ||
} | ||
|
||
public static void setPartition(SeaTunnelRow row, String[] partition) { | ||
row.getMetadata().put(PARTITION, partition); | ||
} | ||
|
||
public static void setEventTime(SeaTunnelRow row, Long delay) { | ||
row.getMetadata().put(EVENT_TIME, delay); | ||
} | ||
|
||
public static Long getDelay(SeaTunnelRow row) { | ||
return (Long) row.getMetadata().get(DELAY); | ||
} | ||
|
||
public static String getDatabase(SeaTunnelRow row) { | ||
TablePath tablePath = TablePath.of(row.getTableId()); | ||
return tablePath.getDatabaseName(); | ||
} | ||
|
||
public static String getTable(SeaTunnelRow row) { | ||
TablePath tablePath = TablePath.of(row.getTableId()); | ||
return tablePath.getTableName(); | ||
} | ||
|
||
public static String getRowKind(SeaTunnelRow row) { | ||
return row.getRowKind().shortString(); | ||
} | ||
|
||
public static String getPartitionStr(SeaTunnelRow row) { | ||
Object partition = row.getMetadata().get(PARTITION); | ||
return Objects.nonNull(partition) ? String.join(",", (String[]) partition) : null; | ||
} | ||
|
||
public static String[] getPartition(SeaTunnelRow row) { | ||
return (String[]) row.getMetadata().get(PARTITION); | ||
} | ||
|
||
public static Long getEventTime(SeaTunnelRow row) { | ||
return (Long) row.getMetadata().get(EVENT_TIME); | ||
} | ||
|
||
public static boolean isMetadataField(String fieldName) { | ||
return METADATA_FIELDS.contains(fieldName); | ||
} | ||
} |
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
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
102 changes: 102 additions & 0 deletions
102
...nnector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_metadata_trans.conf
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,102 @@ | ||
# | ||
# 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. | ||
# | ||
###### | ||
###### This config file is a demonstration of streaming processing in seatunnel config | ||
###### | ||
|
||
env { | ||
# You can set engine configuration here | ||
parallelism = 1 | ||
job.mode = "STREAMING" | ||
checkpoint.interval = 5000 | ||
read_limit.bytes_per_second = 7000000 | ||
read_limit.rows_per_second = 400 | ||
} | ||
|
||
source { | ||
MySQL-CDC { | ||
result_table_name = "customers_mysql_cdc" | ||
server-id = 5652 | ||
username = "st_user_source" | ||
password = "mysqlpw" | ||
table-names = ["mysql_cdc.mysql_cdc_e2e_source_table"] | ||
base-url = "jdbc:mysql://mysql_cdc_e2e:3306/mysql_cdc" | ||
} | ||
} | ||
|
||
transform { | ||
Metadata { | ||
metadata_fields { | ||
database = database | ||
table = table | ||
partition = partition | ||
rowKind = rowKind | ||
ts_ms = ts_ms | ||
delay = delay | ||
} | ||
result_table_name = "trans_result" | ||
} | ||
} | ||
|
||
sink { | ||
Assert { | ||
source_table_name = "trans_result" | ||
rules { | ||
field_rules = [ | ||
{ | ||
field_name = database | ||
field_type = string | ||
field_value = [ | ||
{ | ||
rule_type = NOT_NULL | ||
} | ||
] | ||
}, { | ||
field_name = table | ||
field_type = string | ||
field_value = [ | ||
{ | ||
rule_type = NOT_NULL | ||
} | ||
] | ||
}, { | ||
field_name = partition | ||
field_type = string | ||
}, { | ||
field_name = rowKind | ||
field_type = string | ||
field_value = [ | ||
{ | ||
rule_type = NOT_NULL | ||
} | ||
] | ||
}, { | ||
field_name = ts_ms | ||
field_type = long | ||
field_value = [ | ||
{ | ||
rule_type = NOT_NULL | ||
} | ||
] | ||
}, { | ||
field_name = delay | ||
field_type = long | ||
} | ||
] | ||
} | ||
} | ||
} |
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
Oops, something went wrong.