Hi Chathura, In previous reply, I misunderstood your suggestion. Yes. We can move aggregateFields to object level. So the user can pass the aggregateFields by another interface method or by the object constructor. Thank you for your suggestion!
@Anjana, WDYT? Shall we add another method to pass the fields instead passing fields every time a record is processed. User will have to assign the fields to an object level variable of the object level and use that variable inside the process method. On Mon, Mar 21, 2016 at 11:39 AM, Chathura Ekanayake <[email protected]> wrote: > Hi Gimantha, > > Yes, hard-coding aggregateFields imposes a limitation. But, if I > understood correct.. once we do a REST API call, we have to execute > process(...) method for each record in the store. But for a single REST API > call aggregateFields is a constant. So we can set those fields (at the > object level) after receiving a REST API call (before executing the > process() method for the first record). > > Regards, > Chathura > > > On Mon, Mar 21, 2016 at 11:12 AM, Gimantha Bandara <[email protected]> > wrote: > >> Hi Chathura, >> >> AggregateFields are the fields which are needed to calculate the >> aggregate values. For example, If you want to calculate SUM of >> "subject_mark" of records representing students, then subject_marks will be >> the only element in aggregateFields, since calculating SUM only involves >> one field. AggregateFields are constant for a specific AggregateFunction. >> But the name of the field can be changed. AggregateFields are defined using >> REST APIs or JS APIs as shown below. >> >> *Calling custom aggregate functions through Javascript API* >> >> var queryInfo = { >> tableName:"Students", //table name on which the aggregation is >> performed >> searchParams : { >> groupByField:"location", //grouping field if any >> query : "Grade:10" //additional filtering query >> aggregateFields:[ >> { >> * fields:["Height", "Weight"],* //fields necessary for >> aggregate function >> aggregate:"CUSTOM_AGGREGATE", //unique name of the aggregate >> function, this is what we return using "getAggregateName" method above. >> alias:"aggregated_result" //Alias for the result of the >> aggregate function >> }] >> } >> } >> >> client.searchWithAggregates(queryInfo, function(data) { >> console.log (data["message"]); >> }, function(error) { >> console.log("error occured: " + error["message"]); >> }); >> >> >> >> *Aggregates REST APIs*This is as same as the Javascript API. >> >> POST https://localhost:9443/analytics/aggregates >> { >> "tableName":"Students", >> "groupByField":"location", >> "aggregateFields":[ >> { >> *"fields":["Height", "Weight"],* >> "aggregate":"CUSTOM_AGGREGATE", >> "alias":"aggregated_result" >> }] >> } >> >> Once you define, the aggregateFields using REST APIs or JS APIs, those >> fields will be available as aggregateFields array in the process method. >> >> On Mon, Mar 21, 2016 at 10:18 AM, Chathura Ekanayake <[email protected]> >> wrote: >> >>> >>> >>> >>> This method will get called for all the records which need to be >>>> aggregated. RecordValuesContext will contain the record values of the >>>> current record being processed. aggregateFields will contain an array of >>>> fields which will be used for the aggregation. The order of the >>>> aggregateFields will matter when we implement the logic. For example, lets >>>> say we are going to implement SUM aggregate. Then we know that only one >>>> field will be required to calculate SUM and always aggregateFields will >>>> contain one field name in it, which is the name of the field being SUMed. >>>> >>>> public void process(RecordValuesContext ctx, String[] aggregateFields) >>>> throws AnalyticsException { >>>> if (aggregateFields == null || aggregateFields.length == 0) { >>>> throw new AnalyticsException("Field to be aggregated, is >>>> missing"); >>>> } >>>> Object value = ctx.getValue(aggregateFields[0]); >>>> if (value == null) { >>>> throw new AnalyticsException("Error while calculating SUM: >>>> value of the field, " + >>>> aggregateFields[0] + " is >>>> null"); >>>> } >>>> if (value instanceof Number) { >>>> sum += ((Number)value).doubleValue(); >>>> } else { >>>> throw new AnalyticsException("Error while calculating >>>> Average: Value '" + value.toString() + >>>> "', being aggregated is not >>>> numeric."); >>>> } >>>> } >>>> >>>> >>>> >>> Hi Gimantha >>> >>> Is aggregateFields parameter a constant for an AggregateFunction object? >>> In that case, can we set it just after instantiating an object? >>> >> >> I assume that you are asking if we can define the aggregateFields inside >> AggregateFunction object itself, without passing them using REST API or JS >> API. Yes, we can do that also. In that case, we will be hard-coding the >> aggregateFields names inside the process method and your custom aggregate >> function cannot be used for any other field. >> >>> >>> Regards, >>> Chathura >>> >>> >>> >>> >> >> >> -- >> Gimantha Bandara >> Software Engineer >> WSO2. Inc : http://wso2.com >> Mobile : +94714961919 >> > > -- Gimantha Bandara Software Engineer WSO2. Inc : http://wso2.com Mobile : +94714961919
_______________________________________________ Architecture mailing list [email protected] https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
