PivotData Class

NReco.PivotData Class Library Documentation
Implements generic dictionary-based in-memory high performance multidimensional dataset (OLAP cube).
Inheritance Hierarchy

SystemObject
  NReco.PivotDataPivotData

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

public class PivotData : IPivotData, IEnumerable<KeyValuePair<Object[], IAggregator>>, 
	IEnumerable

The PivotData type exposes the following members.

Constructors

  NameDescription
Public methodPivotData(String, IAggregatorFactory)
Initializes a new instance of the PivotData with specified dimensions and aggregator.
Public methodPivotData(String, IAggregatorFactory, Boolean)
Initializes a new instance of the PivotData with specified dimensions, aggregator and lazy totals mode.
Public methodPivotData(String, IAggregatorFactory, IEnumerableIDictionaryString, Object)
Initializes a new instance of the PivotData with specified dimensions, aggregator and processes specified data.
Public methodPivotData(String, IAggregatorFactory, IDataReader)
Initializes a new instance of the PivotData with specified dimensions, aggregator and processes data from data reader.
Public methodPivotData(String, IAggregatorFactory, IEnumerableIDictionaryString, Object, Boolean)
Initializes new instance of PivotData with specified dimensions, aggregator, lazy totals mode and processes specified data.
Public methodPivotData(String, IAggregatorFactory, IEnumerable, FuncObject, String, Object)
Initializes a new instance of the PivotData with specified dimensions, aggregator, and processes data from enumeration.
Public methodPivotData(String, IAggregatorFactory, IDataReader, Boolean)
Initializes a new instance of the PivotData with specified dimensions configuration, aggregator, lazy totals mode and and processes data from data reader.
Public methodPivotData(String, IAggregatorFactory, IEnumerable, FuncObject, String, Object, Boolean)
Initializes new instance of PivotData with specified dimensions configuration and calculates values for specified data
Top
Properties

  NameDescription
Public propertyAggregatorFactory
Gets IAggregatorFactory instance used for creating measure value aggregators.
Public propertyAllValues
Get all datapoints (dim keys -> aggregator pairs) contained in the PivotData (including totals).
Public propertyCount
Gets the number of unique data point of this multidimensional dataset (calculated data points like totals are not included).
Public propertyDimensions
Gets dimension identifiers of the multidimensional dataset.
Public propertyItemObject
Gets aggegator by specified dimensions keys
Public propertyItemValueKey
Gets value by specified multidimensional key.
Public propertyLazyAdd
Determines behaviour when non-existing key is accessed (true by default).
Public propertyLazyTotals
Determines totals calculation mode. Lazy means that all totals/sub-totals are calculated on first use; otherwise totals/sub-totals are calculated on-the-fly.
Top
Methods

  NameDescription
Public methodClear
Removes all dimension keys and values from the PivotData.
Public methodCopyTo Obsolete.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetDimensionKeys
Returns keys of all PivotData dimensions
Public methodGetDimensionKeys(String)
Returns keys of specified dimensions
Public methodGetDimensionKeys(String, IComparerObject)
Returns keys of specified dimensions
Public methodGetEnumerator
Public methodGetHashCode (Inherited from Object.)
Public methodGetState
Returns compacted state object that contains all values of this PivotData.
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodMerge
Modifies the current PivotData object to merge values from itself and specified PivotData.
Public methodProcessData(IEnumerableIDictionaryString, Object)
Process data from specified list of dictionaries.
Public methodProcessData(IEnumerableDataRow)
Process data from specified sequence of DataRow objects.
Public methodProcessData(IDataReader)
Processes data from the specified IDataReader.
Public methodProcessData(IEnumerable, FuncObject, String, Object)
Processes data from enumerable data.
Public methodProcessData(IPivotData, String)
Processes data from the specified IPivotData instance and calculates PivotData values
Public methodSetState
Restores PivotData from specified state object.
Public methodSlice(String, Boolean) Obsolete.
Public methodSlice(String, Boolean, FuncKeyValuePairValueKey, IAggregator, Boolean) Obsolete.
Public methodSlice(String, Boolean, FuncObject, IAggregator, Boolean) Obsolete.
Public methodToString (Inherited from Object.)
Top
Extension Methods

  NameDescription
Public Extension MethodProcessData
Processes data from specified IPivotDataSource instance.
(Defined by PivotDataExtensions.)
Top
Remarks

PivotData can be used for fast data aggregation from any input source that implements IEnumerable interface.

Totals may be pre-calculated during data processing or calulated on-the-fly on the first access (LazyTotals). Lazy totals calculation mode is recommended for cases when cube has many dimensions and/or large number of unique dimension keys.

Thread safety: a PivotData can support multiple readers concurrently, as long as the data is not modified. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization. When data is processed with ProcessData(IEnumerableIDictionaryString, Object) enumerating through AllValues or GetEnumerator is intrinsically not a thread-safe procedure.

Examples

The following code illustrates how to aggregate data from DataTable:
DataTable dataTbl; // lets assume it has columns: 'Delivery Year', 'Delivery Month', 'Supplier Name'
            var pvtData = new PivotData(
                new []{"Delivery Year", "Delivery Month", "Supplier Name"},
                new CountAggregatorFactory(), true);
            pvtData.ProcessData( new DataTableReader(dataTbl) );  // real ADO.NET data reader can be used too

Measure aggregation logic is controlled by IAggregatorFactory implementations (each measure is represented by IAggregator instance). Several measures may be calculated at once using CompositeAggregatorFactory:

var pvtData = new PivotData(
                new string[]{"country","product"},
                new CompositeAggregatorFactory(
                    new CountAggregatorFactory(),
                    new SumAggregatorFactory("amount")
                ), true );
In this case individual measure values may be accessed in the following way:
var compositeAggr = pvtData["USA",null].AsComposite();
            var countValue = compositeAggr.Aggregators[0].Value; // refers to CountAggregator
            var sumValue = compositeAggr.Aggregators[1].Value; // refers to SumAggregator

See Also

Reference