Skip to content

Commit 4bb78be

Browse files
committed
#AI Commit#
bug fix
1 parent 89a3a09 commit 4bb78be

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

  • dss-orchestrator/orchestrators/dss-workflow/dss-flow-execution-server/src/main/scala/com/webank/wedatasphere/dss/flow/execution/entrance/utils

dss-orchestrator/orchestrators/dss-workflow/dss-flow-execution-server/src/main/scala/com/webank/wedatasphere/dss/flow/execution/entrance/utils/BranchExpressionUtils.scala

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,18 @@ object BranchExpressionUtils {
102102
operators.collectFirst {
103103
case operator if expr.contains(operator) =>
104104
val parts = expr.split(java.util.regex.Pattern.quote(operator), 2).map(_.trim)
105-
if (parts.length != 2) false else compare(resolveValue(parts(0), context), resolveValue(parts(1), context), operator)
105+
if (parts.length != 2) {
106+
false
107+
} else {
108+
(resolveValue(parts(0), context), resolveValue(parts(1), context)) match {
109+
case (Some(left), Some(right)) => compare(left, right, operator)
110+
case _ => false
111+
}
112+
}
106113
}.getOrElse {
107-
val resolved = resolveValue(expr, context)
108-
resolved.equalsIgnoreCase("true") || resolved.nonEmpty
114+
resolveValue(expr, context).exists { resolved =>
115+
resolved.equalsIgnoreCase("true") || resolved.nonEmpty
116+
}
109117
}
110118
}
111119
}
@@ -116,13 +124,29 @@ object BranchExpressionUtils {
116124
} else expression
117125
}
118126

119-
private def resolveValue(token: String, context: Map[String, String]): String = {
120-
val normalized = token.trim
121-
val unquoted = normalized.stripPrefix("\"").stripSuffix("\"").stripPrefix("'").stripSuffix("'")
122-
context.getOrElse(normalized, context.getOrElse(unquoted, unquoted))
127+
private def resolveValue(token: String, context: Map[String, String]): Option[String] = {
128+
val normalized = Option(token).map(_.trim).getOrElse("")
129+
if (normalized.isEmpty) {
130+
None
131+
} else {
132+
val unquoted = normalized.stripPrefix("\"").stripSuffix("\"").stripPrefix("'").stripSuffix("'")
133+
if (isQuotedToken(normalized)) {
134+
Some(unquoted)
135+
} else {
136+
context.get(normalized)
137+
.orElse(context.get(unquoted))
138+
.orElse(if (isLiteralToken(unquoted)) Some(unquoted) else None)
139+
}
140+
}
123141
}
124142

143+
private def isQuotedToken(token: String): Boolean = {
144+
(token.startsWith("\"") && token.endsWith("\"")) || (token.startsWith("'") && token.endsWith("'"))
145+
}
125146

147+
private def isLiteralToken(token: String): Boolean = {
148+
token.equalsIgnoreCase("true") || token.equalsIgnoreCase("false") || toBigDecimal(token).nonEmpty
149+
}
126150

127151
private def getStringValue(value: Any): Option[String] = Option(value).map(_.toString.trim).filter(_.nonEmpty)
128152

0 commit comments

Comments
 (0)