java.lang.Object
com.activeviam.activepivot.copper.api.Copper

public class Copper extends Object
Starting point to describe calculations and then build measures and hierarchies performing the calculations in ActivePivot.

Additionally, these elements (CopperMeasure, CopperHierarchy, CopperLevel...) represent basic bricks that can be combined to express advanced and powerful calculations.

Author:
ActiveViam
  • Method Details

    • experimental

      public static ExperimentalCopper 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

      public static CopperNativeMeasure 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

      public static CopperNativeMeasure 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

      public static CopperMeasureOver sum(CopperMeasure measure)
      Starts defining an aggregation analytic function (sometimes called aggregation window function) with the sum 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

      public static CopperMeasure sum(CopperStoreField field)
      Creates a Copper measure by aggregating a field from a store linked to the cube using the sum aggregation. See avg(CopperStoreField).
      Parameters:
      field - the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • sum

      public static CopperMeasure sum(String fieldName)
      Creates a Copper measure by aggregating a field from the selection using the sum aggregation.
      Parameters:
      fieldName - the name of the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • max

      public static CopperMeasureOver max(CopperMeasure measure)
      Starts defining an aggregation analytic function with the max aggregation. See sum(CopperMeasure).
      Parameters:
      measure - the measure to use as underlying measure
      Returns:
      a partially defined aggregated analytic measure
    • max

      public static CopperMeasure max(CopperStoreField field)
      Creates a Copper measure by aggregating a field from a store linked to the cube using the max aggregation. See avg(CopperStoreField).
      Parameters:
      field - the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • max

      public static CopperMeasure max(String fieldName)
      Creates a Copper measure by aggregating a field from the selection using the max aggregation.
      Parameters:
      fieldName - the name of the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • min

      public static CopperMeasureOver min(CopperMeasure measure)
      Starts defining an aggregation analytic function with the min aggregation. See sum(CopperMeasure).
      Parameters:
      measure - the measure to use as underlying measure
      Returns:
      a partially defined aggregated analytic measure
    • min

      public static CopperMeasure min(CopperStoreField field)
      Creates a Copper measure by aggregating a field from a store linked to the cube using the min aggregation. See avg(CopperStoreField).
      Parameters:
      field - the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • min

      public static CopperMeasure min(String fieldName)
      Creates a Copper measure by aggregating a field from the selection using the min aggregation.
      Parameters:
      fieldName - the name of the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • avg

      public static CopperMeasureOver avg(CopperMeasure measure)
      Starts defining an aggregation analytic function with the average aggregation. See sum(CopperMeasure).
      Parameters:
      measure - the measure to use as underlying measure
      Returns:
      a partially defined aggregated analytic measure
    • avg

      public static CopperMeasure avg(CopperStoreField field)
      Creates a Copper measure by aggregating a field from a store linked to the cube using the average aggregation. Contrary to a lookup 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

      public static CopperMeasure avg(String fieldName)
      Creates a Copper measure by aggregating a field from the selection using the average aggregation.
      Parameters:
      fieldName - the name of the field to aggregate
      Returns:
      The Copper measure representing the aggregated measure
    • sumProduct

      public static CopperMeasure sumProduct(String... fieldNames)
      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, the sum(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

      public static CopperMeasureOver agg(CopperMeasure measure, String pluginKey)
      Starts defining an aggregation analytic function with an IAggregationFunction whose plugin key is the given one. See sum(CopperMeasure).
      Parameters:
      measure - the measure to use as underlying measure
      pluginKey - The plugin key of the custom aggregation function
      Returns:
      a partially defined aggregated analytic measure
    • agg

      public static CopperMeasure agg(CopperStoreField field, String pluginKey)
      Creates a Copper measure by aggregating a field from a store linked to the cube using custom aggregation function. See avg(CopperStoreField).
      Parameters:
      field - the field to aggregate
      pluginKey - the plugin key of the custom aggregation function
      Returns:
      The Copper measure representing the aggregated measure
    • agg

      public static CopperMeasure agg(String fieldName, String pluginKey)
      Creates a Copper measure by aggregating a field using a custom aggregation function.
      Parameters:
      fieldName - The field to aggregate
      pluginKey - The plugin key of the custom aggregation function
      Returns:
      The Copper measure containing the aggregated field
    • agg

      public static CopperMeasure agg(String[] fieldNames, String pluginKey)
      Creates a Copper measure by aggregating multiple fields using a custom multi-source aggregation function.
      Parameters:
      fieldNames - The fields to aggregate
      pluginKey - The plugin key of the custom aggregation function
      Returns:
      The Copper measure containing the aggregated field
    • lead

      public static CopperMeasureOver lead(CopperMeasure measure, int offset, NavigationMode mode)
      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 the Window.

      The window frame specification that can be specified by Window.rangeBetween(int, int) is ignored by every navigation analytic function.

      The mode parameter can be used to determine whether we want the exact value at the desired distance from the current location, whether it is null, or if we want to search for the first non-null value at least at the requested distance from the current location.

      • lag: The lag function returns the value of the given measure for a location at a given offset before the current location.
      • lead: The lead function returns the value of the given measure for a location at a given offset after the current location.
      • first: The first function returns the value of the given measure with respect to the first location in the Window
      • last: The last function returns the value of the given measure with respect to the last location in the Window

      Examples of ordering, partitioning and usage of different navigation function illustrated with a pivot table, given:

      • a cube with a "time" hierarchy with three "year", "month", "day" levels
      • a pre-aggregated measure "pnl.SUM": CopperMeasure pnl = Copper.sum("pnl)
      • A measure that returns the next values of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.lead(pnl, 1, Mode.EXACT).over(Window.orderBy("time").as("lead(exact)")
      • A measure that returns the next non-null values of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.lead(pnl, 1, Mode.NON_NULL).over(Window.orderBy("time").as("lead(non-null)")
      • A measure that returns the previous values of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.lag(pnl, 1, Mode.EXACT).over(Window.orderBy("time").as("lag(exact)")
      • A measure that returns the previous non-null values of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.lag(pnl, 1, Mode.NON_NULL).over(Window.orderBy("time").as("lag(non-null)")
      • A measure that returns the first value of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.first(pnl, Mode.EXACT).over(Window.orderBy("time").as("first(exact)")
      • A measure that returns the first non-null value of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.first(pnl, Mode.NON_NULL).over(Window.orderBy("time").as("first(non-null)")
      • A measure that returns the last value of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.last(pnl, Mode.EXACT).over(Window.orderBy("time").as("last(exact)")
      • A measure that returns the last non-null value of "pnl.SUM" along the time hierarchy, each level being naturally ordered: Copper.last(pnl, Mode.NON_NULL).over(Window.orderBy("time").as("last(non-null)")
      • A measure that returns the first value of "pnl.SUM" along the time hierarchy for each year, each level being naturally ordered: Copper.first(pnl, Mode.EXACT).over(Window.orderBy("time").partitionBy("year") .as("first(exact) per year")
       ┌────────────────┬─────────┬─────────────┬────────────────┬─────────────┬────────────────┬──────────────┬─────────────────┬─────────────┬────────────────┬───────────────────────┐
       │ Year/Month/Day │ pnl.SUM │ lag(exact)  │ lag(non-null)  │ lead(exact) │ lead(non-null) │ first(exact) │ first(non-null) │ last(exact) │ last(non-null) │ first(exact) per year │
       ├────────────────┼─────────┼─────────────┼────────────────┼─────────────┼────────────────┼──────────────┼─────────────────┼─────────────┼────────────────┼───────────────────────┤
       │ (ALL)          │ 14      │ null        │ null           │ null        │ null           │ 14           │ 14              │ 14          │ 14             │ 14                    │
       │   2018         │ 9       │ null        │ null           │ 7           │ 7              │ 9            │ 9               │ 5           │ 5              │ 9                     │
       │     Jan        │ 6       │ null        │ null           │ 3           │ 3              │ 6            │ 6               │ 3           │ 3              │ 6                     │
       │       01       │ null    │ null        │ null           │ 6           │ 6              │ null         │ 6               │ null        │ 3              │ null                  │
       │       02       │ 6       │ null        │ null           │ null        │ 1              │ null         │ 6               │ null        │ 3              │ null                  │
       │       03       │ null    │ 6           │ 6              │ 1           │ 1              │ null         │ 6               │ null        │ 3              │ null                  │
       │     Feb        │ 3       │ 6           │ 6              │ 2           │ 2              │ 6            │ 6               │ 3           │ 3              │ 6                     │
       │       01       │ 1       │ null        │ 6              │ 2           │ 2              │ null         │ 6               │ null        │ 3              │ null                  │
       │       02       │ 2       │ 1           │ 1              │ 2           │ 2              │ null         │ 6               │ null        │ 3              │ null                  │
       │   2019         │ 5       │ 9           │ 9              │ null        │ null           │ 9            │ 9               │ 5           │ 5              │ 5                     │
       │     Jan        │ 2       │ 3           │ 2              │ 5           │ 5              │ 6            │ 6               │ 3           │ 3              │ 2                     │
       │       02       │ 2       │ 2           │ 2              │ 0           │ 0              │ null         │ 6               │ null        │ 3              │ 2                     │
       │       03       │ 0       │ 2           │ 2              │ 3           │ 3              │ null         │ 6               │ null        │ 3              │ 2                     │
       │     Feb        │ 3       │ 2           │ 2              │ null        │ null           │ 6            │ 6               │ 3           │ 3              │ 2                     │
       │       01       │ 3       │ 0           │ 0              │ 2           │ 2              │ null         │ 6               │ null        │ 3              │ 2                     │
       │       02       │ null    │ 3           │ 3              │ null        │ null           │ null         │ 6               │ null        │ 3              │ 2                     │
       └────────────────┴─────────┴─────────────┴────────────────┴─────────────┴────────────────┴──────────────┴─────────────────┴─────────────┴────────────────┴───────────────────────┘
       
      Parameters:
      measure - the measure to use as underlying measure
      offset - the number of rows after the current location to return values for
      mode - the execution mode to use when searching for a value
      Returns:
      a partially defined navigating analytic measure
    • lead

      public static CopperMeasureOver lead(CopperMeasure measure, int offset)
      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 the Window. See lead(CopperMeasure, int, NavigationMode).
      Parameters:
      measure - the measure to use as underlying measure
      offset - the number of rows after the current location to return values for
      Returns:
      a partially defined navigating analytic measure
    • lag

      public static CopperMeasureOver lag(CopperMeasure measure, int offset, NavigationMode mode)
      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 the Window. See lead(CopperMeasure, int, NavigationMode).
      Parameters:
      measure - the measure to use as underlying measure
      offset - the number of rows before the current location to return values for
      mode - the execution mode to use when searching for a value
      Returns:
      a partially defined navigating analytic measure
    • lag

      public static CopperMeasureOver lag(CopperMeasure measure, int offset)
      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 the Window. See lead(CopperMeasure, int).
      Parameters:
      measure - the measure to use as underlying measure
      offset - the number of rows before the current location to return values for
      Returns:
      a partially defined navigating analytic measure
    • first

      public static CopperMeasureOver first(CopperMeasure measure, NavigationMode mode)
      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 the Window. See lead(CopperMeasure, int, NavigationMode).
      Parameters:
      measure - the measure to use as underlying measure
      mode - the execution mode to use when searching for a value
      Returns:
      a partially defined navigating analytic measure
    • first

      public static CopperMeasureOver first(CopperMeasure measure)
      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 the Window. See lead(CopperMeasure, int).
      Parameters:
      measure - the measure to use as underlying measure
      Returns:
      a partially defined navigating analytic measure
    • last

      public static CopperMeasureOver last(CopperMeasure measure, NavigationMode mode)
      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 the Window. See lead(CopperMeasure, int, NavigationMode).
      Parameters:
      measure - the measure to use as underlying measure
      mode - the execution mode to use when searching for a value
      Returns:
      a partially defined navigating analytic measure
    • last

      public static CopperMeasureOver last(CopperMeasure measure)
      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 the Window. See lead(CopperMeasure, int).
      Parameters:
      measure - the measure to use as underlying measure
      Returns:
      a partially defined navigating analytic measure
    • constant

      public static CopperMeasure constant(Object value)
      Creates a Copper measure containing a constant value.
      Parameters:
      value - The value in this measure
      Returns:
      The Copper measure containing the constant value
    • measure

      public static CopperMeasure measure(String measureName)
      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

      public static CopperMeasure measureFromDataCube(String measureName, String type)
      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 measure
      type - the string representation of the type of the measure
      Returns:
      The Copper measure referencing the measure with the given name
      See Also:
      • ILiteralType.DOUBLE
    • member

      public static CopperMeasure member(CopperLevel level)
      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

      public static CopperMeasure member(LevelIdentifier level)
      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

      public 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. 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

      public 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. 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 null
      hierarchyName - the name of the hierarchy. Cannot be null
      Returns:
      the Copper hierarchy referencing the given hierarchy
    • hierarchy

      public static CopperHierarchy hierarchy(@NonNull @NonNull HierarchyIdentifier 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

      public static CopperLevel level(@NonNull @NonNull LevelIdentifier 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

      public 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.
      Parameters:
      measures - The measures to combine
      Returns:
      The combination of measures, on which to call CopperMeasureCombination.map(SerializableBiConsumer, String) map
    • combine

      public 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.
      Parameters:
      elements - The elements to combine
      Returns:
      The combination of elements, to use in CoppernewHierarchy(String, String)
    • newPostProcessor

      public static CopperPostProcessor newPostProcessor(String pluginKey)
      Parameters:
      pluginKey - the plugin key of the post-processor to create
      Returns:
      The Copper measure referencing the post-processor
    • storeLookup

      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:
      • IQueryManager.getByKeyQuery()
    • contextValue

      public static CopperMeasure contextValue(Class<? extends IContextValue> clazz)
      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 create
      hierarchyName - the name of the hierarchy to create
      Returns:
      the builder
    • store

      public static UnlinkedCopperStore store(String storeName)
      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

      public static CopperMeasure newLookupMeasure(CopperStoreField field)
      Creates a Copper measure referencing the records of a joined field, 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 measure rate.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 query rate.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

      public static CopperMeasure userDefinedAgg(String pluginKey, String[] fields)
      Creates a Copper measure performing a user-defined aggregation on multiple fields of the current selection.

      See userDefinedAgg(String...).

      Parameters:
      pluginKey - The plugin key of the user-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

      public static CopperUserDefinedAggregateFunctionBuilder 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.

      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

      public 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. 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 returned
      measure - 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

      public 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. 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 returned
      measure - 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

      public static CopperLevelsAt levelAt(CopperLevel lvl, SerializableFunction<?,?> function)
      Creates a CopperLevelsAt 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

      public static CopperLevelsAt levelAtValue(CopperLevel lvl, Object value)
      Creates a CopperLevelsAt 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 a CopperLevelsAt 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 levels
      consumer - 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.