Search in sources :

Example 1 with QueueRowSet

use of org.apache.hop.core.QueueRowSet in project hop by apache.

the class NullIfTest method testDateWithFormat.

@Test
public void testDateWithFormat() throws HopException {
    HopEnvironment.init();
    NullIf transform = new NullIf(smh.transformMeta, mockProcessRowMeta2(), smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
    transform.init();
    transform.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();
    }
    transform.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[][] { { d1, d2, d3, d4 } }));
    transform.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = transform.processRow();
    } while (hasMoreRows);
    IRowSet outputRowSet = transform.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]);
    }
}
Also used : QueueRowSet(org.apache.hop.core.QueueRowSet) IRowSet(org.apache.hop.core.IRowSet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ILoggingObject(org.apache.hop.core.logging.ILoggingObject) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 2 with QueueRowSet

use of org.apache.hop.core.QueueRowSet in project hop by apache.

the class StreamLookupTest method doTest.

private void doTest(boolean memoryPreservationActive, boolean binaryLookupStream, boolean binaryDataStream) throws HopException {
    StreamLookup transform = new StreamLookup(smh.transformMeta, smh.iTransformMeta, smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
    transform.init();
    transform.addRowSetToInputRowSets(mockLookupRowSet(binaryLookupStream));
    transform.addRowSetToInputRowSets(mockDataRowSet(binaryDataStream));
    transform.addRowSetToOutputRowSets(new QueueRowSet());
    StreamLookupMeta meta = mockProcessRowMeta(memoryPreservationActive);
    StreamLookupData data = new StreamLookupData();
    data.readLookupValues = true;
    IRowSet outputRowSet = transform.getOutputRowSets().get(0);
    // Process rows and collect output
    int rowNumber = 0;
    String[] expectedOutput = { "Name", "", "Value" };
    while (transform.processRow()) {
        Object[] rowData = outputRowSet.getRow();
        if (rowData != null) {
            IRowMeta rowMeta = outputRowSet.getRowMeta();
            assertEquals("Output row is of wrong size", 3, rowMeta.size());
            rowNumber++;
            // Verify output
            for (int valueIndex = 0; valueIndex < rowMeta.size(); valueIndex++) {
                String expectedValue = expectedOutput[valueIndex] + rowNumber;
                Object actualValue = rowMeta.getValueMeta(valueIndex).convertToNormalStorageType(rowData[valueIndex]);
                assertEquals("Unexpected value at row " + rowNumber + " position " + valueIndex, expectedValue, actualValue);
            }
        }
    }
    assertEquals("Incorrect output row number", 2, rowNumber);
}
Also used : QueueRowSet(org.apache.hop.core.QueueRowSet) IRowSet(org.apache.hop.core.IRowSet) IRowMeta(org.apache.hop.core.row.IRowMeta) ILoggingObject(org.apache.hop.core.logging.ILoggingObject) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString)

Example 3 with QueueRowSet

use of org.apache.hop.core.QueueRowSet in project hop by apache.

the class CsvInputMultiCharDelimiterTest method doTest.

private void doTest(String content) throws Exception {
    IRowSet output = new QueueRowSet();
    File tmp = createTestFile(ENCODING, content);
    try {
        CsvInputMeta meta = createMeta(tmp, createInputFileFields("f1", "f2", "f3"));
        CsvInputData data = new CsvInputData();
        csvInput = new CsvInput(transformMockHelper.transformMeta, meta, data, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
        csvInput.init();
        csvInput.addRowSetToOutputRowSets(output);
        try {
            csvInput.processRow();
        } finally {
            csvInput.dispose();
        }
    } finally {
        tmp.delete();
    }
    Object[] row = output.getRowImmediate();
    assertNotNull(row);
    assertEquals("value1", row[0]);
    assertEquals("value2", row[1]);
    assertEquals("value3", row[2]);
    assertNull(output.getRowImmediate());
}
Also used : QueueRowSet(org.apache.hop.core.QueueRowSet) IRowSet(org.apache.hop.core.IRowSet) File(java.io.File)

Example 4 with QueueRowSet

use of org.apache.hop.core.QueueRowSet in project hop by apache.

the class IfNullTest method testStringEmptyIsNull.

@Test
public void testStringEmptyIsNull() throws HopException {
    System.setProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL, "N");
    IfNull transform = new IfNull(smh.transformMeta, mockProcessRowMeta(), smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
    transform.init();
    final RowMeta inputRowMeta = buildInputRowMeta(// 
    new ValueMetaString("some-field"), // 
    new ValueMetaString("null-field"), // 
    new ValueMetaString("empty-field"), // 
    new ValueMetaString("space-field"), // 
    new ValueMetaString("another-field"));
    transform.setInputRowMeta(inputRowMeta);
    final Object[] inputRow = new Object[] { "value1", null, "", "    ", "value5" };
    final Object[] expectedRow = new Object[] { "value1", "replace-value", "replace-value", "    ", "value5" };
    transform.addRowSetToInputRowSets(buildInputRowSet(inputRow));
    transform.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = transform.processRow();
    } while (hasMoreRows);
    IRowSet outputRowSet = transform.getOutputRowSets().get(0);
    assertRowSetMatches("", expectedRow, outputRowSet);
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) QueueRowSet(org.apache.hop.core.QueueRowSet) IRowSet(org.apache.hop.core.IRowSet) ILoggingObject(org.apache.hop.core.logging.ILoggingObject) Test(org.junit.Test)

Example 5 with QueueRowSet

use of org.apache.hop.core.QueueRowSet in project hop by apache.

the class IfNullTest method testStringEmptyIsNotNull.

@Test
public void testStringEmptyIsNotNull() throws HopException {
    System.setProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL, "Y");
    IfNull transform = new IfNull(smh.transformMeta, mockProcessRowMeta(), smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
    transform.init();
    final RowMeta inputRowMeta = buildInputRowMeta(// 
    new ValueMetaString("some-field"), // 
    new ValueMetaString("null-field"), // 
    new ValueMetaString("empty-field"), // 
    new ValueMetaString("space-field"), // 
    new ValueMetaString("another-field"));
    transform.setInputRowMeta(inputRowMeta);
    final Object[] inputRow = new Object[] { "value1", null, "", "    ", "value5" };
    final Object[] expectedRow = new Object[] { "value1", "replace-value", "", "    ", "value5" };
    transform.addRowSetToInputRowSets(buildInputRowSet(inputRow));
    transform.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = transform.processRow();
    } while (hasMoreRows);
    IRowSet outputRowSet = transform.getOutputRowSets().get(0);
    assertRowSetMatches("", expectedRow, outputRowSet);
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) QueueRowSet(org.apache.hop.core.QueueRowSet) IRowSet(org.apache.hop.core.IRowSet) ILoggingObject(org.apache.hop.core.logging.ILoggingObject) Test(org.junit.Test)

Aggregations

QueueRowSet (org.apache.hop.core.QueueRowSet)12 IRowSet (org.apache.hop.core.IRowSet)11 ILoggingObject (org.apache.hop.core.logging.ILoggingObject)7 Test (org.junit.Test)6 File (java.io.File)4 IRowMeta (org.apache.hop.core.row.IRowMeta)3 RowMeta (org.apache.hop.core.row.RowMeta)3 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)3 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HopException (org.apache.hop.core.exception.HopException)1 TextFileInputField (org.apache.hop.core.file.TextFileInputField)1 ValueMetaDate (org.apache.hop.core.row.value.ValueMetaDate)1 InputsReader (org.apache.hop.pipeline.transforms.jsoninput.reader.InputsReader)1 RowOutputConverter (org.apache.hop.pipeline.transforms.jsoninput.reader.RowOutputConverter)1 Ignore (org.junit.Ignore)1