Skip to content

Commit

Permalink
Move copyValueListToArrayWriter method to ValueList
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiayi771 committed Mar 25, 2024
1 parent 0517ccc commit 6ed8a1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
20 changes: 0 additions & 20 deletions velox/exec/tests/SimpleArrayAggAggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ using namespace facebook::velox::exec;
namespace facebook::velox::aggregate {

namespace {

// Write ValueList accumulators to Array-typed intermediate or final result
// vectors.
// TODO: This API only works if it is the only logic writing to `writer`.
template <typename T>
void copyValueListToArrayWriter(ArrayWriter<T>& writer, ValueList& elements) {
writer.resetLength();
auto size = elements.size();
if (size == 0) {
return;
}
writer.reserve(size);

ValueListReader reader(elements);
for (vector_size_t i = 0; i < size; ++i) {
reader.next(*writer.elementsVector(), writer.valuesOffset() + i);
}
writer.resize(size);
}

class ArrayAggAggregate {
public:
// Type(s) of input vector(s) wrapped in Row.
Expand Down
22 changes: 22 additions & 0 deletions velox/functions/lib/aggregates/ValueList.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
#include "velox/common/memory/HashStringAllocator.h"
#include "velox/exec/Aggregate.h"
#include "velox/expression/ComplexViewTypes.h"
#include "velox/expression/ComplexWriterTypes.h"
#include "velox/vector/ComplexVector.h"
#include "velox/vector/DecodedVector.h"

using namespace facebook::velox::exec;

namespace facebook::velox::aggregate {

// Represents a list of values, including nulls, for an array/map/distinct value
Expand Down Expand Up @@ -132,4 +135,23 @@ class ValueListReader {
vector_size_t pos_{0};
};

// Write ValueList accumulators to Array-typed intermediate or final result
// vectors.
// TODO: This API only works if it is the only logic writing to `writer`.
template <typename T>
void copyValueListToArrayWriter(ArrayWriter<T>& writer, ValueList& elements) {
writer.resetLength();
auto size = elements.size();
if (size == 0) {
return;
}
writer.reserve(size);

ValueListReader reader(elements);
for (vector_size_t i = 0; i < size; ++i) {
reader.next(*writer.elementsVector(), writer.valuesOffset() + i);
}
writer.resize(size);
}

} // namespace facebook::velox::aggregate

0 comments on commit 6ed8a1b

Please sign in to comment.