You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by fa...@apache.org on 2022/08/25 08:01:32 UTC
[incubator-seatunnel] branch dev updated: [Bug][Core] Let the SparkCommandArgs do not split the variable value with comma (#2523)
This is an automated email from the ASF dual-hosted git repository.
fanjia 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 8f19dceeb [Bug][Core] Let the SparkCommandArgs do not split the variable value with comma (#2523)
8f19dceeb is described below
commit 8f19dceeb6a3cdae7a3121c8658d033ec08b6545
Author: LinZhaoguan <17...@163.com>
AuthorDate: Thu Aug 25 16:01:24 2022 +0800
[Bug][Core] Let the SparkCommandArgs do not split the variable value with comma (#2523)
* Let the SparkCommandArgs do not split the variable value with comma
* checkstyle
Co-authored-by: LinZhaoguan <pu...@163.com>
---
.../core/base/command/AbstractCommandArgs.java | 7 +++--
.../core/base/command/NoopParameterSplitter.java | 34 ++++++++++++++++++++++
.../core/spark/args/SparkCommandArgsTest.java | 4 +--
3 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/AbstractCommandArgs.java b/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/AbstractCommandArgs.java
index 07f7772ef..022f78457 100644
--- a/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/AbstractCommandArgs.java
+++ b/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/AbstractCommandArgs.java
@@ -29,12 +29,13 @@ import java.util.List;
public abstract class AbstractCommandArgs implements CommandArgs {
@Parameter(names = {"-c", "--config"},
- description = "Config file",
- required = true)
+ description = "Config file",
+ required = true)
private String configFile;
@Parameter(names = {"-i", "--variable"},
- description = "variable substitution, such as -i city=beijing, or -i date=20190318")
+ splitter = NoopParameterSplitter.class,
+ description = "variable substitution, such as -i city=beijing, or -i date=20190318")
private List<String> variables = Collections.emptyList();
// todo: use command type enum
diff --git a/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/NoopParameterSplitter.java b/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/NoopParameterSplitter.java
new file mode 100644
index 000000000..8a07d4c1d
--- /dev/null
+++ b/seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/command/NoopParameterSplitter.java
@@ -0,0 +1,34 @@
+/*
+ * 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.core.base.command;
+
+import com.beust.jcommander.converters.IParameterSplitter;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * An implementation class that does nothing on the value of variable.
+ */
+public class NoopParameterSplitter implements IParameterSplitter {
+
+ @Override
+ public List<String> split(String value) {
+ return Collections.singletonList(value);
+ }
+}
diff --git a/seatunnel-core/seatunnel-core-spark/src/test/java/org/apache/seatunnel/core/spark/args/SparkCommandArgsTest.java b/seatunnel-core/seatunnel-core-spark/src/test/java/org/apache/seatunnel/core/spark/args/SparkCommandArgsTest.java
index 9179d0c10..78fb94985 100644
--- a/seatunnel-core/seatunnel-core-spark/src/test/java/org/apache/seatunnel/core/spark/args/SparkCommandArgsTest.java
+++ b/seatunnel-core/seatunnel-core-spark/src/test/java/org/apache/seatunnel/core/spark/args/SparkCommandArgsTest.java
@@ -29,12 +29,12 @@ public class SparkCommandArgsTest {
@Test
public void testParseSparkArgs() {
- String[] args = {"-c", "app.conf", "-e", "client", "-m", "yarn", "-i", "city=shijiazhuang", "-i", "name=Tom"};
+ String[] args = {"-c", "app.conf", "-e", "client", "-m", "yarn", "-i", "city=shijiazhuang", "-i", "name=Tom", "-i", "hobby=basketball,football"};
SparkCommandArgs sparkArgs = CommandLineUtils.parse(args, new SparkCommandArgs(), "seatunnel-spark", true);
Assertions.assertEquals("app.conf", sparkArgs.getConfigFile());
Assertions.assertEquals(DeployMode.CLIENT, sparkArgs.getDeployMode());
Assertions.assertEquals("yarn", sparkArgs.getMaster());
- Assertions.assertEquals(Arrays.asList("city=shijiazhuang", "name=Tom"), sparkArgs.getVariables());
+ Assertions.assertEquals(Arrays.asList("city=shijiazhuang", "name=Tom", "hobby=basketball,football"), sparkArgs.getVariables());
}
}