Search in sources :

Example 1 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.

the class CheckSumTest method buildHexadecimalChecksumTrans.

private Trans buildHexadecimalChecksumTrans(int checkSumType, boolean compatibilityMode, boolean oldChecksumBehaviour) throws Exception {
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName(getClass().getName());
    // Create a CheckSum Step
    String checkSumStepname = "CheckSum";
    CheckSumMeta meta = new CheckSumMeta();
    // Set the compatibility mode and other required fields
    meta.setCompatibilityMode(compatibilityMode);
    meta.setResultFieldName("hex");
    meta.setCheckSumType(checkSumType);
    meta.setResultType(CheckSumMeta.result_TYPE_HEXADECIMAL);
    meta.setFieldName(new String[] { "test" });
    meta.setOldChecksumBehaviour(oldChecksumBehaviour);
    String checkSumPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, meta);
    StepMeta checkSumStep = new StepMeta(checkSumPluginPid, checkSumStepname, meta);
    transMeta.addStep(checkSumStep);
    // Create a Dummy step
    String dummyStepname = "Output";
    DummyTransMeta dummyMeta = new DummyTransMeta();
    String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
    StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
    transMeta.addStep(dummyStep);
    // Create a hop from CheckSum to Output
    TransHopMeta hop = new TransHopMeta(checkSumStep, dummyStep);
    transMeta.addTransHop(hop);
    return new Trans(transMeta);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 2 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateIifStep.

/**
 * This method generates a 4 steps for every IIF clause... TODO: replace with one step...
 *
 * @param iifField
 * @param lastStep
 * @param transMeta
 * @return steps
 */
private StepMeta generateIifStep(SQLField iifField, TransMeta transMeta, StepMeta lastStep) {
    IifFunction iif = iifField.getIif();
    // The Filter condition...
    // 
    FilterRowsMeta filterMeta = new FilterRowsMeta();
    filterMeta.setCondition(iifField.getIif().getSqlCondition().getCondition());
    StepMeta filterStep = new StepMeta(iifField.getExpression(), filterMeta);
    filterStep.setLocation(xLocation, 50);
    xLocation += 100;
    filterStep.setDraw(true);
    lastStep = addToTrans(filterStep, transMeta, lastStep);
    // The True and false steps...
    // 
    StepMetaInterface trueMetaInterface;
    ValueMetaInterface valueMeta = iif.getTrueValue().getValueMeta();
    if (iif.isTrueField()) {
        CalculatorMeta trueMeta = new CalculatorMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getTrueValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta trueMeta = new ConstantMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        trueMeta.getFieldType()[0] = iif.getTrueValue().getValueMeta().getTypeDesc();
        trueMeta.getValue()[0] = iif.getTrueValue().toString();
        trueMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
    }
    StepMeta trueStep = new StepMeta("TRUE: " + iifField.getExpression(), trueMetaInterface);
    trueStep.setLocation(xLocation, 50);
    trueStep.setDraw(true);
    lastStep = addToTrans(trueStep, transMeta, filterStep);
    StepMetaInterface falseMetaInterface;
    valueMeta = iif.getFalseValue().getValueMeta();
    if (iif.isFalseField()) {
        CalculatorMeta falseMeta = new CalculatorMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getFalseValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        falseMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta falseMeta = new ConstantMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        falseMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        falseMeta.getFieldType()[0] = iif.getFalseValue().getValueMeta().getTypeDesc();
        falseMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
        falseMeta.getValue()[0] = iif.getFalseValue().toString();
    }
    StepMeta falseStep = new StepMeta("FALSE: " + iifField.getExpression(), falseMetaInterface);
    falseStep.setLocation(xLocation, 150);
    xLocation += 100;
    falseStep.setDraw(true);
    lastStep = addToTrans(falseStep, transMeta, filterStep);
    // specify true/false targets
    List<StreamInterface> targetStreams = filterMeta.getStepIOMeta().getTargetStreams();
    targetStreams.get(0).setSubject(trueStep.getName());
    targetStreams.get(1).setSubject(falseStep.getName());
    filterMeta.searchInfoAndTargetSteps(transMeta.getSteps());
    DummyTransMeta dummyMeta = new DummyTransMeta();
    StepMeta dummyStep = new StepMeta("Collect: " + iifField.getExpression(), dummyMeta);
    dummyStep.setLocation(xLocation, 50);
    xLocation += 100;
    dummyStep.setDraw(true);
    lastStep = addToTrans(dummyStep, transMeta, trueStep);
    transMeta.addTransHop(new TransHopMeta(falseStep, dummyStep));
    return lastStep;
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IifFunction(org.pentaho.di.core.sql.IifFunction) CalculatorMeta(org.pentaho.di.trans.steps.calculator.CalculatorMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ConstantMeta(org.pentaho.di.trans.steps.constant.ConstantMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 3 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateResultStep.

private StepMeta generateResultStep() {
    DummyTransMeta meta = new DummyTransMeta();
    StepMeta stepMeta = new StepMeta("RESULT", meta);
    stepMeta.setLocation(xLocation, 50);
    xLocation += 100;
    stepMeta.setDraw(true);
    return stepMeta;
}
Also used : StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 4 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pdi-dataservice-server-plugin by pentaho.

the class AnnotationsQueryServiceTest method testAnnotationsOnCurrentStep2Paths.

@Test
public void testAnnotationsOnCurrentStep2Paths() throws Exception {
    TransMeta transMeta = new TransMeta();
    DummyTransMeta src1Meta = new DummyTransMeta();
    StepMeta src1 = new StepMeta("src1", src1Meta);
    transMeta.addStep(src1);
    final ModelAnnotationGroup mag1 = new ModelAnnotationGroup(new ModelAnnotation<CreateAttribute>(new CreateAttribute()));
    final String name1 = mag1.get(0).getName();
    DummyTransMeta annot1Meta = createPseudoAnnotate(mag1);
    StepMeta annot1 = new StepMeta("annot1", annot1Meta);
    transMeta.addStep(annot1);
    TransHopMeta src1ToAnnot1 = new TransHopMeta(src1, annot1);
    transMeta.addTransHop(src1ToAnnot1);
    DummyTransMeta src2Meta = new DummyTransMeta();
    StepMeta src2 = new StepMeta("src2", src2Meta);
    transMeta.addStep(src2);
    final ModelAnnotationGroup mag2 = new ModelAnnotationGroup(new ModelAnnotation<CreateAttribute>(new CreateAttribute()));
    final String name2 = mag2.get(0).getName();
    DummyTransMeta annot2Meta = createPseudoAnnotate(mag2);
    StepMeta annot2 = new StepMeta("annot2", annot2Meta);
    transMeta.addStep(annot2);
    TransHopMeta src2ToAnnot2 = new TransHopMeta(src2, annot2);
    transMeta.addTransHop(src2ToAnnot2);
    DummyTransMeta mergedMeta = new DummyTransMeta();
    StepMeta mergedStepMeta = new StepMeta("merged", mergedMeta);
    transMeta.addStep(mergedStepMeta);
    transMeta.addTransHop(new TransHopMeta(annot1, mergedStepMeta));
    transMeta.addTransHop(new TransHopMeta(annot2, mergedStepMeta));
    final DataServiceMeta ds1 = new DataServiceMeta((TransMeta) transMeta.clone());
    ds1.setName("dsa");
    ds1.setStepname("annot1");
    final DataServiceMeta dsAll = new DataServiceMeta((TransMeta) transMeta.clone());
    dsAll.setName("ds");
    dsAll.setStepname("merged");
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    when(dataServiceResolver.getDataService("dsAll")).thenReturn(dsAll);
    when(dataServiceResolver.getDataService("ds1")).thenReturn(ds1);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from ds1", 0, Collections.<String, String>emptyMap());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String result = getResultString(outputStream);
    assertTrue(result.contains(name1));
    assertFalse(result.contains(name2));
    queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    query = queryService.prepareQuery("show annotations from dsAll", 0, Collections.<String, String>emptyMap());
    outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String result2 = getResultString(outputStream);
    assertTrue(result2.contains(name1));
    assertTrue(result2.contains(name2));
}
Also used : ModelAnnotationGroup(org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) CreateAttribute(org.pentaho.agilebi.modeler.models.annotations.CreateAttribute) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Test(org.junit.Test)

Example 5 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pdi-dataservice-server-plugin by pentaho.

the class AnnotationsQueryServiceTest method testAnnotationsOnCurrentStep.

@Test
public void testAnnotationsOnCurrentStep() throws Exception {
    TransMeta transMeta = new TransMeta();
    DummyTransMeta src1Meta = new DummyTransMeta();
    StepMeta src1 = new StepMeta("src", src1Meta);
    transMeta.addStep(src1);
    final ModelAnnotationGroup mag1 = new ModelAnnotationGroup(new ModelAnnotation<CreateAttribute>(new CreateAttribute()));
    final String name1 = mag1.get(0).getName();
    DummyTransMeta annot1Meta = createPseudoAnnotate(mag1);
    StepMeta annot1 = Mockito.spy(new StepMeta("annot", annot1Meta));
    transMeta.addStep(annot1);
    TransHopMeta src1ToAnnot1 = new TransHopMeta(src1, annot1);
    transMeta.addTransHop(src1ToAnnot1);
    final DataServiceMeta dsA = new DataServiceMeta(transMeta);
    dsA.setName("dsa");
    dsA.setStepname("annot");
    final DataServiceMeta ds1 = new DataServiceMeta(transMeta);
    ds1.setName("ds");
    ds1.setStepname("src");
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    when(dataServiceResolver.getDataService("ds")).thenReturn(ds1);
    when(dataServiceResolver.getDataService("dsa")).thenReturn(dsA);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from dsa", 0, Collections.<String, String>emptyMap());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String result = getResultString(outputStream);
    assertTrue(result.contains(name1));
    query = queryService.prepareQuery("show annotations from ds", 0, Collections.<String, String>emptyMap());
    outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    result = getResultString(outputStream);
    String output = getResultString(outputStream);
    assertEquals("<annotations></annotations>", output.trim());
}
Also used : ModelAnnotationGroup(org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) CreateAttribute(org.pentaho.agilebi.modeler.models.annotations.CreateAttribute) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Test(org.junit.Test)

Aggregations

DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)85 StepMeta (org.pentaho.di.trans.step.StepMeta)84 TransMeta (org.pentaho.di.trans.TransMeta)53 TransHopMeta (org.pentaho.di.trans.TransHopMeta)52 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)49 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)46 Trans (org.pentaho.di.trans.Trans)46 StepInterface (org.pentaho.di.trans.step.StepInterface)46 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)45 RowStepCollector (org.pentaho.di.trans.RowStepCollector)42 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)38 RowProducer (org.pentaho.di.trans.RowProducer)36 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)11 UniqueRowsMeta (org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta)7 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)6 PartitionSchema (org.pentaho.di.partition.PartitionSchema)5 StepPartitioningMeta (org.pentaho.di.trans.step.StepPartitioningMeta)5 GetVariableMeta (org.pentaho.di.trans.steps.getvariable.GetVariableMeta)5 FieldDefinition (org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition)5