use of org.apache.hop.core.SingleRowRowSet in project hop by apache.
the class FastJsonReader method getEmptyResponse.
private IRowSet getEmptyResponse() {
IRowSet nullInputResponse = new SingleRowRowSet();
nullInputResponse.putRow(null, new Object[fields.length]);
nullInputResponse.setDone();
return nullInputResponse;
}
use of org.apache.hop.core.SingleRowRowSet in project hop by apache.
the class FieldSplitterTest method testSplitFieldsDup.
@Test
public void testSplitFieldsDup() throws Exception {
FieldSplitterMeta meta = new FieldSplitterMeta();
meta.allocate(2);
meta.setDelimiter(" ");
meta.setEnclosure("");
meta.setSplitField("split");
meta.setFieldName(new String[] { "key", "val" });
meta.setFieldType(new int[] { IValueMeta.TYPE_STRING, IValueMeta.TYPE_STRING });
FieldSplitter transform = new FieldSplitter(transformMockHelper.transformMeta, meta, transformMockHelper.iTransformData, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
transform.init();
IRowMeta rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("key"));
rowMeta.addValueMeta(new ValueMetaString("val"));
rowMeta.addValueMeta(new ValueMetaString("split"));
transform.setInputRowMeta(rowMeta);
transform.addRowSetToInputRowSets(transformMockHelper.getMockInputRowSet(new Object[] { "key", "string", "part1 part2" }));
transform.addRowSetToOutputRowSets(new SingleRowRowSet());
assertTrue(transform.processRow());
IRowSet rs = transform.getOutputRowSets().get(0);
Object[] row = rs.getRow();
IRowMeta rm = rs.getRowMeta();
assertArrayEquals(new Object[] { "key", "string", "part1", "part2" }, Arrays.copyOf(row, 4));
assertArrayEquals(new Object[] { "key", "val", "key_1", "val_1" }, rm.getFieldNames());
}
use of org.apache.hop.core.SingleRowRowSet in project hop by apache.
the class XmlInputStreamTest method testFromPreviousTransform.
@Test
public void testFromPreviousTransform() throws Exception {
xmlInputStreamMeta.sourceFromInput = true;
xmlInputStreamMeta.sourceFieldName = "inf";
xmlInputStreamData.outputRowMeta = new RowMeta();
RowMeta rm = new RowMeta();
String xml = "<ProductGroup attribute1=\"v1\"/>";
ValueMetaString ms = new ValueMetaString("inf");
IRowSet rs = new SingleRowRowSet();
rs.putRow(rm, new Object[] { xml });
rs.setDone();
XmlInputStream xmlInputStream = new XmlInputStream(transformMockHelper.transformMeta, xmlInputStreamMeta, xmlInputStreamData, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
xmlInputStream.setInputRowMeta(rm);
xmlInputStream.getInputRowMeta().addValueMeta(ms);
xmlInputStream.addRowSetToInputRowSets(rs);
xmlInputStream.setOutputRowSets(new ArrayList<>());
xmlInputStream.init();
xmlInputStream.addRowListener(rl);
boolean haveRowsToRead;
do {
haveRowsToRead = !xmlInputStream.processRow();
} while (!haveRowsToRead);
int expectedRowNum = 1;
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "<ProductGroup attribute1=\"v1\"/>", rl.getWritten().get(expectedRowNum)[typeDescriptionPos]);
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "START_ELEMENT", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "ProductGroup", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
// attributes
// ATTRIBUTE_1
expectedRowNum++;
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "ATTRIBUTE", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "attribute1", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
assertEquals(INCORRECT_XML_DATA_VALUE_MESSAGE, "v1", rl.getWritten().get(expectedRowNum)[dataValue + 1]);
// check EndElement for the ProductGroup element
expectedRowNum++;
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "END_ELEMENT", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "ProductGroup", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
}
use of org.apache.hop.core.SingleRowRowSet in project hop by apache.
the class XmlInputStreamTest method testCorrectFileSelected.
private void testCorrectFileSelected(String filenameParam, int xmlTagsStartPosition) throws HopException {
xmlInputStreamMeta.sourceFromInput = false;
xmlInputStreamMeta.setFilename(filenameParam);
xmlInputStreamData.outputRowMeta = new RowMeta();
RowMeta rm = new RowMeta();
String pathValue = getFile("default.xml");
ValueMetaString ms = new ValueMetaString("filename");
IRowSet rs = new SingleRowRowSet();
rs.putRow(rm, new Object[] { pathValue });
rs.setDone();
XmlInputStream xmlInputStream = new XmlInputStream(transformMockHelper.transformMeta, xmlInputStreamMeta, xmlInputStreamData, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
xmlInputStream.setInputRowMeta(rm);
xmlInputStream.getInputRowMeta().addValueMeta(ms);
xmlInputStream.addRowSetToInputRowSets(rs);
xmlInputStream.setOutputRowSets(new ArrayList<>());
xmlInputStream.init();
xmlInputStream.addRowListener(rl);
boolean haveRowsToRead;
do {
haveRowsToRead = !xmlInputStream.processRow();
} while (!haveRowsToRead);
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "START_ELEMENT", rl.getWritten().get(1)[xmlTagsStartPosition]);
}
Aggregations