-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26103][SQL] Limit the length of debug strings for query plans #23169
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
Changes from 1 commit
22bd4bd
b7f964d
3f4fe1f
30e4348
5528ca1
3171cf3
3ffdc6a
45a60fc
9678799
a5af842
a4be985
f0f75c2
1b692a0
22fe117
be3f265
f6d0efc
855f540
e83f5f2
db663b7
2eecbfa
4082aa3
f9085e7
b3d43b7
e470ab2
35bc1d5
5ec58c8
bdfaf28
0cfcb4e
eb69888
daf02f2
7d89388
4f56e48
a090fbb
dcb4eb0
b4cb7bf
4fec590
db0db18
b5b30f3
e4afa26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,14 +17,17 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.util | ||
|
|
||
| import java.util.concurrent.atomic.AtomicBoolean | ||
| import java.util.regex.{Pattern, PatternSyntaxException} | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
||
| object StringUtils { | ||
| object StringUtils extends Logging { | ||
|
|
||
| /** | ||
| * Validate and convert SQL 'like' pattern to a Java regular expression. | ||
|
|
@@ -92,31 +95,57 @@ object StringUtils { | |
|
|
||
| /** | ||
| * Concatenation of sequence of strings to final string with cheap append method | ||
| * and one memory allocation for the final string. | ||
| * and one memory allocation for the final string. Can also bound the final size of | ||
| * the string. | ||
| */ | ||
| class StringConcat { | ||
| class StringConcat(val maxLength: Int = Integer.MAX_VALUE) { | ||
|
||
| private val strings = new ArrayBuffer[String] | ||
| private var length: Int = 0 | ||
|
|
||
| def atLimit: Boolean = length >= maxLength | ||
|
|
||
| /** | ||
| * Appends a string and accumulates its length to allocate a string buffer for all | ||
| * appended strings once in the toString method. | ||
| * appended strings once in the toString method. Returns true if the string still | ||
| * has room for further appends before it hits its max limit. | ||
| */ | ||
| def append(s: String): Unit = { | ||
| if (s != null) { | ||
| def append(s: String): Boolean = { | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!atLimit && s != null) { | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| strings.append(s) | ||
| length += s.length | ||
| } | ||
| return !atLimit | ||
| } | ||
|
|
||
| /** | ||
| * The method allocates memory for all appended strings, writes them to the memory and | ||
| * returns concatenated string. | ||
| */ | ||
| override def toString: String = { | ||
| val result = new java.lang.StringBuilder(length) | ||
| strings.foreach(result.append) | ||
| val finalLength = Math.min(length, maxLength) | ||
|
||
| val result = new java.lang.StringBuilder(finalLength) | ||
| strings.dropRight(1).foreach(result.append) | ||
| strings.lastOption.foreach { s => | ||
| val lastLength = Math.min(s.length, maxLength - result.length()) | ||
| result.append(s, 0, lastLength) | ||
| } | ||
| result.toString | ||
DaveDeCaprio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| /** Whether we have warned about plan string truncation yet. */ | ||
| private val planSizeWarningPrinted = new AtomicBoolean(false) | ||
|
||
|
|
||
| /** A string concatenator for plan strings. Uses length from a configured value, and | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * prints a warning the first time a plan is truncated. */ | ||
|
||
| class PlanStringConcat extends StringConcat(SQLConf.get.maxPlanStringLength) { | ||
| override def toString: String = { | ||
| if (atLimit && planSizeWarningPrinted.compareAndSet(false, true)) { | ||
| logWarning( | ||
| "Truncated the string representation of a plan since it was too long. This " + | ||
| s"behavior can be adjusted by setting '${SQLConf.MAX_PLAN_STRING_LENGTH.key}'.") | ||
| } | ||
| super.toString | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.