flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] dawidwys commented on a change in pull request #8162: [FLINK-12174][table] Introduce FlinkAggregateExtractProjectRule and remove extractFieldReferences
Date Mon, 15 Apr 2019 12:36:48 GMT
dawidwys commented on a change in pull request #8162: [FLINK-12174][table] Introduce FlinkAggregateExtractProjectRule
and remove extractFieldReferences
URL: https://github.com/apache/flink/pull/8162#discussion_r275338464
 
 

 ##########
 File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/plan/rules/logical/FlinkAggregateExtractProjectRule.java
 ##########
 @@ -0,0 +1,153 @@
+/*
+ * 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.logical;
+
+import org.apache.flink.table.expressions.ResolvedFieldReference;
+import org.apache.flink.table.plan.logical.LogicalWindow;
+import org.apache.flink.table.plan.logical.rel.LogicalWindowAggregate;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.rules.AggregateExtractProjectRule;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.mapping.Mapping;
+import org.apache.calcite.util.mapping.MappingType;
+import org.apache.calcite.util.mapping.Mappings;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Rule to extract a {@link org.apache.calcite.rel.core.Project}
+ * from a {@link LogicalAggregate} or a {@link LogicalWindowAggregate}
+ * and push it down towards the input.
+ *
+ * <p>Note: Most of the logic in this rule is same with {@link AggregateExtractProjectRule}.
The
+ * difference is this rule has also taken the {@link LogicalWindowAggregate} into consideration.
+ */
+public class FlinkAggregateExtractProjectRule extends AggregateExtractProjectRule {
+
+	public FlinkAggregateExtractProjectRule(RelOptRuleOperand operand, RelBuilderFactory builderFactory)
{
+		super(operand, builderFactory);
+	}
+
+	private int getWindowTimeFieldIndex(LogicalWindowAggregate aggregate, RelNode input) {
+		LogicalWindow logicalWindow = aggregate.getWindow();
+		ResolvedFieldReference timeAttribute = (ResolvedFieldReference) logicalWindow.timeAttribute();
+		return input.getRowType().getFieldNames().indexOf(timeAttribute.name());
+	}
+
+	@Override
+	public boolean matches(RelOptRuleCall call) {
+		final Aggregate aggregate = call.rel(0);
+		return aggregate instanceof LogicalWindowAggregate || aggregate instanceof LogicalAggregate;
+	}
+
+	@Override
+	public void onMatch(RelOptRuleCall call) {
 
 Review comment:
   Could we refactor this method? I know it was mostly copied over from calcite, but as we
want to maintain it on our own we could improve code readability.
   
   I would try splitting this method into smaller ones.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message