odps词频统计

来源:互联网 发布:淘宝马学武白玉城真假 编辑:程序博客网 时间:2024/05/16 14:27

1、搭建maxcompute studio

一、编写udtf

2、在项目下面选择script新建文件:new->maxcomput python->python udtf ,然后编写文本spilt:

from odps.udf import annotatefrom odps.udf import BaseUDTF@annotate('string -> string')class my_first_udtf(BaseUDTF):    def process(self, arg):        props = arg.split(' ')        for p in props:            self.forward(p)

然后运行一下,本地调试,可以查看结果。

3、提交udtf,并注册函数:打开该python源码,在定义的类my_first_udtf中,右键-》deploy to  server,然后填写一下function  name即可上传,并且注册函数function name

4、sql调用函数 测试结果:

create table if not exists chenmo_word_split_tabel1(word string ) lifecycle 1;insert overwrite table  chenmo_word_split_tabel1 select my_first_udtf(word) as word from chenmo_wc_in;

二、编写udaf进行聚合统计




原创粉丝点击