58 lines
2.3 KiB
Java
58 lines
2.3 KiB
Java
package com.databuild.examples.basic_graph;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import java.io.File;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.stream.Collectors;
|
|
|
|
import static com.databuild.examples.basic_graph.GenerateExecute.BASE_PATH;
|
|
|
|
/**
|
|
* Configure class for generating a random number.
|
|
* This class creates a job configuration for generating a random number based on the partition ref.
|
|
*/
|
|
public class SumConfigure {
|
|
public static void main(String[] args) {
|
|
if (args.length != 1) {
|
|
System.err.println("Error: Must provide exactly one partition ref as an argument");
|
|
System.exit(1);
|
|
}
|
|
|
|
String partitionRef = args[0];
|
|
String[] pathParts = partitionRef.split("/");
|
|
String[] upstreams = Arrays.stream(pathParts[pathParts.length - 1].split("_"))
|
|
.map(part -> BASE_PATH + "generated_number/" + part)
|
|
.toArray(String[]::new);
|
|
|
|
// Create and populate JobConfig object
|
|
JobConfig config = new JobConfig();
|
|
config.outputs = Collections.singletonList(BASE_PATH + "sum/" +partitionRef);
|
|
config.inputs = Arrays.stream(upstreams)
|
|
.map(upstream -> {
|
|
DataDep dep = new DataDep();
|
|
dep.depType = "materialize";
|
|
dep.ref = upstream;
|
|
return dep;
|
|
})
|
|
.collect(Collectors.toList());
|
|
config.args = Arrays.asList(upstreams);
|
|
// Create a hashmap for env with {"OUTPUT_REF": "foo"}
|
|
config.env = Collections.singletonMap("OUTPUT_REF", args[0]);
|
|
// inputs and env are already initialized as empty collections in the constructor
|
|
|
|
try {
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
// Convert config to JsonNode and serialize
|
|
JsonNode configNode = mapper.valueToTree(Collections.singletonList(config));
|
|
String jsonConfig = mapper.writeValueAsString(configNode);
|
|
System.out.println(jsonConfig);
|
|
} catch (Exception e) {
|
|
System.err.println("Error: Failed to validate or serialize config: " + e.getMessage());
|
|
System.exit(1);
|
|
}
|
|
}
|
|
}
|