Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaido91 committed May 14, 2018
1 parent ae89d00 commit 06b8b6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MaskExpressionsUtils {
final static int UNMASKED_VAL = -1;

/**
*
* Returns the masking character for {@param c} or {@param c} is it should not be masked.
* @param c the character to transform
* @param maskedUpperChar the character to use instead of a uppercase letter
* @param maskedLowerChar the character to use instead of a lowercase letter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ trait MaskLike {
}

def appendMaskedToStringBuffer(
sb: StringBuffer,
sb: java.lang.StringBuilder,
inputString: String,
startOffset: Int,
numChars: Int): Int = {
Expand All @@ -98,7 +98,7 @@ trait MaskLike {
}

def appendUnchangedToStringBuffer(
sb: StringBuffer,
sb: java.lang.StringBuilder,
inputString: String,
startOffset: Int,
numChars: Int): Int = {
Expand Down Expand Up @@ -128,16 +128,16 @@ object MaskLike {
val defaultMaskedOther: Int = MaskExpressionsUtils.UNMASKED_VAL

def extractCharCount(e: Expression): Int = e match {
case Literal(i, IntegerType|NullType) =>
case Literal(i, IntegerType | NullType) =>
if (i == null) defaultCharCount else i.asInstanceOf[Int]
case Literal(_, dt) => throw new AnalysisException(s"Expected literal expression of type " +
case Literal(_, dt) => throw new AnalysisException("Expected literal expression of type " +
s"${IntegerType.simpleString}, but got literal of ${dt.simpleString}")
case _ => defaultCharCount
}

def extractReplacement(e: Expression): String = e match {
case Literal(s, StringType|NullType) => if (s == null) null else s.toString
case Literal(_, dt) => throw new AnalysisException(s"Expected literal expression of type " +
case Literal(s, StringType | NullType) => if (s == null) null else s.toString
case Literal(_, dt) => throw new AnalysisException("Expected literal expression of type " +
s"${StringType.simpleString}, but got literal of ${dt.simpleString}")
case _ => null
}
Expand Down Expand Up @@ -173,7 +173,7 @@ case class Mask(child: Expression, upper: String, lower: String, digit: String)
override def nullSafeEval(input: Any): Any = {
val str = input.asInstanceOf[UTF8String].toString
val length = str.codePointCount(0, str.length())
val sb = new StringBuffer(length)
val sb = new java.lang.StringBuilder(length)
appendMaskedToStringBuffer(sb, str, 0, length)
UTF8String.fromString(sb.toString)
}
Expand Down Expand Up @@ -249,7 +249,7 @@ case class MaskFirstN(
val str = input.asInstanceOf[UTF8String].toString
val length = str.codePointCount(0, str.length())
val endOfMask = if (charCount > length) length else charCount
val sb = new StringBuffer(length)
val sb = new java.lang.StringBuilder(length)
val offset = appendMaskedToStringBuffer(sb, str, 0, endOfMask)
appendUnchangedToStringBuffer(sb, str, offset, length - endOfMask)
UTF8String.fromString(sb.toString)
Expand Down Expand Up @@ -332,7 +332,7 @@ case class MaskLastN(
val str = input.asInstanceOf[UTF8String].toString
val length = str.codePointCount(0, str.length())
val startOfMask = if (charCount >= length) 0 else length - charCount
val sb = new StringBuffer(length)
val sb = new java.lang.StringBuilder(length)
val offset = appendUnchangedToStringBuffer(sb, str, 0, startOfMask)
appendMaskedToStringBuffer(sb, str, offset, length - startOfMask)
UTF8String.fromString(sb.toString)
Expand Down Expand Up @@ -416,7 +416,7 @@ case class MaskShowFirstN(
val str = input.asInstanceOf[UTF8String].toString
val length = str.codePointCount(0, str.length())
val startOfMask = if (charCount > length) length else charCount
val sb = new StringBuffer(length)
val sb = new java.lang.StringBuilder(length)
val offset = appendUnchangedToStringBuffer(sb, str, 0, startOfMask)
appendMaskedToStringBuffer(sb, str, offset, length - startOfMask)
UTF8String.fromString(sb.toString)
Expand Down Expand Up @@ -499,7 +499,7 @@ case class MaskShowLastN(
val str = input.asInstanceOf[UTF8String].toString
val length = str.codePointCount(0, str.length())
val endOfMask = if (charCount >= length) 0 else length - charCount
val sb = new StringBuffer(length)
val sb = new java.lang.StringBuilder(length)
val offset = appendMaskedToStringBuffer(sb, str, 0, endOfMask)
appendUnchangedToStringBuffer(sb, str, offset, length - endOfMask)
UTF8String.fromString(sb.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class MaskExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
}

test("mask_first_n") {
checkEvaluation(MaskFirstN(Literal("abcd-EFGH-8765-4321"), 6, "U", "l", "#"),
"llll-UFGH-8765-4321")
checkEvaluation(MaskFirstN(Literal("aB3d-EFGH-8765"), 6, "U", "l", "#"),
"lU#l-UFGH-8765")
checkEvaluation(new MaskFirstN(
Literal("abcd-EFGH-8765-4321"), Literal(6), Literal("U"), Literal("l"), Literal("#")),
"llll-UFGH-8765-4321")
Expand Down Expand Up @@ -135,8 +135,8 @@ class MaskExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
"abcd-EFGH-8765-4321")
// scalastyle:off nonascii
checkEvaluation(MaskLastN(Literal("Ul9U"), 2, "\u2200", null, null), "Uln\u2200")
checkEvaluation(new MaskLastN(Literal("あ, 𠀋, Hello World"), Literal(10)),
"あ, 𠀋, Hxxxx Xxxxx")
checkEvaluation(new MaskLastN(Literal("あ, 𠀋, Hello World あ 𠀋"), Literal(10)),
"あ, 𠀋, Hello Xxxxx あ 𠀋")
// scalastyle:on nonascii
}

Expand Down

0 comments on commit 06b8b6c

Please sign in to comment.