use of org.apache.hop.pipeline.transforms.streamlookup.StreamLookupMeta in project hop by apache.
the class BeamPipelineMetaUtil method generateStreamLookupPipelineMeta.
public static final PipelineMeta generateStreamLookupPipelineMeta(String transname, String inputTransformName, String outputTransformName, IHopMetadataProvider metadataProvider) throws Exception {
IHopMetadataSerializer<FileDefinition> serializer = metadataProvider.getSerializer(FileDefinition.class);
FileDefinition customerFileDefinition = createCustomersInputFileDefinition();
serializer.save(customerFileDefinition);
PipelineMeta pipelineMeta = new PipelineMeta();
pipelineMeta.setName(transname);
pipelineMeta.setMetadataProvider(metadataProvider);
// Add the main io transform
//
BeamInputMeta beamInputMeta = new BeamInputMeta();
beamInputMeta.setInputLocation(PipelineTestBase.INPUT_CUSTOMERS_FILE);
beamInputMeta.setFileDefinitionName(customerFileDefinition.getName());
TransformMeta beamInputTransformMeta = new TransformMeta(inputTransformName, beamInputMeta);
beamInputTransformMeta.setTransformPluginId(BeamConst.STRING_BEAM_INPUT_PLUGIN_ID);
pipelineMeta.addTransform(beamInputTransformMeta);
TransformMeta lookupBeamInputTransformMeta = beamInputTransformMeta;
// Add a Memory Group By transform which will
MemoryGroupByMeta memoryGroupByMeta = new MemoryGroupByMeta();
memoryGroupByMeta.allocate(1, 1);
memoryGroupByMeta.getGroupField()[0] = "stateCode";
memoryGroupByMeta.getAggregateType()[0] = MemoryGroupByMeta.TYPE_GROUP_COUNT_ALL;
memoryGroupByMeta.getAggregateField()[0] = "rowsPerState";
memoryGroupByMeta.getSubjectField()[0] = "id";
TransformMeta memoryGroupByTransformMeta = new TransformMeta("rowsPerState", memoryGroupByMeta);
pipelineMeta.addTransform(memoryGroupByTransformMeta);
pipelineMeta.addPipelineHop(new PipelineHopMeta(lookupBeamInputTransformMeta, memoryGroupByTransformMeta));
// Add a Stream Lookup transform ...
//
StreamLookupMeta streamLookupMeta = new StreamLookupMeta();
streamLookupMeta.allocate(1, 1);
streamLookupMeta.getKeystream()[0] = "stateCode";
streamLookupMeta.getKeylookup()[0] = "stateCode";
streamLookupMeta.getValue()[0] = "rowsPerState";
streamLookupMeta.getValueName()[0] = "nrPerState";
streamLookupMeta.getValueDefault()[0] = null;
streamLookupMeta.getValueDefaultType()[0] = IValueMeta.TYPE_INTEGER;
streamLookupMeta.setMemoryPreservationActive(false);
streamLookupMeta.getTransformIOMeta().getInfoStreams().get(0).setTransformMeta(// Read from Mem.GroupBy
memoryGroupByTransformMeta);
TransformMeta streamLookupTransformMeta = new TransformMeta("Stream Lookup", streamLookupMeta);
pipelineMeta.addTransform(streamLookupTransformMeta);
pipelineMeta.addPipelineHop(// Main io
new PipelineHopMeta(beamInputTransformMeta, streamLookupTransformMeta));
pipelineMeta.addPipelineHop(// info stream
new PipelineHopMeta(memoryGroupByTransformMeta, streamLookupTransformMeta));
// Add the output transform to write results
//
BeamOutputMeta beamOutputMeta = new BeamOutputMeta();
beamOutputMeta.setOutputLocation("/tmp/customers/output/");
beamOutputMeta.setFileDefinitionName(null);
beamOutputMeta.setFilePrefix("stream-lookup");
beamOutputMeta.setFileSuffix(".csv");
// Not yet supported
beamOutputMeta.setWindowed(false);
TransformMeta beamOutputTransformMeta = new TransformMeta(outputTransformName, beamOutputMeta);
beamOutputTransformMeta.setTransformPluginId("BeamOutput");
pipelineMeta.addTransform(beamOutputTransformMeta);
pipelineMeta.addPipelineHop(new PipelineHopMeta(streamLookupTransformMeta, beamOutputTransformMeta));
return pipelineMeta;
}
Aggregations