Java Code Examples for org.pentaho.di.trans.step.StepMeta#setDescription()

The following examples show how to use org.pentaho.di.trans.step.StepMeta#setDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeSteps_should_not_sync_unshared() throws Exception {
  final String stepName = "Step";
  TransMeta transformarion1 = createTransMeta();
  StepMeta step1 = createStepMeta( stepName, true );
  transformarion1.addStep( step1 );
  spoonDelegates.trans.addTransformation( transformarion1 );

  TransMeta transformarion2 = createTransMeta();
  StepMeta step2 = createStepMeta( stepName, false );
  transformarion2.addStep( step2 );
  spoonDelegates.trans.addTransformation( transformarion2 );

  step2.setDescription( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeSteps( step2 );
  assertThat( step1.getDescription(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 2
Source File: SpoonJobDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private StepMeta getToStep( DatabaseMeta targetDbInfo, String table ) {
  String tostepname = BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.ToStep.Name" ) + table + "]";
  TableOutputMeta toi = new TableOutputMeta();
  toi.setDatabaseMeta( targetDbInfo );
  toi.setTableName( table );
  toi.setCommitSize( 100 );
  toi.setTruncateTable( true );

  String tostepid = PluginRegistry.getInstance().getPluginId( StepPluginType.class, toi );
  StepMeta tostep = new StepMeta( tostepid, tostepname, toi );
  tostep.setLocation( 500, 100 );
  tostep.setDraw( true );
  tostep
    .setDescription( BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.ToStep.Description1" )
      + table + BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.ToStep.Description2" )
      + targetDbInfo + "]" );
  return tostep;
}
 
Example 3
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeSteps_sync_shared_only() throws Exception {
  final String stepName = "Step";
  TransMeta transformarion1 = createTransMeta();
  StepMeta step1 = createStepMeta( stepName, true );
  transformarion1.addStep( step1 );
  spoonDelegates.trans.addTransformation( transformarion1 );

  TransMeta transformarion2 = createTransMeta();
  StepMeta unsharedStep2 = createStepMeta( stepName, false );
  transformarion2.addStep( unsharedStep2 );
  spoonDelegates.trans.addTransformation( transformarion2 );

  TransMeta transformarion3 = createTransMeta();
  StepMeta step3 = createStepMeta( stepName, true );
  transformarion3.addStep( step3 );
  spoonDelegates.trans.addTransformation( transformarion3 );

  step3.setDescription( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeSteps( step3 );
  assertThat( step1.getDescription(), equalTo( AFTER_SYNC_VALUE ) );
  assertThat( unsharedStep2.getDescription(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 4
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeSteps_use_case_sensitive_name() throws Exception {
  TransMeta transformarion1 = createTransMeta();
  StepMeta step1 = createStepMeta( "STEP", true );
  transformarion1.addStep( step1 );
  spoonDelegates.trans.addTransformation( transformarion1 );

  TransMeta transformarion2 = createTransMeta();
  StepMeta step2 = createStepMeta( "Step", true );
  transformarion2.addStep( step2 );
  spoonDelegates.trans.addTransformation( transformarion2 );

  step2.setDescription( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeSteps( step2 );
  assertThat( step1.getDescription(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 5
Source File: SpoonJobDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private StepMeta getFromStep( DatabaseMeta sourceDbInfo, String[] tables, int i, TableInputMeta tii ) {
  String fromstepname =
    BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.FromStep.Name" ) + tables[i] + "]";


  String fromstepid = PluginRegistry.getInstance().getPluginId( StepPluginType.class, tii );
  StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii );
  fromstep.setLocation( 150, 100 );
  fromstep.setDraw( true );
  fromstep
    .setDescription( BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.FromStep.Description" )
      + tables[i] + BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.FromStep.Description2" )
      + sourceDbInfo + "]" );
  return fromstep;
}
 
Example 6
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private StepMeta generateTableInputStepFromLogicalTable(LogicalTable logicalTable) {

    String name = ConceptUtil.getName(logicalTable, locale);
    String description = ConceptUtil.getDescription(logicalTable, locale);

    TableInputMeta meta = new TableInputMeta();

    // Source database, retain first
    // Source table, retain first
    // Source columns, retain all
    //
    DatabaseMeta sourceDatabaseMeta = null;
    String sourceTable = null;
    List<String> sourceColumns = new ArrayList<String>();
    for (LogicalColumn column : logicalTable.getLogicalColumns()) {
      String phDb = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_DB);
      String phTable = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE);
      String phCol = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN);
      if (!Utils.isEmpty(phDb) && sourceDatabaseMeta==null) {
        sourceDatabaseMeta = DatabaseMeta.findDatabase(databases, phDb);
      }
      if (!Utils.isEmpty(phTable)) {
        sourceTable = phDb;
      }
      if (!Utils.isEmpty(phCol)) {
        sourceColumns.add(phCol);
      }
    }
    String sql = "SELECT * FROM --< Source query for dimension '"+name+"'";

    meta.setDatabaseMeta(sourceDatabaseMeta);

    if (sourceDatabaseMeta!=null && !Utils.isEmpty(sourceTable)) {
      sql = "SELECT ";
      if (sourceColumns.isEmpty()) {
        sql+=" * ";
      } else {
        sql+=Const.CR;
      }
      boolean first=true;
      for (String sourceColumn : sourceColumns) {
        if (first) {
          first=false;
        } else {
          sql+="      , ";
        }
        sql+=sourceDatabaseMeta.quoteField(sourceColumn)+Const.CR;
      }
      sql+="FROM "+sourceDatabaseMeta.getQuotedSchemaTableCombination(null, sourceTable);
    }
    meta.setSQL(sql);

    // Wrap it up...
    //
    StepMeta stepMeta = new StepMeta("Source data for '"+name+"'", meta);
    stepMeta.drawStep();
    stepMeta.setDescription("Reads data for '"+name+"' : "+description);

    return stepMeta;
  }
 
Example 7
Source File: ExecSQLRowIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Basic Test case for Exec SQL Row. This tests a commit size of zero (i.e. autocommit)
 */
@Test
public void testExecSQLRow1() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );
  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the Exec SQL Row step...
  //
  String stepName = "delete from [" + execsqlrow_testtable + "]";
  ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
  execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  execsqlmeta.setCommitSize( 0 ); // use Autocommit
  execsqlmeta.setSqlFieldName( "SQL" );

  String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta );
  StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta );
  execSqlRowStep.setDescription( "Deletes information from table ["
    + execsqlrow_testtable + "] on database [" + dbInfo + "]" );
  transMeta.addStep( execSqlRowStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( stepName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );
}
 
Example 8
Source File: TransMetaTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetCacheVersionWithIrrelevantParameters() throws Exception {
  TransMeta transMeta = new TransMeta( getClass().getResource( "one-step-trans.ktr" ).getPath() );
  int oldCacheVersion = transMeta.getCacheVersion();
  int currCacheVersion;

  transMeta.setSizeRowset( 1000 );
  currCacheVersion = transMeta.getCacheVersion();
  assertNotEquals( oldCacheVersion, currCacheVersion );

  oldCacheVersion = currCacheVersion;

  // scenarios that should not impact the cache version

  // transformation description
  transMeta.setDescription( "transformation description" );

  // transformation status
  transMeta.setTransstatus( 100 );

  // transformation log table
  transMeta.setTransLogTable( mock( TransLogTable.class ) );

  // transformation created user
  transMeta.setCreatedUser( "user" );

  // transformation modified user
  transMeta.setModifiedUser( "user" );

  // transformation created date
  transMeta.setCreatedDate( new Date() );

  // transformation modified date
  transMeta.setModifiedDate( new Date() );

  // transformation is key private flag
  transMeta.setPrivateKey( false );

  // transformation attributes
  Map<String, String> attributes = new HashMap<>();
  attributes.put( "key", "value" );
  transMeta.setAttributes( "group", attributes );

  // step description
  StepMeta stepMeta = transMeta.getStep( 0 );
  stepMeta.setDescription( "stepDescription" );

  // step position
  stepMeta.setLocation( 10, 20 );
  stepMeta.setLocation( new Point( 30, 40 ) );

  // step type id
  stepMeta.setStepID( "Dummy" );

  // step is distributed flag
  stepMeta.setDistributes( false );

  // step copies
  stepMeta.setCopies( 5 );

  // step partitioning meta
  stepMeta.setStepPartitioningMeta( mock( StepPartitioningMeta.class ) );

  // assert that nothing impacted the cache version
  assertEquals( oldCacheVersion, transMeta.getCacheVersion() );
}
 
Example 9
Source File: KettleDatabaseRepositoryStepDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new step by loading the metadata from the specified repository.
 *
 * @param rep
 * @param stepId
 * @param databases
 * @param counters
 * @param partitionSchemas
 * @throws KettleException
 */
public StepMeta loadStepMeta( ObjectId stepId, List<DatabaseMeta> databases,
  List<PartitionSchema> partitionSchemas ) throws KettleException {
  StepMeta stepMeta = new StepMeta();
  PluginRegistry registry = PluginRegistry.getInstance();

  try {
    RowMetaAndData r = getStep( stepId );
    if ( r != null ) {
      stepMeta.setObjectId( stepId );

      stepMeta.setName( r.getString( KettleDatabaseRepository.FIELD_STEP_NAME, null ) );
      stepMeta.setDescription( r.getString( KettleDatabaseRepository.FIELD_STEP_DESCRIPTION, null ) );

      long id_step_type = r.getInteger( KettleDatabaseRepository.FIELD_STEP_ID_STEP_TYPE, -1L );
      RowMetaAndData steptyperow = getStepType( new LongObjectId( id_step_type ) );

      stepMeta.setStepID( steptyperow.getString( KettleDatabaseRepository.FIELD_STEP_TYPE_CODE, null ) );
      stepMeta.setDistributes( r.getBoolean( KettleDatabaseRepository.FIELD_STEP_DISTRIBUTE, true ) );
      int copies = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_COPIES, 1 );
      String copiesString = r.getString( KettleDatabaseRepository.FIELD_STEP_COPIES_STRING, null );
      if ( !Utils.isEmpty( copiesString ) ) {
        stepMeta.setCopiesString( copiesString );
      } else {
        stepMeta.setCopies( copies );
      }

      int x = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_X, 0 );
      int y = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_Y, 0 );
      stepMeta.setLocation( new Point( x, y ) );
      stepMeta.setDraw( r.getBoolean( KettleDatabaseRepository.FIELD_STEP_GUI_DRAW, false ) );

      // Generate the appropriate class...
      PluginInterface sp = registry.findPluginWithId( StepPluginType.class, stepMeta.getStepID() );
      if ( sp == null ) {
        stepMeta.setStepMetaInterface( new MissingTrans( stepMeta.getName(), stepMeta.getStepID() ) );
      } else {
        stepMeta.setStepMetaInterface( (StepMetaInterface) registry.loadClass( sp ) );
      }
      if ( stepMeta.getStepMetaInterface() != null ) {
        // Read the step info from the repository!
        readRepCompatibleStepMeta(
          stepMeta.getStepMetaInterface(), repository, stepMeta.getObjectId(), databases );
        stepMeta.getStepMetaInterface().readRep(
          repository, repository.metaStore, stepMeta.getObjectId(), databases );
      }

      // Get the partitioning as well...
      //
      stepMeta.setStepPartitioningMeta( loadStepPartitioningMeta( stepMeta.getObjectId() ) );
      stepMeta.getStepPartitioningMeta().setPartitionSchemaAfterLoading( partitionSchemas );

      // Get the cluster schema name
      //
      stepMeta.setClusterSchemaName( repository.getStepAttributeString( stepId, "cluster_schema" ) );

      // Are we using a custom row distribution plugin?
      //
      String rowDistributionCode = repository.getStepAttributeString( stepId, 0, "row_distribution_code" );
      RowDistributionInterface rowDistribution =
        PluginRegistry.getInstance().loadClass(
          RowDistributionPluginType.class, rowDistributionCode, RowDistributionInterface.class );
      stepMeta.setRowDistribution( rowDistribution );

      // Load the attribute groups map
      //
      stepMeta.setAttributesMap( loadStepAttributesMap( stepId ) );

      // Done!
      //
      return stepMeta;
    } else {
      throw new KettleException( BaseMessages.getString(
        PKG, "StepMeta.Exception.StepInfoCouldNotBeFound", String.valueOf( stepId ) ) );
    }
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException( BaseMessages.getString( PKG, "StepMeta.Exception.StepCouldNotBeLoaded", String
      .valueOf( stepMeta.getObjectId() ) ), dbe );
  }
}
 
Example 10
Source File: TableInputIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for table input which is taking its input from a hop. This is a regression test case for JIRA PDI-588.
 *
 * The query in the table input step has one '?' and this parameter is filled by values read from an input hop.
 */
public void testTableInputWithParam() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );

  // Execute our setup SQLs in the database.
  Database database = new Database( transMeta, dbInfo );
  database.connect();
  createTables( database );
  createData( database );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the source step...
  //
  String fromstepname = "read from [" + source_table + "]";
  TableInputMeta tii = new TableInputMeta();
  tii.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  tii.setLookupFromStep( injectorStep );
  tii.setExecuteEachInputRow( true );
  String selectSQL = "SELECT " + Const.CR;
  selectSQL += "ID, CODE ";
  selectSQL += "FROM " + source_table + " WHERE CODE = ? ORDER BY ID, CODE;";
  tii.setSQL( selectSQL );

  String fromstepid = registry.getPluginId( StepPluginType.class, tii );
  StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii );
  fromstep.setDescription( "Reads information from table [" + source_table + "] on database [" + dbInfo + "]" );
  transMeta.addStep( fromstep );

  TransHopMeta hi = new TransHopMeta( injectorStep, fromstep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( fromstepname, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );

}
 
Example 11
Source File: UpdateIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {

  KettleEnvironment.init();

  /* SET UP TRANSFORMATION */

  // Create a new transformation...
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "update test" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );

  /* SET UP DATABASE */
  // Create target table
  db = new Database( transMeta, dbInfo );
  db.connect();

  String source = db.getCreateTableStatement( TARGET_TABLE, getTargetTableRowMeta(), null, false, null, true );
  db.execStatement( source );

  // populate target table
  for ( String sql : insertStatement ) {
    db.execStatement( sql );
  }

  /* SET UP TRANSFORMATION STEPS */

  PluginRegistry registry = PluginRegistry.getInstance();

  // create an injector step...
  String injectorStepName = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.
  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepName, im );
  transMeta.addStep( injectorStep );

  // create the update step...
  String updateStepName = "update [" + TARGET_TABLE + "]";
  upd = new UpdateMeta();
  upd.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  upd.setTableName( TARGET_TABLE );
  upd.setUpdateLookup( new String[] { "VALUE" } );
  upd.setUpdateStream( new String[] { "VALUE" } );
  upd.setErrorIgnored( true );

  String fromid = registry.getPluginId( StepPluginType.class, upd );
  StepMeta updateStep = new StepMeta( fromid, updateStepName, upd );
  updateStep.setDescription( "update data in table [" + TARGET_TABLE + "] on database [" + dbInfo + "]" );
  transMeta.addStep( updateStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, updateStep );
  transMeta.addTransHop( hi );

  /* PREPARE TRANSFORMATION EXECUTION */

  trans = new Trans( transMeta );
  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( updateStepName, 0 );
  rc = new RowStepCollector();
  si.addRowListener( rc );

  rp = trans.addRowProducer( injectorStepName, 0 );

}
 
Example 12
Source File: TableOutputIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for normal table output where the table is included in the instream, but the tablename is not stored in
 * the table.
 */
public void testTableOutputJIRA897() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "table output JIRA897 test" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );

  // Execute our setup SQLs in the database.
  Database database = new Database( transMeta, dbInfo );
  database.connect();
  createTable( database, target_table1, createSourceRowMetaInterface1() );
  createTable( database, target_table2, createSourceRowMetaInterface1() );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.
  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the source step...
  //
  String outputname = "output to [" + target_table1 + "] and [" + target_table2 + "]";
  TableOutputMeta tom = new TableOutputMeta();
  tom.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  tom.setTableNameInField( true );
  tom.setTableNameField( "TABLE" );
  tom.setTableNameInTable( false );

  String fromid = registry.getPluginId( StepPluginType.class, tom );
  StepMeta fromstep = new StepMeta( fromid, outputname, tom );
  fromstep.setDescription( "write data to tables on database [" + dbInfo + "]" );
  transMeta.addStep( fromstep );

  TransHopMeta hi = new TransHopMeta( injectorStep, fromstep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( outputname, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createJIRA897DataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();

  // The name of the table should still be in here.
  List<RowMetaAndData> goldRows = createJIRA897DataRows();
  checkRows( goldRows, resultRows );
  checkResultsJIRA897( database );
}
 
Example 13
Source File: DatabaseLookupIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test "Load All Rows" version of BasicDatabaseLookup test with Like predicate.
 */
@Test
public void CacheAndLoadAllRowsDatabaseLookupWithLikePredicate() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the lookup step...
  //
  String lookupName = "look up from [" + lookup_table + "] by 'LIKE'";
  DatabaseLookupMeta dbl = new DatabaseLookupMeta();
  dbl.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  dbl.setTablename( lookup_table );
  dbl.setCached( true );
  dbl.setLoadingAllDataInCache( true );
  dbl.setEatingRowOnLookupFailure( false );
  dbl.setFailingOnMultipleResults( false );
  dbl.setOrderByClause( "" );

  dbl.setTableKeyField( new String[] { "STRING" } );
  dbl.setKeyCondition( new String[] { "LIKE" } );
  dbl.setStreamKeyField1( new String[] { "str_field" } );
  dbl.setStreamKeyField2( new String[] { "" } );

  dbl.setReturnValueField( new String[] { "CODE", "STRING" } );
  dbl.setReturnValueDefaultType( new int[] { ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_STRING } );
  dbl.setReturnValueDefault( new String[] { "-1", "UNDEF" } );
  dbl.setReturnValueNewName( new String[] { "RET_CODE", "RET_STRING" } );

  String lookupId = registry.getPluginId( StepPluginType.class, dbl );
  StepMeta lookupStep = new StepMeta( lookupId, lookupName, dbl );
  lookupStep.setDescription( "Reads information from table ["
      + lookup_table + "] on database ["
      + dbInfo + "] using LIKE condition" );
  transMeta.addStep( lookupStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, lookupStep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( lookupName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );

}
 
Example 14
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected StepMeta generateCombinationLookupStepFromLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
  String name = ConceptUtil.getName(logicalTable, locale);
  String description = ConceptUtil.getDescription(logicalTable, locale);
  String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
  String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, Const.NVL(phTable, name));

  CombinationLookupMeta meta = new CombinationLookupMeta();
  meta.setDatabaseMeta(databaseMeta);
  meta.setSchemaName(null); // TODO
  meta.setTablename(schemaTable);
  meta.setUseAutoinc(databaseMeta.supportsAutoinc());
  meta.setCacheSize(5000);
  meta.setCommitSize(500);
  meta.setReplaceFields(true); // replace attribute fields with a TK

  // Find the technical key (if any defined)
  //
  LogicalColumn keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
  if (keyColumn!=null) {
    ValueMetaInterface keyValue = getValueForLogicalColumn(databaseMeta, keyColumn);
    meta.setTechnicalKeyField(keyValue.getName());
  }

  // Simply add all the attributes as key columns...
  //
  List<LogicalColumn> attributes = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.ATTRIBUTE);
  meta.setKeyLookup(new String[attributes.size()]);
  meta.setKeyField(new String[attributes.size()]);
  for (int i=0;i<attributes.size();i++) {
    LogicalColumn logicalColumn = attributes.get(i);
    ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
    meta.getKeyLookup()[i] = valueMeta.getName();
    meta.getKeyField()[i] = valueMeta.getName();
  }

  StepMeta stepMeta = new StepMeta(name, meta);
  stepMeta.drawStep();
  stepMeta.setDescription(description);

  return stepMeta;
}
 
Example 15
Source File: DatabaseLookupIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Basic Test case for database lookup.
 */
@Test
public void basicDatabaseLookup() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );
  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the lookup step...
  //
  String lookupName = "look up from [" + lookup_table + "]";
  DatabaseLookupMeta dbl = new DatabaseLookupMeta();
  dbl.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  dbl.setTablename( lookup_table );
  dbl.setCached( false );
  dbl.setEatingRowOnLookupFailure( false );
  dbl.setFailingOnMultipleResults( false );
  dbl.setOrderByClause( "" );

  dbl.setTableKeyField( new String[] { "ID" } );
  dbl.setKeyCondition( new String[] { "=" } );
  dbl.setStreamKeyField1( new String[] { "int_field" } );
  dbl.setStreamKeyField2( new String[] { "" } );

  dbl.setReturnValueField( new String[] { "CODE", "STRING" } );
  dbl.setReturnValueDefaultType( new int[] { ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_STRING } );
  dbl.setReturnValueDefault( new String[] { "-1", "UNDEF" } );
  dbl.setReturnValueNewName( new String[] { "RET_CODE", "RET_STRING" } );

  String lookupId = registry.getPluginId( StepPluginType.class, dbl );
  StepMeta lookupStep = new StepMeta( lookupId, lookupName, dbl );
  lookupStep.setDescription( "Reads information from table [" + lookup_table + "] on database [" + dbInfo + "]" );
  transMeta.addStep( lookupStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, lookupStep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( lookupName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );

}
 
Example 16
Source File: CombinationLookupIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for Combination lookup/update.
 */
public void testCombinationLookup() throws Exception {
  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta lookupDBInfo = transMeta.findDatabase( "lookup" );

  // Execute our setup SQLs in the database.
  Database lookupDatabase = new Database( transMeta, lookupDBInfo );
  lookupDatabase.connect();
  createTables( lookupDatabase );
  createData( lookupDatabase );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create the source step...
  //
  String fromstepname = "read from [" + source_table + "]";
  TableInputMeta tii = new TableInputMeta();
  tii.setDatabaseMeta( transMeta.findDatabase( "lookup" ) );
  String selectSQL = "SELECT " + Const.CR;
  selectSQL += "DLR_CD, DLR_NM, DLR_DESC ";
  selectSQL += "FROM " + source_table + " ORDER BY ORDNO;";
  tii.setSQL( selectSQL );

  String fromstepid = registry.getPluginId( StepPluginType.class, tii );
  StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii );
  fromstep.setLocation( 150, 100 );
  fromstep.setDraw( true );
  fromstep.setDescription( "Reads information from table ["
    + source_table + "] on database [" + lookupDBInfo + "]" );
  transMeta.addStep( fromstep );

  //
  // create the combination lookup/update step...
  //
  String lookupstepname = "lookup from [lookup]";
  CombinationLookupMeta clm = new CombinationLookupMeta();
  String[] lookupKey = { "DLR_CD" };
  clm.setTablename( target_table );
  clm.setKeyField( lookupKey );
  clm.setKeyLookup( lookupKey );
  clm.setTechnicalKeyField( "ID" );
  clm.setTechKeyCreation( CombinationLookupMeta.CREATION_METHOD_TABLEMAX );
  clm.setDatabaseMeta( lookupDBInfo );

  String lookupstepid = registry.getPluginId( StepPluginType.class, clm );
  StepMeta lookupstep = new StepMeta( lookupstepid, lookupstepname, clm );
  lookupstep.setDescription( "Looks up information from table [lookup] on database [" + lookupDBInfo + "]" );
  transMeta.addStep( lookupstep );

  TransHopMeta hi = new TransHopMeta( fromstep, lookupstep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );
  trans.execute( null );

  trans.waitUntilFinished();

  checkResults( lookupDatabase );
}
 
Example 17
Source File: InsertUpdateIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {

  KettleEnvironment.init();

  /* SET UP TRANSFORMATION */

  // Create a new transformation...
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "insert/update test" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );

  /* SET UP DATABASE */
  // Create target table
  db = new Database( transMeta, dbInfo );
  db.connect();

  String source = db.getCreateTableStatement( TARGET_TABLE, getTargetTableRowMeta(), null, false, null, true );
  db.execStatement( source );

  // populate target table
  for ( String sql : insertStatement ) {
    db.execStatement( sql );
  }

  /* SET UP TRANSFORMATION STEPS */

  PluginRegistry registry = PluginRegistry.getInstance();

  // create an injector step...
  String injectorStepName = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.
  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepName, im );
  transMeta.addStep( injectorStep );

  // create the update step...
  String updateStepName = "insert/update [" + TARGET_TABLE + "]";
  insupd = new InsertUpdateMeta();
  insupd.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  insupd.setTableName( TARGET_TABLE );

  insupd.setUpdateLookup( new String[] { "VALUE", "ROW_ORDER" } );
  insupd.setUpdateStream( new String[] { "VALUE", "ROW_ORDER" } );
  insupd.setUpdate( new Boolean[] { true, false } );

  String fromid = registry.getPluginId( StepPluginType.class, insupd );
  StepMeta updateStep = new StepMeta( fromid, updateStepName, insupd );
  updateStep.setDescription( "insert/update data in table [" + TARGET_TABLE + "] on database [" + dbInfo + "]" );
  transMeta.addStep( updateStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, updateStep );
  transMeta.addTransHop( hi );

  /* PREPARE TRANSFORMATION EXECUTION */

  trans = new Trans( transMeta );
  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( updateStepName, 0 );
  rc = new RowStepCollector();
  si.addRowListener( rc );

  rp = trans.addRowProducer( injectorStepName, 0 );

}
 
Example 18
Source File: ExecSQLRowIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Basic Test case for Exec SQL Row. This tests a commit size of three (i.e. not autocommit but equal to input row
 * size)
 */
@Test
public void testExecSQLRow4() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );
  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the Exec SQL Row step...
  //
  String stepName = "delete from [" + execsqlrow_testtable + "]";
  ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
  execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  execsqlmeta.setCommitSize( 3 );
  execsqlmeta.setSqlFieldName( "SQL" );

  String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta );
  StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta );
  execSqlRowStep.setDescription( "Deletes information from table ["
    + execsqlrow_testtable + "] on database [" + dbInfo + "]" );
  transMeta.addStep( execSqlRowStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( stepName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );
}
 
Example 19
Source File: ExecSQLRowIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Basic Test case for Exec SQL Row. This tests a commit size of two (i.e. not autocommit and not the input row size)
 */
@Test
public void testExecSQLRow3() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );
  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the Exec SQL Row step...
  //
  String stepName = "delete from [" + execsqlrow_testtable + "]";
  ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
  execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  execsqlmeta.setCommitSize( 2 );
  execsqlmeta.setSqlFieldName( "SQL" );

  String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta );
  StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta );
  execSqlRowStep.setDescription( "Deletes information from table ["
    + execsqlrow_testtable + "] on database [" + dbInfo + "]" );
  transMeta.addStep( execSqlRowStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( stepName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );
}
 
Example 20
Source File: ExecSQLRowIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Basic Test case for Exec SQL Row. This tests a commit size of one (i.e. "simulated" autocommit)
 */
@Test
public void testExecSQLRow2() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );
  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the Exec SQL Row step...
  //
  String stepName = "delete from [" + execsqlrow_testtable + "]";
  ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
  execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  execsqlmeta.setCommitSize( 1 );
  execsqlmeta.setSqlFieldName( "SQL" );

  String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta );
  StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta );
  execSqlRowStep.setDescription( "Deletes information from table ["
    + execsqlrow_testtable + "] on database [" + dbInfo + "]" );
  transMeta.addStep( execSqlRowStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( stepName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );
}