Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/16371#discussion_r94221606 --- 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( + Array[DataType](ArrayType(elementType = child.dataType, containsNull = false))) + projection.apply(InternalRow.apply(array)).getBytes() + } + + protected def _deserialize(bytes: Array[Byte], buffer: T): Unit = { --- End diff -- same here ``` override def deserialize(bytes: ArrayByte): Unit = { val buffer = createAggregationBuffer() ... } ```
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org