Skip to content

Commit

Permalink
Fix nullability of Substring expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
ueshin committed Jul 16, 2014
1 parent 4576d80 commit 80958ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ case class EndsWith(left: Expression, right: Expression)
case class Substring(str: Expression, pos: Expression, len: Expression) extends Expression {

type EvaluatedType = Any
def nullable: Boolean = true

def nullable: Boolean = str.nullable || pos.nullable || len.nullable
def dataType: DataType = {
if (!resolved) {
throw new UnresolvedException(this, s"Cannot resolve since $children are not resolved")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ class ExpressionEvaluationSuite extends FunSuite {

// 2-arg substring from nonzero position
checkEvaluation(Substring(s, Literal(2, IntegerType), Literal(Integer.MAX_VALUE, IntegerType)), "xample", row)

val s_notNull = 'a.string.notNull.at(0)

assert(Substring(s, Literal(0, IntegerType), Literal(2, IntegerType)).nullable === true)
assert(Substring(s_notNull, Literal(0, IntegerType), Literal(2, IntegerType)).nullable === false)
assert(Substring(s_notNull, Literal(null, IntegerType), Literal(2, IntegerType)).nullable === true)
assert(Substring(s_notNull, Literal(0, IntegerType), Literal(null, IntegerType)).nullable === true)
}
}

0 comments on commit 80958ac

Please sign in to comment.