godfreyhe commented on a change in pull request #7931: [FLINK-11854] 
[table-planner-blink] Introduce batch physical nodes
URL: https://github.com/apache/flink/pull/7931#discussion_r264164552
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/common/CommonCalc.scala
 ##########
 @@ -0,0 +1,97 @@
+/*
+ * 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.nodes.common
+
+import org.apache.flink.table.plan.nodes.ExpressionFormat.ExpressionFormat
+import org.apache.flink.table.plan.nodes.{ExpressionFormat, FlinkRelNode}
+
+import org.apache.calcite.plan.{RelOptCluster, RelOptCost, RelOptPlanner, 
RelTraitSet}
+import org.apache.calcite.rel.core.Calc
+import org.apache.calcite.rel.metadata.RelMetadataQuery
+import org.apache.calcite.rel.{RelNode, RelWriter}
+import org.apache.calcite.rex.{RexCall, RexInputRef, RexLiteral, RexProgram}
+
+import scala.collection.JavaConversions._
+
+/**
+  * Base class for flink [[Calc]].
+  */
+abstract class CommonCalc(
+    cluster: RelOptCluster,
+    traitSet: RelTraitSet,
+    input: RelNode,
+    calcProgram: RexProgram)
+  extends Calc(cluster, traitSet, input, calcProgram)
+  with FlinkRelNode {
+
+
+  override def computeSelfCost(planner: RelOptPlanner, mq: RelMetadataQuery): 
RelOptCost = {
+    val calcProgram = getProgram
+    // compute number of expressions that do not access a field or literal, 
i.e. computations,
+    // conditions, etc. We only want to account for computations, not for 
simple projections.
+    // CASTs in RexProgram are reduced as far as possible by 
ReduceExpressionsRule
+    // in normalization stage. So we should ignore CASTs here in optimization 
stage.
+    val compCnt = 
calcProgram.getProjectList.map(calcProgram.expandLocalRef).toList.count {
+      case _: RexInputRef => false
+      case _: RexLiteral => false
+      case c: RexCall if c.getOperator.getName.equals("CAST") => false
+      case _ => true
+    }
+    val newRowCnt = mq.getRowCount(this)
+    // TODO use inputRowCnt to compute cpu cost
+    planner.getCostFactory.makeCost(newRowCnt, newRowCnt * compCnt, 0)
+  }
+
+  override def explainTerms(pw: RelWriter): RelWriter = {
+    pw.input("input", getInput)
+      .item("select", projectionToString())
+      .itemIf("where", conditionToString(), calcProgram.getCondition != null)
+  }
+
+  protected def conditionToString(): String = {
 
 Review comment:
   this method is only used in this class

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to