MaxCompute auto increment PythonUDF
有一些时候需要生成一个自增的id,以便能和mysql的表对应进行同步。参考了相关文档,写了一个python版的udf。
# coding=utf-8
from odps.udf import annotate
@annotate("*->bigint")
class AutoIncrement(object):
count=0
def evaluate(self,*args):
base =0
if len(args)==1 and isinstance(args[0],(int,long)) and args[0]>=0 :
base=args[0]
self.count=self.count+1
return s