Skip to content

Commit

Permalink
[SPARK-23794][SQL] Make UUID as stateful expression
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
viirya authored and hvanhovell committed Mar 27, 2018
1 parent 3e778f5 commit 35997b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ case class CurrentDatabase() extends LeafExpression with Unevaluable {
46707d92-02f4-4817-8116-a4c3b23e6266
""")
// scalastyle:on line.size.limit
case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Nondeterministic {
case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Stateful {

def this() = this(None)

Expand Down Expand Up @@ -152,4 +152,6 @@ case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Non
ev.copy(code = s"final UTF8String ${ev.value} = $randomGen.getNextUUIDUTF8String();",
isNull = "false")
}

override def freshCopy(): Uuid = Uuid(randomSeed)
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class MiscExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
evaluateWithGeneratedMutableProjection(Uuid(seed2)))
assert(evaluateWithUnsafeProjection(Uuid(seed1)) !==
evaluateWithUnsafeProjection(Uuid(seed2)))

val uuid = Uuid(seed1)
assert(uuid.fastEquals(uuid))
assert(!uuid.fastEquals(Uuid(seed1)))
assert(!uuid.fastEquals(uuid.freshCopy()))
assert(!uuid.fastEquals(Uuid(seed2)))
}

test("PrintToStderr") {
Expand Down

0 comments on commit 35997b5

Please sign in to comment.