-
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 18 commits
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
There are no files selected for viewing
| 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 extraChars: Long, val charLimit: Long) extends Exception( | ||
| s"Writer reached limit of $charLimit characters. $extraChars extra characters ignored.") | ||
|
|
||
| /** | ||
| * 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 { | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private var charsWritten: Long = 0 | ||
|
|
||
| override def write(cbuf: Array[Char], off: Int, len: Int): Unit = { | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val charsToWrite = Math.min(charLimit - charsWritten, len).toInt | ||
| underlying.write(cbuf, off, charsToWrite) | ||
| charsWritten += charsToWrite | ||
|
||
| if (charsToWrite < len) { | ||
| throw new WriterSizeException(len - charsToWrite, charLimit) | ||
DaveDeCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| override def flush(): Unit = underlying.flush() | ||
|
|
||
| override def close(): Unit = underlying.close() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,6 +204,27 @@ package object util extends Logging { | |
| truncatedString(seq, "", sep, "", maxFields) | ||
| } | ||
|
|
||
| /** 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 { | ||
| // Subtract 3 from the string length to leave room for the "..." | ||
| val limited = new SizeLimitedWriter(writer, SQLConf.get.maxPlanStringLength - 3) | ||
| 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() { | ||
|
|
||
| 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("truncate at the limit") { | ||
| val writer = new StringBuilderWriter() | ||
| val limited = new SizeLimitedWriter(writer, 5) | ||
| assertThrows[WriterSizeException] { | ||
| limited.write("test") | ||
| limited.write("test") | ||
| } | ||
| assert(writer.toString === "testt") | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.