Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7115#discussion_r34320200
  
    --- Diff: 
unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
    @@ -262,4 +266,63 @@ public int hashCode() {
         }
         return result;
       }
    +
    +  private char[] getSoundexMapping() {
    +    return US_ENGLISH_MAPPING;
    +  }
    +
    +  private char map(final char ch) {
    +    final int index = ch - 'A';
    +    if (index < 0 || index >= getSoundexMapping().length) {
    +      throw new IllegalArgumentException("The character is not mapped: " + 
ch);
    +    }
    +    return getSoundexMapping()[index];
    +  }
    +
    +  private char getMappingCode(final String str, final int index) {
    +    // map() throws IllegalArgumentException
    +    final char mappedChar = map(str.charAt(index));
    +    // HW rule check
    +    if (index > 1 && mappedChar != '0') {
    +      final char hwChar = str.charAt(index - 1);
    +      if ('H' == hwChar || 'W' == hwChar) {
    +        final char preHWChar = str.charAt(index - 2);
    +        final char firstCode = map(preHWChar);
    +        if (firstCode == mappedChar || 'H' == preHWChar || 'W' == 
preHWChar) {
    +          return 0;
    +        }
    +      }
    +    }
    +    return mappedChar;
    +  }
    +
    +  private String soundex(String str) {
    +    final char out[] = {'0', '0', '0', '0'};
    +    char last, mapped;
    +    int incount = 1, count = 1;
    +    out[0] = str.charAt(0);
    +    last = getMappingCode(str, 0);
    +    while (incount < str.length() && count < out.length) {
    +      mapped = getMappingCode(str, incount++);
    +      if (mapped != 0) {
    +        if (mapped != '0' && mapped != last) {
    +          out[count++] = mapped;
    +        }
    +        last = mapped;
    +      }
    +    }
    +    return new String(out);
    +  }
    +
    +  public UTF8String SoundexWrapper(final UTF8String str) {
    --- End diff --
    
    the first letter of a function should be in lowercase. 
    But I don't think we need this function here. It's supposed to be the logic 
of the expression `SoundEx`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to