gpt4 book ai didi

java - Talend-将 IF-THEN ELSE 转换为三元运算符

转载 作者:行者123 更新时间:2023-12-02 03:16:12 30 4
gpt4 key购买 nike

我们正在尝试将 tableau 报告/BI 工具的 IF-THEN-ELSE 语句INTO 三元运算符基于 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 语法中添加 else 部分后。出现错误

enter image description here

最佳答案

您的代码中的括号全部困惑,无法编译。您必须进入作业中“设计器”选项卡附近的“代码”选项卡,才能获取代码的详细信息。它会向您显示编译错误,并提供比错误弹出窗口更多的详细信息。

    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 - Talend-将 IF-THEN ELSE 转换为三元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40256107/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com