flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mushketyk <...@git.apache.org>
Subject [GitHub] flink pull request #2169: [FLINK-3943] Add support for EXCEPT operator
Date Wed, 29 Jun 2016 20:34:54 GMT
Github user mushketyk commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2169#discussion_r69021580
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/plan/nodes/dataset/DataSetMinus.scala
---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.api.table.plan.nodes.dataset
    +
    +import org.apache.calcite.plan.{RelOptCluster, RelOptCost, RelOptPlanner, RelTraitSet}
    +import org.apache.calcite.rel.`type`.RelDataType
    +import org.apache.calcite.rel.metadata.RelMetadataQuery
    +import org.apache.calcite.rel.{BiRel, RelNode, RelWriter}
    +import org.apache.flink.api.common.typeinfo.TypeInformation
    +import org.apache.flink.api.java.DataSet
    +import org.apache.flink.api.table.BatchTableEnvironment
    +
    +import scala.collection.JavaConverters._
    +import scala.collection.JavaConversions._
    +
    +/**
    +  * Flink RelNode which matches along with DataSetOperator.
    +  *
    +  */
    +class DataSetMinus(
    +    cluster: RelOptCluster,
    +    traitSet: RelTraitSet,
    +    left: RelNode,
    +    right: RelNode,
    +    rowType: RelDataType,
    +    all: Boolean)
    +  extends BiRel(cluster, traitSet, left, right)
    +    with DataSetRel {
    +
    +  override def deriveRowType() = rowType
    +
    +  override def copy(traitSet: RelTraitSet, inputs: java.util.List[RelNode]): RelNode
= {
    +    new DataSetMinus(
    +      cluster,
    +      traitSet,
    +      inputs.get(0),
    +      inputs.get(1),
    +      rowType,
    +      all
    +    )
    +  }
    +
    +  override def toString: String = {
    +    s"SetMinus(setMinus: (${rowType.getFieldNames.asScala.toList.mkString(", ")}))"
    +  }
    +
    +  override def explainTerms(pw: RelWriter): RelWriter = {
    +    super.explainTerms(pw).item("setMinus", setMinusSelectionToString)
    +  }
    +
    +  override def computeSelfCost (planner: RelOptPlanner, metadata: RelMetadataQuery):
RelOptCost = {
    +
    +    val children = this.getInputs
    +    val rowCnt = children.foldLeft(0D) { (rows, child) =>
    +      rows + metadata.getRowCount(child)
    +    }
    +
    +    planner.getCostFactory.makeCost(rowCnt, 0, 0)
    +  }
    +
    +  override def translateToPlan(
    +      tableEnv: BatchTableEnvironment,
    +      expectedType: Option[TypeInformation[Any]]): DataSet[Any] = {
    +
    +    var leftDataSet: DataSet[Any] = null
    +    var rightDataSet: DataSet[Any] = null
    +
    +    expectedType match {
    +      case None =>
    +        leftDataSet = left.asInstanceOf[DataSetRel].translateToPlan(tableEnv)
    +        rightDataSet =
    +          right.asInstanceOf[DataSetRel].translateToPlan(tableEnv, Some(leftDataSet.getType))
    +      case _ =>
    +        leftDataSet = left.asInstanceOf[DataSetRel].translateToPlan(tableEnv, expectedType)
    +        rightDataSet = right.asInstanceOf[DataSetRel].translateToPlan(tableEnv, expectedType)
    +    }
    +
    +    val minusRes = leftDataSet.minus(rightDataSet)
    +    if (!all) {
    +      minusRes.distinct()
    --- End diff --
    
    On the second hand "union" method in DataSet.java preserves duplicates and used to implement
UNION ALL. UNION is implemented by using "distinct" operation on top of UNION ALL.
    It seems that what you suggest will only add code duplication since it will basically
implement a specialized version of "distinct" operator specifically for the "minus" method.
    
    I have no strong preferences though.  @fhueske what do you think?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message