Java TALEND 根据 TalendDate 设置上下文变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22983481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TALEND set a context variable depending from TalendDate
提问by user3463383
I want to set a context variable depending from a TalendDate routine in the "value as Table" tab which would allow me to select the day of yesterday : TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"))
我想根据“值作为表”选项卡中的 TalendDate 例程设置上下文变量,这将允许我选择昨天的日期:TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate (),-1,"dd"))
It does not work, I do not have any returns when I include in the selection as date('"+context.date+"').
它不起作用,当我作为日期('“+context.date+”')包含在选择中时,我没有任何回报。
Could you please tell me what I am missing ? I would be very grateful if you could help me with that.
你能告诉我我错过了什么吗?如果你能帮我解决这个问题,我将不胜感激。
采纳答案by Balazs Gunics
You should create a global variable, then in a tJava assign a value to it.
您应该创建一个全局变量,然后在 tJava 中为其分配一个值。
Or according to your current situation, in tJava paste the following:
或者根据您目前的情况,在 tJava 中粘贴以下内容:
context.date = TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"));
context.date = TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"));
Then you can use your variable. It won't be a java Date type, but a string.
然后你可以使用你的变量。它不会是一个java Date 类型,而是一个字符串。
回答by ydaetskcoR
You can use the tContextLoad component to create key value pairs of contexts to be used in your job or child jobs.
您可以使用 tContextLoad 组件来创建要在您的作业或子作业中使用的上下文键值对。
In your case you would want to use a tFixedFlowInput component to specify what you wanted (or this could be any input really but this is just a way of hard coding it directly to the job without needing an external resource) and then link that to the tContextLoad component with a schema of key and value like so:
在您的情况下,您可能希望使用 tFixedFlowInput 组件来指定您想要的内容(或者这实际上可以是任何输入,但这只是将其直接硬编码到作业中而不需要外部资源的一种方式),然后将其链接到tContextLoad 组件具有如下所示的键和值模式:
You'll want to use your original code snippet as the value in your tFixedFlowInput component:
您需要使用原始代码片段作为 tFixedFlowInput 组件中的值:
In the first screenshot above I've also added a tContextDump component and connected it to a tLogRow so you can see the available contexts to the job:
在上面的第一个屏幕截图中,我还添加了一个 tContextDump 组件并将其连接到 tLogRow 以便您可以查看作业的可用上下文: