This is an automated email from the ASF dual-hosted git repository.
gaojun2048 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new 74b61c33a [Connector-V2] [Fake] Add Fake TableSourceFactory (#3345)
74b61c33a is described below
commit 74b61c33a0fb389307e09cd33371e0374626ec27
Author: Hisoka <[email protected]>
AuthorDate: Wed Nov 9 22:03:08 2022 +0800
[Connector-V2] [Fake] Add Fake TableSourceFactory (#3345)
---
docs/en/connector-v2/source/FakeSource.md | 10 ++--
.../connectors/seatunnel/fake/config/Config.java | 41 ++++++++++++++
.../seatunnel/fake/config/FakeConfig.java | 62 ++++++++++------------
.../seatunnel/fake/source/FakeSourceFactory.java | 47 ++++++++++++++++
4 files changed, 122 insertions(+), 38 deletions(-)
diff --git a/docs/en/connector-v2/source/FakeSource.md
b/docs/en/connector-v2/source/FakeSource.md
index 580069476..a1e651e47 100644
--- a/docs/en/connector-v2/source/FakeSource.md
+++ b/docs/en/connector-v2/source/FakeSource.md
@@ -36,11 +36,7 @@ just for some test cases such as type conversion or
connector new feature testin
The schema of fake data that you want to generate
-### common options
-
-Source plugin common parameters, please refer to [Source Common
Options](common-options.md) for details
-
-## Examples
+#### Examples
```hocon
schema = {
@@ -109,6 +105,10 @@ The length of `bytes` type that connector generated
The length of `string` type that connector generated
+### common options
+
+Source plugin common parameters, please refer to [Source Common
Options](common-options.md) for details
+
## Example
```hocon
diff --git
a/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/Config.java
b/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/Config.java
new file mode 100644
index 000000000..2f8ade970
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/Config.java
@@ -0,0 +1,41 @@
+/*
+ * 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.Option;
+import org.apache.seatunnel.api.configuration.Options;
+
+@SuppressWarnings("checkstyle:MagicNumber")
+public class Config {
+
+ public static final Option<Integer> ROW_NUM =
Options.key("row.num").intType().defaultValue(5)
+ .withDescription("The total number of data generated per degree of
parallelism");
+ public static final Option<Integer> SPLIT_NUM =
Options.key("split.num").intType().defaultValue(1)
+ .withDescription("The number of splits generated by the enumerator for
each degree of parallelism");
+ public static final Option<Integer> SPLIT_READ_INTERVAL =
Options.key("split.read-interval").intType().defaultValue(1)
+ .withDescription("The interval(mills) between two split reads in a
reader");
+ public static final Option<Integer> MAP_SIZE =
Options.key("map.size").intType().defaultValue(5)
+ .withDescription("The size of map type that connector generated");
+ public static final Option<Integer> ARRAY_SIZE =
Options.key("array.size").intType().defaultValue(5)
+ .withDescription("The size of array type that connector generated");
+ public static final Option<Integer> BYTES_LENGTH =
Options.key("bytes.length").intType().defaultValue(5)
+ .withDescription("The length of bytes type that connector generated");
+ public static final Option<Integer> STRING_LENGTH =
Options.key("string.length").intType().defaultValue(5)
+ .withDescription("The length of string type that connector generated");
+
+}
diff --git
a/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/FakeConfig.java
b/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/FakeConfig.java
index eb04a92ef..8c84c773b 100644
---
a/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/FakeConfig.java
+++
b/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/config/FakeConfig.java
@@ -17,6 +17,14 @@
package org.apache.seatunnel.connectors.seatunnel.fake.config;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.ARRAY_SIZE;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.BYTES_LENGTH;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.MAP_SIZE;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.ROW_NUM;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.SPLIT_NUM;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.SPLIT_READ_INTERVAL;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.STRING_LENGTH;
+
import org.apache.seatunnel.shade.com.typesafe.config.Config;
import lombok.Builder;
@@ -27,55 +35,43 @@ import java.io.Serializable;
@Builder
@Getter
public class FakeConfig implements Serializable {
- public static final String ROW_NUM = "row.num";
- public static final String SPLIT_NUM = "split.num";
- public static final String SPLIT_READ_INTERVAL = "split.read-interval";
- public static final String MAP_SIZE = "map.size";
- public static final String ARRAY_SIZE = "array.size";
- public static final String BYTES_LENGTH = "bytes.length";
- public static final String STRING_LENGTH = "string.length";
- private static final int DEFAULT_ROW_NUM = 5;
- private static final int DEFAULT_MAP_SIZE = 5;
- private static final int DEFAULT_ARRAY_SIZE = 5;
- private static final int DEFAULT_BYTES_LENGTH = 5;
- private static final int DEFAULT_STRING_LENGTH = 5;
@Builder.Default
- private int rowNum = DEFAULT_ROW_NUM;
+ private int rowNum = ROW_NUM.defaultValue();
@Builder.Default
- private int splitNum = 1;
+ private int splitNum = SPLIT_NUM.defaultValue();
@Builder.Default
- private int splitReadInterval = 1;
+ private int splitReadInterval = SPLIT_READ_INTERVAL.defaultValue();
@Builder.Default
- private int mapSize = DEFAULT_MAP_SIZE;
+ private int mapSize = MAP_SIZE.defaultValue();
@Builder.Default
- private int arraySize = DEFAULT_ARRAY_SIZE;
+ private int arraySize = ARRAY_SIZE.defaultValue();
@Builder.Default
- private int bytesLength = DEFAULT_BYTES_LENGTH;
+ private int bytesLength = BYTES_LENGTH.defaultValue();
@Builder.Default
- private int stringLength = DEFAULT_STRING_LENGTH;
+ private int stringLength = STRING_LENGTH.defaultValue();
public static FakeConfig buildWithConfig(Config config) {
FakeConfigBuilder builder = FakeConfig.builder();
- if (config.hasPath(ROW_NUM)) {
- builder.rowNum(config.getInt(ROW_NUM));
+ if (config.hasPath(ROW_NUM.key())) {
+ builder.rowNum(config.getInt(ROW_NUM.key()));
}
- if (config.hasPath(SPLIT_NUM)) {
- builder.splitNum(config.getInt(SPLIT_NUM));
+ if (config.hasPath(SPLIT_NUM.key())) {
+ builder.splitNum(config.getInt(SPLIT_NUM.key()));
}
- if (config.hasPath(SPLIT_READ_INTERVAL)) {
- builder.splitReadInterval(config.getInt(SPLIT_READ_INTERVAL));
+ if (config.hasPath(SPLIT_READ_INTERVAL.key())) {
+
builder.splitReadInterval(config.getInt(SPLIT_READ_INTERVAL.key()));
}
- if (config.hasPath(MAP_SIZE)) {
- builder.mapSize(config.getInt(MAP_SIZE));
+ if (config.hasPath(MAP_SIZE.key())) {
+ builder.mapSize(config.getInt(MAP_SIZE.key()));
}
- if (config.hasPath(ARRAY_SIZE)) {
- builder.arraySize(config.getInt(ARRAY_SIZE));
+ if (config.hasPath(ARRAY_SIZE.key())) {
+ builder.arraySize(config.getInt(ARRAY_SIZE.key()));
}
- if (config.hasPath(BYTES_LENGTH)) {
- builder.bytesLength(config.getInt(BYTES_LENGTH));
+ if (config.hasPath(BYTES_LENGTH.key())) {
+ builder.bytesLength(config.getInt(BYTES_LENGTH.key()));
}
- if (config.hasPath(STRING_LENGTH)) {
- builder.stringLength(config.getInt(STRING_LENGTH));
+ if (config.hasPath(STRING_LENGTH.key())) {
+ builder.stringLength(config.getInt(STRING_LENGTH.key()));
}
return builder.build();
}
diff --git
a/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeSourceFactory.java
b/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeSourceFactory.java
new file mode 100644
index 000000000..b39fd7d5f
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeSourceFactory.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.connectors.seatunnel.fake.source;
+
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.ARRAY_SIZE;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.BYTES_LENGTH;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.MAP_SIZE;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.ROW_NUM;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.SPLIT_NUM;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.SPLIT_READ_INTERVAL;
+import static
org.apache.seatunnel.connectors.seatunnel.fake.config.Config.STRING_LENGTH;
+
+import org.apache.seatunnel.api.configuration.util.OptionRule;
+import org.apache.seatunnel.api.table.factory.Factory;
+import org.apache.seatunnel.api.table.factory.TableSourceFactory;
+import org.apache.seatunnel.connectors.seatunnel.common.schema.SeaTunnelSchema;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(Factory.class)
+public class FakeSourceFactory implements TableSourceFactory {
+ @Override
+ public String factoryIdentifier() {
+ return "FakeSource";
+ }
+
+ @Override
+ public OptionRule optionRule() {
+ return
OptionRule.builder().required(SeaTunnelSchema.SCHEMA).optional(ROW_NUM,
SPLIT_NUM, SPLIT_READ_INTERVAL, MAP_SIZE,
+ ARRAY_SIZE, BYTES_LENGTH, STRING_LENGTH).build();
+ }
+}