forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FakeSource support generate different CatalogTable for MultipleTable
- Loading branch information
1 parent
72be666
commit 7e9094a
Showing
19 changed files
with
794 additions
and
512 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
519 changes: 249 additions & 270 deletions
519
...-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/FakeConfig.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
74 changes: 74 additions & 0 deletions
74
.../org/apache/seatunnel/connectors/seatunnel/fake/config/MultipleTableFakeSourceConfig.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,74 @@ | ||
/* | ||
* 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.connectors.seatunnel.fake.config; | ||
|
||
import org.apache.seatunnel.api.configuration.ReadonlyConfig; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
|
||
import com.google.common.collect.Lists; | ||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class MultipleTableFakeSourceConfig implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Getter private List<FakeConfig> fakeConfigs; | ||
|
||
public MultipleTableFakeSourceConfig(ReadonlyConfig fakeSourceRootConfig) { | ||
if (fakeSourceRootConfig.getOptional(FakeOption.TABLES_CONFIGS).isPresent()) { | ||
parseFromConfigs(fakeSourceRootConfig); | ||
} else { | ||
parseFromConfig(fakeSourceRootConfig); | ||
} | ||
// validate | ||
assert fakeConfigs != null; | ||
if (fakeConfigs.size() > 1) { | ||
List<String> tableNames = | ||
fakeConfigs.stream() | ||
.map(FakeConfig::getCatalogTable) | ||
.map(catalogTable -> catalogTable.getTableId().toTablePath().toString()) | ||
.collect(Collectors.toList()); | ||
if (CollectionUtils.size(tableNames) != new HashSet<>(tableNames).size()) { | ||
throw new IllegalArgumentException("table name: " + tableNames + " must be unique"); | ||
} | ||
} | ||
} | ||
|
||
private void parseFromConfigs(ReadonlyConfig readonlyConfig) { | ||
List<ReadonlyConfig> readonlyConfigs = | ||
readonlyConfig.getOptional(FakeOption.TABLES_CONFIGS).get().stream() | ||
.map(ReadonlyConfig::fromMap) | ||
.collect(Collectors.toList()); | ||
// Use the config outside if it's not set in sub config | ||
fakeConfigs = | ||
readonlyConfigs.stream() | ||
.map(FakeConfig::buildWithConfig) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private void parseFromConfig(ReadonlyConfig readonlyConfig) { | ||
FakeConfig fakeConfig = FakeConfig.buildWithConfig(readonlyConfig); | ||
fakeConfigs = Lists.newArrayList(fakeConfig); | ||
} | ||
} |
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.