Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache pig 用于在Pig中将数字格式化为字符串的自定义项_Apache Pig - Fatal编程技术网

Apache pig 用于在Pig中将数字格式化为字符串的自定义项

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

在Pig中,我想得到一个数字列,比如说“12345”,并将其转换为一个格式为“$12345”的字符串


现有的自定义项是否有助于使用标准格式,如添加美元符号、逗号、百分比等?我在文档中没有看到任何内容,这是我的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;
这应该对你有用