hawk9821 commented on code in PR #7935:
URL: https://github.com/apache/seatunnel/pull/7935#discussion_r1826577035
##########
seatunnel-connectors-v2/connector-cdc/connector-cdc-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mongodb/MongodbIncrementalSourceFactory.java:
##########
@@ -79,9 +88,28 @@ public Class<? extends SeaTunnelSource> getSourceClass() {
public <T, SplitT extends SourceSplit, StateT extends Serializable>
TableSource<T, SplitT, StateT>
createSource(TableSourceFactoryContext context) {
return () -> {
- List<CatalogTable> catalogTables =
+ List<CatalogTable> configCatalog =
CatalogTableUtil.getCatalogTables(
context.getOptions(), context.getClassLoader());
+ List<String> collections =
context.getOptions().get(MongodbSourceOptions.COLLECTION);
+ if (collections.size() != configCatalog.size()) {
+ throw new MongodbConnectorException(
+ ILLEGAL_ARGUMENT,
+ "The number of collections must be equal to the number
of schema tables");
+ }
Review Comment:
parse the build catalog from the configuration when the mongodb cdc source
creating, cannot parse to build a catalog without specifying the Schema in the
configuration file.
```
public <T, SplitT extends SourceSplit, StateT extends Serializable>
TableSource<T, SplitT, StateT>
createSource(TableSourceFactoryContext context) {
return () -> {
List<CatalogTable> catalogTables =
CatalogTableUtil.getCatalogTables(
context.getOptions(), context.getClassLoader());
SeaTunnelDataType<SeaTunnelRow> dataType =
CatalogTableUtil.convertToMultipleRowType(catalogTables);
return (SeaTunnelSource<T, SplitT, StateT>)
new MongodbIncrementalSource<>(context.getOptions(),
dataType, catalogTables);
};
}
```
If no schema is configured, throw execption
```
Caused by: org.apache.seatunnel.common.utils.SeaTunnelException: Can not
find catalog with factoryId [MongoDB]
at
org.apache.seatunnel.api.table.catalog.CatalogTableUtil.lambda$getCatalogTables$1(CatalogTableUtil.java:141)
at java.util.Optional.orElseThrow(Optional.java:290)
at
org.apache.seatunnel.api.table.catalog.CatalogTableUtil.getCatalogTables(CatalogTableUtil.java:138)
at
org.apache.seatunnel.api.table.catalog.CatalogTableUtil.getCatalogTables(CatalogTableUtil.java:98)
at
org.apache.seatunnel.connectors.seatunnel.cdc.mongodb.MongodbIncrementalSourceFactory.lambda$createSource$0(MongodbIncrementalSourceFactory.java:83)
at
org.apache.seatunnel.api.table.factory.FactoryUtil.createAndPrepareSource(FactoryUtil.java:113)
at
org.apache.seatunnel.api.table.factory.FactoryUtil.createAndPrepareSource(FactoryUtil.java:74)
... 7 more
```
The description in the document is wrong.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]