-
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
22bd4bd
Merge pull request #1 from apache/master
DaveDeCaprio b7f964d
Added a configurable limit on the maximum length of a plan debug string.
DaveDeCaprio 3f4fe1f
Removed unneeded imports
DaveDeCaprio 30e4348
Moved withSizeLimitedWriter to treeString function that uses StringWr…
DaveDeCaprio 5528ca1
Fixed formatting
DaveDeCaprio 3171cf3
Coverted to javadoc style multiline comment
DaveDeCaprio 3ffdc6a
Fixed scalastyle formatting of imports
DaveDeCaprio 45a60fc
Have size limit cut off right at the correct number of characters.
DaveDeCaprio 9678799
Changed name to remove the debug from the config parameter name
DaveDeCaprio a5af842
Fixed formatting error
DaveDeCaprio a4be985
Changed length default to Long.MaxValue to turn off behavior unless i…
DaveDeCaprio f0f75c2
Merge branch 'master' of https://github.com/apache/spark into text-pl…
DaveDeCaprio 1b692a0
Added test case for not limiting plan length and tested with a defaul…
DaveDeCaprio 22fe117
Correctly added test case missed in the previous commit
DaveDeCaprio be3f265
Added more documentation of the plan length parameter.
DaveDeCaprio f6d0efc
Merge branch 'master' of https://github.com/apache/spark into text-pl…
DaveDeCaprio 855f540
Removed tab
DaveDeCaprio e83f5f2
Merge branch 'master' of https://github.com/apache/spark into text-pl…
DaveDeCaprio db663b7
Merge branch 'master' of https://github.com/apache/spark into text-pl…
DaveDeCaprio 2eecbfa
Added plan size limits to StringConcat
DaveDeCaprio 4082aa3
Scalastyle
DaveDeCaprio f9085e7
Incorporated changes from code review
DaveDeCaprio b3d43b7
Missed one error
DaveDeCaprio e470ab2
Cleaned up append function and added tracking of the full plan length.
DaveDeCaprio 35bc1d5
Got rid of unneeded "availableLength" flag.
DaveDeCaprio 5ec58c8
Fixed errors missed
DaveDeCaprio bdfaf28
Updated to handle nulls again.
DaveDeCaprio 0cfcb4e
Tabs to spaces
DaveDeCaprio eb69888
Remove useless test.
DaveDeCaprio daf02f2
Addressed code review comments.
DaveDeCaprio 7d89388
Missed some Boolean->Unit updates
DaveDeCaprio 4f56e48
Missed some Boolean->Unit updates
DaveDeCaprio a090fbb
Code formatting
DaveDeCaprio dcb4eb0
Fixed Fatal Warning.
DaveDeCaprio b4cb7bf
Fixed failing unit tests
DaveDeCaprio 4fec590
Style/formatting issues from code review
DaveDeCaprio db0db18
Style/formatting issues from code review
DaveDeCaprio b5b30f3
Changed plan string length to bytesConf and gave a better message for…
DaveDeCaprio e4afa26
Tabs to spaces
DaveDeCaprio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/SizeLimitedWriter.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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.util | ||
|
|
||
| import java.io.Writer | ||
|
|
||
| class WriterSizeException(val attemptedSize: Long, val charLimit: Long) extends Exception( | ||
| s"Attempted to write $attemptedSize characters to a writer that is limited to $charLimit") | ||
|
|
||
| /** | ||
| * This class is used to control the size of generated writers. Guarantees that the total number | ||
| * of characters written will be less than the specified size. | ||
| * | ||
| * Checks size before writing and throws a WriterSizeException if the total size would count the | ||
| * limit. | ||
| */ | ||
| class SizeLimitedWriter(underlying: Writer, charLimit: Long) extends Writer { | ||
|
|
||
| var charsWritten: Long = 0 | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| override def write(cbuf: Array[Char], off: Int, len: Int): Unit = { | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val newLength = charsWritten + Math.min(cbuf.length - off, len) | ||
| if (newLength > charLimit) { | ||
| throw new WriterSizeException(newLength, charLimit) | ||
| } | ||
| charsWritten = newLength | ||
| underlying.write(cbuf, off, len) | ||
| } | ||
|
|
||
| override def flush(): Unit = underlying.flush() | ||
|
|
||
| override def close(): Unit = underlying.close() | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -202,6 +202,26 @@ package object util extends Logging { | |
| /** Shorthand for calling truncatedString() without start or end strings. */ | ||
| def truncatedString[T](seq: Seq[T], sep: String): String = truncatedString(seq, "", sep, "") | ||
|
|
||
| /** Whether we have warned about plan string truncation yet. */ | ||
| private val planSizeWarningPrinted = new AtomicBoolean(false) | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def withSizeLimitedWriter[T](writer: Writer)(f: (Writer) => T): Option[T] = { | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| val limited = new SizeLimitedWriter(writer, SQLConf.get.maxPlanStringLength) | ||
| Some(f(limited)) | ||
| } | ||
| catch { | ||
| case e: WriterSizeException => | ||
| writer.write("...") | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (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}'.") | ||
| } | ||
| None | ||
| } | ||
| } | ||
|
|
||
| /* FIX ME | ||
| implicit class debugLogging(a: Any) { | ||
| def debugLogging() { | ||
|
|
||
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
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
45 changes: 45 additions & 0 deletions
45
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/SizeLimitedWriterSuite.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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.util | ||
|
|
||
| import org.apache.commons.io.output.StringBuilderWriter | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.catalyst.util.StringUtils._ | ||
|
|
||
| class SizeLimitedWriterSuite extends SparkFunSuite { | ||
|
|
||
| test("normal writer under limit") { | ||
| val writer = new StringBuilderWriter() | ||
| val limited = new SizeLimitedWriter(writer, 100) | ||
| limited.write("test") | ||
| limited.write("test") | ||
|
|
||
| assert(writer.toString === "testtest") | ||
| } | ||
|
|
||
| test("filter pattern") { | ||
| val writer = new StringBuilderWriter() | ||
| val limited = new SizeLimitedWriter(writer, 5) | ||
| assertThrows[WriterSizeException] { | ||
| limited.write("test") | ||
| limited.write("test") | ||
| } | ||
| assert(writer.toString === "test") | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.