[ 
https://issues.apache.org/jira/browse/TRAFODION-2358?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15685074#comment-15685074
 ] 

ASF GitHub Bot commented on TRAFODION-2358:
-------------------------------------------

Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/843#discussion_r89012789
  
    --- Diff: core/sql/exp/exp_function.cpp ---
    @@ -8235,5 +8244,118 @@ ex_expr::exp_return_type ExFunctionIsIP::eval(char 
* op_data[],
       }
     }
     
    +/*
    + * SOUNDEX(str) returns a character string containing the phonetic
    + * representation of the input string. It lets you compare words that
    + * are spelled differently, but sound alike in English.
    + * The phonetic representation is defined in "The Art of Computer 
Programming",
    + * Volume 3: Sorting and Searching, by Donald E. Knuth, as follows:
    + *
    + *  1. Retain the first letter of the string and remove all other 
occurrences
    + *  of the following letters: a, e, h, i, o, u, w, y.
    + *
    + *  2. Assign numbers to the remaining letters (after the first) as 
follows:
    + *        b, f, p, v = 1
    + *        c, g, j, k, q, s, x, z = 2
    + *        d, t = 3
    + *        l = 4
    + *        m, n = 5
    + *        r = 6
    + *
    + *  3. If two or more letters with the same number were adjacent in the 
original
    + *  name (before step 1), or adjacent except for any intervening h and w, 
then
    + *  omit all but the first.
    + *
    + *  4. Return the first four bytes padded with 0.
    + * */
    +ex_expr::exp_return_type ExFunctionSoundex::eval(char *op_data[],
    +                                                CollHeap *heap,
    +                                                ComDiagsArea** diagsArea)
    +{
    +    ULng32 previous = 0;
    +    ULng32 current = 0;
    +
    +    char *srcStr = op_data[1];
    +    char *tgtStr = op_data[0];
    +    Lng32 srcLen = getOperand(1)->getLength(op_data[-MAX_OPERANDS+1]);
    +    Lng32 tgtLen = getOperand(0)->getLength();
    +    
    +    CharInfo::CharSet cs = ((SimpleType *)getOperand(1))->getCharSet();
    +
    +    str_pad(tgtStr, tgtLen, '\0');
    +
    +    tgtStr[0] = toupper(srcStr[0]);    // Retain the first letter, convert 
to capital anyway
    +    Int16 setLen = 1;                  // The first character is set 
already
    +
    +    for(int i=1; i < srcLen; ++i)
    +    {
    +        char chr = toupper(srcStr[i]);
    +        switch(chr)
    +        {
    +            case 'A':
    +            case 'E':
    +            case 'H':
    +            case 'I':
    +            case 'O':
    +            case 'U':
    +            case 'W':
    +            case 'Y':
    +                current = 0;
    +                break;
    +            case 'B':
    +            case 'F':
    +            case 'P':
    +            case 'V':
    +                current = 1;
    +                break;
    +            case 'C':
    +            case 'G':
    +            case 'J':
    +            case 'K':
    +            case 'Q':
    +            case 'S':
    +            case 'X':
    +            case 'Z':
    +                current = 2;
    +                break;
    +            case 'D':
    +            case 'T':
    +                current = 3;
    +                break;
    +            case 'L':
    +                current = 4;
    +                break;
    +            case 'M':
    +            case 'N':
    +                current = 5;
    +                break;
    +            case 'R':
    +                current = 6;
    +                break;
    +            default:
    +                break;
    --- End diff --
    
    Should we set current to something in this case? If we don't, then it just 
has the same value as it had before. Perhaps that is intended?


> Support SOUNDEX() function
> --------------------------
>
>                 Key: TRAFODION-2358
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-2358
>             Project: Apache Trafodion
>          Issue Type: Sub-task
>            Reporter: RuoYu Zuo
>
> To support SOUNDEX() function, which allows user to compare words that are 
> spelled differently, but sound alike in English. This is useful for searching 
> people's names that sound alike.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to