Skip to content

Commit 7a07647

Browse files
wakunGitHub Enterprise
wakun
authored and
GitHub Enterprise
committed
[CARMEL-5861] Limit the max size of statement and executePlan (#874)
1 parent 5e7ce1b commit 7a07647

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,13 @@ object SQLConf {
10881088
.intConf
10891089
.createWithDefault(200)
10901090

1091+
val THRIFTSERVER_UI_STRING_MAX_LENGTH =
1092+
buildConf("spark.sql.thriftserver.ui.string.maxLength")
1093+
.doc("The max length for statement and executePlan in LiveExecutionData")
1094+
.version("3.0.0")
1095+
.intConf
1096+
.createWithDefault(100 * 1024)
1097+
10911098
val SQL_HIGH_CONSUME_ALERT_ENABLED = buildConf("spark.sql.high.consume.enabled")
10921099
.doc("Enable sql high consume alert or not")
10931100
.booleanConf

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/ui/HiveThriftServer2Listener.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private[thriftserver] class HiveThriftServer2Listener(
4646
live: Boolean = true,
4747
queryLogger: Option[QueryLogger] = None) extends SparkListener with Logging {
4848

49+
val stringMaxLength = sparkConf.get(SQLConf.THRIFTSERVER_UI_STRING_MAX_LENGTH)
4950
// Spark execution id to Hive operationId map.
5051
private val execIdToExecutionId = new ConcurrentHashMap[Long, String]()
5152
private val sessionList = new ConcurrentHashMap[String, LiveSessionData]()
@@ -257,7 +258,9 @@ private[thriftserver] class HiveThriftServer2Listener(
257258
}
258259

259260
private def onOperationParsed(e: SparkListenerThriftServerOperationParsed): Unit = {
260-
executionList.get(e.id).executePlan = e.executionPlan
261+
val executionPlan =
262+
e.executionPlan.substring(0, Math.min(e.executionPlan.length, stringMaxLength))
263+
executionList.get(e.id).executePlan = executionPlan
261264
executionList.get(e.id).state = ExecutionState.COMPILED
262265
updateLiveStore(executionList.get(e.id))
263266
}
@@ -342,12 +345,13 @@ private[thriftserver] class HiveThriftServer2Listener(
342345
private def getOrCreateExecution(
343346
execId: String, statement: String,
344347
sessionId: String, startTimestamp: Long, userName: String): LiveExecutionData = {
348+
val subStatement = statement.substring(0, Math.min(statement.length, stringMaxLength))
345349
queryLogger match {
346350
case Some(queryLogger) =>
347351
executionList.computeIfAbsent(execId,
348352
(_: String) => new LiveExecutionData(
349353
execId,
350-
statement,
354+
subStatement,
351355
sessionId,
352356
startTimestamp,
353357
userName,
@@ -357,7 +361,7 @@ private[thriftserver] class HiveThriftServer2Listener(
357361
executionList.computeIfAbsent(execId,
358362
(_: String) => new LiveExecutionData(
359363
execId,
360-
statement,
364+
subStatement,
361365
sessionId,
362366
startTimestamp,
363367
userName))

0 commit comments

Comments
 (0)