Java Code Examples for org.pentaho.di.trans.Trans#getSteps()

The following examples show how to use org.pentaho.di.trans.Trans#getSteps() . 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: TransPreviewDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void transFinished( Trans trans ) throws KettleException {
  // Copy over the data from the previewDelegate...
  //
  if ( trans.getErrors() != 0 ) {
    // capture logging and store it...
    //
    for ( StepMetaDataCombi combi : trans.getSteps() ) {
      if ( combi.copy == 0 ) {
        StringBuffer logBuffer =
          KettleLogStore.getAppender().getBuffer( combi.step.getLogChannel().getLogChannelId(), false );
        previewLogMap.put( combi.stepMeta, logBuffer );
      }
    }
  }
}
 
Example 2
Source File: RunBeamTransExecutionPoint.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
private StepMetaDataCombi findCombi( Trans trans, String metricsName ) {
  for ( StepMetaDataCombi combi : trans.getSteps() ) {
    if ( combi.stepname.equals( metricsName ) ) {
      return combi;
    }
  }
  return null;
}
 
Example 3
Source File: StepBatchTransform.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
private StepMetaDataCombi findCombi( Trans trans, String stepname ) {
  for ( StepMetaDataCombi combi : trans.getSteps() ) {
    if ( combi.stepname.equals( stepname ) ) {
      return combi;
    }
  }
  throw new RuntimeException( "Configuration error, step '" + stepname + "' not found in transformation" );
}
 
Example 4
Source File: StepTransform.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
private StepMetaDataCombi findCombi( Trans trans, String stepname ) {
  for ( StepMetaDataCombi combi : trans.getSteps() ) {
    if ( combi.stepname.equals( stepname ) ) {
      return combi;
    }
  }
  throw new RuntimeException( "Configuration error, step '" + stepname + "' not found in transformation" );
}
 
Example 5
Source File: AbstractKettleTransformationProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private StepInterface findTargetStep( final Trans trans ) throws ReportDataFactoryException {
  final String stepName = getStepName();
  for ( final StepMetaDataCombi metaDataCombi : trans.getSteps() ) {
    if ( stepName.equals( metaDataCombi.stepname ) ) {
      return metaDataCombi.step;
    }
  }
  throw new ReportDataFactoryException( "Cannot find the specified transformation step " + stepName );
}
 
Example 6
Source File: InlineEtlQueryExecutor.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean registerAsStepListener( Trans trans, Query query, Map fieldMap ) throws Exception {
  boolean success = false;
  if ( trans != null ) {
    List<StepMetaDataCombi> stepList = trans.getSteps();
    // assume the last step
    for ( StepMetaDataCombi step : stepList ) {
      if ( !"Unique rows".equals( step.stepname ) ) { //$NON-NLS-1$
        continue;
      }
      if ( logger.isDebugEnabled() ) {
        logger.debug( "STEP NAME: " + step.stepname ); //$NON-NLS-1$
      }
      RowMetaInterface row = trans.getTransMeta().getStepFields( step.stepMeta ); // step.stepname?
      // create the metadata that the Pentaho result sets need
      String[] fieldNames = row.getFieldNames();

      String[][] columns = new String[1][fieldNames.length];
      for ( int column = 0; column < fieldNames.length; column++ ) {
        columns[0][column] = fieldNames[column];
      }

      // build valid metadata
      QueryModelMetaData metadata = new QueryModelMetaData( fieldMap, columns, null, query.getSelections() );

      results = new MemoryResultSet( metadata );
      errorResults = new MemoryResultSet( metadata );

      // add ourself as a row listener
      step.step.addRowListener( this );
      success = true;
    }
  }
  return success;
}
 
Example 7
Source File: InjectDataSetIntoTransExtensionPoint.java    From pentaho-pdi-dataset with Apache License 2.0 4 votes vote down vote up
private void injectDataSetIntoStep( final Trans trans, final String dataSetName,
                                    final MetaStoreFactory<DataSet> dataSetFactory, final StepMeta stepMeta,
                                    TransUnitTestSetLocation inputLocation ) throws MetaStoreException, KettleException {

  final DataSet dataSet = dataSetFactory.loadElement( dataSetName );
  final LogChannelInterface log = trans.getLogChannel();

  final RowProducer rowProducer = trans.addRowProducer( stepMeta.getName(), 0 );

  // Look for the step into which we'll inject rows...
  //
  StepMetaDataCombi combi = null;
  for ( StepMetaDataCombi step : trans.getSteps() ) {
    if ( step.stepname.equals( stepMeta.getName() ) ) {
      combi = step;
      break;
    }
  }

  if ( combi != null ) {

    // Get the rows of the mapped values in the mapped order sorted as asked
    //
    final List<Object[]> dataSetRows = dataSet.getAllRows( log, inputLocation );
    RowMetaInterface dataSetRowMeta = dataSet.getMappedDataSetFieldsRowMeta( inputLocation );

    // The rows to inject are always driven by the dataset, NOT the step it replaces (!) for simplicity
    //
    RowMetaInterface injectRowMeta = new RowMeta();

    // Figure out which fields to pass
    // Only inject those mentioned in the field mappings...
    //
    int[] fieldIndexes = new int[ inputLocation.getFieldMappings().size() ];
    for ( int i = 0; i < inputLocation.getFieldMappings().size(); i++ ) {
      TransUnitTestFieldMapping fieldMapping = inputLocation.getFieldMappings().get( i );
      fieldIndexes[ i ] = dataSetRowMeta.indexOfValue( fieldMapping.getDataSetFieldName() );
      if ( fieldIndexes[ i ] < 0 ) {
        throw new KettleException( "Unable to find mapped field '" + fieldMapping.getDataSetFieldName() + "' in data set '" + dataSet.getName() + "'" );
      }
      ValueMetaInterface injectValueMeta = dataSetRowMeta.getValueMeta( fieldIndexes[ i ] ).clone();
      // Rename to the step output names though...
      //
      injectValueMeta.setName( fieldMapping.getStepFieldName() );
      injectRowMeta.addValueMeta( injectValueMeta );
    }

    log.logDetailed( "Injecting data set '" + dataSetName + "' into step '" + stepMeta.getName() + "', fields: " + Arrays.toString( injectRowMeta.getFieldNames() ) );

    // Pass rows
    //
    Runnable runnable = new Runnable() {
      @Override
      public void run() {
        try {

          for ( Object[] dataSetRow : dataSetRows ) {
            // pass the row with the external names, in the right order and with the selected columns from the data set
            //
            Object[] row = RowDataUtil.allocateRowData( injectRowMeta.size() );
            for ( int i = 0; i < fieldIndexes.length; i++ ) {
              row[ i ] = dataSetRow[ fieldIndexes[ i ] ];
            }
            rowProducer.putRow( injectRowMeta, row );
          }
          rowProducer.finished();

        } catch ( Exception e ) {
          throw new RuntimeException( "Problem injecting data set '" + dataSetName + "' row into step '" + stepMeta.getName() + "'", e );
        }
      }
    };
    Thread thread = new Thread( runnable );
    thread.start();


  }
}