我们正试图将IF-THEN-ELSE语句转换为tableau报告/ BI工具 INTO TERNARY OPERATOR基于Java的Talend工具或基于JAVA的IF-THEN-ELSE
输入数据
if isnull([Ship Date (Calculated)]) then
(if (attr(trim([Corp Acct Name])) = 'ABC'
or attr(trim([Corp Acct Name])) ='BCD'
or attr(trim([Corp Acct Name])) ='CDE')
then
(if DATEPART('weekday',ATTR([ ShipDate])) =1 then (attr([ ShipDate])-3)
elseif DATEPART('weekday',ATTR([ ShipDate])) =2 then (attr([ ShipDate])-3)
else (attr([ShipDate])-2) END
) else (if DATEPART('weekday',ATTR([ ShipDate])) =1 then (attr([ ShipDate])-2)
else (attr([ ShipDate])-1) END
) end)
ELSE
(if (attr(trim([Corp Acct Name])) = 'ABC'
or attr(trim([Corp Acct Name])) ='BCD'
or attr(trim([Corp Acct Name])) ='CDE')
then
(if DATEPART('weekday',[Ship Date (Calculated)])=1 then ([Ship Date (Calculated)]-3)
elseif DATEPART('weekday',[Ship Date (Calculated)])=2 then ([Ship Date (Calculated)]-3)
else ([Ship Date (Calculated)]-2) end)
else (if DATEPART('weekday',[Ship Date (Calculated)])=1 then ([Ship Date (Calculated)]-2)
else ([Ship Date (Calculated)]-1) end) end)
END
此处使用的字段及其数据类型
[Ship Date (Calculated)]- date
[Corp Acct Name] -String
[ ShipDate] - Date
我们尝试过:
row1.ShipDateCalculated==null?("ABC".equalsIgnoreCase(row1.CorpAcctName) || "BCD".equalsIgnoreCase(row1.CorpAcctName
||"CDE".equalsIgnoreCase(row1.CorpAcctName))?(TalendDate.getPartOfDate("DAY_OF_WEEK",row1.ShipDate) ==1?TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-3,"dd"):
(TalendDate.getPartOfDate("DAY_OF_WEEK",row1.ShipDate) ==2?TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-3,"dd"):TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-2,"dd")
:(TalendDate.getPartOfDate("DAY_OF_WEEK",row1.ShipDate) ==1?TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-2,"dd"):TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-1,"dd"):""))
输出数据:
寻找基于JAVA的三元运算符。
condition1?(condition2?value if true:value if false): (condition3?value if true:value if false)
更多错误:在当前tmap语法上添加其他部分后。获取错误
答案 0 :(得分:2)
括号在你的代码中都搞砸了,它没有编译。 您必须进入“代码”选项卡,靠近作业中的“设计器”选项卡,以获取代码的详细信息。它将向您显示编译错误,并提供比错误弹出更多的详细信息。
row1.ShipDateCalculated==null?
("ABC".equalsIgnoreCase(row1.CorpAcctName) || "BCD".equalsIgnoreCase(row1.CorpAcctName)||"CDE".equalsIgnoreCase(row1.CorpAcctName))?
TalendDate.getPartOfDate("DAY_OF_WEEK",row1.ShipDate) ==1?
TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-3,"dd"):
TalendDate.getPartOfDate("DAY_OF_WEEK",row1.ShipDate) ==2?
TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-3,"dd"):
TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-2,"dd"):
TalendDate.getPartOfDate("DAY_OF_WEEK",row1.ShipDate) ==1?
TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-2,"dd"):
TalendDate.addDate(TalendDate.formatDate("MM/dd/yyyy", row1.ShipDate ),"MM/dd/yyyy",-1,"dd"):
""