Skip to content

Commit 35997b5

Browse files
viiryahvanhovell
authored andcommitted
[SPARK-23794][SQL] Make UUID as stateful expression
## What changes were proposed in this pull request? The UUID() expression is stateful and should implement the `Stateful` trait instead of the `Nondeterministic` trait. ## How was this patch tested? Added test. Author: Liang-Chi Hsieh <[email protected]> Closes apache#20912 from viirya/SPARK-23794.
1 parent 3e778f5 commit 35997b5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ case class CurrentDatabase() extends LeafExpression with Unevaluable {
123123
46707d92-02f4-4817-8116-a4c3b23e6266
124124
""")
125125
// scalastyle:on line.size.limit
126-
case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Nondeterministic {
126+
case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Stateful {
127127

128128
def this() = this(None)
129129

@@ -152,4 +152,6 @@ case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Non
152152
ev.copy(code = s"final UTF8String ${ev.value} = $randomGen.getNextUUIDUTF8String();",
153153
isNull = "false")
154154
}
155+
156+
override def freshCopy(): Uuid = Uuid(randomSeed)
155157
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscExpressionsSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ class MiscExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
5959
evaluateWithGeneratedMutableProjection(Uuid(seed2)))
6060
assert(evaluateWithUnsafeProjection(Uuid(seed1)) !==
6161
evaluateWithUnsafeProjection(Uuid(seed2)))
62+
63+
val uuid = Uuid(seed1)
64+
assert(uuid.fastEquals(uuid))
65+
assert(!uuid.fastEquals(Uuid(seed1)))
66+
assert(!uuid.fastEquals(uuid.freshCopy()))
67+
assert(!uuid.fastEquals(Uuid(seed2)))
6268
}
6369

6470
test("PrintToStderr") {

0 commit comments

Comments
 (0)