Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge remote-tracking branch 'upstream/master' into SPARK-22856
  • Loading branch information
viirya committed Apr 4, 2018
commit ac2e5959f204bde0ccd418479482f6f62b51a6f5
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ class CodegenContext {
subexprFunctions += s"${addNewFunction(fnName, fn)}($INPUT_ROW);"
val state = SubExprEliminationState(GlobalValue(isNull, JAVA_BOOLEAN),
GlobalValue(value, javaType(expr.dataType)))
e.foreach(subExprEliminationExprs.put(_, state))
subExprEliminationExprs ++= e.map(_ -> state).toMap
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro
$evalSubexpr
$writeExpressions
"""
ExprCode(code, FalseLiteral, GlobalValue(result, "UnsafeRow"))
// `rowWriter` is declared as a class field, so we can access it directly in methods.
ExprCode(code, FalseLiteral, StatementValue(s"$rowWriter.getRow()", "UnsafeRow",
canDirectAccess = true))
}

protected def canonicalize(in: Seq[Expression]): Seq[Expression] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Sta
randomGenerator.getNextUUIDUTF8String()

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
ev.copy(code = s"final UTF8String ${ev.value} = " +
s"UTF8String.fromString(java.util.UUID.randomUUID().toString());",
val randomGen = ctx.freshName("randomGen")
ctx.addMutableState("org.apache.spark.sql.catalyst.util.RandomUUIDGenerator", randomGen,
forceInline = true,
useFreshName = false)
ctx.addPartitionInitializationStatement(s"$randomGen = " +
"new org.apache.spark.sql.catalyst.util.RandomUUIDGenerator(" +
s"${randomSeed.get}L + partitionIndex);")
ev.copy(code = s"final UTF8String ${ev.value} = $randomGen.getNextUUIDUTF8String();",
isNull = FalseLiteral)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
val ref = BoundReference(0, IntegerType, true)
val add1 = Add(ref, ref)
val add2 = Add(add1, add1)
val dummy = SubExprEliminationState(VariableValue("dummy", "boolean"),
VariableValue("dummy", "boolean"))

// raw testing of basic functionality
{
Expand All @@ -457,7 +459,7 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
ctx.subExprEliminationExprs += ref -> SubExprEliminationState(e.isNull, e.value)
assert(ctx.subExprEliminationExprs.contains(ref))
// call withSubExprEliminationExprs
ctx.withSubExprEliminationExprs(Map(add1 -> SubExprEliminationState("dummy", "dummy"))) {
ctx.withSubExprEliminationExprs(Map(add1 -> dummy)) {
assert(ctx.subExprEliminationExprs.contains(add1))
assert(!ctx.subExprEliminationExprs.contains(ref))
Seq.empty
Expand All @@ -475,7 +477,7 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
ctx.generateExpressions(Seq(add2, add1), doSubexpressionElimination = true) // trigger CSE
assert(ctx.subExprEliminationExprs.contains(add1))
// call withSubExprEliminationExprs
ctx.withSubExprEliminationExprs(Map(ref -> SubExprEliminationState("dummy", "dummy"))) {
ctx.withSubExprEliminationExprs(Map(ref -> dummy)) {
assert(ctx.subExprEliminationExprs.contains(ref))
assert(!ctx.subExprEliminationExprs.contains(add1))
Seq.empty
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.