Apache Flink 操作 Calcite举办SQL的理会和优化,今朝Calcite完全支持LATERAL语法,示譬喻下:
- SELECT
- e.NAME, e.DEPTNO, d.NAME
- FROM EMPS e, LATERAL (
- SELECT
- *
- FORM DEPTS d
- WHERE e.DEPTNO=d.DEPTNO
- ) as d;
查询功效:

我行使的是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)之一。 自界说接口如下:
- /**
- * Base class for all user-defined functions such as scalar functions, table functions,
- * or aggregation functions.
- */
- abstract class UserDefinedFunction extends Serializable {
- // 要害是FunctionContext中提供了多少高级属性(在UDX篇会具体先容)
- def open(context: FunctionContext): Unit = {}
- def close(): Unit = {}
- }
- /**
- * Base class for a user-defined table function (UDTF). A user-defined table functions works on
- * zero, one, or multiple scalar values as input and returns multiple rows as output.
- *
- * The behavior of a [[TableFunction]] can be defined by implementing a custom evaluation
- * method. An evaluation method must be declared publicly, not static and named "eval".
- * Evaluation methods can also be overloaded by implementing multiple methods named "eval".
- *
- * User-defined functions must have a default constructor and must be instantiable during runtime.
- *
- * By default the result type of an evaluation method is determined by Flink's type extraction
- * facilities. This is sufficient for basic types or simple POJOs but might be wrong for more
- * complex, custom, or composite types. In these cases [[TypeInformation]] of the result type
- * can be manually defined by overriding [[getResultType()]].
- */
- abstract class TableFunction[T] extends UserDefinedFunction {
-
- // 对付泛型T,假如是基本范例那么Flink框架可以自动辨认,
- // 对付用户自界说的伟大工具,必要用户overwrite这个实现。
- def getResultType: TypeInformation[T] = null
- }
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|