Skip to content
Snippets Groups Projects
Commit 49efd03b authored by gatorsmile's avatar gatorsmile Committed by Yin Huai
Browse files

[SPARK-12138][SQL] Escape \u in the generated comments of codegen

When \u appears in a comment block (i.e. in /**/), code gen will break. So, in Expression and CodegenFallback, we escape \u to \\u.

yhuai Please review it. I did reproduce it and it works after the fix. Thanks!

Author: gatorsmile <gatorsmile@gmail.com>

Closes #10155 from gatorsmile/escapeU.
parent 04b67999
No related branches found
No related tags found
No related merge requests found
......@@ -220,7 +220,9 @@ abstract class Expression extends TreeNode[Expression] {
* Returns the string representation of this expression that is safe to be put in
* code comments of generated code.
*/
protected def toCommentSafeString: String = this.toString.replace("*/", "\\*\\/")
protected def toCommentSafeString: String = this.toString
.replace("*/", "\\*\\/")
.replace("\\u", "\\\\u")
}
......
......@@ -107,4 +107,13 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
true,
InternalRow(UTF8String.fromString("*/")))
}
test("\\u in the data") {
// When \ u appears in a comment block (i.e. in /**/), code gen will break.
// So, in Expression and CodegenFallback, we escape \ u to \\u.
checkEvaluation(
EqualTo(BoundReference(0, StringType, false), Literal.create("\\u", StringType)),
true,
InternalRow(UTF8String.fromString("\\u")))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment