加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Apache Flink 漫谈系列 - JOIN LATERAL

发布时间:2018-11-30 00:54:47 所属栏目:教程 来源:孙金城
导读:一、聊什么 上一篇《Apache Flink 漫谈系列 - JOIN算子》我们对最常见的JOIN做了细致的说明,本篇先容一个非凡的JOIN,那就是JOIN LATERAL。JOIN LATERAL为什么非凡呢,直观说由于JOIN的右边不是一个现实的物理表,而是一个VIEW可能Table-valued Funciton

Apache Flink 操作 Calcite举办SQL的理会和优化,今朝Calcite完全支持LATERAL语法,示譬喻下:

  1. SELECT 
  2. e.NAME, e.DEPTNO, d.NAME 
  3. FROM EMPS e, LATERAL ( 
  4. SELECT 
  5. FORM DEPTS d 
  6. WHERE e.DEPTNO=d.DEPTNO 
  7. ) as d; 

查询功效:

Apache Flink 漫谈系列 - JOIN LATERAL

我行使的是Calcite官方自带测试数据。

2. Flink

截至到Flink-1.6.2,Apache Flink 中有两种场景行使LATERAL,如下:

  • UDTF(TVF) - User-defined Table Funciton
  • Temporal Table - 涉及内容会在后续篇章单独先容。

本篇我们以在TVF(UDTF)为例声名 Apache Fink中怎样支持LATERAL。

(1) UDTF

UDTF- User-defined Table Function是Apache Flink中三大用户自界说函数(UDF,UDTF,UDAGG)之一。 自界说接口如下:

  • 基类
  1. /** 
  2. * Base class for all user-defined functions such as scalar functions, table functions, 
  3. * or aggregation functions. 
  4. */ 
  5. abstract class UserDefinedFunction extends Serializable { 
  6. // 要害是FunctionContext中提供了多少高级属性(在UDX篇会具体先容) 
  7. def open(context: FunctionContext): Unit = {} 
  8. def close(): Unit = {} 
  • TableFunction
  1. /** 
  2. * Base class for a user-defined table function (UDTF). A user-defined table functions works on 
  3. * zero, one, or multiple scalar values as input and returns multiple rows as output. 
  4. * The behavior of a [[TableFunction]] can be defined by implementing a custom evaluation 
  5. * method. An evaluation method must be declared publicly, not static and named "eval". 
  6. * Evaluation methods can also be overloaded by implementing multiple methods named "eval". 
  7. * User-defined functions must have a default constructor and must be instantiable during runtime. 
  8. * By default the result type of an evaluation method is determined by Flink's type extraction 
  9. * facilities. This is sufficient for basic types or simple POJOs but might be wrong for more 
  10. * complex, custom, or composite types. In these cases [[TypeInformation]] of the result type 
  11. * can be manually defined by overriding [[getResultType()]]. 
  12. */ 
  13. abstract class TableFunction[T] extends UserDefinedFunction { 
  14.  
  15. // 对付泛型T,假如是基本范例那么Flink框架可以自动辨认, 
  16. // 对付用户自界说的伟大工具,必要用户overwrite这个实现。 
  17. def getResultType: TypeInformation[T] = null 

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读