Java Code Examples for org.pentaho.di.trans.TransMeta#setMetaStore()
The following examples show how to use
org.pentaho.di.trans.TransMeta#setMetaStore() .
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: RunBeamTransExecutionPoint.java From kettle-beam with Apache License 2.0 | 6 votes |
private TransMeta copyCleanTransMeta( TransMeta transMeta, Repository repository, IMetaStore metaStore, VariableSpace space ) throws KettleException { try { String transMetaXml = transMeta.getXML(); TransMeta copy = new TransMeta(); copy.setMetaStore( metaStore ); copy.loadXML( XMLHandler.loadXMLString( transMetaXml, TransMeta.XML_TAG ), null, metaStore, repository, true, space, null ); for ( StepMeta stepMeta : copy.getSteps() ) { stepMeta.setCopies( 1 ); DummyTransMeta dummyTransMeta = new DummyTransMeta(); // Replace all stepMeta with a Dummy with the same name // stepMeta.setStepID( "Dummy" ); stepMeta.setStepMetaInterface( dummyTransMeta ); } return copy; } catch ( Exception e ) { throw new KettleException( "Error copying/cleaning transformation metadata", e ); } }
Example 2
Source File: KettleFileRepository.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public TransMeta loadTransformation( String transname, RepositoryDirectoryInterface repdir, ProgressMonitorListener monitor, boolean setInternalVariables, String versionName ) throws KettleException { // This is a standard load of a transformation serialized in XML... // String filename = calcDirectoryName( repdir ) + transname + ".ktr"; TransMeta transMeta = new TransMeta( filename, this, setInternalVariables ); transMeta.setRepository( this ); transMeta.setMetaStore( getMetaStore() ); transMeta.setFilename( null ); transMeta.setName( transname ); transMeta.setObjectId( new StringObjectId( calcObjectId( repdir, transname, EXT_TRANSFORMATION ) ) ); readDatabases( transMeta, true ); transMeta.clearChanged(); return transMeta; }
Example 3
Source File: PurRepository.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private TransMeta buildTransMeta( final RepositoryFile file, final RepositoryDirectoryInterface parentDir, final NodeRepositoryFileData data, final ObjectRevision revision ) throws KettleException { TransMeta transMeta = new TransMeta(); transMeta.setName( file.getTitle() ); transMeta.setFilename( file.getName() ); transMeta.setDescription( file.getDescription() ); transMeta.setObjectId( new StringObjectId( file.getId().toString() ) ); transMeta.setObjectRevision( revision ); transMeta.setRepository( this ); transMeta.setRepositoryDirectory( parentDir ); transMeta.setMetaStore( getMetaStore() ); readTransSharedObjects( transMeta ); // This should read from the local cache transDelegate.dataNodeToElement( data.getNode(), transMeta ); transMeta.clearChanged(); return transMeta; }
Example 4
Source File: MainBeam.java From kettle-beam with Apache License 2.0 | 4 votes |
public static final int mainMethod( final String[] args, final String environment ) { try { System.out.println( "Starting clustered transformation execution on environment: '"+environment+"'" ); System.out.println( "Transformation ktr / args[0] : " + args[ 0 ] ); System.out.println( "MetaStore JSON / args[1] : " + args[ 1 ] ); System.out.println( "Beam Job Config / args[2] : " + args[ 2 ] ); // Read the transformation XML and MetaStore from Hadoop FS // Configuration hadoopConfiguration = new Configuration(); String transMetaXml = readFileIntoString( args[ 0 ], hadoopConfiguration, "UTF-8" ); String metaStoreJson = readFileIntoString( args[ 1 ], hadoopConfiguration, "UTF-8" ); // Third argument: the beam job config // String jobConfigName = args[ 2 ]; // Inflate the metaStore... // IMetaStore metaStore = new SerializableMetaStore( metaStoreJson ); System.out.println( ">>>>>> Loading Kettle Beam Job Config '" + jobConfigName + "'" ); MetaStoreFactory<BeamJobConfig> configFactory = new MetaStoreFactory<>( BeamJobConfig.class, metaStore, PentahoDefaults.NAMESPACE ); BeamJobConfig jobConfig = configFactory.loadElement( jobConfigName ); List<String> stepPluginsList = new ArrayList<>( Arrays.asList( Const.NVL(jobConfig.getStepPluginClasses(), "").split( "," ) ) ); List<String> xpPluginsList = new ArrayList<>( Arrays.asList( Const.NVL(jobConfig.getXpPluginClasses(), "").split( "," ) ) ); System.out.println( ">>>>>> Initializing Kettle runtime (" + stepPluginsList.size() + " step classes, " + xpPluginsList.size() + " XP classes)" ); BeamKettle.init( stepPluginsList, xpPluginsList ); System.out.println( ">>>>>> Loading transformation metadata" ); TransMeta transMeta = new TransMeta( XMLHandler.loadXMLString( transMetaXml, TransMeta.XML_TAG ), null ); transMeta.setMetaStore( metaStore ); String hadoopConfDir = System.getenv( "HADOOP_CONF_DIR" ); System.out.println( ">>>>>> HADOOP_CONF_DIR='" + hadoopConfDir + "'" ); System.out.println( ">>>>>> Building Apache Beam Kettle Pipeline..." ); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface beamInputPlugin = registry.getPlugin( StepPluginType.class, BeamConst.STRING_BEAM_INPUT_PLUGIN_ID ); if ( beamInputPlugin != null ) { System.out.println( ">>>>>> Found Beam Input step plugin class loader" ); } else { throw new KettleException( "Unable to find Beam Input step plugin, bailing out!" ); } ClassLoader pluginClassLoader = PluginRegistry.getInstance().getClassLoader( beamInputPlugin ); if ( pluginClassLoader != null ) { System.out.println( ">>>>>> Found Beam Input step plugin class loader" ); } else { System.out.println( ">>>>>> NOT found Beam Input step plugin class loader, using system classloader" ); pluginClassLoader = ClassLoader.getSystemClassLoader(); } KettleBeamPipelineExecutor executor = new KettleBeamPipelineExecutor( LogChannel.GENERAL, transMeta, jobConfig, metaStore, pluginClassLoader, stepPluginsList, xpPluginsList ); System.out.println( ">>>>>> Pipeline executing starting..." ); executor.setLoggingMetrics( true ); executor.execute( true ); System.out.println( ">>>>>> Execution finished..." ); return 0; } catch ( Exception e ) { System.err.println( "Error running Beam pipeline on '"+environment+"': " + e.getMessage() ); e.printStackTrace(); return 1; } }
Example 5
Source File: BeamTransMetaUtil.java From kettle-beam with Apache License 2.0 | 4 votes |
public static final TransMeta generateBeamInputOutputTransMeta( String transname, String inputStepname, String outputStepname, IMetaStore metaStore ) throws Exception { MetaStoreFactory<FileDefinition> factory = new MetaStoreFactory<>( FileDefinition.class, metaStore, PentahoDefaults.NAMESPACE ); FileDefinition customerFileDefinition = createCustomersInputFileDefinition(); factory.saveElement( customerFileDefinition ); TransMeta transMeta = new TransMeta( ); transMeta.setName( transname ); transMeta.setMetaStore( metaStore ); // Add the io step // BeamInputMeta beamInputMeta = new BeamInputMeta(); beamInputMeta.setInputLocation( "/tmp/customers/io/customers-100.txt" ); beamInputMeta.setFileDescriptionName( customerFileDefinition.getName() ); StepMeta beamInputStepMeta = new StepMeta(inputStepname, beamInputMeta); beamInputStepMeta.setStepID( "BeamInput" ); transMeta.addStep( beamInputStepMeta ); // Add a dummy in between to get started... // DummyTransMeta dummyTransMeta = new DummyTransMeta(); StepMeta dummyStepMeta = new StepMeta("Dummy", dummyTransMeta); transMeta.addStep( dummyStepMeta ); transMeta.addTransHop(new TransHopMeta( beamInputStepMeta, dummyStepMeta ) ); // Add the output step // BeamOutputMeta beamOutputMeta = new BeamOutputMeta(); beamOutputMeta.setOutputLocation( "/tmp/customers/output/" ); beamOutputMeta.setFileDescriptionName( null ); beamOutputMeta.setFilePrefix( "customers" ); beamOutputMeta.setFileSuffix( ".csv" ); beamOutputMeta.setWindowed( false ); // Not yet supported StepMeta beamOutputStepMeta = new StepMeta(outputStepname, beamOutputMeta); beamOutputStepMeta.setStepID( "BeamOutput" ); transMeta.addStep( beamOutputStepMeta ); transMeta.addTransHop(new TransHopMeta( dummyStepMeta, beamOutputStepMeta ) ); return transMeta; }
Example 6
Source File: BeamTransMetaUtil.java From kettle-beam with Apache License 2.0 | 4 votes |
public static final TransMeta generateBeamGroupByTransMeta( String transname, String inputStepname, String outputStepname, IMetaStore metaStore ) throws Exception { MetaStoreFactory<FileDefinition> factory = new MetaStoreFactory<>( FileDefinition.class, metaStore, PentahoDefaults.NAMESPACE ); FileDefinition customerFileDefinition = createCustomersInputFileDefinition(); factory.saveElement( customerFileDefinition ); TransMeta transMeta = new TransMeta( ); transMeta.setName( transname ); transMeta.setMetaStore( metaStore ); // Add the io step // BeamInputMeta beamInputMeta = new BeamInputMeta(); beamInputMeta.setInputLocation( "/tmp/customers/io/customers-100.txt" ); beamInputMeta.setFileDescriptionName( customerFileDefinition.getName() ); StepMeta beamInputStepMeta = new StepMeta(inputStepname, beamInputMeta); beamInputStepMeta.setStepID( BeamConst.STRING_BEAM_INPUT_PLUGIN_ID ); transMeta.addStep( beamInputStepMeta ); // Add a dummy in between to get started... // MemoryGroupByMeta memoryGroupByMeta = new MemoryGroupByMeta(); memoryGroupByMeta.allocate(1, 2 ); memoryGroupByMeta.getGroupField()[0] = "state"; // count(id) memoryGroupByMeta.getAggregateField()[0] = "nrIds"; memoryGroupByMeta.getSubjectField()[0] = "id"; memoryGroupByMeta.getAggregateType()[0] = MemoryGroupByMeta.TYPE_GROUP_COUNT_ALL; // sum(id) memoryGroupByMeta.getAggregateField()[1] = "sumIds"; memoryGroupByMeta.getSubjectField()[1] = "id"; memoryGroupByMeta.getAggregateType()[1] = MemoryGroupByMeta.TYPE_GROUP_SUM; StepMeta memoryGroupByStepMeta = new StepMeta("Group By", memoryGroupByMeta); transMeta.addStep( memoryGroupByStepMeta ); transMeta.addTransHop(new TransHopMeta( beamInputStepMeta, memoryGroupByStepMeta ) ); // Add the output step // BeamOutputMeta beamOutputMeta = new BeamOutputMeta(); beamOutputMeta.setOutputLocation( "/tmp/customers/output/" ); beamOutputMeta.setFileDescriptionName( null ); beamOutputMeta.setFilePrefix( "grouped" ); beamOutputMeta.setFileSuffix( ".csv" ); beamOutputMeta.setWindowed( false ); // Not yet supported StepMeta beamOutputStepMeta = new StepMeta(outputStepname, beamOutputMeta); beamOutputStepMeta.setStepID( "BeamOutput" ); transMeta.addStep( beamOutputStepMeta ); transMeta.addTransHop(new TransHopMeta( memoryGroupByStepMeta, beamOutputStepMeta ) ); return transMeta; }
Example 7
Source File: BeamTransMetaUtil.java From kettle-beam with Apache License 2.0 | 4 votes |
public static final TransMeta generateFilterRowsTransMeta( String transname, String inputStepname, String outputStepname, IMetaStore metaStore ) throws Exception { MetaStoreFactory<FileDefinition> factory = new MetaStoreFactory<>( FileDefinition.class, metaStore, PentahoDefaults.NAMESPACE ); FileDefinition customerFileDefinition = createCustomersInputFileDefinition(); factory.saveElement( customerFileDefinition ); TransMeta transMeta = new TransMeta( ); transMeta.setName( transname ); transMeta.setMetaStore( metaStore ); // Add the io step // BeamInputMeta beamInputMeta = new BeamInputMeta(); beamInputMeta.setInputLocation( "/tmp/customers/io/customers-100.txt" ); beamInputMeta.setFileDescriptionName( customerFileDefinition.getName() ); StepMeta beamInputStepMeta = new StepMeta(inputStepname, beamInputMeta); beamInputStepMeta.setStepID( BeamConst.STRING_BEAM_INPUT_PLUGIN_ID ); transMeta.addStep( beamInputStepMeta ); // Add 2 add constants steps A and B // ConstantMeta constantA = new ConstantMeta(); constantA.allocate( 1 ); constantA.getFieldName()[0]="label"; constantA.getFieldType()[0]="String"; constantA.getValue()[0]="< 'k'"; StepMeta constantAMeta = new StepMeta("A", constantA); transMeta.addStep(constantAMeta); ConstantMeta constantB = new ConstantMeta(); constantB.allocate( 1 ); constantB.getFieldName()[0]="label"; constantB.getFieldType()[0]="String"; constantB.getValue()[0]=">= 'k'"; StepMeta constantBMeta = new StepMeta("B", constantB); transMeta.addStep(constantBMeta); // Add Filter rows step looking for customers name > "k" // Send rows to A (true) and B (false) // FilterRowsMeta filter = new FilterRowsMeta(); filter.getCondition().setLeftValuename( "name" ); filter.getCondition().setFunction( Condition.FUNC_SMALLER ); filter.getCondition().setRightExact( new ValueMetaAndData( "value", "k" ) ); filter.setTrueStepname( "A" ); filter.setFalseStepname( "B" ); StepMeta filterMeta = new StepMeta("Filter", filter); transMeta.addStep( filterMeta ); transMeta.addTransHop( new TransHopMeta( beamInputStepMeta, filterMeta ) ); transMeta.addTransHop( new TransHopMeta( filterMeta, constantAMeta ) ); transMeta.addTransHop( new TransHopMeta( filterMeta, constantBMeta ) ); // Add a dummy behind it all to flatten/merge the data again... // DummyTransMeta dummyTransMeta = new DummyTransMeta(); StepMeta dummyStepMeta = new StepMeta("Flatten", dummyTransMeta); transMeta.addStep( dummyStepMeta ); transMeta.addTransHop(new TransHopMeta( constantAMeta, dummyStepMeta ) ); transMeta.addTransHop(new TransHopMeta( constantBMeta, dummyStepMeta ) ); // Add the output step // BeamOutputMeta beamOutputMeta = new BeamOutputMeta(); beamOutputMeta.setOutputLocation( "/tmp/customers/output/" ); beamOutputMeta.setFileDescriptionName( null ); beamOutputMeta.setFilePrefix( "filter-test" ); beamOutputMeta.setFileSuffix( ".csv" ); beamOutputMeta.setWindowed( false ); // Not yet supported StepMeta beamOutputStepMeta = new StepMeta(outputStepname, beamOutputMeta); beamOutputStepMeta.setStepID( "BeamOutput" ); transMeta.addStep( beamOutputStepMeta ); transMeta.addTransHop(new TransHopMeta( dummyStepMeta, beamOutputStepMeta ) ); return transMeta; }
Example 8
Source File: BeamTransMetaUtil.java From kettle-beam with Apache License 2.0 | 4 votes |
public static final TransMeta generateStreamLookupTransMeta( String transname, String inputStepname, String outputStepname, IMetaStore metaStore ) throws Exception { MetaStoreFactory<FileDefinition> factory = new MetaStoreFactory<>( FileDefinition.class, metaStore, PentahoDefaults.NAMESPACE ); FileDefinition customerFileDefinition = createCustomersInputFileDefinition(); factory.saveElement( customerFileDefinition ); TransMeta transMeta = new TransMeta( ); transMeta.setName( transname ); transMeta.setMetaStore( metaStore ); // Add the main io step // BeamInputMeta beamInputMeta = new BeamInputMeta(); beamInputMeta.setInputLocation( "/tmp/customers/io/customers-100.txt" ); beamInputMeta.setFileDescriptionName( customerFileDefinition.getName() ); StepMeta beamInputStepMeta = new StepMeta(inputStepname, beamInputMeta); beamInputStepMeta.setStepID( BeamConst.STRING_BEAM_INPUT_PLUGIN_ID ); transMeta.addStep( beamInputStepMeta ); StepMeta lookupBeamInputStepMeta = beamInputStepMeta; // Add a Memory Group By step which will MemoryGroupByMeta memoryGroupByMeta = new MemoryGroupByMeta(); memoryGroupByMeta.allocate( 1, 1 ); memoryGroupByMeta.getGroupField()[0] = "stateCode"; memoryGroupByMeta.getAggregateType()[0] = MemoryGroupByMeta.TYPE_GROUP_COUNT_ALL; memoryGroupByMeta.getAggregateField()[0] = "rowsPerState"; memoryGroupByMeta.getSubjectField()[0] = "id"; StepMeta memoryGroupByStepMeta = new StepMeta("rowsPerState", memoryGroupByMeta); transMeta.addStep( memoryGroupByStepMeta ); transMeta.addTransHop( new TransHopMeta( lookupBeamInputStepMeta, memoryGroupByStepMeta ) ); // Add a Stream Lookup step ... // StreamLookupMeta streamLookupMeta = new StreamLookupMeta(); streamLookupMeta.allocate( 1, 1 ); streamLookupMeta.getKeystream()[0] = "stateCode"; streamLookupMeta.getKeylookup()[0] = "stateCode"; streamLookupMeta.getValue()[0] = "rowsPerState"; streamLookupMeta.getValueName()[0] = "nrPerState"; streamLookupMeta.getValueDefault()[0] = null; streamLookupMeta.getValueDefaultType()[0] = ValueMetaInterface.TYPE_INTEGER; streamLookupMeta.setMemoryPreservationActive( false ); streamLookupMeta.getStepIOMeta().getInfoStreams().get(0).setStepMeta( memoryGroupByStepMeta ); // Read from Mem.GroupBy StepMeta streamLookupStepMeta = new StepMeta("Stream Lookup", streamLookupMeta); transMeta.addStep(streamLookupStepMeta); transMeta.addTransHop( new TransHopMeta( beamInputStepMeta, streamLookupStepMeta ) ); // Main io transMeta.addTransHop( new TransHopMeta( memoryGroupByStepMeta, streamLookupStepMeta ) ); // info stream // Add the output step to write results // BeamOutputMeta beamOutputMeta = new BeamOutputMeta(); beamOutputMeta.setOutputLocation( "/tmp/customers/output/" ); beamOutputMeta.setFileDescriptionName( null ); beamOutputMeta.setFilePrefix( "stream-lookup" ); beamOutputMeta.setFileSuffix( ".csv" ); beamOutputMeta.setWindowed( false ); // Not yet supported StepMeta beamOutputStepMeta = new StepMeta(outputStepname, beamOutputMeta); beamOutputStepMeta.setStepID( "BeamOutput" ); transMeta.addStep( beamOutputStepMeta ); transMeta.addTransHop(new TransHopMeta( streamLookupStepMeta, beamOutputStepMeta ) ); return transMeta; }
Example 9
Source File: BeamTransMetaUtil.java From kettle-beam with Apache License 2.0 | 4 votes |
public static final TransMeta generateMergeJoinTransMeta( String transname, String inputStepname, String outputStepname, IMetaStore metaStore ) throws Exception { MetaStoreFactory<FileDefinition> factory = new MetaStoreFactory<>( FileDefinition.class, metaStore, PentahoDefaults.NAMESPACE ); FileDefinition customerFileDefinition = createCustomersInputFileDefinition(); factory.saveElement( customerFileDefinition ); FileDefinition statePopulationFileDefinition = createStatePopulationInputFileDefinition(); factory.saveElement( statePopulationFileDefinition ); TransMeta transMeta = new TransMeta( ); transMeta.setName( transname ); transMeta.setMetaStore( metaStore ); // Add the left io step // BeamInputMeta leftInputMeta = new BeamInputMeta(); leftInputMeta.setInputLocation( "/tmp/customers/io/customers-100.txt" ); leftInputMeta.setFileDescriptionName( customerFileDefinition.getName() ); StepMeta leftInputStepMeta = new StepMeta(inputStepname+" Left", leftInputMeta); leftInputStepMeta.setStepID( BeamConst.STRING_BEAM_INPUT_PLUGIN_ID ); transMeta.addStep( leftInputStepMeta ); BeamInputMeta rightInputMeta = new BeamInputMeta(); rightInputMeta.setInputLocation( "/tmp/customers/io/state-data.txt" ); rightInputMeta.setFileDescriptionName( statePopulationFileDefinition.getName() ); StepMeta rightInputStepMeta = new StepMeta(inputStepname+" Right", rightInputMeta); rightInputStepMeta.setStepID( BeamConst.STRING_BEAM_INPUT_PLUGIN_ID ); transMeta.addStep( rightInputStepMeta ); // Add a Merge Join step // MergeJoinMeta mergeJoin = new MergeJoinMeta(); mergeJoin.allocate( 1, 1 ); mergeJoin.getKeyFields1()[0] = "state"; mergeJoin.getKeyFields2()[0] = "state"; mergeJoin.setJoinType(MergeJoinMeta.join_types[3] ); // FULL OUTER mergeJoin.getStepIOMeta().getInfoStreams().get(0).setStepMeta( leftInputStepMeta ); mergeJoin.getStepIOMeta().getInfoStreams().get(1).setStepMeta( rightInputStepMeta ); StepMeta mergeJoinStepMeta = new StepMeta("Merge Join", mergeJoin); transMeta.addStep( mergeJoinStepMeta ); transMeta.addTransHop( new TransHopMeta( leftInputStepMeta, mergeJoinStepMeta ) ); transMeta.addTransHop( new TransHopMeta( rightInputStepMeta, mergeJoinStepMeta ) ); // Add the output step to write results // BeamOutputMeta beamOutputMeta = new BeamOutputMeta(); beamOutputMeta.setOutputLocation( "/tmp/customers/output/" ); beamOutputMeta.setFileDescriptionName( null ); beamOutputMeta.setFilePrefix( "merge-join" ); beamOutputMeta.setFileSuffix( ".csv" ); beamOutputMeta.setWindowed( false ); // Not yet supported StepMeta beamOutputStepMeta = new StepMeta(outputStepname, beamOutputMeta); beamOutputStepMeta.setStepID( "BeamOutput" ); transMeta.addStep( beamOutputStepMeta ); transMeta.addTransHop(new TransHopMeta( mergeJoinStepMeta, beamOutputStepMeta ) ); return transMeta; }