Class Copper
Additionally, these elements (CopperMeasure
, CopperHierarchy, CopperLevel
...)
represent basic bricks that can be combined to express advanced and powerful calculations.
- Author:
- ActiveViam
-
Method Summary
Modifier and TypeMethodDescriptionstatic CopperMeasureOver
agg
(CopperMeasure measure, String pluginKey) Starts defining an aggregation analytic function with anIAggregationFunction
whose plugin key is the given one.static CopperMeasure
agg
(CopperStoreField field, String pluginKey) Creates a Copper measure by aggregating a field from astore
linked to the cube using custom aggregation function.static CopperMeasure
Creates a Copper measure by aggregating multiple fields using a custommulti-source aggregation function
.static CopperMeasure
Creates a Copper measure by aggregating a field using a custom aggregationfunction
.static CopperMeasure
argmax
(CopperLevel level, CopperMeasure measure) Creates a copper measure returning the first member of the specified level for which the maximum of the underlying measure is reached.static CopperMeasure
argmin
(CopperLevel level, CopperMeasure measure) Creates a copper measure returning the first member of the specified level for which the minimum of the underlying measure is reached.static CopperMeasureOver
avg
(CopperMeasure measure) Starts defining an aggregation analytic function with theaverage
aggregation.static CopperMeasure
avg
(CopperStoreField field) static CopperMeasure
Creates a Copper measure by aggregating a field from the selection using theaverage
aggregation.static CopperMeasureCombination
combine
(CopperMeasure... measures) Combines several Copper measures then map them to obtain a new Copper measure which values are a combination of the values of the input measures.static CopperMultipleElements
combine
(CopperElement... elements) Combines several Copper elements (measures, levels, context values) then map them to obtain a new Copper object which can be used to create new single-level hierarchies.static CopperMeasure
Creates a Copper measure containing a constant value.static CopperMeasure
contextValue
(Class<? extends IContextValue> clazz) Creates a Copper measure referencing a context value to use its value in a calculation.static CopperNativeMeasure
count()
Creates a Copper measure referencing the native measure "contributors.COUNT".static ExperimentalCopper
Experimental API.static CopperMeasureOver
first
(CopperMeasure measure) Starts defining a navigation analytic function.static CopperMeasureOver
first
(CopperMeasure measure, NavigationMode mode) Starts defining a navigation analytic function.static CopperHierarchy
hierarchy
(@NonNull HierarchyIdentifier hierarchy) Creates an object referencing the given hierarchy.static CopperHierarchy
Creates an object referencing the given hierarchy belonging to the given dimension in the cube.static CopperMeasureOver
lag
(CopperMeasure measure, int offset) Starts defining a navigation analytic function.static CopperMeasureOver
lag
(CopperMeasure measure, int offset, NavigationMode mode) Starts defining a navigation analytic function.static CopperMeasureOver
last
(CopperMeasure measure) Starts defining a navigation analytic function.static CopperMeasureOver
last
(CopperMeasure measure, NavigationMode mode) Starts defining a navigation analytic function.static CopperMeasureOver
lead
(CopperMeasure measure, int offset) Starts defining a navigation analytic function.static CopperMeasureOver
lead
(CopperMeasure measure, int offset, NavigationMode mode) Starts defining a navigation analytic function.static CopperLevel
level
(@NonNull LevelIdentifier level) Creates an object referencing the given level.static CopperLevel
Creates an object referencing the given level belonging to the given dimension and hierarchy in the cube.static CopperLevelsAt
levelAt
(CopperLevel lvl, SerializableFunction<?, ?> function) Creates aCopperLevelsAt
representing a location transfer operation applying the input function to this level.static CopperLevelsAt
levelAtValue
(CopperLevel lvl, Object value) Creates aCopperLevelsAt
representing a location transfer operation to the provided value on this level.static CopperLevelsAt
levelsAt
(List<CopperLevel> shiftLevels, SerializableConsumer<IWritableArray> consumer) Creates aCopperLevelsAt
representing a location transfer operation applying the input consumer to the provided list of levels.static CopperMeasureOver
max
(CopperMeasure measure) Starts defining an aggregation analytic function with themax
aggregation.static CopperMeasure
max
(CopperStoreField field) static CopperMeasure
Creates a Copper measure by aggregating a field from the selection using themax
aggregation.static CopperMeasure
Creates a Copper measure referencing an already existing measure (whether already published or created without Copper) by using its name.static CopperMeasure
measureFromDataCube
(String measureName, String type) Creates a Copper measure referencing an already existing measure from a Data cube.static CopperMeasure
member
(CopperHierarchy hierarchy) Creates a Copper measure whose value is the discriminator of the current member on the given hierarchy read from the evaluated location.static CopperMeasure
member
(CopperLevel level) Creates a Copper measure whose value is the member of the given level read from the evaluated location.static CopperMeasure
member
(HierarchyIdentifier hierarchy) Creates a Copper measure whose value is the discriminator of the current member on the given hierarchy read from the evaluated location.static CopperMeasure
member
(LevelIdentifier level) Creates a Copper measure whose value is the member of the given level read from the evaluated location.static CopperMeasureOver
min
(CopperMeasure measure) Starts defining an aggregation analytic function with themin
aggregation.static CopperMeasure
min
(CopperStoreField field) static CopperMeasure
Creates a Copper measure by aggregating a field from the selection using themin
aggregation.newHierarchy
(@NonNull String hierarchyName) Returns a builder to create a Copper hierarchy that can hold several levels.newHierarchy
(@NonNull String dimensionName, @NonNull String hierarchyName) Returns a builder to create a Copper hierarchy that can hold several levels.static CopperMeasure
newLookupMeasure
(CopperStoreField field) Creates a Copper measure referencing the records of a joinedfield
, which can then be used in calculations.static CopperPostProcessor
newPostProcessor
(String pluginKey) Creates a Copper measure referencing a post-processor.static UnlinkedCopperStore
Creates the representation of an isolated store of the database, which can then be joined to the cube.storeLookup
(String storeName) A store lookup is a post processor that runs a get-by-key query on the given store.static CopperMeasureOver
sum
(CopperMeasure measure) Starts defining an aggregation analytic function (sometimes called aggregation window function) with thesum function
commonly known as running total or cumulative sum calculation.static CopperMeasure
sum
(CopperStoreField field) Creates a Copper measure by aggregating a field from astore
linked to the cube using thesum
aggregation.static CopperMeasure
Creates a Copper measure by aggregating a field from the selection using thesum
aggregation.static CopperMeasure
sumProduct
(String... fieldNames) A measure that does the sum product of all the sources it is given.static CopperSwitchMeasure
switchOn
(CopperLevel level, Map<Object, ? extends CopperMeasure> memberToMeasureMapping, CopperMeasure defaultMeasure) Creates a copper measure which selects among several measures the value to return depending on the current value on a level.static CopperNativeMeasure
Creates a Copper measure referencing the native measure "update.TIMESTAMP".userDefinedAgg
(CopperMeasure... measures) Starts building a Copper measure performing a user-defined aggregate function (UDAF) that can be applied on multiple measures.userDefinedAgg
(String... fields) Starts building a Copper measure performing a user-defined aggregate function (UDAF) that can be applied to multiple fields of the current selection.static CopperMeasure
userDefinedAgg
(String pluginKey, String[] fields) Creates a Copper measure performing auser-defined aggregation
on multiple fields of the current selection.
-
Method Details
-
experimental
Experimental API.This API is not guaranteed to be consistent, supported or kept in the next bug fix releases. It should not be used in production.
This API is used to evaluate potential new features and obtain feedback.
-
count
Creates a Copper measure referencing the native measure "contributors.COUNT". It can be used in other calculations or simply to customize it.- Returns:
- a Copper measure referencing the native measure "contributors.COUNT"
-
timestamp
Creates a Copper measure referencing the native measure "update.TIMESTAMP". It can be used in other calculations or simply to customize it.- Returns:
- a Copper measure referencing the native measure "update.TIMESTAMP"
-
sum
Starts defining an aggregation analytic function (sometimes called aggregation window function) with thesum function
commonly known as running total or cumulative sum calculation.An aggregation analytic function is a function that computes aggregated values over a group of other aggregated values defined by a
window specification
. The window determines for each evaluated location the set of aggregated values and in which order the aggregation function operates in order to evaluate the result at this particular location.
Examples of ordering, partitioning and usage of different aggregation function illustrated with a pivot table, given:
- a cube with a "time" hierarchy with three levels "year", "month", "day"
- a pre-aggregated measure "pnl.SUM":
CopperMeasure pnl = Copper.sum("pnl)
- A measure to compute a running total of "pnl.SUM" along the time hierarchy, each level
being naturally ordered:
Copper.sum(pnl).over(Window.orderBy("time").as("run. tot.")
- A measure to compute a running total of "pnl.SUM" in reverse order along the time
hierarchy, each level being naturally ordered:
Copper.sum(pnl).over(Window.orderBy("time").reverse().as("run. tot. reverse")
- A measure to compute a max total of "pnl.SUM" along the time hierarchy, each level being
naturally ordered:
Copper.max(pnl).over(Window.orderBy("time").as("run. max")
- A measure to compute a running total of "pnl.SUM" along the time hierarchy, each level
being naturally ordered:
Copper.sum(pnl).over(Window.orderBy("time").partitionBy("year").as( "run. tot.i partitionBy(year)")
. The cumulative sum starting over for each different year.
┌────────────────┬─────────┬───────────┬───────────────────┬──────────┬─────────────────────────────┐ | Year/Month/Day | pnl.SUM | run. tot. | run. tot. reverse | run. max | run. tot. partitionBy(year) | ├────────────────┼─────────┼───────────┼───────────────────┼──────────┼─────────────────────────────┤ | (ALL) | 17 | 17 | 17 | 17 | 17 | | 2018 | 10 | 10 | 17 | 10 | 10 | | Jan | 7 | 7 | 17 | 7 | 7 | | 01 | 5 | 5 | 17 | 5 | 5 | | 02 | 1 | 6 | 12 | 5 | 6 | | 04 | 1 | 7 | 11 | 5 | 7 | | Feb | 3 | 10 | 10 | 7 | 10 | | 01 | 1 | 8 | 10 | 5 | 8 | | 02 | 2 | 10 | 9 | 5 | 10 | | 2019 | 7 | 17 | 7 | 10 | 7 | | Jan | 2 | 12 | 7 | 7 | 2 | | 02 | 2 | 12 | 7 | 5 | 2 | | 03 | 0 | 12 | 5 | 5 | 2 | | Feb | 5 | 17 | 5 | 7 | 7 | | 01 | 3 | 15 | 5 | 5 | 5 | | 02 | 2 | 17 | 2 | 5 | 7 | └────────────────┴─────────┴───────────┴───────────────────┴──────────┴─────────────────────────────┘
Example of frame specification is illustrated with a pivot table, given:
- a cube with a "date" hierarchy with a single level "date"
- a pre-aggregated measure "pnl.SUM":
CopperMeasure pnl = Copper.sum("pnl)
- A measure to compute a cumulative average of "pnl.SUM" along the time hierarchy, each level being naturally ordered:
Copper.avg(pnl).over(Window.orderBy("time").as("avg tot.")
- A measure to compute a moving average of "pnl.SUM" along the time hierarchy over the last two dates of data, each level being naturally ordered:
Copper.avg(pnl).over(Window.orderBy("time").rangeBetween(-2, 0).as("moving average")
┌────────────┬─────────┬──────────┬──────────────────────┐ │ Date │ pnl.SUM │ avg tot. │ moving average │ ├────────────┼─────────┼──────────┼──────────────────────┤ │ 2018-01-01 │ 2 │ 2 │ 2 │ │ 2018-01-02 │ 0 │ 1 │ 1 │ │ 2018-01-03 │ 4 │ 3 │ 3 │ │ 2018-01-04 │ 2 │ 2 │ 3 │ │ 2018-01-05 │ 6 │ 2.8 │ 4 │ │ 2018-01-06 │ 0 │ 2.33 │ 2.67 │ │ 2018-01-07 │ 3 │ 2.43 │ 3 │ │ 2018-01-08 │ 8 │ 3.125 │ 3.67 │ └────────────┴─────────┴──────────┴──────────────────────┘
- Parameters:
measure
- the measure to use as underlying measure- Returns:
- a partially defined aggregated analytic measure
-
sum
Creates a Copper measure by aggregating a field from astore
linked to the cube using thesum
aggregation. Seeavg(CopperStoreField)
.- Parameters:
field
- the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
sum
Creates a Copper measure by aggregating a field from the selection using thesum
aggregation.- Parameters:
fieldName
- the name of the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
max
Starts defining an aggregation analytic function with themax
aggregation. Seesum(CopperMeasure)
.- Parameters:
measure
- the measure to use as underlying measure- Returns:
- a partially defined aggregated analytic measure
-
max
Creates a Copper measure by aggregating a field from astore
linked to the cube using themax
aggregation. Seeavg(CopperStoreField)
.- Parameters:
field
- the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
max
Creates a Copper measure by aggregating a field from the selection using themax
aggregation.- Parameters:
fieldName
- the name of the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
min
Starts defining an aggregation analytic function with themin
aggregation. Seesum(CopperMeasure)
.- Parameters:
measure
- the measure to use as underlying measure- Returns:
- a partially defined aggregated analytic measure
-
min
Creates a Copper measure by aggregating a field from astore
linked to the cube using themin
aggregation. Seeavg(CopperStoreField)
.- Parameters:
field
- the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
min
Creates a Copper measure by aggregating a field from the selection using themin
aggregation.- Parameters:
fieldName
- the name of the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
avg
Starts defining an aggregation analytic function with theaverage
aggregation. Seesum(CopperMeasure)
.- Parameters:
measure
- the measure to use as underlying measure- Returns:
- a partially defined aggregated analytic measure
-
avg
Creates a Copper measure by aggregating a field from astore
linked to the cube using theaverage
aggregation. Contrary to alookup measure
, it returns values even if a level mapped to a key of the store is not expressed in the query.As a basic example, let us consider a base store containing product prices and an isolated store containing the prices of our competitors:
Product store: (k) - key field ┌───────────────┬───────┐ │ Id (k) │ Price │ ├───────────────┼───────┤ │ 1 │ 10.0 │ │ 2 │ 5.0 │ │ 3 │ 7.0 │ │ 4 │ 1.0 │ └───────────────┴───────┘ Competitor store: (k) - key field ┌───────────────┬────────────────┬────────┐ │ ProductID (k) │ Competitor (k) │ Price │ ├───────────────┼────────────────┼────────┤ │ 1 │ A │ 10.0 │ │ 1 │ B │ 11.0 │ │ 1 │ C │ 15.0 │ │ 2 │ A │ 4.0 │ │ 2 │ B │ 5.5 │ │ 2 │ C │ 6.5 │ │ 3 │ A │ 6.0 │ │ 3 │ B │ 8.0 │ │ 4 │ C │ 1.2 │ └───────────────┴────────────────┴────────┘
Let us consider a cube with a single level hierarchy based on the field "Id". There is a one-to-many relationship between the Product store and the Competitor store so that we cannot define a regular join in our database configuration to compute for instance the average price of our competitors.
However, this relation can be resolved by Copper on-the-fly, at query time thanks to a join operation:CopperStore competitorStore = Copper.store("CompetitorStore").joinToCube().withMapping("Id", "ProductID");
Then, it is possible to define a measure corresponding to the average price values of the competitors and publish it to the cube :
Copper.avg(competitorStore.field("Price")).as("competitorAvgPrice").publish(context);
Now the measure competitorAvgPrice exists and can be queried for every location.
┌─────────┬────────────────────┐ │ Id │ competitorAvgPrice │ ├─────────┼────────────────────┤ │ (ALL) │ 7.467 │ │ 1 │ 12.0 │ │ 2 │ 5.33 │ │ 3 │ 7.0 │ │ 4 │ 1.2 │ └─────────┴────────────────────┘
- Parameters:
field
- the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
avg
Creates a Copper measure by aggregating a field from the selection using theaverage
aggregation.- Parameters:
fieldName
- the name of the field to aggregate- Returns:
- The Copper measure representing the aggregated measure
-
sumProduct
A measure that does the sum product of all the sources it is given. It expects to perform the sum product of at least 2 columns. Else, thesum(com.activeviam.activepivot.copper.api.CopperMeasure)
measure should be used.This measure is only defined for numerical types, nullable or not.
null
values will simply be skipped.This aggregation also accepts a single numerical vector type, as long as it comes last in the list of sources to aggregate.
Example with table Trade:
┌─────────────────┬──────────┬───────┐ │ Underlying │ Quantity │ Value │ ├─────────────────┼──────────┼───────┤ │ AAPL │ 10 │ 7.4 │ │ AAPL │ 15 │ 2.0 │ │ AAPL │ 1 │ 5.33 │ │ AAPL │ 12 │ 6.0 │ └─────────────────┴──────────┴───────┘
SumProduct(Quantity, Value) will output:
Result = 10 * 7.4 + 15 * 2.0 + 1 * 5.33 + 12 * 6.0 = 181.33
- Parameters:
fieldNames
- the fields used for sumProduct- Returns:
- a copper measure that returns the sum product over multiple fields
-
agg
Starts defining an aggregation analytic function with anIAggregationFunction
whose plugin key is the given one. Seesum(CopperMeasure)
.- Parameters:
measure
- the measure to use as underlying measurepluginKey
- The plugin key of the custom aggregation function- Returns:
- a partially defined aggregated analytic measure
-
agg
Creates a Copper measure by aggregating a field from astore
linked to the cube using custom aggregation function. Seeavg(CopperStoreField)
.- Parameters:
field
- the field to aggregatepluginKey
- the plugin key of the custom aggregation function- Returns:
- The Copper measure representing the aggregated measure
-
agg
Creates a Copper measure by aggregating a field using a custom aggregationfunction
.- Parameters:
fieldName
- The field to aggregatepluginKey
- The plugin key of the custom aggregation function- Returns:
- The Copper measure containing the aggregated field
-
agg
Creates a Copper measure by aggregating multiple fields using a custommulti-source aggregation function
.- Parameters:
fieldNames
- The fields to aggregatepluginKey
- The plugin key of the custom aggregation function- Returns:
- The Copper measure containing the aggregated field
-
lead
Starts defining a navigation analytic function. A navigation function computes the value at a given location by copying the value over a different location from the current location in theWindow
. Seelead(CopperMeasure, int, NavigationMode)
.- Parameters:
measure
- the measure to use as underlying measureoffset
- the number of rows after the current location to return values for- Returns:
- a partially defined navigating analytic measure
-
lag
Starts defining a navigation analytic function. A navigation function computes the value at a given location by copying the value over a different location from the current location in theWindow
. Seelead(CopperMeasure, int)
.- Parameters:
measure
- the measure to use as underlying measureoffset
- the number of rows before the current location to return values for- Returns:
- a partially defined navigating analytic measure
-
first
Starts defining a navigation analytic function. A navigation function computes the value at a given location by copying the value over a different location from the current location in theWindow
. Seelead(CopperMeasure, int)
.- Parameters:
measure
- the measure to use as underlying measure- Returns:
- a partially defined navigating analytic measure
-
last
Starts defining a navigation analytic function. A navigation function computes the value at a given location by copying the value over a different location from the current location in theWindow
. Seelead(CopperMeasure, int)
.- Parameters:
measure
- the measure to use as underlying measure- Returns:
- a partially defined navigating analytic measure
-
constant
Creates a Copper measure containing a constant value.- Parameters:
value
- The value in this measure- Returns:
- The Copper measure containing the constant value
-
measure
Creates a Copper measure referencing an already existing measure (whether already published or created without Copper) by using its name.- Parameters:
measureName
- The name of the measure- Returns:
- The Copper measure referencing the measure with the given name
-
measureFromDataCube
Creates a Copper measure referencing an already existing measure from a Data cube.This is a useful object when referring to measures existing in other cubes, since the typing engine cannot determine measure types before the discovery. For that reason such a measure will only work in a query cube.
- Parameters:
measureName
- The name of the measuretype
- thestring representation
of the type of the measure- Returns:
- The Copper measure referencing the measure with the given name
- See Also:
-
member
Creates a Copper measure whose value is the member of the given level read from the evaluated location. If the level is not expressed, an empty result is returned. For instance,Copper.member(Copper.level("Booking", "Desk", "Desk")).as("DeskMemberValue")
leads to┌─────────┬──────────────────┐ │ Desk │ DeskMemberValue │ ├─────────┼──────────────────┤ │ (ALL) │ │ │ DeskA │ DeskA │ │ DeskB │ DeskB │ └─────────┴──────────────────┘
- Parameters:
level
- the level for which the Copper measure is created- Returns:
- the Copper measure whose value is the member of the given level
- See Also:
-
member
Creates a Copper measure whose value is the member of the given level read from the evaluated location. If the level is not expressed, an empty result is returned. For instance,Copper.member(levelIdentifier).as("DeskMemberValue")
leads to┌───────────┬──────────────────┐ │ Desk │ DeskMemberValue │ ├───────────┼──────────────────┤ │ (ALL) │ null │ │ DeskA │ DeskA │ │ Book1 │ DeskA │ │ DeskB │ DeskB │ └───────────┴──────────────────┘
- Parameters:
level
- the level for which the Copper measure is created- Returns:
- the Copper measure whose value is the member of the given level
-
member
Creates a Copper measure whose value is the discriminator of the current member on the given hierarchy read from the evaluated location. For instance,Copper.member(Copper.hierarchy("Booking", "Booking")).as("DeskMemberValue")
leads to┌─────────┬──────────────────┐ │ Desk │ DeskMemberValue │ ├─────────┼──────────────────┤ │ (ALL) │ null │ │ DeskA │ DeskA │ │ Book1 │ Book1 │ │ Book2 │ Book2 │ └─────────┴──────────────────┘
- Parameters:
hierarchy
- the hierarchy for which the Copper measure is created.- Returns:
- the Copper measure whose value is the member of the given hierarchy
- See Also:
-
member
Creates a Copper measure whose value is the discriminator of the current member on the given hierarchy read from the evaluated location. For instance,Copper.member(new HierarchyIdentifier("Desk", "Desk")).as("DeskMemberValue")
leads to┌─────────┬──────────────────┐ │ Desk │ DeskMemberValue │ ├─────────┼──────────────────┤ │ (ALL) │ null │ │ DeskA │ DeskA │ │ Book1 │ Book1 │ │ Book2 │ Book2 │ └─────────┴──────────────────┘
- Parameters:
hierarchy
- the hierarchy for which the Copper measure is created.- Returns:
- the Copper measure whose value is the member of the given hierarchy
-
hierarchy
public static CopperHierarchy hierarchy(@NonNull @NonNull String dimensionName, @NonNull @NonNull String hierarchyName) Creates an object referencing the given hierarchy belonging to the given dimension in the cube.- Parameters:
dimensionName
- the name of the dimension. Cannot be nullhierarchyName
- the name of the hierarchy. Cannot be null- Returns:
- the Copper hierarchy referencing the given hierarchy
-
hierarchy
Creates an object referencing the given hierarchy.- Parameters:
hierarchy
- the unique identifier of the hierarchy- Returns:
- the Copper hierarchy referencing the given hierarchy
-
level
public static CopperLevel level(@NonNull @NonNull String dimensionName, @NonNull @NonNull String hierarchyName, @NonNull @NonNull String levelName) Creates an object referencing the given level belonging to the given dimension and hierarchy in the cube.- Parameters:
dimensionName
- the name of the dimension. Cannot be null.hierarchyName
- the name of the hierarchy. Cannot be null.levelName
- the name of the level. Cannot be null.- Returns:
- the Copper level referencing the given level
-
level
Creates an object referencing the given level.- Parameters:
level
- the unique identifier of the level- Returns:
- the Copper level referencing the given level
-
combine
Combines several Copper measures then map them to obtain a new Copper measure which values are a combination of the values of the input measures.- Parameters:
measures
- The measures to combine- Returns:
- The combination of measures, on which to call
CopperMeasureCombination.map(SerializableBiConsumer, String)
map
-
combine
Combines several Copper elements (measures, levels, context values) then map them to obtain a new Copper object which can be used to create new single-level hierarchies.- Parameters:
elements
- The elements to combine- Returns:
- The combination of elements, to use in Copper
newHierarchy(String, String)
-
newPostProcessor
Creates a Copper measure referencing a post-processor. It can be further customized withCopperPostProcessor.withProperty(String, Object)
,CopperPostProcessor.withUnderlyingMeasures(CopperMeasure...)
,CopperPostProcessor.withContinuousQueryHandlers(String...)
...- Parameters:
pluginKey
- the plugin key of the post-processor to create- Returns:
- The Copper measure referencing the post-processor
-
storeLookup
public static CopperStoreLookup.CopperStoreLookUpBuilderAddingElements storeLookup(String storeName) A store lookup is a post processor that runs a get-by-key query on the given store. Each key field must be associated with either a level, or a measure. For a given location, the get-by-key query will be performed using the values of the selected levels and/or measures.- If a key field is mapped to a level, the value used for the get-by-key query is the member of this level for the queried location. (If this level is expressed at the location)
- If it is mapped to a measure, the value used for the get-by-key query is the value of the measure for the queried location.
If several fields are selected, a function must be provided to reduce their values to the final value of this post-processor for the given location.
If at least one of the key fields is nullable, the defined measure will return a value for a given queried location if and only if :
- All the levels mapped to a key field are expressed in the queried location
- At least one of the underlying measures mapped to a key field has a non-null value for the queried location
Store lookup measures cannot be defined on key-less stores.
- See Also:
-
contextValue
Creates a Copper measure referencing a context value to use its value in a calculation.- Parameters:
clazz
- The type of context value- Returns:
- The Copper measure referencing the context value
-
newHierarchy
public static MultiLevelHierarchyBuilder.SelectHierarchyType newHierarchy(@NonNull @NonNull String hierarchyName) Returns a builder to create a Copper hierarchy that can hold several levels.- Parameters:
hierarchyName
- the name of the hierarchy to create and its dimension- Returns:
- the builder
-
newHierarchy
public static MultiLevelHierarchyBuilder.SelectHierarchyType newHierarchy(@NonNull @NonNull String dimensionName, @NonNull @NonNull String hierarchyName) Returns a builder to create a Copper hierarchy that can hold several levels.- Parameters:
dimensionName
- the dimension of the hierarchy to createhierarchyName
- the name of the hierarchy to create- Returns:
- the builder
-
store
Creates the representation of an isolated store of the database, which can then be joined to the cube.- Parameters:
storeName
- The name of the represented store- Returns:
- The representation of the store
-
newLookupMeasure
Creates a Copper measure referencing the records of a joinedfield
, which can then be used in calculations.This measure will return the values contained in the field's database records if at least a minimal set of required levels is expressed in the queried location, otherwise it will return a
null
value.The aforementioned set of levels correspond to the levels required to establish a one-to-one relation between cube locations and records of the joined store.(i.e. the key fields of the joined store that have not been added to the
mapping
of the join operation as well as the mapped levels of the cube)When a lookup measure is published in the context, all the required levels for querying its values that are not already present in the cube will be automatically published as new single-level hierarchies. It is however possible to customize the created hierarchies by calling
newHierarchy(String, String)
.As a basic example, let us consider a base store containing basic trade data and an isolated Rates store containing rates data between currencies :
Trades store: (k) - key field ┌─────────────┬──────────┬──────┐ │ TradeID (k) │ Currency │ Δ │ ├─────────────┼──────────┼──────┤ │ 1 │ EUR │ 10 │ │ 2 │ USD │ -5 │ │ 3 │ EUR │ -7.5 │ │ 4 │ USD │ 12.5 │ └─────────────┴──────────┴──────┘ Rates store: (k) - key field ┌──────────────┬────────────────┬─────────┐ │ Base cur.(k) │ Target cur.(k) │ Rate │ ├──────────────┼────────────────┼─────────┤ │ EUR │ EUR │ 1 │ │ EUR │ USD │ 1.101 │ │ USD │ EUR │ 0.91 │ │ USD │ USD │ 1 │ └──────────────┴────────────────┴─────────┘
If we consider that the "TradeID" and "Currency" fields of the "Trades" store have been added to the cube, there exist an obvious join relationship between a level of the cube (Currency) and one the "Base cur." field of the Rates store.
We can define our join operation this way :
CopperStore rateStore = Copper.store("Rates").joinToCube().withMapping("Base cur.", "Currency");
Then, it is possible to define a lookup measure corresponding to the values or the "Rate" field of the Rates store, and publish it to the cube :
Copper.newLookupMeasure(rateStore.field("Rate")).as("rate.value").publish(context);
Now the measurerate.value
exists and will return the content of the Rate field for queried locations.However,
rate.value
makes only sense when both a Currency AND a Target currency are expressed (it's in the key fields of the joined store). Therefore, a single-level hierarchy corresponding to the target currency members was added to the cube to be able to queryrate.value
.Results when querying
rate.value
for several locations:┌─────────┬───────────┬─────────────┬──┬────────────┐ │ TradeID │ Currency │ Target cur. │ │ rate.value │ ├─────────┼───────────┼─────────────┼──┼────────────┤ │ (ALL) │ (ALL) │ (ALL) │ │ null │ │ (ALL) │ EUR │ (ALL) │ │ null │ │ (ALL) │ (ALL) │ USD │ │ null │ │ (ALL) │ EUR │ USD │ │ 1.101 │ │ (ALL) │ USD │ USD │ │ 1 │ │ 1 │ (ALL) │ (ALL) │ │ null │ │ 1 │ (ALL) │ EUR │ │ null │ │ 1 │ USD │ EUR │ │ 0.91 │ │ 1 │ EUR │ EUR │ │ 1 │ └─────────┴───────────┴─────────────┴──┴────────────┘
- Parameters:
field
-field
to be represented- Returns:
- the Copper measure whose value is the records of the field.
-
userDefinedAgg
Creates a Copper measure performing auser-defined aggregation
on multiple fields of the current selection.- Parameters:
pluginKey
- The plugin key of theuser-defined aggregation function
fields
- The fields on which the aggregation function will be applied.- Returns:
- the Copper measure containing the aggregation of the input field according to the user-defined function.
-
userDefinedAgg
Starts building a Copper measure performing a user-defined aggregate function (UDAF) that can be applied to multiple fields of the current selection.See Copper documentation for examples.
- Parameters:
fields
- fields on which the function about to be defined will be applied.- Returns:
- a builder for user-defined aggregation functions.
- Throws:
com.activeviam.activepivot.copper.internal.exception.UserErrorException
- if no field is specified
-
userDefinedAgg
public static CopperUserDefinedAggregateFunctionOnMeasuresBuilder userDefinedAgg(CopperMeasure... measures) Starts building a Copper measure performing a user-defined aggregate function (UDAF) that can be applied on multiple measures.See Copper documentation for examples.
- Parameters:
measures
- measures on which the function about to be defined will be applied.- Returns:
- a builder for user-defined aggregation functions.
- Throws:
com.activeviam.activepivot.copper.internal.exception.UserErrorException
- if no measure is specified- See Also:
-
argmax
Creates a copper measure returning the first member of the specified level for which the maximum of the underlying measure is reached. The natural order comparator is used to sort the values of the underlying measure, and the hierarchy's comparator is used to sort the level's members to determine which one is first.- Parameters:
level
- the level whose members will be returnedmeasure
- the underlying measure, its type is expected to be comparable- Returns:
- a copper measure containing the member of the level for which the maximum is reached
-
argmin
Creates a copper measure returning the first member of the specified level for which the minimum of the underlying measure is reached. The reverse order comparator is used to sort the values of the underlying measure, and the hierarchy's comparator is used to sort the level's members to determine which one is first.- Parameters:
level
- the level whose members will be returnedmeasure
- the underlying measure, its type is expected to be comparable- Returns:
- a copper measure containing the member of the level for which the minimum is reached
-
levelAt
Creates aCopperLevelsAt
representing a location transfer operation applying the input function to this level.- Parameters:
function
- the function of apply on the location- Returns:
- the location transfer operation
-
levelAtValue
Creates aCopperLevelsAt
representing a location transfer operation to the provided value on this level.- Parameters:
value
- the value to set on the location- Returns:
- the location transfer operation
-
levelsAt
public static CopperLevelsAt levelsAt(List<CopperLevel> shiftLevels, SerializableConsumer<IWritableArray> consumer) Creates aCopperLevelsAt
representing a location transfer operation applying the input consumer to the provided list of levels.This function is applied to an
array
initially containing the values of the members levelsAt the evaluated location, in the order specified by the list of level names.NOTE: this method should not be used for cross-level shifts. For example, if one uses the following consumer, the behaviour is undefined:
Copper.measure("m").shift( CopperLevel.levelsAt( Arrays.asList( Copper.level("date", "date", "day"), Copper.level("date", "date", "month"), a -> { a.writeInt(0, a.readInt(1)); }))
- Parameters:
shiftLevels
- list of shifted levelsconsumer
- consumer defining the shift operation on the levels- Returns:
- the location transfer operation²
-
switchOn
public static CopperSwitchMeasure switchOn(CopperLevel level, Map<Object, ? extends CopperMeasure> memberToMeasureMapping, CopperMeasure defaultMeasure) Creates a copper measure which selects among several measures the value to return depending on the current value on a level.If we consider a switch on the level Currency, with:
- EUR mapped to m1
- USD mapped to m2
- Other mapped to m3
- m4 as above level measure
We will have this result:
┌──────────┬──────┬──────┬──────┬──────┬────────┐ │ Currency │ m1 │ m2 │ m3 │ m4 │ Switch │ ├──────────┼──────┼──────┼──────┼──────┼────────┤ │ Total │ 37 │ 67 │ 127 │ 157 │ 157 │ │ EUR │ 11 │ 21 │ 41 │ 51 │ 11 │ │ USD │ 12 │ 22 │ 42 │ 52 │ 22 │ │ CAD │ 14 │ 24 │ 44 │ 54 │ 44 │ └──────────┴──────┴──────┴──────┴──────┴────────┘
- Parameters:
level
- The level where we want to perform the switch.memberToMeasureMapping
- A map from member to the specific associated measure.defaultMeasure
- An optional measure that computes the value of members that are not in the mapping.- Returns:
- A copper measure performing the desired switch.
-