How to pass arguments while doing bazel build

1,819 views
Skip to first unread message

chowdam.pr...@gmail.com

unread,
Apr 11, 2017, 7:24:56 AM4/11/17
to bazel-discuss
How to pass arguments while doing bazel build. Actually my program will accepts two arguments .one is directory and the other one is target.csv I need to get the files under a directory and write it to 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();
}
}
}

And the syntax to build bazel which I am trying -

bazel build FlinkEx/com/practice:read_files

facing issues after executing this.

Worker process sent response with exit code: 1.
error: wrong number of type arguments; required 3

John Cater

unread,
Apr 11, 2017, 7:33:38 AM4/11/17
to chowdam.pr...@gmail.com, bazel-discuss

Bazel build only builds the code into an executable form. Bazel run will actually run the executable, and any arguments will be passed in to the binary.

Can you share your repository or at least the BUILD file so we can see what is happening to cause that error message?


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/cb2583e1-f1d1-4002-aa83-dd743b767f8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

chowdam.pr...@gmail.com

unread,
Apr 11, 2017, 7:44:42 AM4/11/17
to bazel-discuss, chowdam.pr...@gmail.com
================

Build file:
------------

java_binary(
name="read_files",
srcs = glob(["ReadFiles.java"]),
main_class="FlinkWorkflow.com.ipractice.ReadFiles",
deps=["//external:flink_java-jar","//external:flink_clients-jar","//external:flink_core-jar"],
)

WORKSPACE
----------
maven_server(name="myserver",url="http://central.maven.org/maven2")
maven_jar(name="flink_java",artifact="org.apache.flink:flink-java:jar:1.2.0",server="myserver")
bind(name="flink_java-jar",actual="@flink_java//jar")

maven_jar(name="flink_clients",artifact="org.apache.flink:flink-clients_2.10:jar:1.0.2",server="myserver")
bind(name="flink_clients-jar",actual="@flink_clients//jar")

maven_jar(name="flink_core",artifact="org.apache.flink:flink-core:jar:1.2.0",server="myserver")
bind(name="flink_core-jar",actual="@flink_core//jar")

Thanks,
Praveen

John Cater

unread,
Apr 11, 2017, 9:07:07 AM4/11/17
to chowdam.pr...@gmail.com, bazel-discuss
I've created a git repository with the files you sent, it is:

With this, when I run the build, I see:
$ bazel build :read_files 
INFO: Reading 'startup' options from /usr/local/google/home/jcater/.bazelrc: --watchfs
INFO: Found 1 target...
ERROR: /usr/local/google/home/jcater/repos/flink-test/BUILD:1:1: Couldn't build file read_files.jar: Java compilation in rule '//:read_files' failed: Worker process sent response with exit code: 1.
ReadFiles.java:36: error: cannot find symbol
      DataSet<Tuple1<String>> output = data.flatMap(new CSVSplitter());
                                                        ^
  symbol:   class CSVSplitter
  location: class ReadFiles
Target //:read_files failed to build

This is different than the error you are seeing, so I must have set this up differently. Can you see what I have different?

Reply all
Reply to author
Forward
0 new messages