You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by yh...@apache.org on 2015/12/06 20:15:06 UTC
spark git commit: [SPARK-12138][SQL] Escape \u in the generated
comments of codegen
Repository: spark
Updated Branches:
refs/heads/master 04b679993 -> 49efd03ba
[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 <ga...@gmail.com>
Closes #10155 from gatorsmile/escapeU.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/49efd03b
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/49efd03b
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/49efd03b
Branch: refs/heads/master
Commit: 49efd03bacad6060d99ed5e2fe53ba3df1d1317e
Parents: 04b6799
Author: gatorsmile <ga...@gmail.com>
Authored: Sun Dec 6 11:15:02 2015 -0800
Committer: Yin Huai <yh...@databricks.com>
Committed: Sun Dec 6 11:15:02 2015 -0800
----------------------------------------------------------------------
.../apache/spark/sql/catalyst/expressions/Expression.scala | 4 +++-
.../sql/catalyst/expressions/CodeGenerationSuite.scala | 9 +++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/49efd03b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
----------------------------------------------------------------------
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 614f0c0..6d807c9 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")
}
http://git-wip-us.apache.org/repos/asf/spark/blob/49efd03b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
----------------------------------------------------------------------
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 fe75424..cd2ef7d 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")))
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org