[
https://issues.apache.org/jira/browse/FLINK-6012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15960634#comment-15960634
]
ASF GitHub Bot commented on FLINK-6012:
---------------------------------------
Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/3693#discussion_r110361425
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/rules/common/WindowExpressionRule.scala
---
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.plan.rules.common
+
+import org.apache.calcite.plan.hep.HepRelVertex
+import org.apache.calcite.plan.{RelOptRule, RelOptRuleCall}
+import org.apache.calcite.rel.RelNode
+import org.apache.calcite.rel.logical.LogicalProject
+import org.apache.calcite.rex.{RexCall, RexNode}
+import org.apache.calcite.sql.fun.SqlStdOperatorTable
+import org.apache.flink.table.calcite.FlinkRelBuilder.NamedWindowProperty
+import org.apache.flink.table.expressions.{WindowEnd, WindowStart}
+import org.apache.flink.table.plan.logical._
+import org.apache.flink.table.plan.logical.rel.LogicalWindowAggregate
+
+import scala.collection.JavaConversions._
+
+class WindowExpressionRule
+ extends RelOptRule(
+ WindowExpressionRule.WINDOW_EXPRESSION_RULE_PREDICATE,
+ "WindowExpressionRule") {
+ override def matches(call: RelOptRuleCall): Boolean = {
+ val project = call.rel(0).asInstanceOf[LogicalProject]
+ val found = project.getProjects.find {
+ case c: RexCall => c.getOperator.isGroupAuxiliary
+ case _ => false
+ }
+ found.isDefined
+ }
+
+ override def onMatch(call: RelOptRuleCall): Unit = {
+ val project = call.rel(0).asInstanceOf[LogicalProject]
+ val innerProject =
WindowExpressionRule.getInput[LogicalProject](project.getInput)
+ val agg =
WindowExpressionRule.getInput[LogicalWindowAggregate](innerProject.getInput)
+
+ // Create an additional project to conform with types
+ val transformed = call.builder()
+ val rexBuilder = transformed.getRexBuilder
+ transformed.push(LogicalWindowAggregate.create(
+ agg.getWindow,
+ Seq(
+ NamedWindowProperty("w$start",
WindowStart(agg.getWindow.alias.get)),
+ NamedWindowProperty("w$end", WindowEnd(agg.getWindow.alias.get))
+ ), agg)
+ )
+ val aggSize = transformed.fields().size()
+
+ transformed
+ .project(innerProject.getProjects ++ Seq(
+ rexBuilder.makeInputRef(transformed.peek(), aggSize - 2),
+ rexBuilder.makeInputRef(transformed.peek(), aggSize - 1)
+ ))
+
+ val n = transformed.fields().size()
+ val (windowStartExprIdx, windowEndExprIdx) = (n - 2, n - 1)
+
+ val windowStart = rexBuilder.makeInputRef(transformed.peek(),
windowStartExprIdx)
+ val windowEnd = rexBuilder.makeInputRef(transformed.peek(),
windowEndExprIdx)
+
+ transformed.project(
+ project.getProjects.map(x =>
+ WindowExpressionRule.identifyAuxiliaryExpr(x, agg.getWindow) match
{
+ case Some(WindowStart(_)) => rexBuilder.makeCast(x.getType,
windowStart, false)
+ case Some(WindowEnd(_)) => rexBuilder.makeCast(x.getType,
windowEnd, false)
+ case _ => x
+ })
+ )
+ val res = transformed.build()
+ call.transformTo(res)
+ }
+}
+
+object WindowExpressionRule {
+ private val WINDOW_EXPRESSION_RULE_PREDICATE =
+ RelOptRule.operand(classOf[LogicalProject],
+ RelOptRule.operand(classOf[LogicalProject],
+ RelOptRule.operand(classOf[LogicalWindowAggregate],
RelOptRule.none())))
+
+ val INSTANCE = new WindowExpressionRule
+
+ private def getInput[T](node: RelNode) : T = {
--- End diff --
not needed. A `RelOptRuleCall` gives access to all matching RelNodes.
> Support WindowStart / WindowEnd functions in streaming SQL
> ----------------------------------------------------------
>
> Key: FLINK-6012
> URL: https://issues.apache.org/jira/browse/FLINK-6012
> Project: Flink
> Issue Type: Sub-task
> Components: Table API & SQL
> Reporter: Haohui Mai
> Assignee: Haohui Mai
>
> This jira proposes to add support for {{TUMBLE_START()}} / {{TUMBLE_END()}} /
> {{HOP_START()}} / {{HOP_END()}} / {{SESSUIB_START()}} / {{SESSION_END()}} in
> the planner in Flink.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)