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/01/02 11:21:20 UTC

[GitHub] [incubator-seatunnel] yx91490 commented on a change in pull request #906: [SeaTunnel #904] [config] improve the config parse logic

yx91490 commented on a change in pull request #906:
URL: https://github.com/apache/incubator-seatunnel/pull/906#discussion_r777197406



##########
File path: seatunnel-config/src/test/java/org/apache/seatunnel/config/CompleteTests.java
##########
@@ -17,35 +17,23 @@
 
 package org.apache.seatunnel.config;
 
-import java.io.File;
-import java.net.URL;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigRenderOptions;
+import com.typesafe.config.ConfigResolveOptions;
+import com.typesafe.config.SeaTunnelConfigFactory;
+import org.apache.seatunnel.config.utils.FileUtils;
 
 public class CompleteTests {
 
     public static void main(String[] args) {

Review comment:
       better to change to junit test method.

##########
File path: seatunnel-config/src/test/java/org/apache/seatunnel/config/SeaTunnelConfigFactoryTest.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.config;
+
+import com.typesafe.config.Config;
+import com.typesafe.config.SeaTunnelConfigFactory;
+import org.apache.seatunnel.config.utils.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+public class SeaTunnelConfigFactoryTest {
+
+    @Test
+    public void testBasicParseAppConf() {
+
+        Config config = SeaTunnelConfigFactory.parseFile(FileUtils.getFileFromResources("factory/app.conf"));
+
+        Assert.assertTrue(config.hasPath("env"));
+        Assert.assertTrue(config.hasPath("source"));
+        Assert.assertTrue(config.hasPath("transform"));
+        Assert.assertTrue(config.hasPath("sink"));
+
+    }
+
+    @Test
+    public void testTransformOrder() {
+
+        Config config = SeaTunnelConfigFactory.parseFile(FileUtils.getFileFromResources("factory/app.conf"));
+
+        String[] pluginNames = {"split", "sql1", "sql2", "sql3", "json"};
+
+        List<? extends Config> transforms = config.getConfigList("transform");
+        for (int i = 0; i < transforms.size(); i++) {

Review comment:
       better to iterate pluginNames to prevent transforms's length is less than pluginNames.

##########
File path: seatunnel-config/src/main/java/com/typesafe/config/impl/SeaTunnelParseableFile.java
##########
@@ -0,0 +1,153 @@
+/*
+ * 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 com.typesafe.config.impl;
+
+import com.typesafe.config.ConfigException;
+import com.typesafe.config.ConfigOrigin;
+import com.typesafe.config.ConfigParseOptions;
+import com.typesafe.config.ConfigParseable;
+import com.typesafe.config.ConfigSyntax;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+
+public class SeaTunnelParseableFile extends Parseable {
+    private final File input;
+
+    public SeaTunnelParseableFile(File input, ConfigParseOptions options) {
+        this.input = input;
+        postConstruct(options);
+    }
+
+    @Override
+    protected Reader reader() throws IOException {
+        if (ConfigImpl.traceLoadsEnabled()) {
+            trace("Loading config from a file: " + input);
+        }
+        InputStream stream = new FileInputStream(input);
+        return readerFromStream(stream, "UTF-8");

Review comment:
       "UTF-8" can  be replaced with StandardCharsets.UTF_8




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