本文整理汇总了Java中org.pentaho.di.trans.step.RowAdapter类的典型用法代码示例。如果您正苦于以下问题:Java RowAdapter类的具体用法?Java RowAdapter怎么用?Java RowAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RowAdapter类属于org.pentaho.di.trans.step包,在下文中一共展示了RowAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test02_SelectFrom
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test02_SelectFrom() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT Category, Country, products_sold as nr, sales_amount as sales FROM Service";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// print the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(8, rows.size());
}
示例2: test04_SelectFromWhereGroupBy
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test04_SelectFromWhereGroupBy() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT Country, SUM(products_sold) as count, SUM(sales_amount) as sales FROM Service WHERE Category = 'A' GROUP BY Country";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// print the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(4, rows.size());
}
示例3: test05_SelectFromGroupBy
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test05_SelectFromGroupBy() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT Country, SUM(products_sold) as count, SUM(sales_amount) as sales FROM Service GROUP BY Country";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// collect the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(4, rows.size());
}
示例4: processRows
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
/**
* So as not to heap up list of taken parameters, we are passing combi, but we expect to see CsvInput class instances
* in it's content.
*/
private int processRows( StepMetaDataCombi combi ) throws Exception {
CsvInput csvInput = (CsvInput) combi.step;
CsvInputData stepData = (CsvInputData) combi.data;
CsvInputMeta stepMeta = (CsvInputMeta) combi.meta;
final int[] writtenRows = { 0 };
csvInput.addRowListener( new RowAdapter() {
@Override
public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
writtenRows[ 0 ]++;
}
} );
boolean haveRowsToRead;
do {
haveRowsToRead = !csvInput.processRow( stepMeta, stepData );
} while ( !haveRowsToRead );
csvInput.dispose( stepMeta, stepData );
return writtenRows[ 0 ];
}
示例5: test03_SelectFromWhere
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test03_SelectFromWhere() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT Category, Country, products_sold as nr, sales_amount as sales FROM Service WHERE Category = 'A'";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// print the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
// Save to temp file for checking
//
File file = new File("/tmp/gen.ktr");
FileOutputStream fos = new FileOutputStream(file);
fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
fos.close();
assertEquals(4, rows.size());
}
示例6: test07_SelectFromGroupCountDistinct
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test07_SelectFromGroupCountDistinct() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT Category, COUNT(DISTINCT Country) as \"Number of countries\" FROM Service GROUP BY Category ORDER BY COUNT(DISTINCT Country) DESC";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// collect the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(2, rows.size());
// Validate results...
//
int rowNr=0;
assertEquals("A", rows.get(rowNr).getString("Category", null));
assertEquals(4, rows.get(rowNr).getInteger("Number of countries", -1));
rowNr++;
assertEquals("B", rows.get(rowNr).getString("Category", null));
assertEquals(4, rows.get(rowNr).getInteger("Number of countries", -1));
}
示例7: test11_NotSelectedHaving
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test11_NotSelectedHaving() throws Exception {
KettleEnvironment.init();
String sqlQuery = "select \"Service\".\"Category\" as \"c0\", \"Service\".\"Country\" as \"c1\" from \"Service\" as \"Service\" where (\"Service\".\"Category\" = 'A') group by \"Service\".\"Category\", \"Service\".\"Country\" having (NOT((sum(\"Service\".\"sales_amount\") is null)) OR NOT((sum(\"Service\".\"products_sold\") is null)) ) order by CASE WHEN \"Service\".\"Category\" IS NULL THEN 1 ELSE 0 END, \"Service\".\"Category\" ASC, CASE WHEN \"Service\".\"Country\" IS NULL THEN 1 ELSE 0 END";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// collect the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Save to temp file for checking
//
File file = new File("/tmp/gen.ktr");
FileOutputStream fos = new FileOutputStream(file);
fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
fos.close();
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(4, rows.size());
}
示例8: test12_DistinctFromPMD
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test12_DistinctFromPMD() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT DISTINCT BT_SERVICE_SERVICE.Country AS COL0 FROM Service BT_SERVICE_SERVICE";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// collect the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Save to temp file for checking
//
File file = new File("/tmp/gen.ktr");
FileOutputStream fos = new FileOutputStream(file);
fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
fos.close();
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(4, rows.size());
}
示例9: test13_DistinctOrderFromPMD
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void test13_DistinctOrderFromPMD() throws Exception {
KettleEnvironment.init();
String sqlQuery = "SELECT DISTINCT BT_SERVICE_SERVICE.Category AS COL0 ,BT_SERVICE_SERVICE.Country AS COL1 FROM Service BT_SERVICE_SERVICE ORDER BY COL0";
SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());
final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
// collect the eventual result rows...
//
executor.executeQuery(new RowAdapter() { @Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
rows.add(new RowMetaAndData(rowMeta, row));
} });
// Save to temp file for checking
//
File file = new File("/tmp/gen.ktr");
FileOutputStream fos = new FileOutputStream(file);
fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
fos.close();
// Now the generated transformation is waiting for input so we
// can start the service transformation
//
executor.waitUntilFinished();
assertEquals(8, rows.size());
}
示例10: testReturnDigitsOnly
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
@Test
public void testReturnDigitsOnly() throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaString nameMeta = new ValueMetaString( "Name" );
inputRowMeta.addValueMeta( nameMeta );
ValueMetaString valueMeta = new ValueMetaString( "Value" );
inputRowMeta.addValueMeta( valueMeta );
RowSet inputRowSet = smh.getMockInputRowSet( new Object[][] { { "name1", "qwe123asd456zxc" }, { "name2", null } } );
inputRowSet.setRowMeta( inputRowMeta );
Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
calculator.getInputRowSets().add( inputRowSet );
calculator.setInputRowMeta( inputRowMeta );
calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface );
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation( new CalculatorMetaFunction[] {
new CalculatorMetaFunction( "digits", CalculatorMetaFunction.CALC_GET_ONLY_DIGITS, "Value", null, null,
ValueMetaInterface.TYPE_STRING, 0, 0, false, "", "", "", "" ) } );
// Verify output
try {
calculator.addRowListener( new RowAdapter() {
@Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
assertEquals( "123456", row[ 2 ] );
}
} );
calculator.processRow( meta, new CalculatorData() );
} catch ( KettleException ke ) {
ke.printStackTrace();
fail();
}
}
示例11: assertRound
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void assertRound( final double expectedResult, final double value ) throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaNumber valueMeta = new ValueMetaNumber( "Value" );
inputRowMeta.addValueMeta( valueMeta );
RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { value } );
inputRowSet.setRowMeta( inputRowMeta );
Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
calculator.getInputRowSets().add( inputRowSet );
calculator.setInputRowMeta( inputRowMeta );
calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface );
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test",
CalculatorMetaFunction.CALC_ROUND_1, "Value", null, null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "",
"", "" ) } );
// Verify output
try {
calculator.addRowListener( new RowAdapter() {
@Override
public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
assertEquals( expectedResult, row[1] );
}
} );
calculator.processRow( meta, new CalculatorData() );
} catch ( KettleException ke ) {
ke.printStackTrace();
fail();
}
}
示例12: assertRound2
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void assertRound2( final double expectedResult, final double value, final long precision )
throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaNumber valueMeta = new ValueMetaNumber( "Value" );
ValueMetaInteger precisionMeta = new ValueMetaInteger( "Precision" );
inputRowMeta.addValueMeta( valueMeta );
inputRowMeta.addValueMeta( precisionMeta );
RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { value, precision } );
inputRowSet.setRowMeta( inputRowMeta );
Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
calculator.getInputRowSets().add( inputRowSet );
calculator.setInputRowMeta( inputRowMeta );
calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface );
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test",
CalculatorMetaFunction.CALC_ROUND_2, "Value", "Precision", null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false,
"", "", "", "" ) } );
// Verify output
try {
calculator.addRowListener( new RowAdapter() {
@Override
public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
assertEquals( expectedResult, row[2] );
}
} );
calculator.processRow( meta, new CalculatorData() );
} catch ( KettleException ke ) {
ke.printStackTrace();
fail();
}
}
示例13: assertRoundStd
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void assertRoundStd( final double expectedResult, final double value ) throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaNumber valueMeta = new ValueMetaNumber( "Value" );
inputRowMeta.addValueMeta( valueMeta );
RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { value } );
inputRowSet.setRowMeta( inputRowMeta );
Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
calculator.getInputRowSets().add( inputRowSet );
calculator.setInputRowMeta( inputRowMeta );
calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface );
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test",
CalculatorMetaFunction.CALC_ROUND_STD_1, "Value", null, null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "",
"", "", "" ) } );
// Verify output
try {
calculator.addRowListener( new RowAdapter() {
@Override
public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
assertEquals( expectedResult, row[1] );
}
} );
calculator.processRow( meta, new CalculatorData() );
} catch ( KettleException ke ) {
ke.printStackTrace();
fail();
}
}
示例14: assertRoundStd2
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
public void assertRoundStd2( final double expectedResult, final double value, final long precision )
throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaNumber valueMeta = new ValueMetaNumber( "Value" );
ValueMetaInteger precisionMeta = new ValueMetaInteger( "Precision" );
inputRowMeta.addValueMeta( valueMeta );
inputRowMeta.addValueMeta( precisionMeta );
RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { value, precision } );
inputRowSet.setRowMeta( inputRowMeta );
Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
calculator.getInputRowSets().add( inputRowSet );
calculator.setInputRowMeta( inputRowMeta );
calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface );
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test",
CalculatorMetaFunction.CALC_ROUND_STD_2, "Value", "Precision", null, ValueMetaInterface.TYPE_NUMBER, 2, 0,
false, "", "", "", "" ) } );
// Verify output
try {
calculator.addRowListener( new RowAdapter() {
@Override
public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
assertEquals( expectedResult, row[2] );
}
} );
calculator.processRow( meta, new CalculatorData() );
} catch ( KettleException ke ) {
ke.printStackTrace();
fail();
}
}
示例15: doTest
import org.pentaho.di.trans.step.RowAdapter; //导入依赖的package包/类
private void doTest( final String fileEncoding, final String stepEncoding, final String testData,
final String delimiter ) throws Exception {
String testFilePath = createTestFile( fileEncoding, testData ).getAbsolutePath();
CsvInputMeta meta = createStepMeta( testFilePath, stepEncoding, delimiter );
CsvInputData data = new CsvInputData();
CsvInput csvInput =
new CsvInput(
stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta,
stepMockHelper.trans );
csvInput.init( meta, data );
csvInput.addRowListener( new RowAdapter() {
@Override
public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
for ( int i = 0; i < rowMeta.size(); i++ ) {
Assert.assertEquals( "Value", row[ i ] );
}
}
} );
boolean haveRowsToRead;
do {
haveRowsToRead = !csvInput.processRow( meta, data );
} while ( !haveRowsToRead );
csvInput.dispose( meta, data );
Assert.assertEquals( 2, csvInput.getLinesWritten() );
}