Skip to content
Snippets Groups Projects
Commit bfa09b01 authored by Michael Armbrust's avatar Michael Armbrust
Browse files

[SQL] Improve debug logging and toStrings.

Author: Michael Armbrust <michael@databricks.com>

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

b7a7e41 [Michael Armbrust] Improve debug logging and toStrings.
parent 5ecb08ea
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
})
......@@ -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) = {
......
......@@ -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] {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment