-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22705][SQL] Case, Coalesce, and In use less global variables #19901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8420c02
bcbe82c
c81d795
96183d3
6a14e16
740f1a0
31ab853
c4691b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,37 +237,44 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate { | |
| val javaDataType = ctx.javaType(value.dataType) | ||
| val valueGen = value.genCode(ctx) | ||
| val listGen = list.map(_.genCode(ctx)) | ||
| ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.value) | ||
| ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull) | ||
| // inTmpResult has 3 possible values: | ||
| // -1 means no matches found and there is at least one value in the list evaluated to null | ||
| val HAS_NULL = -1 | ||
| // 0 means no matches found and all values in the list are not null | ||
| val NOT_MATCHED = 0 | ||
| // 1 means one value in the list is matched | ||
| val MATCHED = 1 | ||
| val tmpResult = ctx.freshName("inTmpResult") | ||
| val valueArg = ctx.freshName("valueArg") | ||
| // All the blocks are meant to be inside a do { ... } while (false); loop. | ||
| // The evaluation of variables can be stopped when we find a matching value. | ||
| val listCode = listGen.map(x => | ||
| s""" | ||
| |${x.code} | ||
| |if (${x.isNull}) { | ||
| | ${ev.isNull} = true; | ||
| | $tmpResult = $HAS_NULL; // ${ev.isNull} = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, seems suggested by other reviewer. Then fine for me. |
||
| |} else if (${ctx.genEqual(value.dataType, valueArg, x.value)}) { | ||
| | ${ev.isNull} = false; | ||
| | ${ev.value} = true; | ||
| | $tmpResult = $MATCHED; // ${ev.isNull} = false; ${ev.value} = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
| | continue; | ||
| |} | ||
| """.stripMargin) | ||
|
|
||
| val codes = ctx.splitExpressionsWithCurrentInputs( | ||
| expressions = listCode, | ||
| funcName = "valueIn", | ||
| extraArguments = (javaDataType, valueArg) :: Nil, | ||
| extraArguments = (javaDataType, valueArg) :: (ctx.JAVA_BYTE, tmpResult) :: Nil, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't read
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to keep the previous value? it's not read in the method. My proposal is:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your proposal makes incorrect result in this case This result should be WDYT?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah got it, actually the |
||
| returnType = ctx.JAVA_BYTE, | ||
| makeSplitFunction = body => | ||
| s""" | ||
| |do { | ||
| | $body | ||
| |} while (false); | ||
| |return $tmpResult; | ||
| """.stripMargin, | ||
| foldFunctions = _.map { funcCall => | ||
| s""" | ||
| |$funcCall; | ||
| |if (${ev.value}) { | ||
| |$tmpResult = $funcCall; | ||
| |if ($tmpResult == $MATCHED) { | ||
| | continue; | ||
| |} | ||
| """.stripMargin | ||
|
|
@@ -276,14 +283,16 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate { | |
| ev.copy(code = | ||
| s""" | ||
| |${valueGen.code} | ||
| |${ev.value} = false; | ||
| |${ev.isNull} = ${valueGen.isNull}; | ||
| |if (!${ev.isNull}) { | ||
| |byte $tmpResult = $HAS_NULL; | ||
| |if (!${valueGen.isNull}) { | ||
| | $tmpResult = 0; | ||
| | $javaDataType $valueArg = ${valueGen.value}; | ||
| | do { | ||
| | $codes | ||
| | } while (false); | ||
| |} | ||
| |final boolean ${ev.isNull} = ($tmpResult == $HAS_NULL); | ||
| |final boolean ${ev.value} = ($tmpResult == $MATCHED); | ||
| """.stripMargin) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resultStateholds the state of the result, which has 3 possible values: