flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-4832) Count/Sum 0 elements
Date Mon, 28 Nov 2016 15:51:58 GMT

    [ https://issues.apache.org/jira/browse/FLINK-4832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15702284#comment-15702284
] 

ASF GitHub Bot commented on FLINK-4832:
---------------------------------------

Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2840#discussion_r89806470
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/plan/rules/dataSet/DataSetAggregateWithNullValuesRule.scala
---
    @@ -0,0 +1,105 @@
    +/*
    + * 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.rules.dataSet
    +
    +import org.apache.calcite.plan._
    +import scala.collection.JavaConversions._
    +import com.google.common.collect.ImmutableList
    +import org.apache.calcite.rel.RelNode
    +import org.apache.calcite.rel.convert.ConverterRule
    +import org.apache.calcite.rel.logical.{LogicalValues, LogicalUnion, LogicalAggregate}
    +import org.apache.calcite.rex.RexLiteral
    +import org.apache.flink.api.table._
    +import org.apache.flink.api.table.plan.nodes.dataset.{DataSetAggregate, DataSetConvention}
    +
    +/**
    +  * Rule for insert [[Row]] with null records into a [[DataSetAggregate]]
    +  * Rule apply for non grouped aggregate query
    +  */
    +class DataSetAggregateWithNullValuesRule
    +  extends ConverterRule(
    +    classOf[LogicalAggregate],
    +    Convention.NONE,
    +    DataSetConvention.INSTANCE,
    +    "DataSetAggregateWithNullValuesRule")
    +{
    +
    +  override def matches(call: RelOptRuleCall): Boolean = {
    +    val agg: LogicalAggregate = call.rel(0).asInstanceOf[LogicalAggregate]
    +
    +    //for grouped agg sets shouldn't attach of null row
    +    //need apply other rules. e.g. [[DataSetAggregateRule]]
    +    if (!agg.getGroupSet.isEmpty) {
    +      return false
    +    }
    +
    +    // TODO code duplicates DataSetAggregateRule#matches
    +    // check if we have distinct aggregates
    +    val distinctAggs = agg.getAggCallList.exists(_.isDistinct)
    +    if (distinctAggs) {
    +      throw TableException("DISTINCT aggregates are currently not supported.")
    +    }
    +
    +    // check if we have grouping sets
    +    val groupSets = agg.getGroupSets.size() == 0 || agg.getGroupSets.get(0) != agg.getGroupSet
    +    if (groupSets || agg.indicator) {
    +      throw TableException("GROUPING SETS are currently not supported.")
    +    }
    +    !distinctAggs && !groupSets && !agg.indicator
    +  }
    +
    +  override def convert(rel: RelNode): RelNode = {
    +    val agg: LogicalAggregate = rel.asInstanceOf[LogicalAggregate]
    +    val traitSet: RelTraitSet = rel.getTraitSet.replace(DataSetConvention.INSTANCE)
    +    val cluster: RelOptCluster = rel.getCluster
    +
    +    val fieldTypes = agg.getInput.getRowType.getFieldList.map(_.getType)
    +    val nullLiterals :ImmutableList[ImmutableList[RexLiteral]] =
    +      ImmutableList.of(ImmutableList.copyOf[RexLiteral](
    +        for (fieldType <- fieldTypes)
    +          yield {
    +            cluster.getRexBuilder.
    +              makeLiteral(null, fieldType, false).asInstanceOf[RexLiteral]
    +          }))
    +
    +    val logicalValues = LogicalValues.create(cluster, agg.getInput.getRowType, nullLiterals)
    +    val logicalUnion = LogicalUnion.create(List(logicalValues, agg.getInput), true)
    +    val logicalAggregate = new LogicalAggregate(
    --- End diff --
    
    I think we do not need the `LogicalAggregate` but can directly create the `DataSetAggregate`


> Count/Sum 0 elements
> --------------------
>
>                 Key: FLINK-4832
>                 URL: https://issues.apache.org/jira/browse/FLINK-4832
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table API & SQL
>            Reporter: Timo Walther
>            Assignee: Anton Mushin
>
> Currently, the Table API is unable to count or sum up 0 elements. We should improve DataSet
aggregations for this. Maybe by union the original DataSet with a dummy record or by using
a MapPartition function. Coming up with a good design for this is also part of this issue.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message