Skip to content

Conversation

@panbingkun
Copy link
Contributor

@panbingkun panbingkun commented May 31, 2024

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.

@panbingkun panbingkun marked this pull request as ready for review May 31, 2024 15:01
@panbingkun
Copy link
Contributor Author

cc @gengliangwang

@panbingkun
Copy link
Contributor Author

@gengliangwang
In addition, we also encountered this issue during migration: #46822

@gengliangwang
Copy link
Member

Thanks, merging to master

*/
class LogEntry(messageWithContext: => MessageWithContext) {
def message: String = messageWithContext.message
def message: String = StringEscapeUtils.unescapeJava(messageWithContext.message)
Copy link
Member

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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)

yaooqinn pushed a commit that referenced this pull request Jun 21, 2024
### 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 <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants