use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class NullIfTest method testDateWithFormat.
@Test
public void testDateWithFormat() throws KettleException {
KettleEnvironment.init();
NullIf step = new NullIf(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
step.init(smh.initStepMetaInterface, smh.stepDataInterface);
step.setInputRowMeta(getInputRowMeta2());
Date d1 = null;
Date d2 = null;
Date d3 = null;
Date d4 = null;
try {
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
d1 = formatter.parse("20150606");
d3 = formatter.parse("20150607");
formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
d2 = formatter.parse("2015/06/06 00:00:00.000");
d4 = formatter.parse("2015/07/06 00:00:00.000");
} catch (ParseException e) {
e.printStackTrace();
}
step.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[][] { { d1, d2, d3, d4 } }));
step.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = step.processRow(mockProcessRowMeta2(), smh.processRowsStepDataInterface);
} while (hasMoreRows);
RowSet outputRowSet = step.getOutputRowSets().get(0);
Object[] actualRow = outputRowSet.getRow();
Object[] expectedRow = new Object[] { null, null, d3, d4 };
Assert.assertEquals("Output row is of an unexpected length", expectedRow.length, outputRowSet.getRowMeta().size());
for (int i = 0; i < expectedRow.length; i++) {
Assert.assertEquals("Unexpected output value at index " + i, expectedRow[i], actualRow[i]);
}
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class GroupByTest method testProcessRow.
@Test
public void testProcessRow() throws KettleException {
GroupByMeta groupByMeta = mock(GroupByMeta.class);
GroupByData groupByData = mock(GroupByData.class);
GroupBy groupBySpy = Mockito.spy(new GroupBy(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans));
doReturn(null).when(groupBySpy).getRow();
doReturn(null).when(groupBySpy).getInputRowMeta();
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("ROWNR"));
List<RowSet> outputRowSets = new ArrayList<RowSet>();
BlockingRowSet rowSet = new BlockingRowSet(1);
rowSet.putRow(rowMeta, new Object[] { new Long(0) });
outputRowSets.add(rowSet);
groupBySpy.setOutputRowSets(outputRowSets);
final String[] sub = { "b" };
doReturn(sub).when(groupByMeta).getSubjectField();
final String[] groupField = { "a" };
doReturn(groupField).when(groupByMeta).getGroupField();
final String[] aggFields = { "b_g" };
doReturn(aggFields).when(groupByMeta).getAggregateField();
final int[] aggType = { GroupByMeta.TYPE_GROUP_CONCAT_COMMA };
doReturn(aggType).when(groupByMeta).getAggregateType();
when(mockHelper.transMeta.getPrevStepFields(mockHelper.stepMeta)).thenReturn(new RowMeta());
groupBySpy.processRow(groupByMeta, groupByData);
assertTrue(groupBySpy.getOutputRowSets().get(0).isDone());
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class IfNullTest method testString_emptyIsNotNull.
@Test
public void testString_emptyIsNotNull() throws KettleException {
// FieldAccessor.ensureEmptyStringIsNotNull( true );
Whitebox.setInternalState(ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", true);
IfNull step = new IfNull(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
step.init(smh.initStepMetaInterface, smh.stepDataInterface);
final RowMeta inputRowMeta = buildInputRowMeta(//
new ValueMetaString("some-field"), //
new ValueMetaString("null-field"), //
new ValueMetaString("empty-field"), //
new ValueMetaString("space-field"), //
new ValueMetaString("another-field"));
step.setInputRowMeta(inputRowMeta);
final Object[] inputRow = new Object[] { "value1", null, "", " ", "value5" };
final Object[] expectedRow = new Object[] { "value1", "replace-value", "", " ", "value5" };
step.addRowSetToInputRowSets(buildInputRowSet(inputRow));
step.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
} while (hasMoreRows);
RowSet outputRowSet = step.getOutputRowSets().get(0);
assertRowSetMatches("", expectedRow, outputRowSet);
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class IfNullTest method testString_emptyIsNull.
@Test
public void testString_emptyIsNull() throws KettleException {
Whitebox.setInternalState(ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", false);
IfNull step = new IfNull(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
step.init(smh.initStepMetaInterface, smh.stepDataInterface);
final RowMeta inputRowMeta = buildInputRowMeta(//
new ValueMetaString("some-field"), //
new ValueMetaString("null-field"), //
new ValueMetaString("empty-field"), //
new ValueMetaString("space-field"), //
new ValueMetaString("another-field"));
step.setInputRowMeta(inputRowMeta);
final Object[] inputRow = new Object[] { "value1", null, "", " ", "value5" };
final Object[] expectedRow = new Object[] { "value1", "replace-value", "replace-value", " ", "value5" };
step.addRowSetToInputRowSets(buildInputRowSet(inputRow));
step.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
} while (hasMoreRows);
RowSet outputRowSet = step.getOutputRowSets().get(0);
assertRowSetMatches("", expectedRow, outputRowSet);
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class JoinRowsTest method testJoinRowsStep.
@Test
public void testJoinRowsStep() throws Exception {
JoinRowsMeta joinRowsMeta = new JoinRowsMeta();
joinRowsMeta.setMainStepname("main step name");
joinRowsMeta.setPrefix("out");
joinRowsMeta.setCacheSize(3);
JoinRowsData joinRowsData = new JoinRowsData();
JoinRows joinRows = getJoinRows();
joinRows.getTrans().setRunning(true);
joinRows.init(joinRowsMeta, joinRowsData);
List<RowSet> rowSets = new ArrayList<>();
rowSets.add(getRowSetWithData(3, "main --", true));
rowSets.add(getRowSetWithData(3, "secondary --", false));
joinRows.setInputRowSets(rowSets);
RowStepCollector rowStepCollector = new RowStepCollector();
joinRows.addRowListener(rowStepCollector);
joinRows.getLogChannel().setLogLevel(LogLevel.ROWLEVEL);
KettleLogStore.init();
while (true) {
if (!joinRows.processRow(joinRowsMeta, joinRowsData)) {
break;
}
}
rowStepCollector.getRowsWritten();
// since we have data join of two row sets with size 3 then we must have 9 written rows
assertEquals(9, rowStepCollector.getRowsWritten().size());
assertEquals(6, rowStepCollector.getRowsRead().size());
Object[][] expectedResult = createExpectedResult();
List<Object[]> rowWritten = rowStepCollector.getRowsWritten().stream().map(RowMetaAndData::getData).collect(Collectors.toList());
for (int i = 0; i < 9; i++) {
assertTrue(Arrays.equals(expectedResult[i], rowWritten.get(i)));
}
}
Aggregations