org.pentaho.di.core.exception.KettleStepException Java Examples

The following examples show how to use org.pentaho.di.core.exception.KettleStepException. 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: FieldSplitterTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private FieldSplitterMeta mockProcessRowMeta() throws KettleStepException {
  FieldSplitterMeta processRowMeta = smh.processRowsStepMetaInterface;
  doReturn( "field to split" ).when( processRowMeta ).getSplitField();
  doCallRealMethod().when( processRowMeta ).getFields( any( RowMetaInterface.class ), anyString(),
      any( RowMetaInterface[].class ), any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ),
      any( IMetaStore.class ) );
  doReturn( new String[] { "a", "b" } ).when( processRowMeta ).getFieldName();
  doReturn( new int[] { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING } ).when( processRowMeta )
      .getFieldType();
  doReturn( new String[] { "a=", "b=" } ).when( processRowMeta ).getFieldID();
  doReturn( new boolean[] { false, false } ).when( processRowMeta ).getFieldRemoveID();
  doReturn( new int[] { -1, -1 } ).when( processRowMeta ).getFieldLength();
  doReturn( new int[] { -1, -1 } ).when( processRowMeta ).getFieldPrecision();
  doReturn( new int[] { 0, 0 } ).when( processRowMeta ).getFieldTrimType();
  doReturn( new String[] { null, null } ).when( processRowMeta ).getFieldFormat();
  doReturn( new String[] { null, null } ).when( processRowMeta ).getFieldDecimal();
  doReturn( new String[] { null, null } ).when( processRowMeta ).getFieldGroup();
  doReturn( new String[] { null, null } ).when( processRowMeta ).getFieldCurrency();
  doReturn( new String[] { null, null } ).when( processRowMeta ).getFieldNullIf();
  doReturn( new String[] { null, null } ).when( processRowMeta ).getFieldIfNull();
  doReturn( ";" ).when( processRowMeta ).getDelimiter();
  doReturn( 2 ).when( processRowMeta ).getFieldsCount();

  return processRowMeta;
}
 
Example #2
Source File: ElasticSearchBulk.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void initFieldIndexes() throws KettleStepException {
  if ( isJsonInsert ) {
    Integer idx = getFieldIdx( data.inputRowMeta, environmentSubstitute( meta.getJsonField() ) );
    if ( idx != null ) {
      jsonFieldIdx = idx.intValue();
    } else {
      throw new KettleStepException( BaseMessages.getString( PKG, "ElasticSearchBulk.Error.NoJsonField" ) );
    }
  }

  idOutFieldName = environmentSubstitute( meta.getIdOutField() );

  if ( StringUtils.isNotBlank( meta.getIdInField() ) ) {
    idFieldIndex = getFieldIdx( data.inputRowMeta, environmentSubstitute( meta.getIdInField() ) );
    if ( idFieldIndex == null ) {
      throw new KettleStepException( BaseMessages.getString( PKG, "ElasticSearchBulk.Error.InvalidIdField" ) );
    }
  } else {
    idFieldIndex = null;
  }
}
 
Example #3
Source File: BaseStep.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Opens socket connections to the remote input steps of this step. <br>
 * This method should be used by steps that don't call getRow() first in which it is executed automatically. <br>
 * <b>This method should be called before any data is read from previous steps.</b> <br>
 * This action is executed only once.
 *
 * @throws KettleStepException
 */
protected void openRemoteInputStepSocketsOnce() throws KettleStepException {
  if ( !remoteInputSteps.isEmpty() ) {
    if ( !remoteInputStepsInitialized ) {
      // Loop over the remote steps and open client sockets to them
      // Just be careful in case we're dealing with a partitioned clustered step.
      // A partitioned clustered step has only one. (see dispatch())
      //
      inputRowSetsLock.writeLock().lock();
      try {
        for ( RemoteStep remoteStep : remoteInputSteps ) {
          try {
            BlockingRowSet rowSet = remoteStep.openReaderSocket( this );
            inputRowSets.add( rowSet );
          } catch ( Exception e ) {
            throw new KettleStepException( "Error opening reader socket to remote step '" + remoteStep + "'", e );
          }
        }
      } finally {
        inputRowSetsLock.writeLock().unlock();
      }
      remoteInputStepsInitialized = true;
    }
  }
}
 
Example #4
Source File: OpenERPObjectInputMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( final RowMetaInterface row, final String origin, final RowMetaInterface[] info,
                       final StepMeta nextStep, final VariableSpace space, Repository repository, IMetaStore metaStore )
  throws KettleStepException {

  if ( databaseMeta == null ) {
    throw new KettleStepException( "There is no OpenERP database server connection defined" );
  }

  final OpenERPHelper helper = new OpenERPHelper( databaseMeta );
  try {
    helper.StartSession();
    final RowMetaInterface rowMeta = this.getRowMeta();
    row.addRowMeta( rowMeta );
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example #5
Source File: SymmetricCryptoTransMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  if ( !Utils.isEmpty( getResultfieldname() ) ) {
    int type = ValueMetaInterface.TYPE_STRING;
    if ( isOutputResultAsBinary() ) {
      type = ValueMetaInterface.TYPE_BINARY;
    }
    try {
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( getResultfieldname(), type );
      v.setOrigin( origin );
      rowMeta.addValueMeta( v );
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example #6
Source File: DatabaseJoinMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta,
  RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository,
  IMetaStore metaStore ) throws KettleStepException {

  // Find the lookupfields...
  //
  RowMetaInterface out = prev.clone();
  getFields( out, stepMeta.getName(), new RowMetaInterface[] { info, }, null, transMeta, repository, metaStore );

  if ( out != null ) {
    for ( int i = 0; i < out.size(); i++ ) {
      ValueMetaInterface outvalue = out.getValueMeta( i );
      DatabaseImpact di =
        new DatabaseImpact(
          DatabaseImpact.TYPE_IMPACT_READ, transMeta.getName(), stepMeta.getName(),
          databaseMeta.getDatabaseName(), "", outvalue.getName(), outvalue.getName(), stepMeta.getName(),
          transMeta.environmentSubstitute( sql ),
          BaseMessages.getString( PKG, "DatabaseJoinMeta.DatabaseImpact.Title" ) );
      impact.add( di );

    }
  }
}
 
Example #7
Source File: WsdlOpParameterList.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a WsdlOpParameter from the message part.
 *
 * @param part
 *          A list of message part.
 * @param requesPart
 *          true if part from request message.
 */
private List<WsdlOpParameter> getParameter( Part part, boolean requesPart ) throws KettleStepException {

  List<WsdlOpParameter> params = new ArrayList<WsdlOpParameter>();

  if ( part.getElementName() != null ) {
    if ( WsdlUtils.isWrappedParameterStyle( _operation.getName(), !requesPart, part.getName() ) ) {
      _parameterStyle = WsdlOperation.SOAPParameterStyle.WRAPPED;
    }
    params.addAll( resolvePartElement( part ) );
  } else {
    params.add( new WsdlOpParameter( part.getName(), part.getTypeName(), _wsdlTypes.findNamedType( part
      .getTypeName() ), _wsdlTypes ) );
  }
  return params;
}
 
Example #8
Source File: BaseStep.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Find output row set.
 *
 * @param targetStep the target step
 * @return the row set
 * @throws KettleStepException the kettle step exception
 */
public RowSet findOutputRowSet( String targetStep ) throws KettleStepException {

  // Check to see that "targetStep" only runs in a single copy
  // Otherwise you'll see problems during execution.
  //
  StepMeta targetStepMeta = transMeta.findStep( targetStep );
  if ( targetStepMeta == null ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "BaseStep.Exception.TargetStepToWriteToDoesntExist", targetStep ) );
  }

  if ( targetStepMeta.getCopies() > 1 ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "BaseStep.Exception.TargetStepToWriteToCantRunInMultipleCopies", targetStep, Integer
        .toString( targetStepMeta.getCopies() ) ) );
  }

  return findOutputRowSet( getStepname(), getCopy(), targetStep, 0 );
}
 
Example #9
Source File: SpoonJobDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private String getSQLString( DatabaseMeta sourceDbInfo, TableInputMeta tii, TransMeta transMeta )
  throws InvocationTargetException {
  // First set the limit to 1 to speed things up!
  String tmpSql = tii.getSQL();
  tii.setSQL( tii.getSQL() + sourceDbInfo.getLimitClause( 1 ) );
  String sql;
  try {
    sql = transMeta.getSQLStatementsString();
  } catch ( KettleStepException kse ) {
    throw new InvocationTargetException( kse, BaseMessages.getString(
      PKG, "Spoon.RipDB.Exception.ErrorGettingSQLFromTransformation" )
      + transMeta + "] : " + kse.getMessage() );
  }
  // remove the limit
  tii.setSQL( tmpSql );
  return sql;
}
 
Example #10
Source File: OpenERPObjectDeleteDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private String[] getSteamFieldsNames( boolean showError ) {
  String[] fields = null;

  // Set stream fields
  RowMetaInterface row;
  try {
    row = transMeta.getPrevStepFields( stepMeta );
    fields = new String[row.size()];
    for ( int i = 0; i < row.size(); i++ ) {
      fields[i] = row.getValueMeta( i ).getName();
    }
  } catch ( KettleStepException e ) {
    if ( showError ) {
      new ErrorDialog( shell,
        BaseMessages.getString( PKG, "OpenERPObjectOutputDialog.UnableToFindStreamFieldsTitle" ), BaseMessages
        .getString( PKG, "OpenERPObjectOutputDialog.UnableToFindStreamFieldsMessage" ), e );
    }
    return null;
  }

  return fields;
}
 
Example #11
Source File: TableProducerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void rowWrittenEvent_boolean() throws KettleStepException, ReportDataFactoryException, KettleValueException {
  Boolean[] row = new Boolean[] { true };
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.size() ).thenReturn( 1 );

  ValueMetaInterface valueMeta1 = mock( ValueMetaInterface.class );
  when( valueMeta1.getName() ).thenReturn( "COLUMN_1" );
  when( valueMeta1.getType() ).thenReturn( ValueMetaInterface.TYPE_BOOLEAN );
  when( rowMetaInterface.getValueMeta( eq( 0 ) ) ).thenReturn( valueMeta1 );
  when( rowMetaInterface.getBoolean( eq( row ), eq( 0 ) ) ).thenReturn( row[0] );

  TableProducer tableProducer = new TableProducer( rowMetaInterface, 0, true );
  tableProducer.rowWrittenEvent( rowMetaInterface, row );

  TypedTableModel expectedModel = new TypedTableModel( new String[] { "COLUMN_1" }, new Class[] { Boolean.class } );
  expectedModel.addRow( true );

  assertEquals( expectedModel, tableProducer.getTableModel() );
}
 
Example #12
Source File: TableProducerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void rowWrittenEvent_bignumber() throws KettleStepException, ReportDataFactoryException, KettleValueException {
  BigDecimal[] row = new BigDecimal[] { new BigDecimal( 1 ) };
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.size() ).thenReturn( 1 );

  ValueMetaInterface valueMeta1 = mock( ValueMetaInterface.class );
  when( valueMeta1.getName() ).thenReturn( "COLUMN_1" );
  when( valueMeta1.getType() ).thenReturn( ValueMetaInterface.TYPE_BIGNUMBER );
  when( rowMetaInterface.getValueMeta( eq( 0 ) ) ).thenReturn( valueMeta1 );
  when( rowMetaInterface.getBigNumber( eq( row ), eq( 0 ) ) ).thenReturn( row[0] );

  TableProducer tableProducer = new TableProducer( rowMetaInterface, 0, true );
  tableProducer.rowWrittenEvent( rowMetaInterface, row );

  TypedTableModel expectedModel = new TypedTableModel( new String[] { "COLUMN_1" }, new Class[] { BigDecimal.class } );
  expectedModel.addRow( new BigDecimal( 1 ) );

  assertEquals( expectedModel, tableProducer.getTableModel() );
}
 
Example #13
Source File: TableProducerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void rowWrittenEvent_date() throws KettleStepException, ReportDataFactoryException, KettleValueException {
  Date[] row = new Date[] { new Date( 1 ) };
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.size() ).thenReturn( 1 );

  ValueMetaInterface valueMeta1 = mock( ValueMetaInterface.class );
  when( valueMeta1.getName() ).thenReturn( "COLUMN_1" );
  when( valueMeta1.getType() ).thenReturn( ValueMetaInterface.TYPE_DATE );
  when( rowMetaInterface.getValueMeta( eq( 0 ) ) ).thenReturn( valueMeta1 );
  when( rowMetaInterface.getDate( eq( row ), eq( 0 ) ) ).thenReturn( row[0] );

  TableProducer tableProducer = new TableProducer( rowMetaInterface, 0, true );
  tableProducer.rowWrittenEvent( rowMetaInterface, row );

  TypedTableModel expectedModel = new TypedTableModel( new String[] { "COLUMN_1" }, new Class[] { BigDecimal.class } );
  expectedModel.addRow( new Date( 1 ) );

  assertEquals( expectedModel, tableProducer.getTableModel() );
}
 
Example #14
Source File: TableProducerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void rowWrittenEvent_none() throws KettleStepException, ReportDataFactoryException, KettleValueException {
  String[] row = new String[] { "NONE" };
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.size() ).thenReturn( 1 );

  ValueMetaInterface valueMeta1 = mock( ValueMetaInterface.class );
  when( valueMeta1.getName() ).thenReturn( "COLUMN_1" );
  when( valueMeta1.getType() ).thenReturn( ValueMetaInterface.TYPE_NONE );
  when( rowMetaInterface.getValueMeta( eq( 0 ) ) ).thenReturn( valueMeta1 );
  when( rowMetaInterface.getString( eq( row ), eq( 0 ) ) ).thenReturn( row[0] );

  TableProducer tableProducer = new TableProducer( rowMetaInterface, 0, true );
  tableProducer.rowWrittenEvent( rowMetaInterface, row );

  TypedTableModel expectedModel = new TypedTableModel( new String[] { "COLUMN_1" }, new Class[] { String.class } );
  expectedModel.addRow( "NONE" );

  assertEquals( expectedModel, tableProducer.getTableModel() );
}
 
Example #15
Source File: TransMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void infoStepFieldsAreNotIncludedInGetStepFields() throws KettleStepException {
  // validates that the fields from info steps are not included in the resulting step fields for a stepMeta.
  //  This is important with steps like StreamLookup and Append, where the previous steps may or may not
  //  have their fields included in the current step.

  TransMeta transMeta = new TransMeta( new Variables() );
  StepMeta toBeAppended1 = testStep( "toBeAppended1",
    emptyList(),  // no info steps
    asList( "field1", "field2" )  // names of fields from this step
  );
  StepMeta toBeAppended2 = testStep( "toBeAppended2", emptyList(), asList( "field1", "field2" ) );

  StepMeta append = testStep( "append",
    asList( "toBeAppended1", "toBeAppended2" ),  // info step names
    singletonList( "outputField" )   // output field of this step
  );
  StepMeta after = new StepMeta( "after", new DummyTransMeta() );

  wireUpTestTransMeta( transMeta, toBeAppended1, toBeAppended2, append, after );

  RowMetaInterface results = transMeta.getStepFields( append, after, mock( ProgressMonitorListener.class ) );

  assertThat( 1, equalTo( results.size() ) );
  assertThat( "outputField", equalTo( results.getFieldNames()[ 0 ] ) );
}
 
Example #16
Source File: XBaseInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  FileInputList fileList = getTextFileList( space );
  if ( fileList.nrOfFiles() == 0 ) {
    throw new KettleStepException( BaseMessages
      .getString( PKG, "XBaseInputMeta.Exception.NoFilesFoundToProcess" ) );
  }

  row.addRowMeta( getOutputFields( fileList, name ) );
}
 
Example #17
Source File: CalculatorUnitTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@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.addRowSetToInputRowSets( 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();
  }
}
 
Example #18
Source File: CalculatorBackwardCompatibilityUnitTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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.addRowSetToInputRowSets( 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();
  }

}
 
Example #19
Source File: FieldSplitterMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // Remove the field to split
  int idx = r.indexOfValue( getSplitField() );
  if ( idx < 0 ) { // not found
    throw new RuntimeException( BaseMessages.getString(
      PKG, "FieldSplitter.Log.CouldNotFindFieldToSplit", getSplitField() ) );
  }

  // Add the new fields at the place of the index --> replace!
  int count = getFieldsCount();
  for ( int i = 0; i < count; i++ ) {
    try {
      final ValueMetaInterface v = ValueMetaFactory.createValueMeta( getFieldName()[i], getFieldType()[i] );
      v.setLength( getFieldLength()[i], getFieldPrecision()[i] );
      v.setOrigin( name );
      v.setConversionMask( getFieldFormat()[i] );
      v.setDecimalSymbol( getFieldDecimal()[i] );
      v.setGroupingSymbol( getFieldGroup()[i] );
      v.setCurrencySymbol( getFieldCurrency()[i] );
      v.setTrimType( getFieldTrimType()[i] );
      // TODO when implemented in UI
      // v.setDateFormatLenient(dateFormatLenient);
      // TODO when implemented in UI
      // v.setDateFormatLocale(dateFormatLocale);
      if ( i == 0 && idx >= 0 ) {
        // the first valueMeta (splitField) will be replaced
        r.setValueMeta( idx, v );
      } else {
        // other valueMeta will be added
        if ( idx >= r.size() ) {
          r.addValueMeta( v );
        }
        r.addValueMeta( idx + i, v );
      }
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example #20
Source File: GetTableNames.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void processIncludeSchema( Object[] outputRow )
  throws KettleDatabaseException, KettleStepException, KettleValueException {
  // Schemas
  if ( meta.isIncludeSchema() ) {
    String ObjectType = BaseMessages.getString( PKG, "GetTableNamesDialog.ObjectType.Schema" );
    // Views
    String[] schemaNames = new String[] {};
    if ( !Utils.isEmpty( data.realSchemaName ) ) {
      schemaNames = new String[] { data.realSchemaName };
    } else {
      schemaNames = data.db.getSchemas();
    }
    for ( int i = 0; i < schemaNames.length && !isStopped(); i++ ) {

      // Clone current input row
      Object[] outputRowSchema = outputRow.clone();

      int outputIndex = data.totalpreviousfields;

      String schemaName = schemaNames[i];
      outputRowSchema[outputIndex++] = schemaName;

      if ( !Utils.isEmpty( data.realObjectTypeFieldName ) ) {
        outputRowSchema[outputIndex++] = ObjectType;
      }
      if ( !Utils.isEmpty( data.realIsSystemObjectFieldName ) ) {
        outputRowSchema[outputIndex++] = Boolean.valueOf( data.db.isSystemTable( schemaName ) );
      }
      if ( !Utils.isEmpty( data.realSQLCreationFieldName ) ) {
        outputRowSchema[outputIndex++] = null;
      }
      data.rownr++;
      putRow( data.outputRowMeta, outputRowSchema ); // copy row to output rowset(s);

      logInfo( outputRowSchema );
    }
  }
}
 
Example #21
Source File: MergeRowsMetaCheckTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckInputRowsBothNonEmpty() throws KettleStepException {
  when( transMeta.getPrevStepFields( REFERENCE_STEP_NAME ) ).thenReturn( generateRowMeta10Strings() );
  when( transMeta.getPrevStepFields( COMPARISON_STEP_NAME ) ).thenReturn( generateRowMeta10Strings() );

  meta.check( remarks, transMeta, stepMeta, (RowMeta) null, new String[0], new String[0],
    (RowMeta) null, new Variables(), (Repository) null, (IMetaStore) null );

  assertNotNull( remarks );
  assertTrue( remarks.size() >= 2 );
  assertEquals( remarks.get( 1 ).getType(), CheckResultInterface.TYPE_RESULT_OK );
}
 
Example #22
Source File: FixedInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    for ( int i = 0; i < fieldDefinition.length; i++ ) {
      FixedFileInputField field = fieldDefinition[i];

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getName(), field.getType() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setTrimType( field.getTrimType() );
      valueMeta.setLength( field.getLength() );
      valueMeta.setPrecision( field.getPrecision() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setDecimalSymbol( field.getDecimal() );
      valueMeta.setGroupingSymbol( field.getGrouping() );
      valueMeta.setCurrencySymbol( field.getCurrency() );
      valueMeta.setStringEncoding( space.environmentSubstitute( encoding ) );
      if ( lazyConversionActive ) {
        valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
      }

      // In case we want to convert Strings...
      //
      ValueMetaInterface storageMetadata =
        ValueMetaFactory.cloneValueMeta( valueMeta, ValueMetaInterface.TYPE_STRING );
      storageMetadata.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );

      valueMeta.setStorageMetadata( storageMetadata );

      valueMeta.setOrigin( origin );

      rowMeta.addValueMeta( valueMeta );
    }
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example #23
Source File: ExecSQLRowMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  RowMetaAndData add =
    ExecSQL.getResultRow( new Result(), getUpdateField(), getInsertField(), getDeleteField(), getReadField() );

  r.mergeRowMeta( add.getRowMeta() );
}
 
Example #24
Source File: UserDefinedJavaClass.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void putRow( RowMetaInterface row, Object[] data ) throws KettleStepException {
  if ( child == null ) {
    putRowImpl( row, data );
  } else {
    child.putRow( row, data );
  }
}
 
Example #25
Source File: GetTableNames.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void processIncludeProcedure( Object[] outputRow )
  throws KettleDatabaseException, KettleStepException, KettleValueException {
  if ( meta.isIncludeProcedure() ) {
    String[] procNames = data.db.getProcedures();
    String ObjectType = BaseMessages.getString( PKG, "GetTableNamesDialog.ObjectType.Procedure" );
    for ( int i = 0; i < procNames.length && !isStopped(); i++ ) {
      Object[] outputRowProc = outputRow.clone();
      int outputIndex = data.totalpreviousfields;

      String procName = procNames[i];
      outputRowProc[outputIndex++] = procName;

      if ( !Utils.isEmpty( data.realObjectTypeFieldName ) ) {
        outputRowProc[outputIndex++] = ObjectType;
      }
      if ( !Utils.isEmpty( data.realIsSystemObjectFieldName ) ) {
        outputRowProc[outputIndex++] = Boolean.valueOf( data.db.isSystemTable( procName ) );
      }
      if ( !Utils.isEmpty( data.realSQLCreationFieldName ) ) {
        outputRowProc[outputIndex++] = null;
      }
      data.rownr++;
      putRow( data.outputRowMeta, outputRowProc ); // copy row to output rowset(s);

      logInfo( outputRowProc );
    }
  }
}
 
Example #26
Source File: BeamOutputStepHandler.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
private FileDefinition getDefaultFileDefition( StepMeta beamOutputStepMeta ) throws KettleStepException {
  FileDefinition fileDefinition = new FileDefinition();

  fileDefinition.setName( "Default" );
  fileDefinition.setEnclosure( "\"" );
  fileDefinition.setSeparator( "," );

  return fileDefinition;
}
 
Example #27
Source File: NullIfTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private NullIfMeta mockProcessRowMeta() throws KettleStepException {
  NullIfMeta processRowMeta = smh.processRowsStepMetaInterface;
  Field[] fields = createArrayWithOneField( "nullable-field", "nullable-value" );
  doReturn( fields ).when( processRowMeta ).getFields();
  doCallRealMethod().when( processRowMeta ).getFields( any( RowMetaInterface.class ), anyString(),
      any( RowMetaInterface[].class ), any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ),
      any( IMetaStore.class ) );

  return processRowMeta;
}
 
Example #28
Source File: NormalExecutionIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void errorRowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
  if ( !isListening() ) {
    ignoredError++;
  } else {
    error++;
  }
}
 
Example #29
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
                       VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // do not call the super class from TextFileOutputMeta since it modifies the source meta data
  // see getFieldsModifyInput() instead

  // remove selected fields from the stream when true
  if ( removeSelectedFields ) {
    if ( getOutputFields().length > 0 ) {
      for ( int i = 0; i < getOutputFields().length; i++ ) {
        TextFileField field = getOutputFields()[ i ];
        try {
          row.removeValueMeta( field.getName() );
        } catch ( KettleValueException e ) {
          // just ignore exceptions since missing fields are handled in the ConcatFields class
        }
      }
    } else { // no output fields selected, take them all, remove them all
      row.clear();
    }
  }

  // Check Target Field Name
  if ( Utils.isEmpty( targetFieldName ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "ConcatFieldsMeta.CheckResult.TargetFieldNameMissing" ) );
  }
  // add targetFieldName
  ValueMetaInterface vValue = new ValueMetaString( targetFieldName );
  vValue.setLength( targetFieldLength, 0 );
  vValue.setOrigin( name );
  if ( !Utils.isEmpty( getEncoding() ) ) {
    vValue.setStringEncoding( getEncoding() );
  }
  row.addValueMeta( vValue );
}
 
Example #30
Source File: SFTPPut.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void checkRemoteFilenameField( String remoteFilenameFieldName, SFTPPutData data )
  throws KettleStepException {
  remoteFilenameFieldName = environmentSubstitute( remoteFilenameFieldName );
  if ( !Utils.isEmpty( remoteFilenameFieldName ) ) {
    data.indexOfRemoteFilename = getInputRowMeta().indexOfValue( remoteFilenameFieldName );
    if ( data.indexOfRemoteFilename == -1 ) {
      // remote file name field is set, but was not found
      throw new KettleStepException( BaseMessages.getString(
        PKG, "SFTPPut.Error.CanNotFindField", remoteFilenameFieldName ) );
    }
  }
}