You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/10/31 09:17:23 UTC

[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #3145: [Feature][st-engine] Support for transform-v2 API

Hisoka-X commented on code in PR #3145:
URL: https://github.com/apache/incubator-seatunnel/pull/3145#discussion_r1009153778


##########
seatunnel-common/src/main/java/org/apache/seatunnel/common/config/Common.java:
##########
@@ -129,6 +130,30 @@ public static Path connectorDir() {
         }
     }
 
+    /**
+     * lib Dir
+     */
+    public static Path libDir() {
+        String seatunnelHome = System.getProperty("SEATUNNEL_HOME");
+        if (StringUtils.isBlank(seatunnelHome)) {
+            seatunnelHome = appRootDir().toString();
+        }
+        return Paths.get(seatunnelHome, "lib");
+    }
+
+    /**
+     * return lib jars, which located in 'lib/*'.
+     */
+    public static List<Path> getLibJars() {
+        Path libRootDir = Common.libDir();
+        if (!Files.exists(libRootDir) || !Files.isDirectory(libRootDir)) {
+            return Collections.emptyList();
+        }
+        return Arrays.stream(libRootDir.toFile().listFiles((dir, name) -> name.endsWith(".jar")))

Review Comment:
   The method seem like not support `lib/other/test.jar`? Maybe use `Files.walk` could be better.



##########
seatunnel-core/seatunnel-flink-starter/src/main/java/org/apache/seatunnel/core/starter/flink/execution/FlinkExecution.java:
##########
@@ -109,10 +108,22 @@ private void registerPlugin() {
                 }
             })
             .collect(Collectors.toList());
-
         pluginsJarDependencies.forEach(url -> FlinkCommon.ADD_URL_TO_CLASSLOADER.accept(Thread.currentThread().getContextClassLoader(), url));
 
+        List<URL> libJarDependencies = Common.getLibJars().stream()

Review Comment:
   Please reduce same code.



##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/CopyFieldTransform.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.transform;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.api.transform.SeaTunnelTransform;
+import org.apache.seatunnel.transform.common.SeaTunnelRowAccessor;
+import org.apache.seatunnel.transform.common.SingleFieldOutputTransform;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(SeaTunnelTransform.class)
+public class CopyFieldTransform extends SingleFieldOutputTransform {
+
+    private static final String SRC_FIELD = "src_field";
+    private static final String DEST_FIELD = "dest_field";
+
+    private String srcField;
+    private int srcFieldIndex;
+    private SeaTunnelDataType srcFieldDataType;
+    private String destField;
+
+    @Override
+    public String getPluginName() {
+        return "Copy";
+    }
+
+    @Override
+    protected void setConfig(Config pluginConfig) {
+        if (!pluginConfig.hasPath(SRC_FIELD)) {
+            throw new IllegalArgumentException("The configuration missing key: " + SRC_FIELD);
+        }
+        if (!pluginConfig.hasPath(DEST_FIELD)) {
+            throw new IllegalArgumentException("The configuration missing key: " + DEST_FIELD);
+        }
+        this.srcField = pluginConfig.getString(SRC_FIELD);
+        this.destField = pluginConfig.getString(DEST_FIELD);
+    }
+
+    @Override
+    protected void setInputRowType(SeaTunnelRowType inputRowType) {
+        srcFieldIndex = inputRowType.indexOf(srcField);
+        if (srcFieldIndex == -1) {
+            throw new IllegalArgumentException("Cannot find [" + srcField + "] field in input row type");
+        }
+        srcFieldDataType = inputRowType.getFieldType(srcFieldIndex);
+    }
+
+    @Override
+    protected String getOutputFieldName() {
+        return destField;
+    }
+
+    @Override
+    protected SeaTunnelDataType getOutputFieldDataType() {
+        return srcFieldDataType;
+    }
+
+    @Override
+    protected Object getOutputFieldValue(SeaTunnelRowAccessor inputRow) {
+        return inputRow.getField(srcFieldIndex);

Review Comment:
   Use deep copy?



##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/ReplaceTransform.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.transform;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.api.transform.SeaTunnelTransform;
+import org.apache.seatunnel.transform.common.SeaTunnelRowAccessor;
+import org.apache.seatunnel.transform.common.SingleFieldOutputTransform;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(SeaTunnelTransform.class)
+public class ReplaceTransform extends SingleFieldOutputTransform {
+
+    private static final String KEY_REPLACE_FIELD = "replace_field";
+    private static final String KEY_PATTERN = "pattern";
+    private static final String KEY_REPLACEMENT = "replacement";
+    private static final String KEY_IS_REGEX = "is_regex";
+    private static final String KEY_REPLACE_FIRST = "replace_first";
+
+    private int inputFieldIndex;
+    private String replaceField;
+    private String pattern;
+    private String replacement;
+    private boolean isRegex;
+    private boolean replaceFirst;
+
+    @Override
+    public String getPluginName() {
+        return "Replace";
+    }
+
+    @Override
+    protected void setConfig(Config pluginConfig) {
+        if (!pluginConfig.hasPath(KEY_REPLACE_FIELD)) {

Review Comment:
   Just use `CheckConfigUtil.checkAllExists`



##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/SplitTransform.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.transform;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.api.transform.SeaTunnelTransform;
+import org.apache.seatunnel.transform.common.MultipleFieldOutputTransform;
+import org.apache.seatunnel.transform.common.SeaTunnelRowAccessor;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.auto.service.AutoService;
+
+import java.util.function.IntFunction;
+import java.util.stream.IntStream;
+
+@AutoService(SeaTunnelTransform.class)
+public class SplitTransform extends MultipleFieldOutputTransform {
+
+    private static final String KEY_SEPARATOR = "separator";
+    private static final String KEY_SPLIT_FIELD = "split_field";
+    private static final String KEY_OUTPUT_FIELDS = "output_fields";
+
+    private String separator;
+    private String splitField;
+    private int splitFieldIndex;
+    private String[] outputFields;
+    private String[] emptySplits;
+
+    @Override
+    public String getPluginName() {
+        return "Split";
+    }
+
+    @Override
+    protected void setConfig(Config pluginConfig) {
+        if (!pluginConfig.hasPath(KEY_SEPARATOR)) {

Review Comment:
   Just use `CheckConfigUtil.checkAllExists`



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org