@@ -179,14 +179,6 @@ case class CaseWhen(
179179 " CASE" + cases + elseCase + " END"
180180 }
181181
182- private def wrapInDoWhileFalse (code : String ): String = {
183- s """
184- do {
185- $code
186- } while (false);
187- """
188- }
189-
190182 override def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
191183 // This variable represents whether the first successful condition is met or not.
192184 // It is initialized to `false` and it is set to `true` when the first condition which
@@ -232,10 +224,9 @@ case class CaseWhen(
232224 val allConditions = cases ++ elseCode
233225
234226 val code = if (ctx.INPUT_ROW == null || ctx.currentVars != null ) {
235- wrapInDoWhileFalse( allConditions.mkString(" \n " ) )
227+ allConditions.mkString(" \n " )
236228 } else {
237229 // This generates code like:
238- // do {
239230 // conditionMet = caseWhen_1(i);
240231 // if(conditionMet) {
241232 // continue;
@@ -245,35 +236,45 @@ case class CaseWhen(
245236 // continue;
246237 // }
247238 // ...
248- // } while (false);
239+ // and the declared methods are:
240+ // private boolean caseWhen_1234() {
241+ // boolean conditionMet = false;
242+ // do {
243+ // // here the evaluation of the conditions
244+ // } while (false);
245+ // return conditionMet;
246+ // }
249247 ctx.splitExpressions(allConditions, " caseWhen" ,
250248 (" InternalRow" , ctx.INPUT_ROW ) :: Nil ,
251249 returnType = ctx.JAVA_BOOLEAN ,
252250 makeSplitFunction = {
253251 func =>
254252 s """
255253 ${ctx.JAVA_BOOLEAN } $conditionMet = false;
256- ${wrapInDoWhileFalse(func)}
254+ do {
255+ $func
256+ } while (false);
257257 return $conditionMet;
258258 """
259259 },
260260 foldFunctions = { funcCalls =>
261- val loopBody = funcCalls.map { funcCall =>
261+ funcCalls.map { funcCall =>
262262 s """
263263 $conditionMet = $funcCall;
264264 if ( $conditionMet) {
265265 continue;
266266 } """
267267 }.mkString
268- wrapInDoWhileFalse(loopBody)
269268 })
270269 }
271270
272271 ev.copy(code = s """
273272 ${ev.isNull} = true;
274273 ${ev.value} = ${ctx.defaultValue(dataType)};
275274 ${ctx.JAVA_BOOLEAN } $conditionMet = false;
276- $code""" )
275+ do {
276+ $code
277+ } while (false); """ )
277278 }
278279}
279280
0 commit comments