Java Code Examples for org.pentaho.di.trans.TransMeta#setVariable()
The following examples show how to use
org.pentaho.di.trans.TransMeta#setVariable() .
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: KettleBeamPipelineExecutor.java From kettle-beam with Apache License 2.0 | 6 votes |
private void setVariablesInTransformation( BeamJobConfig config, TransMeta transMeta ) { String[] parameters = transMeta.listParameters(); for ( JobParameter parameter : config.getParameters() ) { if ( StringUtils.isNotEmpty( parameter.getVariable() ) ) { if ( Const.indexOfString( parameter.getVariable(), parameters ) >= 0 ) { try { transMeta.setParameterValue( parameter.getVariable(), parameter.getValue() ); } catch ( UnknownParamException e ) { transMeta.setVariable( parameter.getVariable(), parameter.getValue() ); } } else { transMeta.setVariable( parameter.getVariable(), parameter.getValue() ); } } } transMeta.activateParameters(); }
Example 2
Source File: SpoonFlagUnitTestExtensionPoint.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
@Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { if ( !( object instanceof TransMeta ) ) { return; } TransMeta transMeta = (TransMeta) object; TransUnitTest unitTest = DataSetHelper.getCurrentUnitTest( transMeta ); if ( unitTest == null ) { return; } String unitTestName = unitTest.getName(); if ( !StringUtil.isEmpty( unitTestName ) ) { // We're running in Spoon and there's a unit test selected : test it // transMeta.setVariable( DataSetConst.VAR_RUN_UNIT_TEST, "Y" ); transMeta.setVariable( DataSetConst.VAR_UNIT_TEST_NAME, unitTestName ); } }
Example 3
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
public void detachUnitTest() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); try { TransGraph transGraph = spoon.getActiveTransGraph(); if ( transGraph == null ) { return; } TransMeta transMeta = spoon.getActiveTransformation(); if ( transMeta == null ) { return; } // Remove // activeTests.remove( transMeta ); transMeta.setVariable( DataSetConst.VAR_RUN_UNIT_TEST, "N" ); spoon.refreshGraph(); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error detaching unit test", e ); } }
Example 4
Source File: TablespaceDDLFragmentIT.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testMySQLDatabase() { try { TransMeta transMeta = new TransMeta(); DatabaseMeta databaseMeta = new DatabaseMeta( MySQLDatabaseXML ); transMeta.setVariable( "TablespaceDDLFragmentTest_DATA_TABLESPACE", "TABLES" ); transMeta.setVariable( "TablespaceDDLFragmentTest_INDEX_TABLESPACE", "INDEXES" ); String ddlFragment = ""; ddlFragment = databaseMeta.getDatabaseInterface().getDataTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "" ); ddlFragment = databaseMeta.getDatabaseInterface().getIndexTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "" ); } catch ( Exception e ) { e.printStackTrace(); } }
Example 5
Source File: TablespaceDDLFragmentIT.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testH2Database() { try { TransMeta transMeta = new TransMeta(); DatabaseMeta databaseMeta = new DatabaseMeta( h2DatabaseXML ); transMeta.setVariable( "TablespaceDDLFragmentTest_DATA_TABLESPACE", "TABLES" ); transMeta.setVariable( "TablespaceDDLFragmentTest_INDEX_TABLESPACE", "INDEXES" ); String ddlFragment = ""; ddlFragment = databaseMeta.getDatabaseInterface().getDataTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "" ); ddlFragment = databaseMeta.getDatabaseInterface().getIndexTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "" ); } catch ( Exception e ) { e.printStackTrace(); } }
Example 6
Source File: TransMetaConverterTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testIncludesSubTransformationsFromRepository() throws Exception { TransMeta parentTransMeta = new TransMeta( getClass().getResource( "trans-meta-converter-parent.ktr" ).getPath() ); Repository repository = mock( Repository.class ); TransMeta transMeta = new TransMeta( ); RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory( null, "public"); String directory = getClass().getResource( "" ).toString().replace( File.separator, "/" ); when( repository.findDirectory( "public" ) ).thenReturn( repositoryDirectory ); when( repository.loadTransformation( "trans-meta-converter-sub.ktr", repositoryDirectory, null, true, null ) ).thenReturn( transMeta ); parentTransMeta.setRepository( repository ); parentTransMeta.setRepositoryDirectory( repositoryDirectory ); parentTransMeta.setVariable( "Internal.Entry.Current.Directory", "public" ); Transformation transformation = TransMetaConverter.convert( parentTransMeta ); @SuppressWarnings( { "unchecked", "ConstantConditions" } ) HashMap<String, Transformation> config = (HashMap<String, Transformation>) transformation.getConfig( TransMetaConverter.SUB_TRANSFORMATIONS_KEY ).get(); assertEquals( 1, config.size() ); assertNotNull( config.get( "public/trans-meta-converter-sub.ktr" ) ); }
Example 7
Source File: JobGraph.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static void copyInternalJobVariables( JobMeta sourceJobMeta, TransMeta targetTransMeta ) { // Also set some internal JOB variables... // String[] internalVariables = Const.INTERNAL_JOB_VARIABLES; for ( String variableName : internalVariables ) { targetTransMeta.setVariable( variableName, sourceJobMeta.getVariable( variableName ) ); } }
Example 8
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
/** * Ask which data set to write to * Ask for the mapping between the output row and the data set field * Start the transformation and capture the output of the step, write to the database table backing the data set. */ public void writeStepDataToDataSet() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); IMetaStore metaStore = spoon.getMetaStore(); if ( transGraph == null ) { return; } StepMeta stepMeta = transGraph.getCurrentStep(); TransMeta transMeta = spoon.getActiveTransformation(); if ( stepMeta == null || transMeta == null ) { return; } if ( transMeta.hasChanged() ) { MessageBox box = new MessageBox( spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION ); box.setText( "Save transformation" ); box.setMessage( "Please save your transformation first." ); box.open(); return; } try { FactoriesHierarchy hierarchy = getHierarchy(); MetaStoreFactory<DataSetGroup> groupFactory = hierarchy.getGroupFactory(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = hierarchy.getSetFactory(); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); // Ask which data set to write to // List<String> setNames = setFactory.getElementNames(); Collections.sort( setNames ); EnterSelectionDialog esd = new EnterSelectionDialog( spoon.getShell(), setNames.toArray( new String[ setNames.size() ] ), "Select the set", "Select the data set to edit..." ); String setName = esd.open(); if ( setName == null ) { return; } DataSet dataSet = setFactory.loadElement( setName ); String[] setFields = new String[ dataSet.getFields().size() ]; for ( int i = 0; i < setFields.length; i++ ) { setFields[ i ] = dataSet.getFields().get( i ).getFieldName(); } RowMetaInterface rowMeta = transMeta.getStepFields( stepMeta ); String[] stepFields = new String[ rowMeta.size() ]; for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); stepFields[ i ] = valueMeta.getName(); } // Ask for the mapping between the output row and the data set field // EnterMappingDialog mappingDialog = new EnterMappingDialog( spoon.getShell(), stepFields, setFields ); List<SourceToTargetMapping> mapping = mappingDialog.open(); if ( mapping == null ) { return; } // Run the transformation. We want to use the standard Spoon runFile() method // So we need to leave the source to target mapping list somewhere so it can be picked up later. // For now we'll leave it where we need it. // WriteToDataSetExtensionPoint.stepsMap.put( transMeta.getName(), stepMeta ); WriteToDataSetExtensionPoint.mappingsMap.put( transMeta.getName(), mapping ); WriteToDataSetExtensionPoint.setsMap.put( transMeta.getName(), dataSet ); // Signal to the transformation xp plugin to inject data into some data set // transMeta.setVariable( DataSetConst.VAR_WRITE_TO_DATASET, "Y" ); spoon.runFile(); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new data set", e ); } }
Example 9
Source File: TablespaceDDLFragmentIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void testOracleDatabase() { try { // keep in mind that this execution will read a kettle.properties file TransMeta transMeta = new TransMeta(); // set up variables to be used for tablespace specification // the variables specified should not be specified in the kettle.proeprties file // these should not have quotes generated arounf them transMeta.setVariable( "TablespaceDDLFragmentTest_DATA_TABLESPACE_1", "TABLES" ); transMeta.setVariable( "TablespaceDDLFragmentTest_INDEX_TABLESPACE_1", "INDEXES" ); // these do have quotes generated around them transMeta.setVariable( "TablespaceDDLFragmentTest_DATA_TABLESPACE_2", "TABLE" ); transMeta.setVariable( "TablespaceDDLFragmentTest_INDEX_TABLESPACE_2", "INDEX" ); String ddlFragment = ""; // test without tablespaces not specified DatabaseMeta databaseMeta = new DatabaseMeta( OracleDatabaseXMLWithoutTablespaces ); ddlFragment = databaseMeta.getDatabaseInterface().getDataTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "" ); ddlFragment = databaseMeta.getDatabaseInterface().getIndexTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "" ); // test with tablespaces specified by value databaseMeta = new DatabaseMeta( OracleDatabaseXMLWithTablespacesAsValues ); ddlFragment = databaseMeta.getDatabaseInterface().getDataTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "TABLESPACE TABLES" ); ddlFragment = databaseMeta.getDatabaseInterface().getIndexTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "TABLESPACE INDEXES" ); // test with tablespaces specified as variables: TEST CASE 1 databaseMeta = new DatabaseMeta( OracleDatabaseXMLWithTablespacesAsVariables ); ddlFragment = databaseMeta.getDatabaseInterface().getDataTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "TABLESPACE TABLES" ); ddlFragment = databaseMeta.getDatabaseInterface().getIndexTablespaceDDL( transMeta, databaseMeta ); assertEquals( ddlFragment, "TABLESPACE INDEXES" ); } catch ( Exception e ) { e.printStackTrace(); } }
Example 10
Source File: TimedTransRunner.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public boolean runEngine( boolean printDescription ) throws KettleException { System.gc(); KettleEnvironment.init(); transMeta = new TransMeta( filename ); transMeta.setVariable( "NR_OF_ROWS", Long.toString( records ) ); if ( printDescription ) { printTransDescription(); } // Replace the TARGET database connection settings with the one provided if ( targetDatabaseMeta != null ) { transMeta.addOrReplaceDatabase( targetDatabaseMeta ); } // OK, now run this transFormation. Trans trans = new Trans( transMeta ); trans.setLogLevel( logLevel ); try { trans.prepareExecution( null ); } catch ( Exception e ) { System.err.println( KettleLogStore.getAppender().getBuffer( trans.getLogChannelId(), true ) ); trans.getLogChannel().logError( "Error preparing / initializing transformation", e ); return false; } if ( !Utils.isEmpty( rowListenerStep ) ) { StepInterface step = trans.findRunThread( rowListenerStep ); if ( step != null ) { step.addRowListener( rowListener ); } } long startTime = System.currentTimeMillis(); trans.startThreads(); trans.waitUntilFinished(); long stopTime = System.currentTimeMillis(); result = trans.getResult(); runTime = (double) ( stopTime - startTime ) / 1000; speed = records / ( runTime ); printStats( "V3 results", records, runTime, speed ); return true; }
Example 11
Source File: JobEntryTransTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void testGetTransMeta() throws KettleException { String param1 = "param1"; String param2 = "param2"; String param3 = "param3"; String parentValue1 = "parentValue1"; String parentValue2 = "parentValue2"; String childValue3 = "childValue3"; JobEntryTrans jobEntryTrans = spy( getJobEntryTrans() ); Repository rep = Mockito.mock( Repository.class ); RepositoryDirectory repositoryDirectory = Mockito.mock( RepositoryDirectory.class ); RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock( RepositoryDirectoryInterface.class ); Mockito.doReturn( repositoryDirectoryInterface ).when( rep ).loadRepositoryDirectoryTree(); Mockito.doReturn( repositoryDirectory ).when( repositoryDirectoryInterface ).findDirectory( "/home/admin" ); TransMeta meta = new TransMeta(); meta.setVariable( param2, "childValue2 should be override" ); meta.setVariable( param3, childValue3 ); Mockito.doReturn( meta ).when( rep ) .loadTransformation( Mockito.eq( "test.ktr" ), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyBoolean(), Mockito.anyObject() ); VariableSpace parentSpace = new Variables(); parentSpace.setVariable( param1, parentValue1 ); parentSpace.setVariable( param2, parentValue2 ); jobEntryTrans.setFileName( "/home/admin/test.ktr" ); Mockito.doNothing().when( jobEntryTrans ).logBasic( Mockito.anyString() ); jobEntryTrans.setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); TransMeta transMeta; jobEntryTrans.setPassingAllParameters( false ); transMeta = jobEntryTrans.getTransMeta( rep, null, parentSpace ); Assert.assertEquals( null, transMeta.getVariable( param1 ) ); Assert.assertEquals( parentValue2, transMeta.getVariable( param2 ) ); Assert.assertEquals( childValue3, transMeta.getVariable( param3 ) ); jobEntryTrans.setPassingAllParameters( true ); transMeta = jobEntryTrans.getTransMeta( rep, null, parentSpace ); Assert.assertEquals( parentValue1, transMeta.getVariable( param1 ) ); Assert.assertEquals( parentValue2, transMeta.getVariable( param2 ) ); Assert.assertEquals( childValue3, transMeta.getVariable( param3 ) ); }
Example 12
Source File: JobEntryTransTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void testGetTransMetaRepo() throws KettleException { String param1 = "dir"; String param2 = "file"; String parentValue1 = "/home/admin"; String parentValue2 = "test"; JobEntryTrans jobEntryTrans = spy( getJobEntryTrans() ); Repository rep = Mockito.mock( Repository.class ); RepositoryDirectory repositoryDirectory = Mockito.mock( RepositoryDirectory.class ); RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock( RepositoryDirectoryInterface.class ); Mockito.doReturn( repositoryDirectoryInterface ).when( rep ).loadRepositoryDirectoryTree(); Mockito.doReturn( repositoryDirectory ).when( repositoryDirectoryInterface ).findDirectory( parentValue1 ); TransMeta meta = new TransMeta(); meta.setVariable( param2, "childValue2 should be override" ); Mockito.doReturn( meta ).when( rep ) .loadTransformation( Mockito.eq( "test" ), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyBoolean(), Mockito.anyObject() ); VariableSpace parentSpace = new Variables(); parentSpace.setVariable( param1, parentValue1 ); parentSpace.setVariable( param2, parentValue2 ); jobEntryTrans.setDirectory( "${dir}" ); jobEntryTrans.setTransname( "${file}" ); Mockito.doNothing().when( jobEntryTrans ).logBasic( Mockito.anyString() ); jobEntryTrans.setSpecificationMethod( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME ); TransMeta transMeta; jobEntryTrans.setPassingAllParameters( false ); transMeta = jobEntryTrans.getTransMeta( rep, null, parentSpace ); Assert.assertEquals( null, transMeta.getVariable( param1 ) ); Assert.assertEquals( parentValue2, transMeta.getVariable( param2 ) ); jobEntryTrans.setPassingAllParameters( true ); transMeta = jobEntryTrans.getTransMeta( rep, null, parentSpace ); Assert.assertEquals( parentValue1, transMeta.getVariable( param1 ) ); Assert.assertEquals( parentValue2, transMeta.getVariable( param2 ) ); }