Search in sources :

Example 6 with SortRowsMeta

use of org.pentaho.di.trans.steps.sort.SortRowsMeta in project pentaho-kettle by pentaho.

the class UniqueRowsIT method testSortCaseInsensitiveUniqueCaseInsensitive.

public void testSortCaseInsensitiveUniqueCaseInsensitive() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("uniquerowstest");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector step...
    // 
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // 
    // Create a sort rows step
    // 
    String sortRowsStepname = "sort rows step";
    SortRowsMeta srm = new SortRowsMeta();
    srm.setFieldName(new String[] { "KEY" });
    srm.setAscending(new boolean[] { true });
    srm.setCaseSensitive(new boolean[] { false });
    srm.setPreSortedField(new boolean[] { false });
    srm.setPrefix("SortRowsTest");
    srm.setDirectory(".");
    String sortRowsStepPid = registry.getPluginId(StepPluginType.class, srm);
    StepMeta sortRowsStep = new StepMeta(sortRowsStepPid, sortRowsStepname, srm);
    transMeta.addStep(sortRowsStep);
    transMeta.addTransHop(new TransHopMeta(injectorStep, sortRowsStep));
    // 
    // Create a unique rows step
    // 
    String uniqueRowsStepname = "unique rows step";
    UniqueRowsMeta urm = new UniqueRowsMeta();
    urm.setCompareFields(new String[] { "KEY" });
    urm.setCaseInsensitive(new boolean[] { true });
    String uniqueRowsStepPid = registry.getPluginId(StepPluginType.class, urm);
    StepMeta uniqueRowsStep = new StepMeta(uniqueRowsStepPid, uniqueRowsStepname, urm);
    transMeta.addStep(uniqueRowsStep);
    transMeta.addTransHop(new TransHopMeta(sortRowsStep, uniqueRowsStep));
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    transMeta.addTransHop(new TransHopMeta(uniqueRowsStep, dummyStep));
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    for (RowMetaAndData rm : inputList) {
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> resultRows = dummyRc.getRowsWritten();
    checkRows(createResultDataSortCaseInsensitiveUniqueCaseInsensitive(), resultRows);
}
Also used : UniqueRowsMeta(org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta) RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) SortRowsMeta(org.pentaho.di.trans.steps.sort.SortRowsMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)6 SortRowsMeta (org.pentaho.di.trans.steps.sort.SortRowsMeta)6 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 RowProducer (org.pentaho.di.trans.RowProducer)4 RowStepCollector (org.pentaho.di.trans.RowStepCollector)4 Trans (org.pentaho.di.trans.Trans)4 TransHopMeta (org.pentaho.di.trans.TransHopMeta)4 TransMeta (org.pentaho.di.trans.TransMeta)4 StepInterface (org.pentaho.di.trans.step.StepInterface)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)4 UniqueRowsMeta (org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta)4 KettleException (org.pentaho.di.core.exception.KettleException)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 SQLField (org.pentaho.di.core.sql.SQLField)1