Skip to content

Commit

Permalink
[SQL] Improve debug logging and toStrings.
Browse files Browse the repository at this point in the history
Author: Michael Armbrust <[email protected]>

Closes apache#2004 from marmbrus/codgenDebugging and squashes the following commits:

b7a7e41 [Michael Armbrust] Improve debug logging and toStrings.
  • Loading branch information
marmbrus committed Aug 18, 2014
1 parent 5ecb08e commit bfa09b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin
.build(
new CacheLoader[InType, OutType]() {
override def load(in: InType): OutType = globalLock.synchronized {
create(in)
val startTime = System.nanoTime()
val result = create(in)
val endTime = System.nanoTime()
def timeMs = (endTime - startTime).toDouble / 1000000
logInfo(s"Code generated expression $in in $timeMs ms")
result
}
})

Expand Down Expand Up @@ -413,7 +418,19 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin
""".children
}

EvaluatedExpression(code, nullTerm, primitiveTerm, objectTerm)
// Only inject debugging code if debugging is turned on.
val debugCode =
if (log.isDebugEnabled) {
val localLogger = log
val localLoggerTree = reify { localLogger }
q"""
$localLoggerTree.debug(${e.toString} + ": " + (if($nullTerm) "null" else $primitiveTerm))
""" :: Nil
} else {
Nil
}

EvaluatedExpression(code ++ debugCode, nullTerm, primitiveTerm, objectTerm)
}

protected def getColumn(inputRow: TermName, dataType: DataType, ordinal: Int) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ case class IsNull(child: Expression) extends Predicate with trees.UnaryNode[Expr
override def eval(input: Row): Any = {
child.eval(input) == null
}

override def toString = s"IS NULL $child"
}

case class IsNotNull(child: Expression) extends Predicate with trees.UnaryNode[Expression] {
Expand Down

0 comments on commit bfa09b0

Please sign in to comment.