Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/16371#discussion_r93677654
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/collect.scala
---
@@ -44,39 +43,52 @@ 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()
- }
-
- override def update(b: InternalRow, input: InternalRow): Unit = {
- // 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
+ protected def _serialize(obj: Iterable[Any]): Array[Byte] = {
+ val buffer = new Array[Byte](4 << 10) // 4K
+ val bos = new ByteArrayOutputStream()
+ val out = new DataOutputStream(bos)
+ try {
+ val projection =
UnsafeProjection.create(Array[DataType](child.dataType))
+ obj.foreach { value =>
+ val row = InternalRow.apply(value)
+ val unsafeRow = projection.apply(row)
+ out.writeInt(unsafeRow.getSizeInBytes)
+ unsafeRow.writeToStream(out, buffer)
+ }
+ out.writeInt(-1)
+ out.flush()
+
+ bos.toByteArray
+ } finally {
+ out.close()
+ bos.close()
}
}
- override def merge(buffer: InternalRow, input: InternalRow): Unit = {
- sys.error("Collect cannot be used in partial aggregations.")
- }
-
- override def eval(input: InternalRow): Any = {
- new GenericArrayData(buffer.toArray)
+ protected def _deserialize(bytes: Array[Byte], updater: (Any) => Unit):
Unit = {
--- End diff --
You could also pass in a `Growable[]` instead of an anonymous function.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]