[
https://issues.apache.org/jira/browse/FLINK-6012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15960636#comment-15960636
]
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_r110362631
--- 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)
--- End diff --
can be `val windowStart = transformed.field("w$start")`
> 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)