-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-36792][SQL] InSet should handle NaN #34033
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a74a310
[SPARK-36792][SQL] InSet should handle NaN
AngersZhuuuu 320b5ea
Update predicates.scala
AngersZhuuuu 1925e81
Update predicates.scala
AngersZhuuuu c3addf6
Update PredicateSuite.scala
AngersZhuuuu 141dc5f
Update predicates.scala
AngersZhuuuu 4ad6439
Merge branch 'master' into SPARK-36792
AngersZhuuuu 87df7b0
Update predicates.scala
AngersZhuuuu 174ac71
Update predicates.scala
AngersZhuuuu a48e77c
Update predicates.scala
AngersZhuuuu 293daea
Update predicates.scala
AngersZhuuuu 4878d5c
Update predicates.scala
AngersZhuuuu d6d517c
Update predicates.scala
AngersZhuuuu ef0e81f
trigger
AngersZhuuuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[SPARK-36792][SQL] InSet should handle NaN
- Loading branch information
commit a74a3104e66dcfbfe7561e524a2b75555addfbba
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -554,6 +554,11 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with | |
| } | ||
|
|
||
| @transient private[this] lazy val hasNull: Boolean = hset.contains(null) | ||
| private[this] val isNaN: Any => Boolean = child.dataType match { | ||
| case DoubleType => (value: Any) => java.lang.Double.isNaN(value.asInstanceOf[java.lang.Double]) | ||
| case FloatType => (value: Any) => java.lang.Float.isNaN(value.asInstanceOf[java.lang.Float]) | ||
| case _ => (_: Any) => false | ||
| } | ||
|
|
||
| override def nullable: Boolean = child.nullable || hasNull | ||
|
|
||
|
|
@@ -562,6 +567,8 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with | |
| protected override def nullSafeEval(value: Any): Any = { | ||
| if (set.contains(value)) { | ||
| true | ||
| } else if (isNaN(value)) { | ||
| set.exists(isNaN(_)) | ||
|
||
| } else if (hasNull) { | ||
| null | ||
| } else { | ||
|
|
@@ -593,15 +600,40 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with | |
| private def genCodeWithSet(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| nullSafeCodeGen(ctx, ev, c => { | ||
| val setTerm = ctx.addReferenceObj("set", set) | ||
| val i = ctx.freshName("i") | ||
| val elem = ctx.freshName("elem") | ||
| val jt = CodeGenerator.javaType(child.dataType) | ||
|
|
||
| val setIsNull = if (hasNull) { | ||
| s"${ev.isNull} = !${ev.value};" | ||
| } else { | ||
| "" | ||
| } | ||
| s""" | ||
| |${ev.value} = $setTerm.contains($c); | ||
| |$setIsNull | ||
| """.stripMargin | ||
| val ret = child.dataType match { | ||
| case DoubleType => Some((v: String) => s"java.lang.Double.isNaN((double)$v)") | ||
| case FloatType => Some((v: String) => s"java.lang.Float.isNaN((float)$v)") | ||
| case _ => None | ||
| } | ||
| ret.map { isNaN => | ||
| s""" | ||
| |if ($setTerm.contains($c)) { | ||
| | ${ev.value} = true; | ||
| |} else if (${isNaN(c)}) { | ||
| | for (int $i = 0; $i < $setTerm.size(); $i++) { | ||
| | $jt $elem = $setTerm.elems()[$i]; | ||
| | if (${isNaN(s"$elem")}) { | ||
| | ${ev.value} = true; | ||
| | break; | ||
| | } | ||
| | } | ||
| |} | ||
| |$setIsNull | ||
| |""".stripMargin | ||
| }.getOrElse( | ||
| s""" | ||
| |${ev.value} = $setTerm.contains($c); | ||
| |$setIsNull | ||
| """.stripMargin) | ||
| }) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.