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);
}
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);
}
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));
}
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"));
}
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;
}
Aggregations