通过改造例子中的 Concatenate 实现。
/* Copyright (c) 2005 - 2015 Hewlett Packard Enterprise Development LP -*- C++ -*- */
/*
* Description: Example User Defined Aggregate Function: ListAgg strings
*
*/
#include "Vertica.h"
#include
#include
#include
using namespace Vertica;
using namespace std;
/**
* User Defined Aggregate Function ListAgg that takes in strings and concatenates
* them together. Right now, the max length of the resulting string is ten times the
* maximum length of the input string.
*/
class ListAgg : public AggregateFunction
{
virtual void initAggregate(ServerInterface &srvInterface, IntermediateAggs &aggs)
{
//初始化聚合函数返回结果
try {
VString &concat = aggs.getStringRef(0);
concat.copy("");
} catch(exception& e) {
// Standard exception. Quit.
vt_report_error(0, "Exception while initializing intermediate aggregates: [%s]", e.what());
}
}
void aggregate(ServerInterface &srvInterface,
BlockReader &argReader,
IntermediateAggs &aggs)
{