spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mateiz <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-11578] [SQL] User API for Typed Aggrega...
Date Mon, 09 Nov 2015 03:24:46 GMT
Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9555#discussion_r44238545
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/expressions/Aggregator.scala ---
    @@ -0,0 +1,81 @@
    +/*
    + * 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.spark.sql.expressions
    +
    +import org.apache.spark.sql.catalyst.encoders.{encoderFor, Encoder}
    +import org.apache.spark.sql.catalyst.expressions.aggregate.{Complete, AggregateExpression2}
    +import org.apache.spark.sql.execution.aggregate.TypedAggregateExpression
    +import org.apache.spark.sql.{Dataset, DataFrame, TypedColumn}
    +
    +/**
    + * A base class for user-defined aggregations, which can be used in [[DataFrame]] and
[[Dataset]]
    + * operations to take all of the elements of a group and reduce them to a single value.
    + *
    + * For example, the following aggregator extracts an `int` from a specific class and
adds them up:
    + * {{{
    + *   case class Data(i: Int)
    + *
    + *   val customSummer =  new Aggregator[Data, Int, Int] {
    + *     def prepare(d: Data) = d.i
    + *     def reduce(l: Int, r: Int) = l + r
    + *     def present(r: Int) = r
    + *   }.toColumn()
    + *
    + *   val ds: Dataset[Data]
    + *   val aggregated = ds.select(customSummer)
    + * }}}
    + *
    + * Based loosely on Aggregator from Algebird: https://github.com/twitter/algebird
    + *
    + * @tparam A The input type for the aggregation.
    + * @tparam B The type of the intermediate value of the reduction.
    + * @tparam C The type of the final result.
    + */
    +abstract class Aggregator[-A, B, C] {
    --- End diff --
    
    This particular interface for Aggregator isn't that efficient, because every A needs to
be converted to a B with prepare() before being merged into another B. It would be better
to have methods from A -> B, (B, A) -> B and (B, B) -> B, similar to some of the
operations in RDD. Also, the "reduce" methods should be allowed to modify the left-hand "B"
in-place.
    
    Another option is to add a "zero" method and then (B, A) -> B. What happens if you
aggregate an empty list, are you just going to get null?


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message