@Test public void testGetFields() throws Exception { TableInputMetaHandler meta = new TableInputMetaHandler(); meta.setLazyConversionActive( true ); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); meta.setDatabaseMeta( dbMeta ); Database mockDB = meta.getDatabase(); when( mockDB.getQueryFields( anyString(), anyBoolean() ) ).thenReturn( createMockFields() ); RowMetaInterface expectedRowMeta = new RowMeta(); ValueMetaInterface valueMeta = new ValueMetaString( "field1" ); valueMeta.setStorageMetadata( new ValueMetaString( "field1" ) ); valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); expectedRowMeta.addValueMeta( valueMeta ); VariableSpace space = mock( VariableSpace.class ); RowMetaInterface rowMetaInterface = new RowMeta(); meta.getFields( rowMetaInterface, "TABLE_INPUT_META", null, null, space, null, null ); assertEquals( expectedRowMeta.toString(), rowMetaInterface.toString() ); }
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( databaseMeta == null ) { return; } boolean param = false; Database db = getDatabase(); databases = new Database[] { db }; String sNewSQL = sql; if ( isVariableReplacementActive() ) { sNewSQL = db.environmentSubstitute( sql ); if ( space != null ) { sNewSQL = space.environmentSubstitute( sNewSQL ); } } RowMetaInterface add = null; try { add = db.getQueryFields( sNewSQL, param ); } catch ( KettleDatabaseException dbe ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe ); } if ( add != null ) { for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } else { try { db.connect(); RowMetaInterface paramRowMeta = null; Object[] paramData = null; StreamInterface infoStream = getStepIOMeta().getInfoStreams().get( 0 ); if ( !Utils.isEmpty( infoStream.getStepname() ) ) { param = true; if ( info.length >= 0 && info[0] != null ) { paramRowMeta = info[0]; paramData = RowDataUtil.allocateRowData( paramRowMeta.size() ); } } add = db.getQueryFields( sNewSQL, param, paramRowMeta, paramData ); if ( add == null ) { return; } for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } catch ( KettleException ke ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke ); } finally { db.disconnect(); } } if ( isLazyConversionActive() ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); try { if ( v.getType() == ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta( v ); storageMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); v.setStorageMetadata( storageMeta ); v.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); } } catch ( KettlePluginException e ) { throw new KettleStepException( "Unable to clone meta for lazy conversion: " + Const.CR + v, e ); } } } }
TableInputMeta extends BaseStepMeta implements StepMetaInterface { public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( databaseMeta == null ) { return; } boolean param = false; Database db = getDatabase(); databases = new Database[] { db }; String sNewSQL = sql; if ( isVariableReplacementActive() ) { sNewSQL = db.environmentSubstitute( sql ); if ( space != null ) { sNewSQL = space.environmentSubstitute( sNewSQL ); } } RowMetaInterface add = null; try { add = db.getQueryFields( sNewSQL, param ); } catch ( KettleDatabaseException dbe ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe ); } if ( add != null ) { for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } else { try { db.connect(); RowMetaInterface paramRowMeta = null; Object[] paramData = null; StreamInterface infoStream = getStepIOMeta().getInfoStreams().get( 0 ); if ( !Utils.isEmpty( infoStream.getStepname() ) ) { param = true; if ( info.length >= 0 && info[0] != null ) { paramRowMeta = info[0]; paramData = RowDataUtil.allocateRowData( paramRowMeta.size() ); } } add = db.getQueryFields( sNewSQL, param, paramRowMeta, paramData ); if ( add == null ) { return; } for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } catch ( KettleException ke ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke ); } finally { db.disconnect(); } } if ( isLazyConversionActive() ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); try { if ( v.getType() == ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta( v ); storageMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); v.setStorageMetadata( storageMeta ); v.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); } } catch ( KettlePluginException e ) { throw new KettleStepException( "Unable to clone meta for lazy conversion: " + Const.CR + v, e ); } } } } }
TableInputMeta extends BaseStepMeta implements StepMetaInterface { public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( databaseMeta == null ) { return; } boolean param = false; Database db = getDatabase(); databases = new Database[] { db }; String sNewSQL = sql; if ( isVariableReplacementActive() ) { sNewSQL = db.environmentSubstitute( sql ); if ( space != null ) { sNewSQL = space.environmentSubstitute( sNewSQL ); } } RowMetaInterface add = null; try { add = db.getQueryFields( sNewSQL, param ); } catch ( KettleDatabaseException dbe ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe ); } if ( add != null ) { for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } else { try { db.connect(); RowMetaInterface paramRowMeta = null; Object[] paramData = null; StreamInterface infoStream = getStepIOMeta().getInfoStreams().get( 0 ); if ( !Utils.isEmpty( infoStream.getStepname() ) ) { param = true; if ( info.length >= 0 && info[0] != null ) { paramRowMeta = info[0]; paramData = RowDataUtil.allocateRowData( paramRowMeta.size() ); } } add = db.getQueryFields( sNewSQL, param, paramRowMeta, paramData ); if ( add == null ) { return; } for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } catch ( KettleException ke ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke ); } finally { db.disconnect(); } } if ( isLazyConversionActive() ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); try { if ( v.getType() == ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta( v ); storageMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); v.setStorageMetadata( storageMeta ); v.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); } } catch ( KettlePluginException e ) { throw new KettleStepException( "Unable to clone meta for lazy conversion: " + Const.CR + v, e ); } } } } TableInputMeta(); }
TableInputMeta extends BaseStepMeta implements StepMetaInterface { public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( databaseMeta == null ) { return; } boolean param = false; Database db = getDatabase(); databases = new Database[] { db }; String sNewSQL = sql; if ( isVariableReplacementActive() ) { sNewSQL = db.environmentSubstitute( sql ); if ( space != null ) { sNewSQL = space.environmentSubstitute( sNewSQL ); } } RowMetaInterface add = null; try { add = db.getQueryFields( sNewSQL, param ); } catch ( KettleDatabaseException dbe ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe ); } if ( add != null ) { for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } else { try { db.connect(); RowMetaInterface paramRowMeta = null; Object[] paramData = null; StreamInterface infoStream = getStepIOMeta().getInfoStreams().get( 0 ); if ( !Utils.isEmpty( infoStream.getStepname() ) ) { param = true; if ( info.length >= 0 && info[0] != null ) { paramRowMeta = info[0]; paramData = RowDataUtil.allocateRowData( paramRowMeta.size() ); } } add = db.getQueryFields( sNewSQL, param, paramRowMeta, paramData ); if ( add == null ) { return; } for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } catch ( KettleException ke ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke ); } finally { db.disconnect(); } } if ( isLazyConversionActive() ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); try { if ( v.getType() == ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta( v ); storageMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); v.setStorageMetadata( storageMeta ); v.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); } } catch ( KettlePluginException e ) { throw new KettleStepException( "Unable to clone meta for lazy conversion: " + Const.CR + v, e ); } } } } TableInputMeta(); boolean isExecuteEachInputRow(); void setExecuteEachInputRow( boolean oncePerRow ); DatabaseMeta getDatabaseMeta(); void setDatabaseMeta( DatabaseMeta database ); String getRowLimit(); void setRowLimit( String rowLimit ); String getSQL(); void setSQL( String sql ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
    RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
    Repository repository, IMetaStore metaStore ); void searchInfoAndTargetSteps( List<StepMeta> steps ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
    TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); @Override void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta,
    RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository,
    IMetaStore metaStore ); DatabaseMeta[] getUsedDatabaseConnections(); boolean isVariableReplacementActive(); void setVariableReplacementActive( boolean variableReplacementActive ); boolean isLazyConversionActive(); void setLazyConversionActive( boolean lazyConversionActive ); StepIOMetaInterface getStepIOMeta(); void resetStepIoMeta(); void setLookupFromStep( StepMeta stepMeta ); StepMeta getLookupFromStep(); @Override TableInputMetaInjection getStepMetaInjectionInterface(); List<StepInjectionMetaEntry> extractStepMetadataEntries(); }
TableInputMeta extends BaseStepMeta implements StepMetaInterface { public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( databaseMeta == null ) { return; } boolean param = false; Database db = getDatabase(); databases = new Database[] { db }; String sNewSQL = sql; if ( isVariableReplacementActive() ) { sNewSQL = db.environmentSubstitute( sql ); if ( space != null ) { sNewSQL = space.environmentSubstitute( sNewSQL ); } } RowMetaInterface add = null; try { add = db.getQueryFields( sNewSQL, param ); } catch ( KettleDatabaseException dbe ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe ); } if ( add != null ) { for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } else { try { db.connect(); RowMetaInterface paramRowMeta = null; Object[] paramData = null; StreamInterface infoStream = getStepIOMeta().getInfoStreams().get( 0 ); if ( !Utils.isEmpty( infoStream.getStepname() ) ) { param = true; if ( info.length >= 0 && info[0] != null ) { paramRowMeta = info[0]; paramData = RowDataUtil.allocateRowData( paramRowMeta.size() ); } } add = db.getQueryFields( sNewSQL, param, paramRowMeta, paramData ); if ( add == null ) { return; } for ( int i = 0; i < add.size(); i++ ) { ValueMetaInterface v = add.getValueMeta( i ); v.setOrigin( origin ); } row.addRowMeta( add ); } catch ( KettleException ke ) { throw new KettleStepException( "Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke ); } finally { db.disconnect(); } } if ( isLazyConversionActive() ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); try { if ( v.getType() == ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta( v ); storageMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); v.setStorageMetadata( storageMeta ); v.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); } } catch ( KettlePluginException e ) { throw new KettleStepException( "Unable to clone meta for lazy conversion: " + Const.CR + v, e ); } } } } TableInputMeta(); boolean isExecuteEachInputRow(); void setExecuteEachInputRow( boolean oncePerRow ); DatabaseMeta getDatabaseMeta(); void setDatabaseMeta( DatabaseMeta database ); String getRowLimit(); void setRowLimit( String rowLimit ); String getSQL(); void setSQL( String sql ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
    RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
    Repository repository, IMetaStore metaStore ); void searchInfoAndTargetSteps( List<StepMeta> steps ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
    TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); @Override void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta,
    RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository,
    IMetaStore metaStore ); DatabaseMeta[] getUsedDatabaseConnections(); boolean isVariableReplacementActive(); void setVariableReplacementActive( boolean variableReplacementActive ); boolean isLazyConversionActive(); void setLazyConversionActive( boolean lazyConversionActive ); StepIOMetaInterface getStepIOMeta(); void resetStepIoMeta(); void setLookupFromStep( StepMeta stepMeta ); StepMeta getLookupFromStep(); @Override TableInputMetaInjection getStepMetaInjectionInterface(); List<StepInjectionMetaEntry> extractStepMetadataEntries();  }