use of org.pentaho.di.trans.steps.sort.SortRowsMeta in project pentaho-kettle by pentaho.
the class TestUtilities method createSortRowsStep.
/**
* Create and return a SortRows step.
*
* @param name
* @param sortFields
* [] Fields to sort by
* @param ascending
* [] Boolean indicating whether the corresponding field is to be sorted in ascending or descending order.
* @param caseSensitive
* [] Boolean indicating whether the corresponding field is to have case as a factor in the sort.
* @param directory
* The directory in the file system where the sort is to take place if it can't fit into memory?
* @param sortSize
* ???
* @param pluginRegistry
* The environment's Kettle plugin registry.
* @return
*/
public static synchronized StepMeta createSortRowsStep(String name, String[] sortFields, boolean[] ascending, boolean[] caseSensitive, String directory, int sortSize, PluginRegistry pluginRegistry) {
SortRowsMeta sortRowsMeta = new SortRowsMeta();
sortRowsMeta.setSortSize(Integer.toString(sortSize / 10));
sortRowsMeta.setFieldName(sortFields);
sortRowsMeta.setAscending(ascending);
sortRowsMeta.setCaseSensitive(caseSensitive);
sortRowsMeta.setDirectory(directory);
String sortRowsStepPid = pluginRegistry.getPluginId(StepPluginType.class, sortRowsMeta);
StepMeta sortRowsStep = new StepMeta(sortRowsStepPid, name, sortRowsMeta);
return sortRowsStep;
}
use of org.pentaho.di.trans.steps.sort.SortRowsMeta 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.steps.sort.SortRowsMeta 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.steps.sort.SortRowsMeta 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.steps.sort.SortRowsMeta in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGenerator method generateSortStep.
private StepMeta generateSortStep(RowMetaInterface rowMeta) throws KettleException {
List<SQLField> fields = sql.getOrderFields().getFields();
List<SQLField> selectFields = sql.getSelectFields().getFields();
SortRowsMeta meta = new SortRowsMeta();
meta.allocate(fields.size());
for (int i = 0; i < fields.size(); i++) {
SQLField sqlField = fields.get(i);
ValueMetaInterface valueMeta = rowMeta.searchValueMeta(sqlField.getField());
if (valueMeta == null) {
// This could be an alias used in an order by clause.
// In that case, we need to find the correct original name in the selectFields...
//
SQLField selectField = SQLField.searchSQLFieldByFieldOrAlias(selectFields, sqlField.getField());
if (selectField != null) {
// Yep, verify this original name...
//
valueMeta = rowMeta.searchValueMeta(selectField.getField());
} else {
valueMeta = rowMeta.searchValueMeta(sqlField.getAlias());
}
}
if (valueMeta == null) {
throw new KettleException("Unable to find field to sort on: " + sqlField.getField() + " nor the alias: " + sqlField.getAlias());
}
meta.getFieldName()[i] = valueMeta.getName();
meta.getAscending()[i] = sqlField.isAscending();
meta.getCaseSensitive()[i] = true;
}
meta.setSortSize("1000000");
StepMeta stepMeta = new StepMeta("Sort rows", meta);
stepMeta.setLocation(xLocation, 50);
xLocation += 100;
stepMeta.setDraw(true);
return stepMeta;
}
Aggregations