Pentaho 将变量从修改后的 java 脚本值传递到表输入 [英] Pentaho passing variable from modified java script value to table input
问题描述
我需要从修改后的java脚本值中传递变量并将其传递给表输入查询
I need to passing variable from modified java script value and pass it to table input query
这是我的
如果我点击预览输出
initator_reference | a | '' |
1 | a | null |
2 | a | null |
3 | a | null |
4 | a | null |
它不应该为空,而是第三个字段上的测试"字符串不要问我为什么把那个变量放在选择中,它只是为了在我把它放在where condition=variable"之前进行测试
It shouldnt be null but "testing" string on that third field and dont ask me why i put that variable in select, its just for testing before i put it in "where condition=variable"
推荐答案
表输入支持两种不同的使 SQL 动态化的方式:变量替换和从传入流插入数据.
Table Input supports two different ways of making the SQL dynamic: Variable Substitution and inserting data from an incoming stream.
变量替换
这是您当前在表输入中配置的内容:您将 ${variable} 放在某处,当步骤初始化时,该值将作为文本粘贴到 SQL 中.
This is what you currently have configured in the Table Input: You put ${variable} somewhere and when the step initializes, the value is pasted as text into the SQL.
因为在一次转换中所有步骤同时初始化,您的 Javascript 步骤还没有来得及设置值.在 PDI 中,您不能在同一个转换中设置和使用变量.
Because all the steps initialize at the same time in a transformation, your Javascript step has not had time to set the value. In PDI you cannot set and use a variable within the same transformation.
插入步骤中的数据
第二种方法是通过在表输入的从步骤插入数据"选项中选择源步骤来使用.在此模式下,表输入从所选步骤中取出一行,并在您插入的问号 (?) 处将字段(按顺序)插入到 SQL 中.通常它需要一行,但您可以选择为每一行执行.
The second way is used by selecting a source step in the "Insert data from step" option in the Table input. In this mode, the Table Input takes a row from the selected step and inserts fields (in order) into the SQL at question marks (?) you insert. Normally it expects a single row, but you can choose to execute for EACH row.
这种方式应该适用于您的场景:
This way should work for your scenario:
- 在开始处放置一个 Generate Rows 步骤并将其设置为生成 1 行.
- 将其连接到 Javascript 步骤.
- 在 Javascript 步骤中,将返回变量指定为底部网格中的输出字段,它将被添加到流中.
- 在表输入中,选择从步骤插入数据"处的 Javascript 步骤
- 在您的 SQL 中,插入 ?在变量的位置.如果值是字符串,您可能需要用单引号将其括起来:WHERE column = '?'.
- 预览转换以查看结果,由于依赖关系,Table Input 的预览被禁用.
注意事项:
- 可能不需要第 1 步和第 2 步,我不确定 JS 步骤是否会自行生成一行.我喜欢明确说明这一点,通常将生成行步骤命名为生成 1 行".
- 如果您有一个现有的流或多个要插入的字段,您可以使用选择值"步骤将字段按需要插入 SQL 的顺序排列.
这篇关于Pentaho 将变量从修改后的 java 脚本值传递到表输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!