1 Reply Latest reply on Oct 15, 2015 8:46 AM by brianf RSS
    brianf Newbie

    Error in Aggregating Stream Data

    <p><p class="MsoNormal">I apologize for reposting this, but since you folks are so

    wonderful at responding so quickly and since I did not get a near-instantaneous

    response on this one, I figure it might be because it got lost in the last

    thread.<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p>I am having problems aggregating the values from one of my

    data streams. I keep getting ‘Execution error in service script: Wrapped

    java.lang.NullPointerException’ errors in the logger. I can see that the

    GetStreamEntiresWithData call is working fine and I get a significant number of

    rows coming back (I moved the for each snippet up and commented out the

    aggregate call). However, it seems like it keeps failing when I go to call the

    Aggregate function (I do not see the count posted at all in the logger when I

    try to get it from the Aggregate result). I originally had it where I was

    reusing the result and params variables like Andy’s earlier example, but I

    changed them to see if they were the ones causing the issue; does not look like

    that is the culprit. I also double-checked the column names but they are all

    correct (including case). Any ideas on what I might be doing wrong? Thanks!</p><p class="MsoNormal"><o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">var result = new Object();<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p> </p>

     

    <p class="MsoNormal">var StreamParams = {<o:p></o:p></p>

     

    <p class="MsoNormal">                oldestFirst

    : false,<o:p></o:p></p>

     

    <p class="MsoNormal">                maxItems

    : 500<o:p></o:p></p>

     

    <p class="MsoNormal">};<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">// GetStreamEntriesWithData(oldestFirst:BOOLEAN,

    maxItems:NUMBER(500)):INFOTABLE(ProductDataShape)<o:p></o:p></p>

     

    <p class="MsoNormal">result =

    Things['SSProductionStream'].GetStreamEntriesWithData(StreamParams);<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">var result2 = new Object();<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">var AggParams = {<o:p></o:p></p>

     

    <p class="MsoNormal">                t :

    result,<o:p></o:p></p>

     

    <p class="MsoNormal">                aggregates

    : "SUM,SUM,SUM",<o:p></o:p></p>

     

    <p class="MsoNormal">                columns

    : "Rejects,EnergyUsage,WaterUsage",<o:p></o:p></p>

     

    <p class="MsoNormal">                groupByColumns

    : "ProductID"<o:p></o:p></p>

     

    <p class="MsoNormal">};<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">// Aggregate(t:INFOTABLE, aggregates:STRING, columns:STRING,

    groupByColumns:STRING):INFOTABLE(Undefined)<o:p></o:p></p>

     

    <p class="MsoNormal">result2 =

    Resources['InfoTableFunctions'].Aggregate(AggParams);<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">var count = 0;<o:p></o:p></p>

     

    <p class="MsoNormal"><o:p> </o:p></p>

     

    <p class="MsoNormal">for each (var line in result2.rows) {<o:p></o:p></p>

     

    <p class="MsoNormal">count++;<o:p></o:p></p>

     

    <p class="MsoNormal">}<o:p></o:p></p>

     

    <p class="MsoNormal">logger.warn(count);<o:p></o:p></p></p>

      • Error in Aggregating Stream Data
        paic Collaborator

        Hi Brian that error generally means there is a syntax issue somewhere. Not sure if all those columns were defined by you, but I know Andy uses camelBack notation so it would be rejects, energyUsage, waterUsage. (shouldn't give the Java lang error though I think)


        Can you try it the following way to see if it makes a difference:

         

         

        Put columns before aggregates (although this shouldn't matter)

        or put it all in the call like:

        result2 = Resources['InfoTableFunctions'].Aggregate({"t":result, "columns":"Rejects,EnergyUsage,WaterUsage", "aggregates":"SUM,SUM,SUM", "groupByColumns":"ProductID"});