-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-48490][CORE] Unescapes any literals for message of MessageWithContext #46824
Conversation
common/utils/src/main/scala/org/apache/spark/internal/Logging.scala
Outdated
Show resolved
Hide resolved
@gengliangwang |
Thanks, merging to master |
…Context ### What changes were proposed in this pull request? The pr aims to `unescapes` any literals for `message` of `MessageWithContext` ### Why are the changes needed? - For example, before this PR ``` logInfo("This is a log message\nThis is a new line \t other msg") ``` It will output: ``` 24/05/31 22:53:27 INFO PatternLoggingSuite: This is a log message This is a new line other msg ``` But: ``` logInfo(log"This is a log message\nThis is a new line \t other msg") ``` It will output: ``` 24/05/31 22:53:59 ERROR PatternLoggingSuite: This is a log message\nThis is a new line \t other msg ``` Obviously, the latter is not the result we `expected`. ### Does this PR introduce _any_ user-facing change? Yes, fix bug. ### How was this patch tested? - Add new UT. - Pass GA. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#46824 from panbingkun/SPARK-48490. Authored-by: panbingkun <panbingkun@baidu.com> Signed-off-by: Gengliang Wang <gengliang@apache.org>
@@ -99,7 +100,7 @@ case class MessageWithContext(message: String, context: java.util.HashMap[String | |||
* Companion class for lazy evaluation of the MessageWithContext instance. | |||
*/ | |||
class LogEntry(messageWithContext: => MessageWithContext) { | |||
def message: String = messageWithContext.message | |||
def message: String = StringEscapeUtils.unescapeJava(messageWithContext.message) |
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.
Hi, @panbingkun and @gengliangwang .
This seems to break SparkR somehow. Could you take a look at this?
-- Error ('test_basic.R:25:3'): create DataFrame from list or data.frame -------
Error in `handleErrors(returnStatus, conn)`: java.lang.IllegalArgumentException: Unable to parse unicode value: serF
at org.apache.commons.text.translate.UnicodeUnescaper.translate(UnicodeUnescaper.java:55)
at org.apache.commons.text.translate.AggregateTranslator.translate(AggregateTranslator.java:58)
at org.apache.commons.text.translate.CharSequenceTranslator.translate(CharSequenceTranslator.java:101)
at org.apache.commons.text.translate.CharSequenceTranslator.translate(CharSequenceTranslator.java:63)
at org.apache.commons.text.StringEscapeUtils.unescapeJava(StringEscapeUtils.java:802)
at org.apache.spark.internal.LogEntry.message(Logging.scala:103)
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.
Okay, Let me investigate it
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.
@dongjoon-hyun
I have identified the root cause of this issue and am currently attempting to fix it
#46897 (comment)
### What changes were proposed in this pull request? Even with the fix in #46824, the escape sequences (`\r`, `\n`, `\t`, etc) are not handled properly. For example, when we use `log"\n"`, the StringContext interprets `\n` as a literal backslash `\` followed by `n` instead of a newline character. As a result, the bytes of `log"\n".message` becomes `[92, 110]`, instead of `[10]`. This PR is to fix the issue by using the method StringContext.processEscapes in `LogStringContext`. ### Why are the changes needed? To ensure that escape sequences are properly processed in Spark logs ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New UT ### Was this patch authored or co-authored using generative AI tooling? No Closes #47050 from gengliangwang/fixEscape. Authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Kent Yao <yao@apache.org>
### What changes were proposed in this pull request? Even with the fix in apache#46824, the escape sequences (`\r`, `\n`, `\t`, etc) are not handled properly. For example, when we use `log"\n"`, the StringContext interprets `\n` as a literal backslash `\` followed by `n` instead of a newline character. As a result, the bytes of `log"\n".message` becomes `[92, 110]`, instead of `[10]`. This PR is to fix the issue by using the method StringContext.processEscapes in `LogStringContext`. ### Why are the changes needed? To ensure that escape sequences are properly processed in Spark logs ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New UT ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#47050 from gengliangwang/fixEscape. Authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Kent Yao <yao@apache.org>
What changes were proposed in this pull request?
The pr aims to
unescapes
any literals formessage
ofMessageWithContext
Why are the changes needed?
It will output:
But:
It will output:
Obviously, the latter is not the result we
expected
.Does this PR introduce any user-facing change?
Yes, fix bug.
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No.