Passing 3rd argument in IntermediateAggs

jumanjijumanji Registered User
edited November 12 in Vertica Forum

Hi,
Based on the

https://www.vertica.com/docs/8.1.x/HTML/index.htm#Authoring/ExtendingVertica/UDx/AggregateFunctions/ExampleAverage.htm?Highlight=IntermediateAggs

I wrote below code.

virtual void initAggregate(ServerInterface &si, IntermediateAggs &aggs)
    {  try{
        VString &arg1 = aggs.getStringRef(0);
        arg1.setNull();

        VString &arg2 = aggs.getStringRef(1);
        arg2.setNull();

        VString &arg3 = aggs.getStringRef(2);
        arg3.setNull();

        }catch(std::exception &e) {
          vt_report_error(0, "Exception while initializing intermediate aggregates: [% s]", e.what());
      }
    }

The problem is I’ll have 3 arguments to pass around between aggregate to combine function instead of 2. I’m getting an exception because of “VString &arg3 = aggs.getStringRef(2);”

error code: 0, message: Exception while initializing intermediate aggregates: [vector::_M_range_check]
LOCATION: initAgg, /scratch_a/release/svrtar4536/vbuild/vertica/EE/Functions/UserDefinedAggregate.cpp:143

My requirement is to pass 3 arguments, how can I do this?

Comments

  • arindamnandidblarindamnandidbl Employee, Registered User

    You need to specify the third intermediate in the AggregateFunctionFactory class -

    virtual void getIntermediateTypes(ServerInterface &srvInterface,
    const SizedColumnTypes &inputTypes,
    SizedColumnTypes &intermediateTypeMetaData)
    {
    const VerticaType &inType = inputTypes.getColumnType(0);
    intermediateTypeMetaData.addNumeric(interPrec, inType.getNumericScale());
    intermediateTypeMetaData.addInt();
    // Add your 3rd type here...
    }

  • jumanjijumanji Registered User

    got the answer we need define it in . the getIntermediateTypes methods

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file