Apache pig 筑巢猪
我在“product”字段中有一个字符串,格式如下:Apache pig 筑巢猪,apache-pig,Apache Pig,我在“product”字段中有一个字符串,格式如下: ";TT_RAV;44;22;" 我想先在“;”上分手然后在‘‘’上拆分,以便返回的是 "RAV" 我知道我可以这样做: parse_1 = foreach { splitup = STRSPLIT(product,';',3); generate splitup.$1 as depiction; }; 这将返回字符串'TT_RAV',然后我可以进行另一次拆分并投影出'RAV',但是这
";TT_RAV;44;22;"
我想先在“;”上分手然后在‘‘’上拆分,以便返回的是
"RAV"
我知道我可以这样做:
parse_1 = foreach {
splitup = STRSPLIT(product,';',3);
generate splitup.$1 as depiction;
};
这将返回字符串'TT_RAV',然后我可以进行另一次拆分并投影出'RAV',但是这似乎将通过多个地图作业传递数据--是否可以在一次传递中解析出所需的字段
此示例不起作用,因为内部splitstring重新运行元组,但显示了逻辑:
c parse_1 = foreach {
splitup = STRSPLIT(STRSPLIT(product,';',3),'_',1);
generate splitup.$1 as depiction;
};
在没有多个映射阶段的情况下,是否可以在纯拉丁语中执行此操作 不要使用
STRSPLIT
。您正在查找REGEX\u EXTRACT
:
REGEX_EXTRACT(product, '_([^;]*);', 1) AS depiction
如果能够准确地挑出第二个分号分隔的字段和第二个下划线分隔的子字段很重要,则可以使正则表达式更复杂:
REGEX_EXTRACT(product, '^[^;]*;[^_;]*_([^_;]*)', 1) AS depiction
下面是该正则表达式的工作原理:
^ // Start at the beginning
[^;]* // Match as many non-semicolons as possible, if any (first field)
; // Match the semicolon; now we'll start the second field
[^_;]* // Match any characters in the first subfield
_ // Match the underscore; now we'll start the second subfield (what we want)
( // Start capturing!
[^_;]* // Match any characters in the second subfield
) // End capturing
只有当您有一个操作符触发reduce(JOIN、GROUP等)时,才会出现多个映射。如果在脚本上运行解释,您可以看到是否有多个reduce阶段