use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class CsvInputDoubleLineEndTest method doTest.
private void doTest(final String fileEncoding, final String stepEncoding, final String testData) throws Exception {
String testFilePath = createTestFile(fileEncoding, testData).getAbsolutePath();
CsvInputMeta meta = createStepMeta(testFilePath, stepEncoding);
CsvInputData data = new CsvInputData();
CsvInput csvInput = new CsvInput(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
csvInput.init(meta, data);
csvInput.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
for (int i = 0; i < rowMeta.size(); i++) {
assertEquals("Value", row[i]);
}
}
});
boolean haveRowsToRead;
do {
haveRowsToRead = !csvInput.processRow(meta, data);
} while (!haveRowsToRead);
csvInput.dispose(meta, data);
assertEquals(2, csvInput.getLinesWritten());
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class CsvInputUnicodeTest method doTest.
private void doTest(final String fileEncoding, final String stepEncoding, final String testData, final String delimiter) throws Exception {
String testFilePath = createTestFile(fileEncoding, testData).getAbsolutePath();
CsvInputMeta meta = createStepMeta(testFilePath, stepEncoding, delimiter);
CsvInputData data = new CsvInputData();
CsvInput csvInput = new CsvInput(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
csvInput.init(meta, data);
csvInput.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
for (int i = 0; i < rowMeta.size(); i++) {
Assert.assertEquals("Value", row[i]);
}
}
});
boolean haveRowsToRead;
do {
haveRowsToRead = !csvInput.processRow(meta, data);
} while (!haveRowsToRead);
csvInput.dispose(meta, data);
Assert.assertEquals(2, csvInput.getLinesWritten());
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class CsvProcessRowInParallelTest method processRows.
/**
* So as not to heap up list of taken parameters, we are passing combi, but we expect to see CsvInput class instances
* in it's content.
*/
private int processRows(StepMetaDataCombi combi) throws Exception {
CsvInput csvInput = (CsvInput) combi.step;
CsvInputData stepData = (CsvInputData) combi.data;
CsvInputMeta stepMeta = (CsvInputMeta) combi.meta;
final int[] writtenRows = { 0 };
csvInput.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
writtenRows[0]++;
}
});
boolean haveRowsToRead;
do {
haveRowsToRead = !csvInput.processRow(stepMeta, stepData);
} while (!haveRowsToRead);
csvInput.dispose(stepMeta, stepData);
return writtenRows[0];
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class GetPreviousRowFieldMeta method getFields.
@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
// Add new field?
for (int i = 0; i < fieldOutStream.length; i++) {
if (!Utils.isEmpty(fieldOutStream[i])) {
int index = inputRowMeta.indexOfValue(fieldInStream[i]);
if (index >= 0) {
ValueMetaInterface in = inputRowMeta.getValueMeta(index);
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(fieldOutStream[i]), in.getType());
v.setName(space.environmentSubstitute(fieldOutStream[i]));
v.setLength(in.getLength());
v.setPrecision(in.getPrecision());
v.setConversionMask(in.getConversionMask());
v.setOrigin(name);
inputRowMeta.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class RulesAccumulator method runtimeInit.
public boolean runtimeInit() throws KettleStepException {
try {
data.setOutputRowMeta(getInputRowMeta().clone());
meta.setKeepInputFields(false);
meta.getFields(data.getOutputRowMeta(), getStepname(), null, null, this, repository, metaStore);
data.setRuleFilePath(meta.getRuleFile());
data.setRuleString(meta.getRuleDefinition());
data.initializeRules();
data.initializeInput(getInputRowMeta());
return true;
} catch (Exception e) {
throw new KettleStepException(e);
}
}
Aggregations