Search in sources :

Example 16 with MemoryResultSet

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());
}
Also used : JavaScriptResultSet(org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 17 with MemoryResultSet

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"));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet) Test(org.junit.Test)

Example 18 with MemoryResultSet

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;
}
Also used : SQLMetaData(org.pentaho.platform.plugin.services.connections.sql.SQLMetaData) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 19 with MemoryResultSet

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();
    }
}
Also used : MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 20 with MemoryResultSet

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();
    }
}
Also used : MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Aggregations

MemoryResultSet (org.pentaho.commons.connection.memory.MemoryResultSet)31 MemoryMetaData (org.pentaho.commons.connection.memory.MemoryMetaData)24 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)7 JavaScriptResultSet (org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet)7 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)2 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 Name (javax.xml.soap.Name)1 Node (javax.xml.soap.Node)1 SOAPBody (javax.xml.soap.SOAPBody)1 SOAPConnection (javax.xml.soap.SOAPConnection)1 SOAPElement (javax.xml.soap.SOAPElement)1