当前位置: 首页 > wzjs >正文

承德网站建设公司今日新闻头条新闻摘抄

承德网站建设公司,今日新闻头条新闻摘抄,产品内页设计,在线精品课程网站开发大纲 udtaf要求func_type必须是generaldelegate function要求非func_type必须是pandas 在研究Flink的“用户自定义方法”(UserDefinedFunction)时,我们看到存在如下几种类型的装饰器: UDF:User Defined Scalar Functio…

大纲

  • udtaf要求func_type必须是general
  • delegate function要求非func_type必须是pandas

在研究Flink的“用户自定义方法”(UserDefinedFunction)时,我们看到存在如下几种类型的装饰器:

  1. UDF:User Defined Scalar Function
  2. UDTF:User Defined Table Function
  3. UDAF:User Defined Aggregate Function
  4. UDTAF:User Defined Table Aggregate Function

在很多案例中,我们看到udf、udtf和udaf几个装饰器修饰function

@udf(result_type=DataTypes.BIGINT())
def add(i, j):return i + j@udtf(result_types=[DataTypes.BIGINT(), DataTypes.BIGINT()])
def range_emit(s, e):for i in range(e):yield s, i@udaf(result_type=DataTypes.FLOAT(), func_type="pandas")
def mean_udaf(v):return v.mean()

但是没有见到udtaf修饰function的案例,比如

# 错误的
@udtaf(result_type=DataTypes.ROW([DataTypes.FIELD("word", DataTypes.STRING()) , DataTypes.FIELD("count", DataTypes.BIGINT())]), accumulator_type=DataTypes.ROW([DataTypes.FIELD("word", DataTypes.STRING())]), func_type="general")
def lower(line):yield Row('a', 1)

这是因为这儿存在一个悖论

udtaf要求func_type必须是general

def udtaf(f: Union[Callable, TableAggregateFunction, Type] = None,input_types: Union[List[DataType], DataType, str, List[str]] = None,result_type: Union[DataType, str] = None,accumulator_type: Union[DataType, str] = None,deterministic: bool = None, name: str = None,func_type: str = 'general') -> Union[UserDefinedAggregateFunctionWrapper, Callable]:"""Helper method for creating a user-defined table aggregate function.:param f: user-defined table aggregate function.:param input_types: optional, the input data types.:param result_type: the result data type.:param accumulator_type: optional, the accumulator data type.:param deterministic: the determinism of the function's results. True if and only if a call tothis function is guaranteed to always return the same result given thesame parameters. (default True):param name: the function name.:param func_type: the type of the python function, available value: general(default: general):return: UserDefinedAggregateFunctionWrapper or function... versionadded:: 1.13.0"""if func_type != 'general':raise ValueError("The func_type must be 'general', got %s."% func_type)if f is None:return functools.partial(_create_udtaf, input_types=input_types, result_type=result_type,accumulator_type=accumulator_type, func_type=func_type,deterministic=deterministic, name=name)else:return _create_udtaf(f, input_types, result_type, accumulator_type, func_type,deterministic, name)

如果func_type不是’general’,则会抛出错误,所以func_type="pandas"是不可以的。
udtaf修饰方法后的返回类型是UserDefinedAggregateFunctionWrapper。

def _create_udtaf(f, input_types, result_type, accumulator_type, func_type, deterministic, name):return UserDefinedAggregateFunctionWrapper(f, input_types, result_type, accumulator_type, func_type, deterministic, name, True)

delegate function要求非func_type必须是pandas

Table API下只有这些方法接受udtaf修饰function返回的UserDefinedAggregateFunctionWrapper。

  • def aggregate(self, func: Union[Expression, UserDefinedAggregateFunctionWrapper]) -> ‘AggregatedTable’
  • def flat_aggregate(self, func: Union[Expression, UserDefinedAggregateFunctionWrapper]) -> ‘FlatAggregateTable’

这些方法的在底层会调用被修饰的UserDefinedFunctionWrapper。

    def aggregate(self, func: Union[Expression, UserDefinedAggregateFunctionWrapper]) \-> 'AggregatedTable':"""Performs a global aggregate operation with an aggregate function. You have to close theaggregate with a select statement... versionadded:: 1.13.0"""if isinstance(func, Expression):return AggregatedTable(self._j_table.aggregate(func._j_expr), self._t_env)else:func._set_takes_row_as_input()if hasattr(func, "_alias_names"):alias_names = getattr(func, "_alias_names")func = func(with_columns(col("*"))).alias(*alias_names)else:func = func(with_columns(col("*")))return AggregatedTable(self._j_table.aggregate(func._j_expr), self._t_env)

进而会调用到_java_user_defined_function。由于udtaf修饰的方法不是UserDefinedFunction对象,而是一个function,所以它会通过_create_delegate_function创建新的func 。

class UserDefinedFunctionWrapper(object):
……def _java_user_defined_function(self):……if not isinstance(self._func, UserDefinedFunction):func = self._create_delegate_function()……

而_create_delegate_function则要求udtaf中的function的func_type必须是pandas

    def _create_delegate_function(self) -> UserDefinedFunction:assert self._func_type == 'pandas'return DelegatingPandasAggregateFunction(self._func)

这就和之前udtaf中要求func_type必须是general相背。
所以我们没看到udtaf修饰function的案例。

http://www.dtcms.com/wzjs/219478.html

相关文章:

  • 如何进行网站建设分析网站怎么做的
  • wordpress导航站模板线上线下推广方案
  • 淘宝官网免费开店入口上海营销seo
  • 有没有高质量的网站都懂的今日世界杯比分预测最新
  • 本地推广找哪些网站挖掘关键词工具
  • WordPress url 数据表百度网站排名优化
  • 网站二次开发的模板种类英文外链代发
  • 辽阳做网站爱网站查询挖掘工具
  • 泸州市住房和城乡建设局网站百度站长资源
  • wordpress 多网址合肥网络公司seo建站
  • 杭州桐庐网站建设沈阳seo整站优化
  • 访问网站需要账号密码济宁百度推广公司有几家
  • 网站开发人员的岗位有短视频seo推广隐迅推专业
  • app开发公司选择技巧秦皇岛网站seo
  • 推广网站的广告怎样做博客是哪个软件
  • 如何自己开网站利用搜索引擎营销成功的案例
  • 城市建设法规考试网站电商运营培训机构哪家好
  • 上班自己花钱做的网站营销宝
  • 微信服务商平台官网seo是付费还是免费推广
  • 什么摄像头做直播网站怎么制作网页里面的内容
  • 营销网站定位微信群免费推广平台
  • 我要素材网网页设计素材上海优化排名网站
  • 做设计在哪个网站接单高端网站优化公司
  • 一般做网站销售提成做网络推广怎么收费
  • 怎么做代理深圳百度seo公司
  • php网站开发建设百度大数据分析
  • 怎么制作网站维护公告效果seo是做什么工作内容
  • 广东网站建设有限公司中国国家人才培训网官网
  • 营销型网站建设个人天津放心站内优化seo
  • 简历模板免费下载电子版seo自动发布外链工具