代码改变世界

kettle---用户手册(7:变量)

2013-05-18 11:07  很大很老实  阅读(2384)  评论(0编辑  收藏  举报

我觉得这一章是比较重要的,在kettle中定义变量。

变量可以用在PDI的任何地方,包括转换和job。

通过set Variable在转换或者job中设置变量,也可以设置在kettle.properties文件中,不过,kettle.properties文件要放在以下位置:

$HOME/.kettle (Unix/Linux/OSX)
C:\Documents and Settings\<username>\.kettle\ (Windows)
C:\Users\<username>\.kettle\ (Windows Vista)

我们可以通过使用“Get Variable”step(在job里)来获取变量。
也可以通过•${VARIABLE}(unix)或者•%%VARIABLE%%(windows)获取变量。这两种方式甚至可以混用。


变量的作用域:
环境变量(不建议用)

The first usage (and only usage in previous Kettle versions) was to set an environment variable. Traditionally, this was accomplished by passing options to the Java Virtual Machine (JVM) with the -D option. It's also an easy way to specify the location of temporary files in a platform independent way, for example using variable ${java.io.tmpdir}. This variable points to directory /tmp on Unix/Linux/OSX and to C:\Documents and Settings\<username\Local Settings\Temp on Windows machines. The only problem with using environment variables is that the usage is not dynamic and problems arise if you try to use them in a dynamic way. For example, if you run two or more transformations or jobs run at the same time on an application server (for example the Pentaho platform) you get conflicts. Changes to the environment variables are visible to all software running on the virtual machine.

kettle变量:

内部已有变量:

下面的变量是已经定义的:

The following variables are always defined:

Variable NameSample value
Internal.Kettle.Build.Date 2007/05/22 18:01:39
Internal.Kettle.Build.Version 2045
Internal.Kettle.Version 2.5.0

These variables are defined in a transformation:

Variable NameSample value
Internal.Transformation.Filename.Directory D:\Kettle\samples
Internal.Transformation.Filename.Name Denormaliser - 2 series of key-value pairs.ktr
Internal.Transformation.Name Denormaliser - 2 series of key-value pairs sample
Internal.Transformation.Repository.Directory /

These are the internal variables that are defined in a Job:

Variable NameSample value
Internal.Job.Filename.Directory /home/matt/jobs
Internal.Job.Filename.Name Nested jobs.kjb
Internal.Job.Name Nested job test case
Internal.Job.Repository.Directory /

These variables are defined in a transformation running on a slave server, executed in clustered mode:

Variable NameSample value
Internal.Slave.Transformation.Number 0..<cluster size-1> (0,1,2,3 or 4)
Internal.Cluster.Size <cluster size> (5)