org.pentaho.di.core.variables.Variables类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.pentaho.di.core.variables.Variables类的一些代码示例,展示了Variables类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables类的具体详情如下:
包路径:org.pentaho.di.core.variables.Variables
类名称:Variables

Variables介绍

[英]This class is an implementation of VariableSpace
[中]这个类是VariableSpace的一个实现

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Please supply real namespace as it is required for proper VFS operation
 */
@Deprecated
public FTPSConnection( int connectionType, String hostname, int port, String username, String password ) {
 this( connectionType, hostname, port, username, password, new Variables() );
}

代码示例来源:origin: pentaho/pentaho-kettle

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 );
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setAuthProperties() {
 Variables variables = new Variables();
 variables.initializeVariablesFrom( null );
 this.principal = variables.getVariable( KETTLE_AEL_PDI_DAEMON_PRINCIPAL, null );
 this.keytab = variables.getVariable( KETTLE_AEL_PDI_DAEMON_KEYTAB, null );
 String reuse = variables.getVariable( KETTLE_AEL_PDI_DAEMON_CONTEXT_REUSE, Boolean.FALSE.toString() );
 this.reuseSparkContext =
  Boolean.TRUE.toString().equals( reuse.toLowerCase() ) || Y_LWC.equals( reuse.toLowerCase() );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * @return new var space with follow vars from parent space or just new space if parent was null
 * 
 * {@link org.pentaho.di.core.Const#INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY}
 * {@link org.pentaho.di.core.Const#INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY}
 * {@link org.pentaho.di.core.Const#INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY}
 * {@link org.pentaho.di.core.Const#INTERNAL_VARIABLE_JOB_FILENAME_NAME}
 */
private static VariableSpace getVarSpaceOnlyWithRequiredParentVars( VariableSpace parentSpace ) {
 Variables tmpSpace = new Variables();
 if ( parentSpace != null ) {
  tmpSpace.setVariable( INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, parentSpace.getVariable( INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) );
  tmpSpace.setVariable( INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, parentSpace.getVariable( INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY ) );
  tmpSpace.setVariable( INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, parentSpace.getVariable( INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY ) );
  tmpSpace.setVariable( INTERNAL_VARIABLE_JOB_FILENAME_NAME, parentSpace.getVariable( INTERNAL_VARIABLE_JOB_FILENAME_NAME ) );
 }
 return tmpSpace;
}

代码示例来源:origin: pentaho/big-data-plugin

public GatewayConnectivityTestImpl( MessageGetterFactory messageGetterFactory, URI uri, String testPath,
                  String user, String password, RuntimeTestEntrySeverity severity ) {
 super( messageGetterFactory, uri.getHost(), Integer.toString( uri.getPort() ), true,
  severity );
 // The connection information might be parameterized. Since we aren't tied to a transformation or job, in order to
 // use a parameter, the value would have to be set as a system property or in kettle.properties, etc.
 // Here we try to resolve the parameters if we can:
 variables = new Variables();
 variables.initializeVariablesFrom( null );
 this.path = variables.environmentSubstitute( testPath );
 this.password = variables.environmentSubstitute( password );
 this.user = variables.environmentSubstitute( user );
 this.uri = uri.resolve( uri.getPath() + path );
}

代码示例来源:origin: pentaho/pentaho-kettle

public static void applyKettleProperties( Map<?, ?> kettleProperties, boolean override ) {
 Variables variables = new Variables();
 for ( Object key : kettleProperties.keySet() ) {
  String variable = (String) key;
  String value = variables.environmentSubstitute( (String) kettleProperties.get( key ) );
  variables.setVariable( variable, value );
 for ( String variable : variables.listVariables() ) {
  String value = variables.getVariable( variable );

代码示例来源:origin: pentaho/pentaho-kettle

Variables tmpSpace = new Variables();
tmpSpace.setParentVariableSpace( parentVariables );
tmpSpace.initializeVariablesFrom( parentVariables );
 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 {
  tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() );
  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 ) {

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Creates the appropriate trans.  Either
 * 1)  A {@link TransWebSocketEngineAdapter} wrapping an Engine
 * if an alternate execution engine has been selected
 * 2)  A legacy {@link Trans} otherwise.
 */
public Trans get() {
 if ( Utils.isEmpty( transMeta.getVariable( "engine" ) ) ) {
  log.logBasic( "Using legacy execution engine" );
  return fallbackSupplier.get();
 }
 Variables variables = new Variables();
 variables.initializeVariablesFrom( null );
 String protocol = transMeta.getVariable( "engine.protocol" );
 String host = transMeta.getVariable( "engine.host" );
 String port = transMeta.getVariable( "engine.port" );
 //default value for ssl for now false
 boolean ssl = "https".equalsIgnoreCase( protocol ) || "wss".equalsIgnoreCase( protocol );
 return new TransWebSocketEngineAdapter( transMeta, host, port, ssl );
}

代码示例来源:origin: pentaho/pentaho-kettle

public void getUsedVariables( TransMeta transMeta ) {
 Properties sp = new Properties();
 VariableSpace space = Variables.getADefaultVariableSpace();
 String[] keys = space.listVariables();
 for ( int i = 0; i < keys.length; i++ ) {
  sp.put( keys[i], space.getVariable( keys[i] ) );
 }
 List<String> vars = transMeta.getUsedVariables();
 if ( vars != null && vars.size() > 0 ) {
  HashMap<String, String> newVariables = new HashMap<String, String>();
  for ( int i = 0; i < vars.size(); i++ ) {
   String varname = vars.get( i );
   if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) {
    newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) );
   }
  }
  // variables.clear();
  variables.putAll( newVariables );
 }
 // Also add the internal job variables if these are set...
 //
 for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) {
  String value = transMeta.getVariable( variableName );
  if ( !Utils.isEmpty( value ) ) {
   variables.put( variableName, value );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public String[] environmentSubstitute( String[] string ) {
 String[] retval = new String[string.length];
 for ( int i = 0; i < string.length; i++ ) {
  retval[i] = environmentSubstitute( string[i] );
 }
 return retval;
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void testPassEmbeddedMetastoreKey() {
 Variables mockVariables = mock( Variables.class );
 namedClusterEmbedManager.passEmbeddedMetastoreKey( mockVariables, "key" );
 verify( mockVariables ).setVariable( anyString(), anyString() );
}

代码示例来源:origin: pentaho/big-data-plugin

public ConnectivityTestImpl( MessageGetterFactory messageGetterFactory, String hostname, String port,
               boolean haPossible,
               RuntimeTestEntrySeverity severityOfFailures, SocketFactory socketFactory,
               InetAddressFactory inetAddressFactory ) {
 this.messageGetter = messageGetterFactory.create( PKG );
 // The connection information might be parameterized. Since we aren't tied to a transformation or job, in order to
 // use a parameter, the value would have to be set as a system property or in kettle.properties, etc.
 // Here we try to resolve the parameters if we can:
 Variables variables = new Variables();
 variables.initializeVariablesFrom( null );
 this.hostname = variables.environmentSubstitute( hostname );
 this.port = variables.environmentSubstitute( port );
 this.haPossible = haPossible;
 this.severityOfFalures = severityOfFailures;
 this.socketFactory = socketFactory;
 this.inetAddressFactory = inetAddressFactory;
}

代码示例来源:origin: pentaho/pentaho-kettle

@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() );
}

代码示例来源:origin: pentaho/big-data-plugin

@Override public RuntimeTestResultSummary runTest( Object objectUnderTest ) {
  // Safe to cast as our accepts method will only return true for named clusters
  NamedCluster namedCluster = (NamedCluster) objectUnderTest;

  // The connection information might be parameterized. Since we aren't tied to a transformation or job, in order to
  // use a parameter, the value would have to be set as a system property or in kettle.properties, etc.
  // Here we try to resolve the parameters if we can:
  Variables variables = new Variables();
  variables.initializeVariablesFrom( null );

  if ( !namedCluster.isUseGateway()  ) {
   return super.runTest( objectUnderTest );
  } else {
   return new RuntimeTestResultSummaryImpl(
    new ClusterRuntimeTestEntry( RuntimeTestEntrySeverity.SKIPPED,
     messageGetter.getMessage( GATEWAY_PING_ZOOKEEPER_NOT_SUPPORT_DESC ),
     messageGetter.getMessage( GATEWAY_PING_ZOOKEEPER_NOT_SUPPORT_MESSAGE ), null
    )
   );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public void getUsedVariables( JobMeta jobMeta ) {
 Properties sp = new Properties();
 VariableSpace space = Variables.getADefaultVariableSpace();
 String[] keys = space.listVariables();
 for ( int i = 0; i < keys.length; i++ ) {
  sp.put( keys[i], space.getVariable( keys[i] ) );
 }
 List<String> vars = jobMeta.getUsedVariables();
 if ( vars != null && vars.size() > 0 ) {
  HashMap<String, String> newVariables = new HashMap<String, String>();
  for ( int i = 0; i < vars.size(); i++ ) {
   String varname = vars.get( i );
   if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) {
    // add all new non-internal variables to newVariablesMap
    newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) );
   }
  }
  // variables.clear();
  variables.putAll( newVariables );
 }
 // Also add the internal job variables if these are set...
 //
 for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) {
  String value = jobMeta.getVariable( variableName );
  if ( !Utils.isEmpty( value ) ) {
   variables.put( variableName, value );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ) {
 if ( !Utils.isEmpty( variableName ) ) {
  String value = environmentSubstitute( variableName );
  if ( !Utils.isEmpty( value ) ) {
   return ValueMetaBase.convertStringToBoolean( value );
  }
 }
 return defaultValue;
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void testNullMin() throws Exception {
 variables.setVariable( Const.KETTLE_AGGREGATION_MIN_NULL_IS_VALUED, "Y" );
 addColumn( new ValueMetaInteger( "intg" ), null, 0L, 1L, -1L );
 addColumn( new ValueMetaString( "str" ), "A", null, "B", null );
 aggregates = Maps.toMap( ImmutableList.of( "min", "max" ), Functions.forMap( default_aggregates ) );
 RowMetaAndData output = runStep();
 assertThat( output.getInteger( "intg_min" ), nullValue() );
 assertThat( output.getInteger( "intg_max" ), is( 1L ) );
 assertThat( output.getString( "str_min", null ), nullValue() );
 assertThat( output.getString( "str_max", "invalid" ), is( "B" ) );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Get a default variable space as a placeholder. Everytime you will get a new instance.
 *
 * @return a default variable space.
 */
public static VariableSpace getADefaultVariableSpace() {
 VariableSpace space = new Variables();
 space.initializeVariablesFrom( null );
 return space;
}

代码示例来源:origin: pentaho/big-data-plugin

@Override public RuntimeTestResultSummary runTest( Object objectUnderTest ) {
  // Safe to cast as our accepts method will only return true for named clusters
  NamedCluster namedCluster = (NamedCluster) objectUnderTest;

  // The connection information might be parameterized. Since we aren't tied to a transformation or job, in order to
  // use a parameter, the value would have to be set as a system property or in kettle.properties, etc.
  // Here we try to resolve the parameters if we can:
  Variables variables = new Variables();
  variables.initializeVariablesFrom( null );

  if ( !namedCluster.isUseGateway() ) {
   return super.runTest( objectUnderTest );
  } else {
   return new RuntimeTestResultSummaryImpl( new ClusterRuntimeTestEntry( messageGetterFactory,
    connectivityTestFactory.create( messageGetterFactory,
     variables.environmentSubstitute( namedCluster.getGatewayUrl() ), TEST_PATH,
     variables.environmentSubstitute( namedCluster.getGatewayUsername() ),
     variables.environmentSubstitute( namedCluster.getGatewayPassword() ) )
     .runTest(), ClusterRuntimeTestEntry.DocAnchor.OOZIE ) );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

@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() );
 testRoundTrip( meta );
}

相关文章