-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
107 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...va/org/apache/shardingsphere/data/pipeline/api/config/ingest/BaseDumperConfiguration.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,122 @@ | ||
/* | ||
* 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.shardingsphere.data.pipeline.api.config.ingest; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.apache.shardingsphere.data.pipeline.api.config.TableNameSchemaNameMapping; | ||
import org.apache.shardingsphere.data.pipeline.api.datasource.config.PipelineDataSourceConfiguration; | ||
import org.apache.shardingsphere.data.pipeline.api.ingest.position.IngestPosition; | ||
import org.apache.shardingsphere.data.pipeline.api.metadata.ActualTableName; | ||
import org.apache.shardingsphere.data.pipeline.api.metadata.ColumnName; | ||
import org.apache.shardingsphere.data.pipeline.api.metadata.LogicTableName; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Base dumper configuration. | ||
*/ | ||
@Getter | ||
@Setter | ||
@ToString(exclude = {"dataSourceConfig", "tableNameSchemaNameMapping"}) | ||
public abstract class BaseDumperConfiguration { | ||
|
||
private String dataSourceName; | ||
|
||
private PipelineDataSourceConfiguration dataSourceConfig; | ||
|
||
private IngestPosition position; | ||
|
||
private Map<ActualTableName, LogicTableName> tableNameMap; | ||
|
||
private TableNameSchemaNameMapping tableNameSchemaNameMapping; | ||
|
||
// LinkedHashSet is required | ||
private Map<LogicTableName, Collection<ColumnName>> targetTableColumnsMap = new HashMap<>(); | ||
|
||
/** | ||
* Get logic table name. | ||
* | ||
* @param actualTableName actual table name | ||
* @return logic table name | ||
*/ | ||
public LogicTableName getLogicTableName(final String actualTableName) { | ||
return tableNameMap.get(new ActualTableName(actualTableName)); | ||
} | ||
|
||
private LogicTableName getLogicTableName(final ActualTableName actualTableName) { | ||
return tableNameMap.get(actualTableName); | ||
} | ||
|
||
/** | ||
* Whether contains table. | ||
* | ||
* @param actualTableName actual table name | ||
* @return contains or not | ||
*/ | ||
public boolean containsTable(final String actualTableName) { | ||
return tableNameMap.containsKey(new ActualTableName(actualTableName)); | ||
} | ||
|
||
/** | ||
* Get schema name. | ||
* | ||
* @param logicTableName logic table name | ||
* @return schema name. nullable | ||
*/ | ||
public String getSchemaName(final LogicTableName logicTableName) { | ||
return tableNameSchemaNameMapping.getSchemaName(logicTableName); | ||
} | ||
|
||
/** | ||
* Get schema name. | ||
* | ||
* @param actualTableName actual table name | ||
* @return schema name. nullable | ||
*/ | ||
public String getSchemaName(final ActualTableName actualTableName) { | ||
return tableNameSchemaNameMapping.getSchemaName(getLogicTableName(actualTableName)); | ||
} | ||
|
||
/** | ||
* Get column names. | ||
* | ||
* @param logicTableName logic table name | ||
* @return column names | ||
*/ | ||
public Collection<String> getColumnNames(final LogicTableName logicTableName) { | ||
return targetTableColumnsMap.containsKey(logicTableName) | ||
? targetTableColumnsMap.get(logicTableName).stream().map(ColumnName::getOriginal).collect(Collectors.toList()) | ||
: Collections.singleton("*"); | ||
} | ||
|
||
/** | ||
* Get column names. | ||
* | ||
* @param actualTableName actual table name | ||
* @return column names | ||
*/ | ||
public Collection<ColumnName> getColumnNames(final String actualTableName) { | ||
return targetTableColumnsMap.getOrDefault(getLogicTableName(actualTableName), Collections.emptySet()); | ||
} | ||
} |
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