Search in sources :

Example 1 with MappingOutput

use of org.apache.hop.pipeline.transforms.output.MappingOutput in project hop by apache.

the class SimpleMapping method prepareMappingExecution.

public void prepareMappingExecution() throws HopException {
    SimpleMappingData simpleMappingData = getData();
    // Create the pipeline from meta-data...
    simpleMappingData.mappingPipeline = new LocalPipelineEngine(simpleMappingData.mappingPipelineMeta, this, this);
    // Copy the parameters over...
    // 
    simpleMappingData.mappingPipeline.copyParametersFromDefinitions(simpleMappingData.mappingPipelineMeta);
    // Set the parameters values in the mapping.
    // 
    TransformWithMappingMeta.activateParams(simpleMappingData.mappingPipeline, simpleMappingData.mappingPipeline, this, simpleMappingData.mappingPipelineMeta.listParameters(), meta.getMappingParameters().getVariable(), meta.getMappingParameters().getInputField(), meta.getMappingParameters().isInheritingAllVariables());
    // Leave a path up so that we can set variables in sub-pipelines...
    // 
    simpleMappingData.mappingPipeline.setParentPipeline(getPipeline());
    // Pass down the safe mode flag to the mapping...
    // 
    simpleMappingData.mappingPipeline.setSafeModeEnabled(getPipeline().isSafeModeEnabled());
    // Pass down the metrics gathering flag:
    // 
    simpleMappingData.mappingPipeline.setGatheringMetrics(getPipeline().isGatheringMetrics());
    // 
    try {
        simpleMappingData.mappingPipeline.prepareExecution();
    } catch (HopException e) {
        throw new HopException(BaseMessages.getString(PKG, "SimpleMapping.Exception.UnableToPrepareExecutionOfMapping"), e);
    }
    // If there is no read/write logging transform set, we can insert the data from
    // the first mapping input/output transform...
    // 
    List<MappingInput> mappingInputs = findMappingInputs(simpleMappingData.mappingPipeline);
    if (mappingInputs.isEmpty()) {
        throw new HopException("The simple mapping transform needs one Mapping Input transform to write to in the sub-pipeline");
    }
    if (mappingInputs.size() > 1) {
        throw new HopException("The simple mapping transform does not support multiple Mapping Input transforms to write to in the sub-pipeline");
    }
    simpleMappingData.mappingInput = mappingInputs.get(0);
    List<MappingOutput> mappingOutputs = findMappingOutputs(simpleMappingData.mappingPipeline);
    if (mappingOutputs.isEmpty()) {
        throw new HopException("The simple mapping transform needs one Mapping Output transform to read from in the sub-pipeline");
    }
    if (mappingOutputs.size() > 1) {
        throw new HopException("The simple mapping transform does not support multiple Mapping Output transforms to read from in the sub-pipeline");
    }
    simpleMappingData.mappingOutput = mappingOutputs.get(0);
    // Finally, add the mapping pipeline to the active sub-pipelines
    // map in the parent pipeline
    // 
    getPipeline().addActiveSubPipeline(getTransformName(), simpleMappingData.mappingPipeline);
}
Also used : MappingInput(org.apache.hop.pipeline.transforms.input.MappingInput) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) HopException(org.apache.hop.core.exception.HopException) MappingOutput(org.apache.hop.pipeline.transforms.output.MappingOutput)

Example 2 with MappingOutput

use of org.apache.hop.pipeline.transforms.output.MappingOutput in project hop by apache.

the class SimpleMappingTest method setup.

@Before
public void setup() throws Exception {
    transformMockHelper = new TransformMockHelper<>("SIMPLE_MAPPING_TEST", SimpleMappingMeta.class, SimpleMappingData.class);
    when(transformMockHelper.logChannelFactory.create(any(), any(ILoggingObject.class))).thenReturn(transformMockHelper.iLogChannel);
    when(transformMockHelper.pipeline.isRunning()).thenReturn(true);
    // Mock for MappingInput
    MappingInput mpInputMock = mock(MappingInput.class);
    when(mpInputMock.getTransformName()).thenReturn(MAPPING_INPUT_TRANSFORM_NAME);
    // Mock for MappingOutput
    MappingOutput mpOutputMock = mock(MappingOutput.class);
    when(mpOutputMock.getTransformName()).thenReturn(MAPPING_OUTPUT_TRANSFORM_NAME);
    // Mock for RowDataInputMapper
    RowDataInputMapper rdInputMpMock = mock(RowDataInputMapper.class);
    IRowMeta rwMetaInMock = mock(RowMeta.class);
    doReturn(Boolean.TRUE).when(rdInputMpMock).putRow(rwMetaInMock, new Object[] {});
    // Mock for RowProducer
    RowProducer rProducerMock = mock(RowProducer.class);
    when(rProducerMock.putRow(any(IRowMeta.class), any(Object[].class), anyBoolean())).thenReturn(true);
    // Mock for MappingIODefinition
    MappingIODefinition mpIODefMock = mock(MappingIODefinition.class);
    // Set up real SimpleMappingData with some mocked elements
    simpleMpData.mappingInput = mpInputMock;
    simpleMpData.mappingOutput = mpOutputMock;
    simpleMpData.rowDataInputMapper = rdInputMpMock;
    simpleMpData.mappingPipeline = transformMockHelper.pipeline;
    Mockito.doReturn(mpOutputMock).when(transformMockHelper.pipeline).getTransform(MAPPING_OUTPUT_TRANSFORM_NAME, 0);
    Mockito.doReturn(rProducerMock).when(transformMockHelper.pipeline).addRowProducer(MAPPING_INPUT_TRANSFORM_NAME, 0);
    when(transformMockHelper.iTransformMeta.getInputMapping()).thenReturn(mpIODefMock);
}
Also used : ILoggingObject(org.apache.hop.core.logging.ILoggingObject) MappingInput(org.apache.hop.pipeline.transforms.input.MappingInput) RowProducer(org.apache.hop.pipeline.RowProducer) IRowMeta(org.apache.hop.core.row.IRowMeta) MappingOutput(org.apache.hop.pipeline.transforms.output.MappingOutput) Before(org.junit.Before)

Example 3 with MappingOutput

use of org.apache.hop.pipeline.transforms.output.MappingOutput in project hop by apache.

the class SimpleMappingTest method testTransformShouldStopProcessingInput_IfUnderlyingTransitionIsStopped.

@Test
public void testTransformShouldStopProcessingInput_IfUnderlyingTransitionIsStopped() throws Exception {
    MappingInput mappingInput = mock(MappingInput.class);
    when(mappingInput.getTransformName()).thenReturn(MAPPING_INPUT_TRANSFORM_NAME);
    transformMockHelper.iTransformData.mappingInput = mappingInput;
    RowProducer rowProducer = mock(RowProducer.class);
    when(rowProducer.putRow(any(IRowMeta.class), any(Object[].class), anyBoolean())).thenReturn(true);
    ITransform transform = mock(ITransform.class);
    Pipeline mappingPipeline = mock(Pipeline.class);
    when(mappingPipeline.addRowProducer(anyString(), anyInt())).thenReturn(rowProducer);
    when(mappingPipeline.getTransform(anyString(), anyInt())).thenReturn(transform);
    when(mappingPipeline.isFinishedOrStopped()).thenReturn(Boolean.FALSE).thenReturn(Boolean.TRUE);
    transformMockHelper.iTransformData.mappingPipeline = mappingPipeline;
    MappingOutput mappingOutput = mock(MappingOutput.class);
    when(mappingOutput.getTransformName()).thenReturn(MAPPING_OUTPUT_TRANSFORM_NAME);
    transformMockHelper.iTransformData.mappingOutput = mappingOutput;
    smp = new SimpleMapping(transformMockHelper.transformMeta, transformMockHelper.iTransformMeta, transformMockHelper.iTransformData, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
    smp.init();
    smp.addRowSetToInputRowSets(transformMockHelper.getMockInputRowSet(new Object[] {}));
    smp.addRowSetToInputRowSets(transformMockHelper.getMockInputRowSet(new Object[] {}));
    assertTrue(smp.processRow());
    assertFalse(smp.processRow());
}
Also used : MappingInput(org.apache.hop.pipeline.transforms.input.MappingInput) ITransform(org.apache.hop.pipeline.transform.ITransform) RowProducer(org.apache.hop.pipeline.RowProducer) IRowMeta(org.apache.hop.core.row.IRowMeta) ILoggingObject(org.apache.hop.core.logging.ILoggingObject) MappingOutput(org.apache.hop.pipeline.transforms.output.MappingOutput) Pipeline(org.apache.hop.pipeline.Pipeline) Test(org.junit.Test)

Example 4 with MappingOutput

use of org.apache.hop.pipeline.transforms.output.MappingOutput in project hop by apache.

the class SimpleMapping method findMappingOutputs.

private List<MappingOutput> findMappingOutputs(Pipeline mappingPipeline) {
    List<MappingOutput> list = new ArrayList<>();
    List<IEngineComponent> components = mappingPipeline.getComponents();
    for (IEngineComponent component : components) {
        if (component instanceof MappingOutput) {
            list.add((MappingOutput) component);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) MappingOutput(org.apache.hop.pipeline.transforms.output.MappingOutput) IEngineComponent(org.apache.hop.pipeline.engine.IEngineComponent)

Aggregations

MappingOutput (org.apache.hop.pipeline.transforms.output.MappingOutput)4 MappingInput (org.apache.hop.pipeline.transforms.input.MappingInput)3 ILoggingObject (org.apache.hop.core.logging.ILoggingObject)2 IRowMeta (org.apache.hop.core.row.IRowMeta)2 RowProducer (org.apache.hop.pipeline.RowProducer)2 ArrayList (java.util.ArrayList)1 HopException (org.apache.hop.core.exception.HopException)1 Pipeline (org.apache.hop.pipeline.Pipeline)1 IEngineComponent (org.apache.hop.pipeline.engine.IEngineComponent)1 LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)1 ITransform (org.apache.hop.pipeline.transform.ITransform)1 Before (org.junit.Before)1 Test (org.junit.Test)1