[ https://issues.apache.org/jira/browse/FLINK-3940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15404141#comment-15404141 ]
ASF GitHub Bot commented on FLINK-3940: --------------------------------------- Github user twalthr commented on a diff in the pull request: https://github.com/apache/flink/pull/2282#discussion_r73172521 --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/plan/logical/operators.scala --- @@ -150,6 +150,47 @@ case class Sort(order: Seq[Ordering], child: LogicalNode) extends UnaryNode { } } +case class Offset(offset: Int, child: LogicalNode) extends UnaryNode { + override def output: Seq[Attribute] = child.output + + override protected[logical] def construct(relBuilder: RelBuilder): RelBuilder = { + child.construct(relBuilder) + relBuilder.limit(offset, -1) + } + + override def validate(tableEnv: TableEnvironment): LogicalNode = { + if (tableEnv.isInstanceOf[StreamTableEnvironment]) { + throw new TableException(s"Offset on stream tables is currently not supported.") + } + if (!child.validate(tableEnv).isInstanceOf[Sort]) { + throw new TableException(s"Offset operator must follow behind orderBy clause.") + } + super.validate(tableEnv) + } +} + +case class Fetch(fetch: Int, child: LogicalNode) extends UnaryNode { + override def output: Seq[Attribute] = child.output + + override protected[logical] def construct(relBuilder: RelBuilder): RelBuilder = { + + val newChild = child.asInstanceOf[Offset].child + newChild.construct(relBuilder) + val relNode = child.toRelNode(relBuilder).asInstanceOf[LogicalSort] + relBuilder.limit(RexLiteral.intValue(relNode.offset), fetch) + } + + override def validate(tableEnv: TableEnvironment): LogicalNode = { + if (tableEnv.isInstanceOf[StreamTableEnvironment]) { + throw new TableException(s"Fetch on stream tables is currently not supported.") + } + if (!child.validate(tableEnv).isInstanceOf[Offset]) { --- End diff -- Some comment as above. > Add support for ORDER BY OFFSET FETCH > ------------------------------------- > > Key: FLINK-3940 > URL: https://issues.apache.org/jira/browse/FLINK-3940 > Project: Flink > Issue Type: New Feature > Components: Table API & SQL > Affects Versions: 1.1.0 > Reporter: Fabian Hueske > Assignee: GaoLun > Priority: Minor > > Currently only ORDER BY without OFFSET and FETCH are supported. > This issue tracks the effort to add support for OFFSET and FETCH and involves: > - Implementing the execution strategy in `DataSetSort` > - adapting the `DataSetSortRule` to support OFFSET and FETCH > - extending the Table API and validation to support OFFSET and FETCH and > generate a corresponding RelNode. -- This message was sent by Atlassian JIRA (v6.3.4#6332)