我在字段“product”中有一个字符串,形式如下:
";TT_RAV;44;22;" 我想先在“;”上拆分,然后在“_”上拆分,这样返回的内容是
"RAV" 我知道我可以这样做:
parse_1 = foreach {
splitup = STRSPLIT(product,';',3);
generate splitup.$1 as depiction;
}; 这将返回字符串'TT_RAV‘,然后我可以执行另一个拆分,并投影出'RAV’,但是这似乎将通过多个Map作业传递数据--是否可以一次解析所需的字段?
此示例不起作用,因为内部拆分字符串复述元组,但显示了逻辑:
c parse_1 = foreach {
splitup = STRSPLIT(STRSPLIT(product,';',3),'_',1);
generate splitup.$1 as depiction;
}; 在没有多个map相的纯吡格林中可以做到这一点吗?
发布于 2014-04-25 14:37:20
不要使用STRSPLIT。你在找REGEX_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发布于 2014-04-27 04:51:48
唯一会出现多个映射的情况是,如果您有一个操作符来触发一个减缩(JOIN、GROUP等)。如果您在脚本上运行解释,您可以看到是否有多个减缩阶段。
https://stackoverflow.com/questions/23295439
复制相似问题