Search in sources :

Example 46 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class XQueryIT method testRowLimit.

public void testRowLimit() throws Exception {
    XQConnection connection = new XQConnection();
    connection.setMaxRows(2);
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    assertTrue("result set is wrong type", data instanceof XQResultSet);
    assertEquals("row count is wrong", 2, data.getRowCount());
    assertEquals("column header is wrong", "title", data.getMetaData().getColumnHeaders()[0][0]);
    assertEquals("column header is wrong", "author", data.getMetaData().getColumnHeaders()[0][1]);
    assertEquals("column header is wrong", "year", data.getMetaData().getColumnHeaders()[0][2]);
    assertEquals("column header is wrong", "price", data.getMetaData().getColumnHeaders()[0][3]);
    Object[] row = data.next();
    assertEquals("Everyday Italian", row[0]);
    assertEquals("Giada De Laurentiis", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("30.00", row[3]);
    row = data.next();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = data.next();
    assertNull(row);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XQResultSet(org.pentaho.platform.plugin.services.connections.xquery.XQResultSet)

Example 47 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class XQueryIT method testPeek.

public void testPeek() throws Exception {
    XQConnection connection = new XQConnection();
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    assertTrue("result set is wrong type", data instanceof XQResultSet);
    assertEquals("row count is wrong", 4, data.getRowCount());
    assertEquals("column header is wrong", "title", data.getMetaData().getColumnHeaders()[0][0]);
    assertEquals("column header is wrong", "author", data.getMetaData().getColumnHeaders()[0][1]);
    assertEquals("column header is wrong", "year", data.getMetaData().getColumnHeaders()[0][2]);
    assertEquals("column header is wrong", "price", data.getMetaData().getColumnHeaders()[0][3]);
    assertTrue("result set is not peekable", data instanceof IPeekable);
    IPeekable peekable = (IPeekable) data;
    Object[] row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    assertEquals("Giada De Laurentiis", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("30.00", row[3]);
    row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    row = data.next();
    assertEquals("Everyday Italian", row[0]);
    assertEquals("Giada De Laurentiis", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("30.00", row[3]);
    row = peekable.peek();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = peekable.peek();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = data.next();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = peekable.peek();
    assertNotNull(row);
    row = data.next();
    assertNotNull(row);
    row = peekable.peek();
    assertNotNull(row);
    row = data.next();
    assertNotNull(row);
    row = peekable.peek();
    assertNull(row);
    row = data.next();
    assertNull(row);
    row = peekable.peek();
    assertNull(row);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XQResultSet(org.pentaho.platform.plugin.services.connections.xquery.XQResultSet) IPeekable(org.pentaho.commons.connection.IPeekable)

Example 48 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class XQueryIT method testValueAt.

public void testValueAt() throws Exception {
    XQConnection connection = new XQConnection();
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    assertEquals("2005", data.getValueAt(0, 2));
    assertEquals("Everyday Italian", data.getValueAt(0, 0));
    assertEquals("J K. Rowling", data.getValueAt(1, 1));
    assertEquals("29.99", data.getValueAt(1, 3));
    assertNull(data.getValueAt(-1, -1));
    assertNull(data.getValueAt(99, 0));
    assertNull(data.getValueAt(0, 99));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection)

Example 49 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet 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 50 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project data-access by pentaho.

the class DatasourceInMemoryServiceHelper method getSerializeableResultSet.

public static SerializedResultSet getSerializeableResultSet(String connectionName, String query, int rowLimit, IPentahoSession session) throws DatasourceServiceException {
    SerializedResultSet serializedResultSet = null;
    SQLConnection sqlConnection = null;
    try {
        sqlConnection = getConnection(connectionName);
        sqlConnection.setMaxRows(rowLimit);
        sqlConnection.setReadOnly(true);
        IPentahoResultSet resultSet = sqlConnection.executeQuery(query);
        MarshallableResultSet marshallableResultSet = new MarshallableResultSet();
        marshallableResultSet.setResultSet(resultSet);
        IPentahoMetaData ipmd = resultSet.getMetaData();
        if (ipmd instanceof SQLMetaData) {
            // Hack warning - get JDBC column types
            // TODO: Need to generalize this amongst all IPentahoResultSets
            SQLMetaData smd = (SQLMetaData) ipmd;
            int[] columnTypes = smd.getJDBCColumnTypes();
            List<List<String>> data = new ArrayList<List<String>>();
            for (MarshallableRow row : marshallableResultSet.getRows()) {
                String[] rowData = row.getCell();
                List<String> rowDataList = new ArrayList<String>(rowData.length);
                for (int j = 0; j < rowData.length; j++) {
                    rowDataList.add(rowData[j]);
                }
                data.add(rowDataList);
            }
            serializedResultSet = new SerializedResultSet(columnTypes, marshallableResultSet.getColumnNames().getColumnName(), data);
        }
    } catch (Exception e) {
        logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } finally {
        if (sqlConnection != null) {
            sqlConnection.close();
        }
    }
    return serializedResultSet;
}
Also used : MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) ArrayList(java.util.ArrayList) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) SQLException(java.sql.SQLException) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLMetaData(org.pentaho.platform.plugin.services.connections.sql.SQLMetaData) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MarshallableRow(org.pentaho.commons.connection.marshal.MarshallableRow) ArrayList(java.util.ArrayList) List(java.util.List) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)113 Test (org.junit.Test)26 Node (org.dom4j.Node)18 ArrayList (java.util.ArrayList)17 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)12 Iterator (java.util.Iterator)10 List (java.util.List)10 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)10 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 OutputStream (java.io.OutputStream)9 ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)8 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)8 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)8 SQLException (java.sql.SQLException)7 HashMap (java.util.HashMap)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 Map (java.util.Map)5 Set (java.util.Set)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5