spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request #16371: [SPARK-18932][SQL] Support partial aggregation fo...
Date Fri, 30 Dec 2016 11:41:20 GMT
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16371#discussion_r94221696
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/collect.scala
---
    @@ -44,39 +44,48 @@ abstract class Collect extends ImperativeAggregate {
     
       override def dataType: DataType = ArrayType(child.dataType)
     
    -  override def supportsPartial: Boolean = false
    -
    -  override def aggBufferAttributes: Seq[AttributeReference] = Nil
    -
    -  override def aggBufferSchema: StructType = StructType.fromAttributes(aggBufferAttributes)
    -
    -  override def inputAggBufferAttributes: Seq[AttributeReference] = Nil
    -
       // Both `CollectList` and `CollectSet` are non-deterministic since their results depend
on the
       // actual order of input rows.
       override def deterministic: Boolean = false
     
    -  protected[this] val buffer: Growable[Any] with Iterable[Any]
    -
    -  override def initialize(b: InternalRow): Unit = {
    -    buffer.clear()
    +  private def generateOutput(results: Iterable[Any]): Any = {
    +    if (results.isEmpty) {
    +      null
    +    } else {
    +      new GenericArrayData(results.toArray)
    +    }
       }
     
    -  override def update(b: InternalRow, input: InternalRow): Unit = {
    +  override def update(buffer: T, input: InternalRow): T = {
    +    val value = child.eval(input).asInstanceOf[Any]
    +
         // Do not allow null values. We follow the semantics of Hive's collect_list/collect_set
here.
         // See: org.apache.hadoop.hive.ql.udf.generic.GenericUDAFMkCollectionEvaluator
    -    val value = child.eval(input)
         if (value != null) {
           buffer += value
         }
    +    buffer
       }
     
    -  override def merge(buffer: InternalRow, input: InternalRow): Unit = {
    -    sys.error("Collect cannot be used in partial aggregations.")
    +  override def merge(buffer: T, other: T): T = {
    +    buffer ++= other
       }
     
    -  override def eval(input: InternalRow): Any = {
    -    new GenericArrayData(buffer.toArray)
    +  override def eval(buffer: T): Any = {
    +    generateOutput(buffer)
    +  }
    +
    +  protected def _serialize(obj: Iterable[Any]): Array[Byte] = {
    +    val array = new GenericArrayData(obj.toArray)
    +    val projection = UnsafeProjection.create(
    --- End diff --
    
    make this project a member variable, then we don't need to create it everytime we call
`serialize`


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