1. CONCAT:
- 描述: 将两个或多个字符串连接起来。
- 示例:
A = LOAD 'data.txt' AS (first_name:chararray, last_name:chararray);
B = FOREACH A GENERATE CONCAT(first_name, ' ', last_name) AS full_name;
2. SUBSTRING:
- 描述: 从字符串中提取子字符串。
- 示例:
A = LOAD 'data.txt' AS (text:chararray);
B = FOREACH A GENERATE SUBSTRING(text, 0, 5) AS substring_text;
3. INDEXOF:
- 描述: 查找字符串中子字符串的位置。
- 示例:
A = LOAD 'data.txt' AS (text:chararray);
B = FOREACH A GENERATE INDEXOF(text, 'search') AS index;
4. UPPER 和 LOWER:
- 描述: 将字符串转换为大写或小写。
- 示例:
A = LOAD 'data.txt' AS (text:chararray);
B = FOREACH A GENERATE UPPER(text) AS uppercase_text, LOWER(text) AS lowercase_text;
5. TRIM:
- 描述: 移除字符串两端的空格。
- 示例:
A = LOAD 'data.txt' AS (text:chararray);
B = FOREACH A GENERATE TRIM(text) AS trimmed_text;
6. REPLACE:
- 描述: 替换字符串中的指定子字符串。
- 示例:
A = LOAD 'data.txt' AS (text:chararray);
B = FOREACH A GENERATE REPLACE(text, 'old', 'new') AS replaced_text;
7. STRSPLIT:
- 描述: 将字符串分割为子字符串并返回一个包。
- 示例:
A = LOAD 'data.txt' AS (text:chararray);
B = FOREACH A GENERATE STRSPLIT(text, ' ', 2) AS words:bag{t:tuple(word:chararray)};
这些是一些常用的字符串函数示例。你可以根据具体的需求选择适当的函数。字符串函数在数据清理、转换和分析中非常有用。
转载请注明出处:http://www.zyzy.cn/article/detail/11112/Apache Pig