Github user wuchong commented on a diff in the pull request: https://github.com/apache/flink/pull/2282#discussion_r71898802 --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/plan/logical/operators.scala --- @@ -150,6 +150,41 @@ 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.") + } + 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.") + } --- End diff -- I think we need to check the 'fetch' is followed after a 'orderby' and 'offset' here. Otherwise, the class cast in construct will throw exception.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---