您可以使用$_
.
假设您有一个管道参数executionId
。然后要在脚本中访问它,您可以执行$_executionId
.
以下是测试管道。
![管道](https://i.stack.imgur.com/lCjhy.png)
使用以下管道参数。
![管道参数](https://i.stack.imgur.com/RAy1O.png)
以下是测试数据。
![测试数据](https://i.stack.imgur.com/f57mT.png)
以下是脚本
# Import the interface required by the Script snap.
from com.snaplogic.scripting.language import ScriptHook
import java.util
class TransformScript(ScriptHook):
def __init__(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
# The "execute()" method is called once when the pipeline is started
# and allowed to process its inputs or just send data to its outputs.
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
try:
# Read the next document, wrap it in a map and write out the wrapper
in_doc = self.input.next()
wrapper = java.util.HashMap()
wrapper['output'] = in_doc
wrapper['output']['executionId'] = $_executionId
self.output.write(in_doc, wrapper)
except Exception as e:
errWrapper = {
'errMsg' : str(e.args)
}
self.log.error("Error in python script")
self.error.write(errWrapper)
self.log.info("Finished executing the Transform script")
# The Script Snap will look for a ScriptHook object in the "hook"
# variable. The snap will then call the hook's "execute" method.
hook = TransformScript(input, output, error, log)
输出:
![输出](https://i.stack.imgur.com/hjg01.png)
在这里,您可以看到executionId
是从管道参数中读取的。
注意:从脚本访问管道参数是一种有效的方案,但从脚本访问其他外部系统很复杂(因为您需要加载所需的库)并且不推荐。使用 SnapLogic 提供的快照访问外部系统。此外,如果您想在脚本中使用其他库,请尝试坚持使用 Javascript 而不是使用 python,因为您可以在脚本中使用很多开源 CDN。
此外,您不能直接从脚本访问任何已配置的表达式库。如果您需要脚本中的一些逻辑,您可以将其保存在脚本中,而不是其他地方。而且,在脚本(或映射器)中访问帐户名没有意义,因为即使您知道帐户名,也不能直接使用存储在该帐户中的凭据/配置;由 SnapLogic 处理。尽可能使用提供的快照和映射器。
更新#1
- 您无法直接访问该帐户。帐户由快照在内部管理和使用。您只能通过相关快照的帐户选项卡创建和设置帐户。
- 尽量避免使用脚本快照;特别是,如果您可以使用普通快照来做同样的事情。
更新#2
此要求的最简单解决方案如下。
- 使用文件阅读器读取文件
- 拆分依据
;
- 使用Generic JDBC Execute Snap执行每个 SQL 命令