Apache pig 用于在Pig中将数字格式化为字符串的自定义项
在Pig中,我想得到一个数字列,比如说“12345”,并将其转换为一个格式为“$12345”的字符串Apache pig 用于在Pig中将数字格式化为字符串的自定义项,apache-pig,Apache Pig,在Pig中,我想得到一个数字列,比如说“12345”,并将其转换为一个格式为“$12345”的字符串 现有的自定义项是否有助于使用标准格式,如添加美元符号、逗号、百分比等?我在文档中没有看到任何内容,这是我的python UDF,您可以利用它 #!/usr/bin/python @outputSchema("formatted:chararray") def toDol(number): s = '%d' % number groups = [] while s and
现有的自定义项是否有助于使用标准格式,如添加美元符号、逗号、百分比等?我在文档中没有看到任何内容,这是我的python UDF,您可以利用它
#!/usr/bin/python
@outputSchema("formatted:chararray")
def toDol(number):
s = '%d' % number
groups = []
while s and s[-1].isdigit():
groups.append(s[-3:])
s = s[:-3]
res = s + ','.join(reversed(groups))
res = '$' + res
return res
这就是你的猪脚本的样子
Register 'locale_udf.py' using jython as myfuncs;
DT = LOAD 'sample_data.txt' Using PigStorage() as (dol:float);
DTR = FOREACH DT GENERATE dol,myfuncs.toDol(dol) as formattedstring;
dump DTR;
这应该对你有用