我们正试图将计算字段作为发货日期if-then-else语句写入带有eclipse的Java(Talend DI TOOL)
环境: 我们正试图在talend创造就业机会。
source systems (sql server and excel file)---->tmap---->Target system(Excel file)
输入表达式:if-then-else formula
发货日期
if ([Customer])='0000001' or
(TRIM([Corp Acct Name]))='GENERAL' or (TRIM([Corp Acct Name]))='ABC' or (TRIM([Corp Acct Name]))='XYZ'
or (TRIM([Corp Acct Name]))='CDE' then ([ShipDate])
elseif DATEPART('weekday',([MABD])) =1 and [Total Lead Time]<=5 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =1 and [Total Lead Time]>5 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =2 and [Total Lead Time]<=1 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =2 and [Total Lead Time]<=6 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =2 and [Total Lead Time]>6 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =3 and [Total Lead Time]<=2 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =3 and [Total Lead Time]<=7 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =3 and [Total Lead Time]>7 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =4 and [Total Lead Time]<=3 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =4 and [Total Lead Time]<=8 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =4 and [Total Lead Time]>8 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =5 and [Total Lead Time]<=4 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =5 and [Total Lead Time]<=9 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =5 and [Total Lead Time]>9 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =6 and [Total Lead Time]<=4 then (([MABD])-[Total Lead Time]-1)
elseif DATEPART('weekday',([MABD])) =6 and [Total Lead Time]<=9 then (([MABD])-[Total Lead Time]-3)
elseif DATEPART('weekday',([MABD])) =6 and [Total Lead Time]>9 then (([MABD])-[Total Lead Time]-5)
elseif DATEPART('weekday',([MABD])) =7 and [Total Lead Time]<=4 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =7 and [Total Lead Time]<=9 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =7 and [Total Lead Time]>9 then (([MABD])-[Total Lead Time]-6)
END
我们尝试过:Ternery运营商在talend
row1.customer='0000001'|| trim(row1.CorpAcctName)='GENERAL'|| trim(row1.CorpAcctName)='ABC' or trim(row1.CorpAcctName)='XYZ or trim(row1.CorpAcctName)=='SCDE' ||?row1.ShipDate:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD)=1)-1) and row2.L+1<5?row1.MABD-row2.L+1-2:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=1)-1) and row2.L+1>5?row1.MABD-row2.L+1-4:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=2)-1) and row2.L+1<=1?row1.MABD-row2.L+1:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=2)-1) and row2.L+1<=6?row1.MABD-row2.L+1-2:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=2)-1) and row2.L+1>6?row1.MABD-row2.L+1-4:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=3)-1) and row2.L+1<=2?row1.MABD-row2.L+1:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=3)-1) and row2.L+1<=7?row1.MABD-row2.L+1-2:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=3)-1) and row2.L+1>7?row1.MABD-row2.L+1-4:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=4)-1) and row2.L+1<=3?row1.MABD-row2.L+1:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=4)-1) and row2.L+1<=8?row1.MABD-row2.L+1-2:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=4)-1) and row2.L+1>8?row1.MABD-row2.L+1-4:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=5)-1) and row2.L+1<=4?row1.MABD-row2.L+1:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=5)-1) and row2.L+1<=9?row1.MABD-row2.L+1-2:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=5)-1) and row2.L+1>9?row1.MABD-row2.L+1-4:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=6)-1) and row2.L+1<=4?row1.MABD-row2.L+1-1:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=6)-1) and row2.L+1<=9?row1.MABD-row2.L+1-3:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=6)-1) and row2.L+1>9?row1.MABD-row2.L+1-5:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=7)-1) and row2.L+1<=4?row1.MABD-row2.L+1-2:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=7)-1) and row2.L+1<=9?row1.MABD-row2.L+1-4:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=7)-1) and row2.L+1>9?row1.MABD-row2.L+1-6:""
对此有任何帮助将不胜感激?
答案 0 :(得分:1)
首先,表达式中存在多个语法错误:如果要比较2个Int,则正确的运算符为&#34; ==&#34;。
(如果你想比较两个String,你应该使用"0000001".equals(row1.customer)
)。
这个表达没有意义:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=1)-1)
如果您想将DAY_OF_WEEK与1进行比较,请使用
(TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD)-1) ==1
然后,在tMap中使用原始的Ternary运算符可能不是最好的事情:它不适合像这样的复杂表达式(没有可用的注释,没有可能的重用)。你应该在&#34; Routine&#34;中创建一个方法。 section,并将row1.customer,row1.CorpAcctName,row1.ShipDate,row1.MABD作为参数。 在这个例程方法中,您可以使用IF / ELSE运算符,这些运算符不能直接在tMap中使用。
public static int myFunction(String customer,String CorpAcctName,Integer ShipDate,Integer MABD) {
//adding comment is possible here
if ("0000001".equals(customer).......) {
然后在tMap中,你只需要在表达式构造函数中调用你的函数。