use of org.pentaho.commons.connection.memory.MemoryResultSet in project pentaho-platform by pentaho.
the class XQueryIT method testIterators.
public void testIterators() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet dataSet = new MemoryResultSet(metadata);
JavaScriptResultSet data = new JavaScriptResultSet();
data.setResultSet(dataSet);
data.addRow(new Object[] { "a", new Integer(1) });
data.addRow(new Object[] { "b", new Integer(2) });
data.addRow(new Object[] { "c", new Integer(3) });
assertEquals(3, data.getRowCount());
assertEquals("a", data.getValueAt(0, 0));
assertEquals(1, data.getValueAt(0, 1));
assertEquals("b", data.getValueAt(1, 0));
assertEquals(2, data.getValueAt(1, 1));
assertEquals("c", data.getValueAt(2, 0));
assertEquals(3, data.getValueAt(2, 1));
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.beforeFirst();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.close();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.closeConnection();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.dispose();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
}
use of org.pentaho.commons.connection.memory.MemoryResultSet in project pdi-platform-plugin by pentaho.
the class PdiActionTest method testTransformationInjector.
@Test
public void testTransformationInjector() throws Exception {
String[][] columnNames = { { "REGION", "DEPARTMENT", "POSITIONTITLE" } };
MemoryMetaData metadata = new MemoryMetaData(columnNames, null);
MemoryResultSet rowsIn = new MemoryResultSet(metadata);
rowsIn.addRow(new Object[] { "abc", "123", "bogus" });
rowsIn.addRow(new Object[] { "region2", "Sales", "bad" });
rowsIn.addRow(new Object[] { "Central", "Sales", "test title" });
rowsIn.addRow(new Object[] { "Central", "xyz", "bad" });
PdiAction component = new PdiAction();
component.setRepositoryName(KettleFileRepositoryMeta.REPOSITORY_TYPE_ID);
component.setDirectory(SOLUTION_REPOSITORY);
component.setTransformation("/org/pentaho/platform/plugin/kettle/PdiActionTest_testTransformationInjector.ktr");
component.setInjectorRows(rowsIn);
component.setInjectorStep("Injector");
component.setMonitorStep("Output");
component.execute();
assertEquals(1, component.getTransformationOutputRowsCount());
assertEquals(0, component.getTransformationOutputErrorRowsCount());
IPentahoResultSet rows = component.getTransformationOutputRows();
assertNotNull(rows);
assertEquals(1, rows.getRowCount());
assertEquals("Central", rows.getValueAt(0, 0));
assertEquals("Sales", rows.getValueAt(0, 1));
assertEquals("test title", rows.getValueAt(0, 2));
assertEquals("Hello, test title", rows.getValueAt(0, 3));
rows = component.getTransformationOutputErrorRows();
assertNotNull(rows);
String log = component.getLog();
assertTrue(log.contains("Injector"));
assertTrue(log.contains("R=1"));
assertTrue(log.contains("Filter rows"));
assertTrue(log.contains("W=1"));
assertTrue(log.contains("Java Script Value"));
assertTrue(log.contains("W=1"));
assertTrue(log.contains("Output"));
assertTrue(log.contains("W=4"));
}
use of org.pentaho.commons.connection.memory.MemoryResultSet in project data-access by pentaho.
the class DatasourceServiceHelper method convertToMemoryResultSet.
/**
* Convert the live result set to memory result set.
*
* @param resultSet
* @return
*/
private static IPentahoResultSet convertToMemoryResultSet(IPentahoResultSet resultSet) throws SQLException {
MemoryResultSet cachedResultSet = null;
try {
IPentahoMetaData meta = resultSet.getMetaData();
Object[][] columnHeaders = meta.getColumnHeaders();
MemoryMetaData cachedMetaData = new MemoryMetaData(columnHeaders, null);
String[] colTypesAsString;
// If the IPentahoMetaData is an instanceof SQLMetaData then get the column types from the metadata
if (meta instanceof SQLMetaData) {
SQLMetaData sqlMeta = (SQLMetaData) meta;
// Column Types in SQLMetaData are int. MemoryMetaData stores column types as string. So we will store them
// as string in MemoryMetaData
int[] colTypes = sqlMeta.getJDBCColumnTypes();
colTypesAsString = new String[colTypes.length];
for (int i = 0; i < colTypes.length; i++) {
colTypesAsString[i] = Integer.toString(colTypes[i]);
}
cachedMetaData.setColumnTypes(colTypesAsString);
}
cachedResultSet = new MemoryResultSet(cachedMetaData);
Object[] rowObjects = resultSet.next();
while (rowObjects != null) {
cachedResultSet.addRow(rowObjects);
rowObjects = resultSet.next();
}
} finally {
resultSet.close();
}
return cachedResultSet;
}
use of org.pentaho.commons.connection.memory.MemoryResultSet in project pentaho-platform by pentaho.
the class HQLResultSet method memoryCopy.
public IPentahoResultSet memoryCopy() {
try {
IPentahoMetaData localMetadata = getMetaData();
Object[][] columnHeaders = localMetadata.getColumnHeaders();
MemoryMetaData cachedMetaData = new MemoryMetaData(columnHeaders, null);
MemoryResultSet cachedResultSet = new MemoryResultSet(cachedMetaData);
Object[] rowObjects = next();
while (rowObjects != null) {
cachedResultSet.addRow(rowObjects);
rowObjects = next();
}
return cachedResultSet;
} finally {
close();
}
}
use of org.pentaho.commons.connection.memory.MemoryResultSet in project pentaho-platform by pentaho.
the class MDXResultSet method memoryCopy.
public IPentahoResultSet memoryCopy() {
try {
IPentahoMetaData metadata = getMetaData();
Object[][] columnHeaders = metadata.getColumnHeaders();
Object[][] rowHeaders = metadata.getRowHeaders();
MemoryMetaData cachedMetaData = new MemoryMetaData(columnHeaders, rowHeaders);
MemoryResultSet cachedResultSet = new MemoryResultSet(cachedMetaData);
Object[] rowObjects = next();
while (rowObjects != null) {
cachedResultSet.addRow(rowObjects);
rowObjects = next();
}
return cachedResultSet;
} finally {
close();
}
}
Aggregations