Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29.4k
[SPARK-27088][SQL] Add a configuration to set log level for each batch at RuleExecutor#24136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
55 changes: 36 additions & 19 deletions
55 sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 13 additions & 5 deletions
18 sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -184,8 +184,8 @@ object SQLConf { | ||
| val OPTIMIZER_PLAN_CHANGE_LOG_LEVEL = buildConf("spark.sql.optimizer.planChangeLog.level") | ||
| .internal() | ||
| .doc("Configures the log level for logging the change from the original plan to the new " + | ||
| "plan after a rule is applied. The value can be 'trace', 'debug', 'info', 'warn', or " + | ||
| "'error'. The default log level is 'trace'.") | ||
| "plan after a rule or batch is applied. The value can be 'trace', 'debug', 'info', " + | ||
chakravarthiT marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| "'warn', or 'error'. The default log level is 'trace'.") | ||
| .stringConf | ||
| .transform(_.toUpperCase(Locale.ROOT)) | ||
| .checkValue(logLevel => Set("TRACE", "DEBUG", "INFO", "WARN", "ERROR").contains(logLevel), | ||
| @@ -195,9 +195,15 @@ object SQLConf { | ||
| val OPTIMIZER_PLAN_CHANGE_LOG_RULES = buildConf("spark.sql.optimizer.planChangeLog.rules") | ||
| .internal() | ||
| .doc("If this configuration is set, the optimizer will only log plan changes caused by " + | ||
| "applying the rules specified in this configuration. The value can be a list of rule " + | ||
| "names separated by comma.") | ||
| .doc("Configures a list of rules to be logged in the optimizer, in which the rules are " + | ||
| "specified by their rule names and separated by comma.") | ||
| .stringConf | ||
| .createOptional | ||
| val OPTIMIZER_PLAN_CHANGE_LOG_BATCHES = buildConf("spark.sql.optimizer.planChangeLog.batches") | ||
chakravarthiT marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| .internal() | ||
| .doc("Configures a list of batches to be logged in the optimizer, in which the batches " + | ||
| "are specified by their batch names and separated by comma.") | ||
| .stringConf | ||
| .createOptional | ||
| @@ -1751,6 +1757,8 @@ class SQLConf extends Serializable with Logging { | ||
| def optimizerPlanChangeRules: Option[String] = getConf(OPTIMIZER_PLAN_CHANGE_LOG_RULES) | ||
| def optimizerPlanChangeBatches: Option[String] = getConf(OPTIMIZER_PLAN_CHANGE_LOG_BATCHES) | ||
| def stateStoreProviderClass: String = getConf(STATE_STORE_PROVIDER_CLASS) | ||
| def stateStoreMinDeltasForSnapshot: Int = getConf(STATE_STORE_MIN_DELTAS_FOR_SNAPSHOT) | ||
45 changes: 38 additions & 7 deletions
45 ...talyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/OptimizerLoggingSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,17 +32,20 @@ import org.apache.spark.sql.internal.SQLConf | ||
| class OptimizerLoggingSuite extends PlanTest { | ||
| object Optimize extends RuleExecutor[LogicalPlan] { | ||
| val batches = Batch("Optimizer Batch", FixedPoint(100), | ||
| PushDownPredicate, | ||
| ColumnPruning, | ||
| CollapseProject) :: Nil | ||
| val batches = | ||
| Batch("Optimizer Batch", FixedPoint(100), | ||
| PushDownPredicate, ColumnPruning, CollapseProject) :: | ||
| Batch("Batch Has No Effect", Once, | ||
| ColumnPruning) :: Nil | ||
| } | ||
| class MockAppender extends AppenderSkeleton { | ||
| val loggingEvents = new ArrayBuffer[LoggingEvent]() | ||
| override def append(loggingEvent: LoggingEvent): Unit = { | ||
| if (loggingEvent.getRenderedMessage().contains("Applying Rule")) { | ||
| if (loggingEvent.getRenderedMessage().contains("Applying Rule") || | ||
| loggingEvent.getRenderedMessage().contains("Result of Batch") || | ||
| loggingEvent.getRenderedMessage().contains("has no effect")) { | ||
| loggingEvents.append(loggingEvent) | ||
| } | ||
| } | ||
| @@ -51,7 +54,18 @@ class OptimizerLoggingSuite extends PlanTest { | ||
| override def requiresLayout(): Boolean = false | ||
| } | ||
| private def verifyLog(expectedLevel: Level, expectedRules: Seq[String]): Unit = { | ||
| private def withLogLevelAndAppender(level: Level, appender: Appender)(f: => Unit): Unit = { | ||
| val logger = Logger.getLogger(Optimize.getClass.getName.dropRight(1)) | ||
| val restoreLevel = logger.getLevel | ||
| logger.setLevel(level) | ||
| logger.addAppender(appender) | ||
| try f finally { | ||
| logger.setLevel(restoreLevel) | ||
| logger.removeAppender(appender) | ||
| } | ||
| } | ||
| private def verifyLog(expectedLevel: Level, expectedRulesOrBatches: Seq[String]): Unit = { | ||
| val logAppender = new MockAppender() | ||
| withLogAppender(logAppender, | ||
| loggerName = Some(Optimize.getClass.getName.dropRight(1)), level = Some(Level.TRACE)) { | ||
| @@ -61,7 +75,8 @@ class OptimizerLoggingSuite extends PlanTest { | ||
| comparePlans(Optimize.execute(query), expected) | ||
| } | ||
| val logMessages = logAppender.loggingEvents.map(_.getRenderedMessage) | ||
| assert(expectedRules.forall(rule => logMessages.exists(_.contains(rule)))) | ||
| assert(expectedRulesOrBatches.forall | ||
| (ruleOrBatch => logMessages.exists(_.contains(ruleOrBatch)))) | ||
| assert(logAppender.loggingEvents.forall(_.getLevel == expectedLevel)) | ||
| } | ||
| @@ -135,4 +150,20 @@ class OptimizerLoggingSuite extends PlanTest { | ||
| } | ||
| } | ||
| } | ||
| test("test log batches which change the plan") { | ||
| withSQLConf( | ||
| SQLConf.OPTIMIZER_PLAN_CHANGE_LOG_BATCHES.key -> "Optimizer Batch", | ||
chakravarthiT marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| SQLConf.OPTIMIZER_PLAN_CHANGE_LOG_LEVEL.key -> "INFO") { | ||
| verifyLog(Level.INFO, Seq("Optimizer Batch")) | ||
| } | ||
| } | ||
| test("test log batches which do not change the plan") { | ||
| withSQLConf( | ||
| SQLConf.OPTIMIZER_PLAN_CHANGE_LOG_BATCHES.key -> "Batch Has No Effect", | ||
| SQLConf.OPTIMIZER_PLAN_CHANGE_LOG_LEVEL.key -> "INFO") { | ||
| verifyLog(Level.INFO, Seq("Batch Has No Effect")) | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same thing for line 148?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config "spark.sql.optimizer.planChangeLog.level", is used for logging plan changes after applying rule or batch . As per Line 148,it is logging when there is no change in plan,which conflicts the parameter(spark.sql.optimizer.planChangeLog.level). Its not required to log this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile please review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address them in a followup if there are further comments.