Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ trait Logging {
log.isTraceEnabled
}

protected def withLogLevel(level: Slf4jLevel)(f: => Unit): Unit = {
if (log.isEnabledForLevel(level)) f
}

protected def logBasedOnLevel(level: Slf4jLevel)(f: => MessageWithContext): Unit = {
level match {
case Slf4jLevel.TRACE => logTrace(f.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,24 @@ class PlanChangeLogger[TreeType <: TreeNode[_]] extends Logging {
private val logBatches = SQLConf.get.planChangeBatches.map(Utils.stringToSeq)

def logRule(ruleName: String, oldPlan: TreeType, newPlan: TreeType): Unit = {
if (!newPlan.fastEquals(oldPlan)) {
if (logRules.isEmpty || logRules.get.contains(ruleName)) {
def message(): MessageWithContext = {
val oldPlanStringWithOutput = oldPlan.treeString(verbose = false,
printOutputColumns = true)
val newPlanStringWithOutput = newPlan.treeString(verbose = false,
printOutputColumns = true)
// scalastyle:off line.size.limit
withLogLevel(logLevel) {
if ((logRules.isEmpty || logRules.get.contains(ruleName)) &&
!newPlan.fastEquals(oldPlan)) {
val oldPlanStringWithOutput = oldPlan.treeString(verbose = false,
printOutputColumns = true)
val newPlanStringWithOutput = newPlan.treeString(verbose = false,
printOutputColumns = true)
// scalastyle:off line.size.limit
logBasedOnLevel(logLevel) {
log"""
|=== Applying Rule ${MDC(RULE_NAME, ruleName)} ===
|${MDC(QUERY_PLAN, sideBySide(oldPlan.treeString, newPlan.treeString).mkString("\n"))}
|
|Output Information:
|${MDC(QUERY_PLAN, sideBySide(oldPlanStringWithOutput, newPlanStringWithOutput).mkString("\n"))}
""".stripMargin
// scalastyle:on line.size.limit
|=== Applying Rule ${MDC(RULE_NAME, ruleName)} ===
|${MDC(QUERY_PLAN, sideBySide(oldPlan.treeString, newPlan.treeString).mkString("\n"))}
|
|Output Information:
|${MDC(QUERY_PLAN, sideBySide(oldPlanStringWithOutput, newPlanStringWithOutput).mkString("\n"))}
""".stripMargin
}

logBasedOnLevel(logLevel)(message())
// scalastyle:on line.size.limit
}
}
}
Expand Down