日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Flink的UDF写法整理

發(fā)布時(shí)間:2023/12/31 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flink的UDF写法整理 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

概述

這篇博客并不是簡(jiǎn)單地翻譯官方文檔,

而是挑選常用的信息,其他忽略(例如類型推斷這種內(nèi)容)

?

Overview

幾種UDF文檔中的解釋備注
Scalar functions?map scalar values to a new scalar value.進(jìn)一出一
Table functions

map scalar values to new rows(row指的是一行數(shù)據(jù)).

進(jìn)一出多
Aggregate functions?map scalar values of multiple rows to a new scalar value.聚合操作
Table aggregate functionsmap scalar values of multiple rows to new rows.進(jìn)多出多
Async table functions?are special functions for table sources that perform a lookup.文檔里面沒寫

?

Function Class

udf類必須是public,不能是abstract,必須全局可訪問,non-static或者匿名的類是不允許的。

For storing a user-defined function in a persistent catalog, the class must have a default constructor and must be instantiable during runtime.

?

Mandatory and Optional Methods

這里講的是各種UDF中:

哪些函數(shù)強(qiáng)制要求實(shí)現(xiàn)

哪些函數(shù)是可選的,可以不實(shí)現(xiàn)。

?

?成員函數(shù)實(shí)現(xiàn)要求哪些特殊場(chǎng)景下必須實(shí)現(xiàn)該函數(shù)備注官方文檔完整實(shí)例
UDFeval必須實(shí)現(xiàn)?返回常見類型的數(shù)據(jù)完整案例
UDAFcreateAccumulator必須實(shí)現(xiàn)?返回自定義類完整案例
accumulate必須實(shí)現(xiàn)?操作自定義類
getValue必須實(shí)現(xiàn)?

操作自定義類

返回常見類型的數(shù)據(jù)

merge

不要求實(shí)現(xiàn)

bounded aggregations

session group window

session window

hop window

two phase aggregation optimization

操作自定義類

返回常見類型的數(shù)據(jù)

retract不要求實(shí)現(xiàn)

OVER?windows

操作自定義類

返回常見類型的數(shù)據(jù)

UDTFeval必須實(shí)現(xiàn)?返回Collector完整案例
UDTAFcreateAccumulator必須實(shí)現(xiàn)?操作自定義類完整案例
accumulate必須實(shí)現(xiàn)?操作自定義類

emitValue

或 emitUpdateWithRetract

二選一

必須實(shí)現(xiàn)?操作Collector
merge不要求實(shí)現(xiàn)

session group window

many?bounded aggregations

unbounded session

hop window aggregations

操作自定義類
retract不要求實(shí)現(xiàn)aggregations on OVER windows?
emitValue不要求實(shí)現(xiàn)?bounded and window aggregations

emits the full data according to the accumulator

?

Take a Top N function as an example.?
The emitValue(...) would emit all N values each time.?

emitUpdateWithRetract不要求實(shí)現(xiàn)emit values that have been updated under retract mode

Once there is an update, the method can retract old records before sending new, updated ones. The method will be used in preference to the emitValue(...) method.

?

操作Collector

所有上述提到的函數(shù)必須被聲明為public以及非static

返回多條數(shù)據(jù)的都需要寫和Collector相關(guān)的語句。

上述表格中的所有案例都來自官方文檔的補(bǔ)全,并且測(cè)試通過。(需要注意例子中的value是FLINK SQL的關(guān)鍵詞,所以需要加上``,也就是`value`)

?

下面這個(gè)沒看懂

If the table aggregate function can only be applied in an OVER window, this can be declared by returning the requirement FunctionRequirement.OVER_WINDOW_ONLY in getRequirements().

  • ?

Reference:

[1]User-defined Functions

[2]User-defined Sources & Sinks

[3]General User-defined Functions

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Flink的UDF写法整理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。