Skip to content

Commit

Permalink
[Optimization] optimization execute jar params parse (DataLinkDC#3277)
Browse files Browse the repository at this point in the history
Co-authored-by: Pandas886 <[email protected]>
  • Loading branch information
Pandas886 and Pandas886 authored Mar 20, 2024
1 parent 8a9b530 commit 6b6b52e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.dinky.trans.AbstractOperation;
import org.dinky.trans.ExtendOperation;
import org.dinky.trans.parse.ExecuteJarParseStrategy;
import org.dinky.utils.RunTimeUtil;
import org.dinky.utils.URLUtils;

import org.apache.commons.lang.StringUtils;
import org.apache.flink.api.dag.Pipeline;
import org.apache.flink.client.program.PackagedProgram;
import org.apache.flink.client.program.PackagedProgramUtils;
Expand All @@ -37,7 +37,10 @@

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -99,7 +102,7 @@ public static StreamGraph getStreamGraph(
.setEntryPointClassName(submitParam.getMainClass())
.setConfiguration(configuration)
.setSavepointRestoreSettings(savepointRestoreSettings)
.setArguments(RunTimeUtil.handleCmds(submitParam.getArgs()))
.setArguments(extractArgs(submitParam.getArgs().trim()).toArray(new String[0]))
.setUserClassPaths(classpaths)
.build();
int parallelism = StrUtil.isNumeric(submitParam.getParallelism())
Expand All @@ -114,6 +117,30 @@ public static StreamGraph getStreamGraph(
}
}

public static List<String> extractArgs(String args) {
List<String> programArgs = new ArrayList<>();
if (StringUtils.isNotEmpty(args)) {
String[] array = args.split("\\s+");
Iterator<String> iter = Arrays.asList(array).iterator();
while (iter.hasNext()) {
String v = iter.next();
String p = v.substring(0, 1);
if (p.equals("'") || p.equals("\"")) {
String value = v;
if (!v.endsWith(p)) {
while (!value.endsWith(p) && iter.hasNext()) {
value += " " + iter.next();
}
}
programArgs.add(value.substring(1, value.length() - 1));
} else {
programArgs.add(v);
}
}
}
return programArgs;
}

@Override
public String asSummaryString() {
return statement;
Expand Down Expand Up @@ -142,7 +169,6 @@ protected JarSubmitParam() {}
public static JarSubmitParam build(String statement) {
JarSubmitParam submitParam = ExecuteJarParseStrategy.getInfo(statement);
Assert.notBlank(submitParam.getUri());
Assert.notBlank(submitParam.getMainClass());
return submitParam;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
*
* 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.dinky.trans.dml;

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import com.google.common.collect.Lists;

class ExecuteJarOperationTest {

public static final List<String> RESULT1 = Lists.newArrayList(
"merge_into",
"--warehouse",
"hdfs:///tmp/paimon",
"--database",
"default",
"--table",
"T",
"--source_table",
"S",
"--on",
"T.id = S.order_id",
"--merge_actions",
"matched-upsert,matched-delete",
"--matched_upsert_condition",
"T.price > 100",
"--matched_upsert_set",
"mark = 'important'",
"--matched_delete_condition",
"T.price < 10");

@Test
void extractArgs() {
List<String> args1 = ExecuteJarOperation.extractArgs(
"merge_into --warehouse hdfs:///tmp/paimon --database default --table T --source_table S --on \"T.id = S.order_id\" --merge_actions matched-upsert,matched-delete --matched_upsert_condition \"T.price > 100\" --matched_upsert_set \"mark = 'important'\" --matched_delete_condition \"T.price < 10\"");
Assert.assertArrayEquals(args1.toArray(new String[0]), RESULT1.toArray(new String[0]));
}
}

0 comments on commit 6b6b52e

Please sign in to comment.