Repository: spark Updated Branches: refs/heads/master fc7edc9e7 -> cc965eea5
[SPARK-2518][SQL] Fix foldability of Substring expression. This is a follow-up of #1428. Author: Takuya UESHIN <ues...@happy-camper.st> Closes #1432 from ueshin/issues/SPARK-2518 and squashes the following commits: 37d1ace [Takuya UESHIN] Fix foldability of Substring expression. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/cc965eea Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/cc965eea Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/cc965eea Branch: refs/heads/master Commit: cc965eea510397642830acb21f61127b68c098d6 Parents: fc7edc9 Author: Takuya UESHIN <ues...@happy-camper.st> Authored: Wed Jul 16 11:13:38 2014 -0700 Committer: Reynold Xin <r...@apache.org> Committed: Wed Jul 16 11:13:38 2014 -0700 ---------------------------------------------------------------------- .../sql/catalyst/expressions/stringOperations.scala | 2 ++ .../catalyst/optimizer/ConstantFoldingSuite.scala | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/cc965eea/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala ---------------------------------------------------------------------- diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala index f1b27c3..97fc3a3 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala @@ -216,6 +216,8 @@ case class Substring(str: Expression, pos: Expression, len: Expression) extends type EvaluatedType = Any + override def foldable = str.foldable && pos.foldable && len.foldable + def nullable: Boolean = str.nullable || pos.nullable || len.nullable def dataType: DataType = { if (!resolved) { http://git-wip-us.apache.org/repos/asf/spark/blob/cc965eea/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ConstantFoldingSuite.scala ---------------------------------------------------------------------- diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ConstantFoldingSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ConstantFoldingSuite.scala index 0ff8206..ff8d0d0 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ConstantFoldingSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ConstantFoldingSuite.scala @@ -201,7 +201,12 @@ class ConstantFoldingSuite extends PlanTest { Like(Literal(null, StringType), "abc") as 'c13, Like("abc", Literal(null, StringType)) as 'c14, - Upper(Literal(null, StringType)) as 'c15) + Upper(Literal(null, StringType)) as 'c15, + + Substring(Literal(null, StringType), 0, 1) as 'c16, + Substring("abc", Literal(null, IntegerType), 1) as 'c17, + Substring("abc", 0, Literal(null, IntegerType)) as 'c18 + ) val optimized = Optimize(originalQuery.analyze) @@ -228,8 +233,12 @@ class ConstantFoldingSuite extends PlanTest { Literal(null, BooleanType) as 'c13, Literal(null, BooleanType) as 'c14, - Literal(null, StringType) as 'c15) - .analyze + Literal(null, StringType) as 'c15, + + Literal(null, StringType) as 'c16, + Literal(null, StringType) as 'c17, + Literal(null, StringType) as 'c18 + ).analyze comparePlans(optimized, correctAnswer) }