Skip to content

Commit

Permalink
add foldable and remove null checking
Browse files Browse the repository at this point in the history
  • Loading branch information
zhichao-li committed Jul 24, 2015
1 parent 9546991 commit 515519b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ case class Substring_index(strExpr: Expression, delimExpr: Expression, countExpr
extends Expression with ImplicitCastInputTypes {

override def dataType: DataType = StringType
override def foldable: Boolean = strExpr.foldable && delimExpr.foldable && countExpr.foldable
override def inputTypes: Seq[DataType] = Seq(StringType, StringType, IntegerType)
override def nullable: Boolean = strExpr.nullable || delimExpr.nullable || countExpr.nullable
override def children: Seq[Expression] = Seq(strExpr, delimExpr, countExpr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public byte[] getBytes() {
*/
public UTF8String substring(final int start, final int until) {
if (until <= start || start >= numBytes) {
return fromBytes(new byte[0]);
return UTF8String.EMPTY_UTF8;
}
int j = firstByteIndex(0, 0, start);
int i = firstByteIndex(j, start, until);
Expand Down Expand Up @@ -502,9 +502,6 @@ private int doOrdinalIndexOf(
* right) is returned. substring_index performs a case-sensitive match when searching for delim.
*/
public UTF8String subStringIndex(UTF8String delim, int count) {
if (delim == null) {
return null;
}
if (delim.numBytes == 0 || count == 0) {
return UTF8String.EMPTY_UTF8;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ public void substring_index() {
fromString("www||apache||org").subStringIndex(fromString("||"), 2));
assertEquals(fromString("apache||org"),
fromString("www||apache||org").subStringIndex(fromString("||"), -2));
// null
assertEquals(null,
fromString("www.apache.org").subStringIndex(null, -2));
// non ascii chars
assertEquals(fromString("大千世界大"),
fromString("大千世界大千世界").subStringIndex(fromString("千"), 2));
Expand Down

0 comments on commit 515519b

Please sign in to comment.