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?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---