Skip to content

Commit

Permalink
[SPARK-2518][SQL] Fix foldability of Substring expression.
Browse files Browse the repository at this point in the history
This is a follow-up of #1428.

Author: Takuya UESHIN <ueshin@happy-camper.st>

Closes #1432 from ueshin/issues/SPARK-2518 and squashes the following commits:

37d1ace [Takuya UESHIN] Fix foldability of Substring expression.
  • Loading branch information
ueshin authored and rxin committed Jul 16, 2014
1 parent fc7edc9 commit cc965ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Expand Down

0 comments on commit cc965ee

Please sign in to comment.