Custom Calculator

From Documentation
Revision as of 08:59, 28 May 2012 by SimonPai (talk | contribs)
Custom Calculator



TabularPivotModel

In TabularPivotModel, Calculator is implemented by two segments: summarization and context. Given a Calculator as an aggregation operation, the context refers to the intermediate result we keep track of while iterating over the operands (accumulation), while summarization refers to the computation from the context to the end result. For example, if we want to compute the AVERAGE over a list of numbers, we would likely keep track of their SUM and COUNT, and then retrieve the final result by dividing the two. In the above example, the context would be a data structure holding the sum and the count, while the summarization would be the division.

Therefore, to create a custom calculator, you must specify a ContextType so the model knows what to keep track of in accumulation phase.

public interface ContextualCalculator<C extends Context<C>> extends Calculator {
	
	public Number getResult(C context); // summarize the end result from the context
	
	public ContextType<C> getContextType(); // specify the context type
	
}

You can either use an existing ContextType, or create your own. The built-in context type are: TODO

It is encouraged to make ContextType as singletons, as Calculators can share Context if they are of the same ContextType.

public interface ContextType<C extends Context<C>> {
	
	public C create(); // ContextType has the responsibility as a Context factory
	
}
public interface Context<C extends Context<C>> {
	
	public void add(Object item); // what to do when iterating over raw data.
	
	public void merge(C ctx); // what to do when merging from contexts of a partition of its raw data set.
	
}


Example: Data Range

Example: Distinct Count

Version History

Last Update : 2012/05/28


Version Date Content
2.0.0 June 2012 ContextualCalculator



Last Update : 2012/05/28

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.