hailin0 commented on code in PR #2406:
URL: 
https://github.com/apache/incubator-seatunnel/pull/2406#discussion_r950047362


##########
seatunnel-examples/seatunnel-spark-connector-v2-example/src/main/resources/examples/spark.batch.conf:
##########
@@ -45,20 +62,20 @@ source {
   # }
 
   # If you would like to get more information about how to configure seatunnel 
and see full list of input plugins,
-  # please go to 
https://seatunnel.apache.org/docs/spark/configuration/source-plugins/Fake
+  # please go to https://seatunnel.apache.org/docs/2.1.3/category/source
 }
 
 transform {
   # split data by specific delimiter
 
   # you can also use other transform plugins, such as sql
   sql {
-    sql = "select name,age from fake"
+    sql = "select 
c_string,c_boolean,c_tinyint,c_smallint,c_int,c_bigint,c_float,c_double,c_null,c_bytes
 from fake"
     result_table_name = "sql"
   }
 
   # If you would like to get more information about how to configure seatunnel 
and see full list of transform plugins,
-  # please go to 
https://seatunnel.apache.org/docs/spark/configuration/transform-plugins/Split
+  # please go to https://seatunnel.apache.org/docs/2.1.3/category/transform

Review Comment:
   Use https://seatunnel.apache.org/docs/category/transform ?



##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeRandomData.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.api.table.type.BasicType.BOOLEAN_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.BYTE_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.DOUBLE_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.FLOAT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.INT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.LONG_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.SHORT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.STRING_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.VOID_TYPE;
+
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.MapType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.schema.SeatunnelSchema;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.RandomUtils;
+
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public class FakeRandomData {
+
+    private final SeatunnelSchema schema;
+
+    public FakeRandomData(SeatunnelSchema schema) {
+        this.schema = schema;
+    }
+
+    public SeaTunnelRow randomRow() {
+        SeaTunnelRowType seaTunnelRowType = schema.getSeaTunnelRowType();
+        String[] fieldNames = seaTunnelRowType.getFieldNames();
+        SeaTunnelDataType<?>[] fieldTypes = seaTunnelRowType.getFieldTypes();
+        List<Object> randomRow = new ArrayList<>(fieldNames.length);
+        for (SeaTunnelDataType<?> fieldType : fieldTypes) {
+            randomRow.add(randomColumnValue(fieldType));
+        }
+        return new SeaTunnelRow(randomRow.toArray());
+    }
+
+    @SuppressWarnings("magicnumber")
+    private Object randomColumnValue(SeaTunnelDataType<?> fieldType) {
+        if (BOOLEAN_TYPE.equals(fieldType)) {
+            return RandomUtils.nextInt(0, 2) == 1;
+        } else if (BYTE_TYPE.equals(fieldType)) {
+            return (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE);
+        } else if (SHORT_TYPE.equals(fieldType)) {
+            return (short) RandomUtils.nextInt(Byte.MAX_VALUE, 
Short.MAX_VALUE);
+        } else if (INT_TYPE.equals(fieldType)) {
+            return RandomUtils.nextInt(Short.MAX_VALUE, Integer.MAX_VALUE);
+        } else if (LONG_TYPE.equals(fieldType)) {
+            return RandomUtils.nextLong(Integer.MAX_VALUE, Long.MAX_VALUE);
+        } else if (FLOAT_TYPE.equals(fieldType)) {
+            return RandomUtils.nextFloat(Float.MIN_VALUE, Float.MAX_VALUE);
+        } else if (DOUBLE_TYPE.equals(fieldType)) {
+            return RandomUtils.nextDouble(Float.MAX_VALUE, Double.MAX_VALUE);
+        } else if (STRING_TYPE.equals(fieldType)) {
+            return RandomStringUtils.randomAlphabetic(10);
+        } else if (LocalTimeType.LOCAL_DATE_TYPE.equals(fieldType)) {
+            return randomLocalDateTime().toLocalDate();
+        } else if (LocalTimeType.LOCAL_TIME_TYPE.equals(fieldType)) {
+            return randomLocalDateTime().toLocalTime();
+        } else if (LocalTimeType.LOCAL_DATE_TIME_TYPE.equals(fieldType)) {
+            return randomLocalDateTime();
+        } else if (fieldType instanceof DecimalType) {
+            DecimalType decimalType = (DecimalType) fieldType;
+            return new 
BigDecimal(RandomStringUtils.randomNumeric(decimalType.getPrecision() - 
decimalType.getScale()) + "." +
+                RandomStringUtils.randomNumeric(decimalType.getPrecision() - 
decimalType.getScale()));
+        } else if (fieldType instanceof ArrayType) {
+            ArrayType<?, ?> arrayType = (ArrayType<?, ?>) fieldType;
+            BasicType<?> elementType = arrayType.getElementType();
+            Object value = randomColumnValue(elementType);
+            Object arr = Array.newInstance(elementType.getTypeClass(), 1);
+            Array.set(arr, 0, value);
+            return arr;
+        } else if (fieldType instanceof MapType) {
+            MapType<?, ?> mapType = (MapType<?, ?>) fieldType;
+            SeaTunnelDataType<?> keyType = mapType.getKeyType();
+            Object key = randomColumnValue(keyType);
+            SeaTunnelDataType<?> valueType = mapType.getValueType();
+            Object value = randomColumnValue(valueType);
+            HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
+            objectObjectHashMap.put(key, value);
+            return objectObjectHashMap;
+        } else if (fieldType instanceof PrimitiveByteArrayType) {
+            return RandomUtils.nextBytes(10);
+        } else if (VOID_TYPE.equals(fieldType) || fieldType == null) {
+            return Void.TYPE;
+        } else {
+            throw new IllegalStateException("Unexpected value: " + fieldType);

Review Comment:
   Change to UnsupportedOperationException?



##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeRandomData.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.api.table.type.BasicType.BOOLEAN_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.BYTE_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.DOUBLE_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.FLOAT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.INT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.LONG_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.SHORT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.STRING_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.VOID_TYPE;
+
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.MapType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.schema.SeatunnelSchema;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.RandomUtils;
+
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public class FakeRandomData {
+
+    private final SeatunnelSchema schema;
+
+    public FakeRandomData(SeatunnelSchema schema) {
+        this.schema = schema;
+    }
+
+    public SeaTunnelRow randomRow() {
+        SeaTunnelRowType seaTunnelRowType = schema.getSeaTunnelRowType();
+        String[] fieldNames = seaTunnelRowType.getFieldNames();
+        SeaTunnelDataType<?>[] fieldTypes = seaTunnelRowType.getFieldTypes();
+        List<Object> randomRow = new ArrayList<>(fieldNames.length);
+        for (SeaTunnelDataType<?> fieldType : fieldTypes) {
+            randomRow.add(randomColumnValue(fieldType));
+        }
+        return new SeaTunnelRow(randomRow.toArray());
+    }
+
+    @SuppressWarnings("magicnumber")
+    private Object randomColumnValue(SeaTunnelDataType<?> fieldType) {
+        if (BOOLEAN_TYPE.equals(fieldType)) {
+            return RandomUtils.nextInt(0, 2) == 1;
+        } else if (BYTE_TYPE.equals(fieldType)) {
+            return (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE);
+        } else if (SHORT_TYPE.equals(fieldType)) {
+            return (short) RandomUtils.nextInt(Byte.MAX_VALUE, 
Short.MAX_VALUE);
+        } else if (INT_TYPE.equals(fieldType)) {
+            return RandomUtils.nextInt(Short.MAX_VALUE, Integer.MAX_VALUE);
+        } else if (LONG_TYPE.equals(fieldType)) {
+            return RandomUtils.nextLong(Integer.MAX_VALUE, Long.MAX_VALUE);
+        } else if (FLOAT_TYPE.equals(fieldType)) {
+            return RandomUtils.nextFloat(Float.MIN_VALUE, Float.MAX_VALUE);
+        } else if (DOUBLE_TYPE.equals(fieldType)) {
+            return RandomUtils.nextDouble(Float.MAX_VALUE, Double.MAX_VALUE);
+        } else if (STRING_TYPE.equals(fieldType)) {
+            return RandomStringUtils.randomAlphabetic(10);
+        } else if (LocalTimeType.LOCAL_DATE_TYPE.equals(fieldType)) {
+            return randomLocalDateTime().toLocalDate();
+        } else if (LocalTimeType.LOCAL_TIME_TYPE.equals(fieldType)) {
+            return randomLocalDateTime().toLocalTime();
+        } else if (LocalTimeType.LOCAL_DATE_TIME_TYPE.equals(fieldType)) {
+            return randomLocalDateTime();
+        } else if (fieldType instanceof DecimalType) {
+            DecimalType decimalType = (DecimalType) fieldType;
+            return new 
BigDecimal(RandomStringUtils.randomNumeric(decimalType.getPrecision() - 
decimalType.getScale()) + "." +
+                RandomStringUtils.randomNumeric(decimalType.getPrecision() - 
decimalType.getScale()));

Review Comment:
   Should used `RandomStringUtils.randomNumeric(decimalType.getScale())` ?



##########
seatunnel-examples/seatunnel-spark-connector-v2-example/src/main/resources/examples/spark.batch.conf:
##########
@@ -33,8 +33,25 @@ env {
 source {
   # This is a example input plugin **only for test and demonstrate the feature 
input plugin**
   FakeSource {
+    fields {
+      c_map = "map<string, string>"
+      c_array = "array<tinyint>"
+      c_string = string
+      c_boolean = boolean
+      c_tinyint = tinyint
+      c_smallint = smallint
+      c_int = int
+      c_bigint = bigint
+      c_float = float
+      c_double = double
+      c_decimal = "decimal(30, 8)"
+      c_null = "null"
+      c_bytes = bytes
+      c_date = date
+      c_time = time
+      c_timestamp = timestamp
+    }
     result_table_name = "fake"
-    field_name = "name,age,timestamp"
   }

Review Comment:
   Should you change all testcase?  
   
   
https://github.com/apache/incubator-seatunnel/tree/dev/seatunnel-examples/seatunnel-flink-connector-v2-example/src/main/resources/examples
   
https://github.com/apache/incubator-seatunnel/tree/dev/seatunnel-examples/seatunnel-spark-connector-v2-example/src/main/resources/examples
   
https://github.com/apache/incubator-seatunnel/tree/dev/seatunnel-e2e/seatunnel-flink-connector-v2-e2e/src/test/resources
   
https://github.com/apache/incubator-seatunnel/tree/dev/seatunnel-e2e/seatunnel-spark-connector-v2-e2e/src/test/resources



##########
seatunnel-examples/seatunnel-spark-connector-v2-example/src/main/resources/examples/spark.batch.conf:
##########
@@ -45,20 +62,20 @@ source {
   # }
 
   # If you would like to get more information about how to configure seatunnel 
and see full list of input plugins,
-  # please go to 
https://seatunnel.apache.org/docs/spark/configuration/source-plugins/Fake
+  # please go to https://seatunnel.apache.org/docs/2.1.3/category/source

Review Comment:
   Use https://seatunnel.apache.org/docs/category/source-v2 ?



##########
seatunnel-connectors-v2/connector-fake/src/main/java/org/apache/seatunnel/connectors/seatunnel/fake/source/FakeRandomData.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.api.table.type.BasicType.BOOLEAN_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.BYTE_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.DOUBLE_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.FLOAT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.INT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.LONG_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.SHORT_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.STRING_TYPE;
+import static org.apache.seatunnel.api.table.type.BasicType.VOID_TYPE;
+
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.MapType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.schema.SeatunnelSchema;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.RandomUtils;
+
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public class FakeRandomData {
+
+    private final SeatunnelSchema schema;
+
+    public FakeRandomData(SeatunnelSchema schema) {
+        this.schema = schema;
+    }
+
+    public SeaTunnelRow randomRow() {
+        SeaTunnelRowType seaTunnelRowType = schema.getSeaTunnelRowType();
+        String[] fieldNames = seaTunnelRowType.getFieldNames();
+        SeaTunnelDataType<?>[] fieldTypes = seaTunnelRowType.getFieldTypes();
+        List<Object> randomRow = new ArrayList<>(fieldNames.length);
+        for (SeaTunnelDataType<?> fieldType : fieldTypes) {
+            randomRow.add(randomColumnValue(fieldType));
+        }
+        return new SeaTunnelRow(randomRow.toArray());
+    }
+
+    @SuppressWarnings("magicnumber")
+    private Object randomColumnValue(SeaTunnelDataType<?> fieldType) {
+        if (BOOLEAN_TYPE.equals(fieldType)) {
+            return RandomUtils.nextInt(0, 2) == 1;
+        } else if (BYTE_TYPE.equals(fieldType)) {
+            return (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE);

Review Comment:
   Should used `RandomUtils.nextInt(Byte.MIN_VALUE, Byte.MAX_VALUE)` or 
`RandomUtils.nextInt(0, 255)` ?



##########
seatunnel-examples/seatunnel-spark-connector-v2-example/src/main/resources/examples/spark.batch.conf:
##########
@@ -72,5 +89,5 @@ sink {
   # }
 
   # If you would like to get more information about how to configure seatunnel 
and see full list of output plugins,
-  # please go to 
https://seatunnel.apache.org/docs/spark/configuration/sink-plugins/Console
+  # please go to https://seatunnel.apache.org/docs/2.1.3/category/sink

Review Comment:
   Use https://seatunnel.apache.org/docs/category/sink-v2 ?



-- 
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]

Reply via email to