aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorgatorsmile <gatorsmile@gmail.com>2015-12-06 11:15:02 -0800
committerYin Huai <yhuai@databricks.com>2015-12-06 11:15:02 -0800
commit49efd03bacad6060d99ed5e2fe53ba3df1d1317e (patch)
tree37b6fa211d641a2232228cb9165a2d7cba0bbfa7 /sql
parent04b6799932707f0a4aa4da0f2fc838bdb29794ce (diff)
downloadspark-49efd03bacad6060d99ed5e2fe53ba3df1d1317e.tar.gz
spark-49efd03bacad6060d99ed5e2fe53ba3df1d1317e.tar.bz2
spark-49efd03bacad6060d99ed5e2fe53ba3df1d1317e.zip
[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.
Diffstat (limited to 'sql')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala4
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala9
2 files changed, 12 insertions, 1 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
index 614f0c075f..6d807c9ecf 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
@@ -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")
}
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
index fe754240dc..cd2ef7dcd0 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
@@ -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")))
+ }
}