From 78d77e29727147e454b3bbf9414a35166a39d5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AE=97=E6=96=87?= Date: Tue, 29 Mar 2022 23:36:39 +0800 Subject: [PATCH] [Feature][core] base interface. (#1608) --- .../seatunnel/catalog/CatalogTable.java | 20 ++++++++ .../factories/MultipleTableFactory.java | 47 +++++++++++++++++++ .../factories/MultipleTableSinkFactory.java | 37 +++++++++++++++ .../factories/MultipleTableSourceFactory.java | 39 +++++++++++++++ .../java/org/apache/seatunnel/sink/Sink.java | 22 +++++++++ .../org/apache/seatunnel/source/Source.java | 30 ++++++++++++ .../apache/seatunnel/source/SourceReader.java | 20 ++++++++ .../apache/seatunnel/source/SourceSplit.java | 29 ++++++++++++ .../source/SourceSplitEnumerator.java | 20 ++++++++ 9 files changed, 264 insertions(+) create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/catalog/CatalogTable.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableFactory.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSinkFactory.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSourceFactory.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/sink/Sink.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/Source.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceReader.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplit.java create mode 100644 seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplitEnumerator.java diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/catalog/CatalogTable.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/catalog/CatalogTable.java new file mode 100644 index 000000000000..8338a0d0eb5a --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/catalog/CatalogTable.java @@ -0,0 +1,20 @@ +/* + * 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.catalog; + +public class CatalogTable {} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableFactory.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableFactory.java new file mode 100644 index 000000000000..33a3a18f4c54 --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableFactory.java @@ -0,0 +1,47 @@ +/* + * 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.factories; + +import org.apache.seatunnel.catalog.CatalogTable; + +import java.util.List; +import java.util.Map; + +/** + * This factory is used with Java's Service Provider Interfaces (SPI) for discovering. + * + *

Classes that implement this interface can be added to the + * "META_INF/services/org.apache.seatunnel.factories.TableFactory" file of a JAR file in the current + * classpath to be found. + * + * @since 2022/03/29 + */ +public interface MultipleTableFactory { + + /** Returns a unique identifier among same factory interfaces. */ + String identifier(); + + /** Provides information describing the multi-table to be accessed. */ + interface Context { + + List getMultipleCatalogTable(); + + /** Gives read-only access to the options of the current session. */ + Map getOptions(); + } +} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSinkFactory.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSinkFactory.java new file mode 100644 index 000000000000..7dafd180b5ad --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSinkFactory.java @@ -0,0 +1,37 @@ +/* + * 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.factories; + +import org.apache.seatunnel.sink.Sink; + +/** + * A factory to create configured multi-table sink instances. + * + * @since 2022/03/29 + */ +public interface MultipleTableSinkFactory extends MultipleTableFactory { + + /** + * Creates a {@link Sink} instance from multi-table {@link + * org.apache.seatunnel.catalog.CatalogTable} and additional context information. + * + *

An implementation should perform validation and the discovery of further (nested) + * factories in this method. + */ + Sink createMultipleTableSink(Context context); +} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSourceFactory.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSourceFactory.java new file mode 100644 index 000000000000..394d410de72e --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/factories/MultipleTableSourceFactory.java @@ -0,0 +1,39 @@ +/* + * 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.factories; + +import org.apache.seatunnel.source.Source; +import org.apache.seatunnel.source.SourceSplit; + +/** + * A factory to create configured multi-table source instances. + * + * @since 2022/03/29 + */ +public interface MultipleTableSourceFactory extends MultipleTableFactory { + + /** + * Creates a {@link Source} instance from multi-table {@link + * org.apache.seatunnel.catalog.CatalogTable} and additional context information. + * + *

An implementation should perform validation and the discovery of further (nested) + * factories in this method. + */ + Source createMultipleTableSource( + MultipleTableFactory.Context context); +} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/sink/Sink.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/sink/Sink.java new file mode 100644 index 000000000000..4d25df52247f --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/sink/Sink.java @@ -0,0 +1,22 @@ +/* + * 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.sink; + +import java.io.Serializable; + +public interface Sink extends Serializable {} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/Source.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/Source.java new file mode 100644 index 000000000000..66404de81591 --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/Source.java @@ -0,0 +1,30 @@ +/* + * 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.source; + +import java.io.Serializable; + +/** + * The interface for Source. It acts like a factory class that helps construct the {@link + * SourceSplitEnumerator} and {@link SourceReader} and corresponding serializers. + * + * @param The type of records produced by the source. + * @param The type of splits handled by the source. + * @param The type of state to store. + */ +public interface Source extends Serializable {} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceReader.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceReader.java new file mode 100644 index 000000000000..9fa09b8ffbaf --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceReader.java @@ -0,0 +1,20 @@ +/* + * 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.source; + +public interface SourceReader {} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplit.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplit.java new file mode 100644 index 000000000000..84fbf5371b63 --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplit.java @@ -0,0 +1,29 @@ +/* + * 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.source; + +/** An interface for all the Split types to extend. */ +public interface SourceSplit { + + /** + * Get the split id of this source split. + * + * @return id of this source split. + */ + String splitId(); +} diff --git a/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplitEnumerator.java b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplitEnumerator.java new file mode 100644 index 000000000000..b0b98fe159ba --- /dev/null +++ b/seatunnel-apis/seatunnel-api-base/src/main/java/org/apache/seatunnel/source/SourceSplitEnumerator.java @@ -0,0 +1,20 @@ +/* + * 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.source; + +public interface SourceSplitEnumerator {}