-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdc] Added database action factory base class (#2793)
- Loading branch information
1 parent
58113a7
commit 8d51ae5
Showing
7 changed files
with
161 additions
and
144 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...k-cdc/src/main/java/org/apache/paimon/flink/action/cdc/SyncDatabaseActionFactoryBase.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,59 @@ | ||
/* | ||
* 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.paimon.flink.action.cdc; | ||
|
||
import org.apache.paimon.flink.action.Action; | ||
import org.apache.paimon.flink.action.ActionFactory; | ||
import org.apache.paimon.flink.action.MultipleParameterToolAdapter; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.EXCLUDING_TABLES; | ||
import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.INCLUDING_TABLES; | ||
import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.TABLE_PREFIX; | ||
import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.TABLE_SUFFIX; | ||
import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.TYPE_MAPPING; | ||
|
||
/** Base {@link ActionFactory} for synchronizing into database. */ | ||
public abstract class SyncDatabaseActionFactoryBase<T extends SyncDatabaseActionBase> | ||
extends SynchronizationActionFactoryBase<T> { | ||
|
||
protected String warehouse; | ||
protected String database; | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
this.warehouse = getRequiredValue(params, WAREHOUSE); | ||
this.database = getRequiredValue(params, DATABASE); | ||
return super.create(params); | ||
} | ||
|
||
@Override | ||
protected void withParams(MultipleParameterToolAdapter params, T action) { | ||
action.withTablePrefix(params.get(TABLE_PREFIX)) | ||
.withTableSuffix(params.get(TABLE_SUFFIX)) | ||
.includingTables(params.get(INCLUDING_TABLES)) | ||
.excludingTables(params.get(EXCLUDING_TABLES)); | ||
|
||
if (params.has(TYPE_MAPPING)) { | ||
String[] options = params.get(TYPE_MAPPING).split(","); | ||
action.withTypeMapping(TypeMapping.parse(options)); | ||
} | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...dc/src/main/java/org/apache/paimon/flink/action/cdc/SynchronizationActionFactoryBase.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,54 @@ | ||
/* | ||
* 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.paimon.flink.action.cdc; | ||
|
||
import org.apache.paimon.flink.action.Action; | ||
import org.apache.paimon.flink.action.ActionFactory; | ||
import org.apache.paimon.flink.action.MultipleParameterToolAdapter; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** Base {@link ActionFactory} for table/database synchronizing job. */ | ||
public abstract class SynchronizationActionFactoryBase<T extends SynchronizationActionBase> | ||
implements ActionFactory { | ||
|
||
protected Map<String, String> catalogConfig; | ||
protected Map<String, String> cdcSourceConfig; | ||
|
||
protected abstract String cdcConfigIdentifier(); | ||
|
||
public abstract T createAction(); | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
checkRequiredArgument(params, cdcConfigIdentifier()); | ||
this.catalogConfig = optionalConfigMap(params, CATALOG_CONF); | ||
this.cdcSourceConfig = optionalConfigMap(params, cdcConfigIdentifier()); | ||
|
||
T action = createAction(); | ||
|
||
action.withTableConfig(optionalConfigMap(params, TABLE_CONF)); | ||
withParams(params, action); | ||
|
||
return Optional.of(action); | ||
} | ||
|
||
protected abstract void withParams(MultipleParameterToolAdapter params, T action); | ||
} |
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
Oops, something went wrong.