use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TextFileOutputIT method testTextFileOutput5.
/**
* Tests the GZIP output capability of the TextFileOutput step
*
* @throws Exception
*/
@Test
public void testTextFileOutput5() throws Exception {
KettleEnvironment.init();
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("testTextFileOutput5");
PluginRegistry registry = PluginRegistry.getInstance();
// create an injector step
String injectorStepName = "injector step";
StepMeta injectorStep = TestUtilities.createInjectorStep(injectorStepName, registry);
transMeta.addStep(injectorStep);
// create a row generator step
StepMeta rowGeneratorStep = createRowGeneratorStep("Create rows for testTextFileOutput5", registry);
transMeta.addStep(rowGeneratorStep);
// create a TransHopMeta for injector and add it to the transMeta
TransHopMeta hop_injectory_rowGenerator = new TransHopMeta(injectorStep, rowGeneratorStep);
transMeta.addTransHop(hop_injectory_rowGenerator);
// create the text file output step with GZIP compression
// but first lets get a filename
String textFileName = "testTextFileOutput5";
String textFileOutputStepName = "text file output step";
StepMeta textFileOutputStep = createTextFileOutputStep(textFileOutputStepName, textFileName, "GZip", registry);
transMeta.addStep(textFileOutputStep);
// create a TransHopMeta for textFileOutputStep and add it to the transMeta
TransHopMeta hop_RowGenerator_outputTextFile = new TransHopMeta(rowGeneratorStep, textFileOutputStep);
transMeta.addTransHop(hop_RowGenerator_outputTextFile);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
// Create a row collector and add it to the dummy step interface
StepInterface dummyStepInterface = trans.getStepInterface(textFileOutputStepName, 0);
RowStepCollector dummyRowCollector = new RowStepCollector();
dummyStepInterface.addRowListener(dummyRowCollector);
trans.startThreads();
trans.waitUntilFinished();
// Compare the results
List<RowMetaAndData> resultRows = dummyRowCollector.getRowsWritten();
Object[][] rows = new Object[10][3];
File f = new File(textFileName + "." + EXTENSION + ".gz");
f.deleteOnExit();
try {
FileInputStream fin = new FileInputStream(f);
GZIPInputStream gzis = new GZIPInputStream(fin);
InputStreamReader xover = new InputStreamReader(gzis);
BufferedReader input = new BufferedReader(xover);
readData1Rows(rows, input);
fin.close();
} catch (IOException e) {
fail(e.getLocalizedMessage());
}
List<RowMetaAndData> outFileRows = createResultDataFromObjects(rows);
try {
TestUtilities.checkRows(resultRows, outFileRows);
} catch (TestFailedException tfe) {
fail(tfe.getMessage());
}
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class UniqueRowsIT method testSortCaseSensitiveUniqueCaseSensitive.
public void testSortCaseSensitiveUniqueCaseSensitive() 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[] { true });
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[] { false });
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(createResultDataSortCaseSensitiveUniqueCaseSensitive(), resultRows);
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class UniqueRowsIT method testSortCaseSensitiveUniqueCaseInsensitive.
public void testSortCaseSensitiveUniqueCaseInsensitive() 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[] { true });
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(createResultDataSortCaseSensitiveUniqueCaseInsensitive(), resultRows);
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class UniqueRowsIT method testSortCaseInsensitiveUniqueCaseSensitive.
public void testSortCaseInsensitiveUniqueCaseSensitive() 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[] { false });
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(createResultDataSortCaseInsensitiveUniqueCaseSensitive(), resultRows);
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class UniqueRowsIT method testAllUnique.
@Test
public void testAllUnique() 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 unique rows step
//
String uniqueRowsStepname = "unique rows step";
UniqueRowsMeta urm = new UniqueRowsMeta();
urm.setCompareFields(new String[] { "KEY" });
urm.setCaseInsensitive(new boolean[] { true });
urm.setRejectDuplicateRow(true);
String uniqueRowsStepPid = registry.getPluginId(StepPluginType.class, urm);
StepMeta uniqueRowsStep = new StepMeta(uniqueRowsStepPid, uniqueRowsStepname, urm);
uniqueRowsStep.setDistributes(false);
transMeta.addStep(uniqueRowsStep);
transMeta.addTransHop(new TransHopMeta(injectorStep, uniqueRowsStep));
//
// Create a dummy step to receive the unique rows
//
String dummyStepname1 = "dummy step";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
transMeta.addTransHop(new TransHopMeta(uniqueRowsStep, dummyStep1));
//
// Create a dummy step to receive the duplicate rows (errors)
//
String dummyStepname2 = "dummy step2";
DummyTransMeta dm2 = new DummyTransMeta();
String dummyPid2 = registry.getPluginId(StepPluginType.class, dm2);
StepMeta dummyStep2 = new StepMeta(dummyPid2, dummyStepname2, dm2);
transMeta.addStep(dummyStep2);
// Set up error (aka duplicates) handling info
StepErrorMeta stepErrorMeta = new StepErrorMeta(new Variables(), uniqueRowsStep);
stepErrorMeta.setTargetStep(dummyStep2);
stepErrorMeta.setEnabled(true);
stepErrorMeta.setNrErrorsValuename("numErrors");
stepErrorMeta.setErrorDescriptionsValuename("duplicates");
stepErrorMeta.setErrorFieldsValuename("KEY");
stepErrorMeta.setErrorCodesValuename("errorCodes");
stepErrorMeta.setMaxErrors("9999");
stepErrorMeta.setMaxPercentErrors("");
stepErrorMeta.setMinPercentRows("");
uniqueRowsStep.setStepErrorMeta(stepErrorMeta);
transMeta.addTransHop(new TransHopMeta(uniqueRowsStep, dummyStep2));
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector dummyRc1 = new RowStepCollector();
si.addRowListener(dummyRc1);
StepInterface si2 = trans.getStepInterface(dummyStepname2, 0);
RowStepCollector dummyRc2 = new RowStepCollector();
si2.addRowListener(dummyRc2);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createDataAllUnique();
for (RowMetaAndData rm : inputList) {
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
checkRows(createResultDataAllUnique(), resultRows);
List<RowMetaAndData> errorRows = dummyRc2.getRowsWritten();
// There should be no duplicates for this test
assertEquals(errorRows.size(), 0);
}
Aggregations