如何在进行bazel构建时传递参数。实际上我的程序将接受两个参数.one是目录,另一个是target.csv 我需要将文件放在目录下并将其写入csv。
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collector;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.tuple.Tuple1;
import org.apache.flink.api.java.utils.ParameterTool;
public class ReadFiles {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// set up the execution environment
try {
final ParameterTool params = ParameterTool.fromArgs(args);
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1); // without this multiple files creating
env.getConfig().setGlobalJobParameters(params);
List<String> paths = new ArrayList<String>();
File dir = new File(params.getRequired("input"));
for (File f : dir.listFiles()) {
if (f.isFile()) {
paths.add(f.getName());
}
}
DataSet<String> data = env.fromCollection(paths).rebalance();
DataSet<Tuple1<String>> output = data.flatMap(new CSVSplitter());
env.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// The operations are defined by specialized classes, here the Splitter class.
class CSVSplitter implements FlatMapFunction<String, Tuple1<String>> {
public void flatMap(String value, Collector<Tuple1<String>> out) throws Exception {
out.collect(new Tuple1<String>(value));
}
}
构建我正在尝试的bazel的语法 -
bazel build FlinkEx/com/practice:read_files
执行此操作后面临问题。
Worker process sent response with exit code: 1.
error: wrong number of type arguments; required 3
我需要传递像bazel build FlinkEx / com / practice这样的参数:read_files c:/ c:/target.csv
答案 0 :(得分:3)
你的意思是bazel run
?您可以通过使用--
:
bazel run FlinkEx/com/practice:read_files -- c:/ c:/target.csv
或者您可以直接运行二进制文件并“正常”传递参数:
bazel build FlinkEx/com/practice:read_files
bazel-bin/FlinkEx/com/practice:read_files c:/ c:/target.csv
(假设bazel build
将read_files
放入bazel-bin
。如果它位于bazel-genfiles
下,则只需从那里运行它。)