Custom Calculator"
(Created page with "{{ZKPivottableEssentialsPageHeader}} ==Version History== {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- | | | |} {{ZKPivott...") |
|||
Line 1: | Line 1: | ||
{{ZKPivottableEssentialsPageHeader}} | {{ZKPivottableEssentialsPageHeader}} | ||
+ | |||
+ | =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. | ||
+ | |||
+ | <source lang="java"> | ||
+ | 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 | ||
+ | |||
+ | } | ||
+ | </source> | ||
+ | |||
+ | You can either use an existing ContextType, or create your own. The built-in context type are: <tt>TODO</tt> | ||
+ | |||
+ | It is encouraged to make ContextType as singletons, as Calculators can share Context if they are of the same ContextType. | ||
+ | |||
+ | <source lang="java"> | ||
+ | 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. | ||
+ | |||
+ | } | ||
+ | </source> | ||
+ | |||
+ | |||
+ | |||
+ | ===Example: Data Range=== | ||
+ | |||
+ | ===Example: Distinct Count=== | ||
==Version History== | ==Version History== | ||
Line 6: | Line 48: | ||
! Version !! Date !! Content | ! Version !! Date !! Content | ||
|- | |- | ||
− | | | + | | 2.0.0 |
− | | | + | | June 2012 |
− | | | + | | ContextualCalculator |
|} | |} | ||
{{ZKPivottableEssentialsPageFooter}} | {{ZKPivottableEssentialsPageFooter}} |
Revision as of 08:59, 28 May 2012
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
Version | Date | Content |
---|---|---|
2.0.0 | June 2012 | ContextualCalculator |