I am trying to get the Data Generator to work in Java but I dont understand how. The documentation is not very clear. Also I am having trouble creating a new sequence with java.
Hi Nathan,
DataGenerator had the setter methods private, so it really didn’t work . There is correct version in svn now or you need to change setRandomFields(String) and setSequenceFields(String) methods to public.
Then following example will work:
import org.jetel.component.DataGenerator;
import org.jetel.component.DelimitedDataWriter;
import org.jetel.data.DataRecord;
import org.jetel.data.sequence.Sequence;
import org.jetel.exception.GraphConfigurationException;
import org.jetel.graph.Edge;
import org.jetel.graph.OutputPort;
import org.jetel.graph.Phase;
import org.jetel.graph.TransformationGraph;
import org.jetel.main.runGraph;
import org.jetel.metadata.DataFieldMetadata;
import org.jetel.metadata.DataRecordMetadata;
import org.jetel.sequence.PrimitiveSequence;
public class GenerateData {
public static void main(String args) throws GraphConfigurationException{
runGraph.initEngine(“…\\cloveretl.engine\\plugins”, null);
DataRecordMetadata metadata = new DataRecordMetadata(“in”,DataRecordMetadata.DELIMITED_RECORD);
metadata.addField(new DataFieldMetadata(“id”,DataFieldMetadata.INTEGER_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value1”,DataFieldMetadata.INTEGER_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value2”,DataFieldMetadata.NUMERIC_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value3”,DataFieldMetadata.STRING_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value4”,DataFieldMetadata.LONG_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value5”,DataFieldMetadata.INTEGER_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value6”,DataFieldMetadata.NUMERIC_FIELD,“;”));
metadata.addField(new DataFieldMetadata(“value7”,DataFieldMetadata.INTEGER_FIELD,“;”));
TransformationGraph graph = new TransformationGraph();
Sequence seq = new PrimitiveSequence(“sequence0”,graph,“sequence0”);
graph.addSequence(“sequence0”, seq);
DataGenerator generator = new DataGenerator(“generator”,“10;”,500);
generator.setRandomFields(“value1=random(10,100);value2=random(-1,2);value3=random(1);” +
“value4=random(-9000000000000000000,1000000000000000000);value5=random(-100,100);” +
“value6=random(0,4.8);”);
generator.setSequenceFields(“id”);
DelimitedDataWriter writer = new DelimitedDataWriter(“writer”,“…\\cloveretl.engine\\data\\data.dat”,false);
Edge edge = new Edge(“edge”,metadata);
edge.connectReader(generator, 0);
edge.connectWriter(writer, 0);
generator.addOutputPort(0, edge);
writer.addInputPort(0, edge);
Phase phase = new Phase(0);
graph.addDataRecordMetadata(“metadata”, metadata);
graph.addPhase(phase);
phase.addNode(generator);
phase.addNode(writer);
phase.addEdge(edge);
graph.init();
graph.run();
}
}