SliceQuery Class

NReco.PivotData Class Library Documentation
Represents a query operation over specified IPivotData instance.
Inheritance Hierarchy

SystemObject
  NReco.PivotDataSliceQuery

Namespace:  NReco.PivotData
Assembly:  NReco.PivotData (in NReco.PivotData.dll) Version: 1.4.1
Syntax

public class SliceQuery

The SliceQuery type exposes the following members.

Constructors

  NameDescription
Public methodSliceQuery
Initializes new slicing query to specified PivotData instance.
Top
Methods

  NameDescription
Public methodDimension(String)
Define dimension to select in result of this query.
Public methodDimension(String, FuncObject, Object)
Define dimension constructed from keys of existing dimensions.
Public methodEquals (Inherited from Object.)
Public methodExecute
Execute the query and return operation result as new PivotData instance.
Public methodExecute(Boolean)
Execute the query and return operation result as new PivotData instance.
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodMeasure(Int32)
Define measure aggregator at specified index to select in result of this query.
Public methodMeasure(IAggregatorFactory, FuncIAggregator, IAggregator)
Define new measure aggregator calculated from existing cube measure(s).
Public methodMeasure(IAggregatorFactory, FuncKeyValuePairObject, IAggregator, IAggregator)
Define new measure aggregator calculated from existing cube measure(s).
Public methodMeasure(String, FuncIAggregator, Object, Int32)
Define formula measure.
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Public methodWhere(FuncKeyValuePairObject, IAggregator, Boolean)
Filters data points based on a predicate.
Public methodWhere(String, FuncObject, Boolean)
Filters dimension keys based on a predicate.
Public methodWhere(String, Object)
Filters dimension keys by explicit list of values.
Top
Remarks

SliceQuery can be used for querying data cube (slice, dice, roll-up).
Examples

Lets assume that we have some cube that represents sales data with the following dimensions: "year", "month", "day", "country", "product" and 2 measures collected with CountAggregatorFactory (=count of orders) and SumAggregatorFactory (= sum of sales amount):
var salesCube = new PivotData(
                new [] {"year","month","day","country","product"},
                new CompositeAggregatorFactory(
                    new CountAggregatorFactory(),
                    new SumAggregatorFactory("amount")
                ), true );
The following query illustrates how to reduce number of dimensions, filter by specific dimension values and get resulting PivotData with single measure:
var q = new SliceQuery(salesCube)
                .Dimension("year")
                .Dimension("country")
                .Dimension("product")
                .Where("country", new[]{"USA","Canada"})
                .Measure(1);
            var salesAmountForUsaAndCanada = q.Execute(true);
Resulting data cube will contain only specified dimensions, "country" dimension will contain only "USA" and "Canada" keys and only one measure (index=1 refers to SumAggregatorFactory("amount")).
Examples

SliceQuery can be used in the more complex filtering cases; lets calculate derived dimension and skip all days with <10 orders:
var q = new SliceQuery(salesCube)
                .Dimension("year")
                .Dimension("quarter", (dimKeys) => {  
                    var month = Convert.ToInt32( dimKeys[1] ); // "month" dimension index
                    return (int)Math.Ceiling((float)(month)/3);
                }).Where( (dataPoint) => {
                    var compositeAggr = dataPoint.Value.AsComposite(); // CompositeAggregator is used if cube has >1 measure
                    var countOrders = Convert.ToInt32( compositeAggr.Aggregators[0].Value );
                    return countOrders>=10; // include data point by custom condition
                });
            var bigSalesByYearAndQuarter = q.Execute(true);
See Also

Reference