当前位置: 首页>>代码示例>>Java>>正文


Java Variables.setVariable方法代码示例

本文整理汇总了Java中org.pentaho.di.core.variables.Variables.setVariable方法的典型用法代码示例。如果您正苦于以下问题:Java Variables.setVariable方法的具体用法?Java Variables.setVariable怎么用?Java Variables.setVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.pentaho.di.core.variables.Variables的用法示例。


在下文中一共展示了Variables.setVariable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testVariableCondition

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testVariableCondition() throws KettleException {
  Variables varSpace = new Variables();
  varSpace.setVariable( "myVarCondition", realCondition );

  JavaFilterMeta meta = new JavaFilterMeta();
  meta.setCondition( "${myVarCondition}" );

  TransMeta trans = TransTestFactory.generateTestTransformation( varSpace, meta, stepName );
  List<RowMetaAndData> input = getInputData();

  List<RowMetaAndData> result = TransTestFactory.executeTestTransformation( trans,
    TransTestFactory.INJECTOR_STEPNAME, stepName, TransTestFactory.DUMMY_STEPNAME, input );

  //Only the "Car" row should be returned, based upon the Java Filter condition
  assertTrue( result.size() == 1 );
  assertTrue( result.get( 0 ).getString( fieldName, null ).equals( "Car" ) );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:19,代码来源:JavaFilterIT.java

示例2: testFilterVariables

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testFilterVariables() throws Exception {

  initByFile( "default.csv" );

  Variables vars = new Variables();
  vars.setVariable( "VAR_TEST", "second" );
  data.filterProcessor =
      new TextFileFilterProcessor( new TextFileFilter[] { new TextFileFilter( 0, "${VAR_TEST}", false, false ) },
          vars );
  setFields( new BaseFileField( "f1", -1, -1 ), new BaseFileField( "f2", -1, -1 ),
    new BaseFileField( "f2", -1, -1 ) );

  process();

  check( new Object[][] { { "first", "1", "1.1" }, { "third", "3", "3.3" } } );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:18,代码来源:TextFileInputContentParsingTest.java

示例3: testParameterFolderName

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testParameterFolderName() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ ".*" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Create a file that will be found in the GetFileNames step
  String expectedFilename = "PDI14800_test.tmp";
  tempFolder.newFile( expectedFilename );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 1, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedFilename, result.get( 0 ).getString( "short_filename", "failure" ) );
  
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:38,代码来源:GetFileNamesIntIT.java

示例4: resolveCurrentDirectory

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
public VariableSpace resolveCurrentDirectory( VariableSpace parentVariables, RepositoryDirectoryInterface directory,
    String filename ) {
  Variables tmpSpace = new Variables();
  tmpSpace.setParentVariableSpace( parentVariables );
  tmpSpace.initializeVariablesFrom( parentVariables );

  if ( directory != null ) {
    tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, directory.toString() );
    tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, directory.toString() );
    tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, directory.toString() );
  } else if ( filename != null ) {
    try {
      FileObject fileObject = KettleVFS.getFileObject( filename, tmpSpace );

      if ( !fileObject.exists() ) {
        // don't set variables if the file doesn't exist
        return tmpSpace;
      }

      FileName fileName = fileObject.getName();

      // The filename of the transformation
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() );

      // The directory of the transformation
      FileName fileDir = fileName.getParent();
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() );
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() );
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, fileDir.getURI() );
    } catch ( Exception e ) {
    }
  }
  return tmpSpace;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:35,代码来源:CurrentDirectoryResolver.java

示例5: testCheckErrorsOnVariables

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testCheckErrorsOnVariables() {
  List<CheckResultInterface> remarks = new ArrayList<>();
  Variables space = new Variables();
  space.setVariable( "something", "1000" );
  meta.setBatchSize( "${something}" );
  meta.setBatchDuration( "0" );
  meta.check( remarks, null, null, null, null, null, null, space, null, null );
  assertEquals( 0, remarks.size() );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:11,代码来源:BaseStreamStepMetaTest.java

示例6: testCheckErrorsOnVariablesSubstituteError

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testCheckErrorsOnVariablesSubstituteError() {
  List<CheckResultInterface> remarks = new ArrayList<>();
  Variables space = new Variables();
  space.setVariable( "something", "0" );
  meta.setBatchSize( "${something}" );
  meta.setBatchDuration( "${something}" );
  meta.check( remarks, null, null, null, null, null, null, space, null, null );
  assertEquals( 1, remarks.size() );
  assertEquals( "The \"Number of records\" and \"Duration\" fields can’t both be set to 0. Please set a value of 1 "
    + "or higher for one of the fields.", remarks.get( 0 ).getText() );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:13,代码来源:BaseStreamStepMetaTest.java

示例7: testResolvePasswordVariable

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testResolvePasswordVariable() {
  String passwordKey = "PASS_VAR";
  String passwordVar = "${" + passwordKey + "}";
  String passwordValue = "password";
  Variables vars = new Variables();
  vars.setVariable( passwordKey, passwordValue );
  //resolvePassword gets variable
  assertSame( passwordValue, Utils.resolvePassword( vars, passwordVar ).intern() );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:11,代码来源:UtilsTest.java

示例8: testPDI12897

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
@Test
public void testPDI12897() throws KettleException, IOException {
  File tempOutputFile = File.createTempFile( "testPDI11374", ".cube" );
  tempOutputFile.deleteOnExit();

  String stepName = "Cube Output";
  CubeOutputMeta meta = new CubeOutputMeta();
  meta.setDefault();
  meta.setFilename( tempOutputFile.getAbsolutePath() );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, stepName );
  List<RowMetaAndData> inputList = getSampleData();
  TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
    TransTestFactory.DUMMY_STEPNAME, inputList );

  try {
    Thread.sleep( 1000 );
  } catch ( InterruptedException ignored ) {
    // Continue
  }

  // Now, check the result
  Variables varSpace = new Variables();
  varSpace.setVariable( "ROWS", "2" );

  String checkStepName = "Cube Input";
  CubeInputMeta inputMeta = new CubeInputMeta();
  inputMeta.setFilename( tempOutputFile.getAbsolutePath() );
  inputMeta.setRowLimit( "${ROWS}" );

  transMeta = TransTestFactory.generateTestTransformation( varSpace, inputMeta, checkStepName );

  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( stepName ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  inputList = new ArrayList<RowMetaAndData>();
  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
      TransTestFactory.DUMMY_STEPNAME, inputList );

  assertNotNull( result );
  assertEquals( 2, result.size() );
  assertEquals( 1, result.get( 0 ).getRowMeta().size() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 0 ).getType() );
  assertEquals( "col1", result.get( 0 ).getValueMeta( 0 ).getName() );
  assertEquals( "data1", result.get( 0 ).getString( 0, "fail" ) );
  assertEquals( "data2", result.get( 1 ).getString( 0, "fail" ) );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:51,代码来源:CubeInputStepIntIT.java

示例9: reapplyCurrentDir

import org.pentaho.di.core.variables.Variables; //导入方法依赖的package包/类
private String reapplyCurrentDir( String oldCurrentDir, String newCurrentDir, String path ) {
  Variables vars = new Variables();
  vars.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, oldCurrentDir );
  String newPath = vars.environmentSubstitute( path );
  return getPath( newCurrentDir, newPath );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:7,代码来源:EntryCurrentDirectoryChangedListener.java


注:本文中的org.pentaho.di.core.variables.Variables.setVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。