The super fast, super simple real time dimensional aggregator for high performance analytics and reporting in .NET

In-Process, In-Memory

In this example we create a in-memory cube with three dimensions, WebPageId, Year and Month. We then add a value - "count" of type int, and a sum-measure "MySum", using the value "count".

We then create a transaction containing 10 records, mapped to each dimension and our value.

Finally we query the cube which will give us the sum of 10 for the current year.

            using (var inMemoryCube = new InMemoryCube())
            {
                //Create cube structure
                inMemoryCube
                    .AddDimensions("WebPageId", "Year", "Month")
                    .AddFactValue("count", FactValueTypes.Int)
                    .AddMeasure("MySum", new Sum(), "count")
                    .BuildStorageSpace();

                //Add some data
                var transaction = new CubeTransaction();
                for (var i = 0; i < 10; i++)
                {
                    transaction.AddItem(new DataMap()
                        .AddMemberMap("WebPageId", "StartPage")
                        .AddMemberMap("Year", DateTime.Now.Year)
                        .AddMemberMap("Month", DateTime.Now.Month)
                        .AddValueMap("count", 1));
                }
                inMemoryCube.CommitTransaction(transaction);

                //Query
                var results = inMemoryCube.Query(x => x
                                                    .Select()
                                                    .Dimension("Year").Members()
                                                    .ToQuery());
            }
            

In-Process, Persistent - Creating a database

To create a persistent cube we first need to create a persistent database to host our cube.

A database is a container of one or many cubes sharing one or many dimensions. The dimensions and their members are stored in the database, and the cubes then only reference some or all of those dimensions

Here we create a database with id 1, named "PersistentDB placed in the directory c:\\dagger". We add 3 dimensions and persist the database model to disk

                    using (var database = PersistentDatabase.Create(1, "PersistentDB", "c:\\dagger"))
                    {
                        database
                            .AddDimension("WebPageId", "WebPage dimension")
                            .AddDimension("Year", "Year dimension")
                            .AddDimension("Month", "Month dimension")
                            .PersistChanges();
                    }
        

In-Process, Persistent - Creating a cube

When creating a new persistent cube we need to add it to our database, so lets load database 1 from the directory c:\\dagger

We then add references to the dimensions we want to use in our cube, we also add a fact value and a measure. We finish by persisting the changes to the database model.

            using (var database = PersistentDatabase.Load(1, "c:\\dagger"))
            {
                new PersistentCube(1, "WebTraffic", database)
                    .AddDimensions("WebPageId", "Year", "Month")
                    .AddFactValue("count", FactValueTypes.Int)
                    .AddMeasure("MySum", new Sum(), "count")
                    .BuildStorageSpace();
                database.PersistChanges();
            }
        

In-Process, Persistent - Adding data

To add data to our cube we simply load the cube from the database and commit transactions mapped to our dimensions and values.

            using (var database = PersistentDatabase.Load(1, "c:\\dagger1"))
            {
                var cube = database.GetCubeById(1);

                //Add some data
                var transaction = new CubeTransaction();
                for (var i = 0; i < 10; i++)
                {
                    transaction.AddItem(new DataMap()
                        .AddMemberMap("WebPageId", "StartPage")
                        .AddMemberMap("Year", DateTime.Now.Year)
                        .AddMemberMap("Month", DateTime.Now.Month)
                        .AddValueMap("count", 1));
                }
                cube.CommitTransaction(transaction);
            }
        

In-Process - Querying

            var result = database.GetCubeById(1).Query(x => x
                                        .Select()
                                        .Dimension("Year").Members()
                                        .ToQuery());
        

Client / Server - Creating a database and a cube

The client uses the DaggerHttpClient to communicate using JSon over Http. A database is created by sending a CreateDatabaseRequest with the database and cube structure.

            var client = new DaggerHttpClient(new Uri("http://127.0.0.1:123"));

            var database = new Database(1, "WebTraffic")
                .AddDimension("WebPageId", "WebPage dimension")
                .AddDimension("Year", "Year dimension")
                .AddDimension("Month", "Month dimension");

            var cube = new Cube(1, "WebTraffic", StorageModes.Persistent, database)
                .AddDimensions("WebPageId", "Year", "Month")
                .AddFactValue("count", FactValueTypes.UInt)
                .AddMeasure("MySum", MeasureTypes.Sum, "count");
            
            database.AddCube(cube);

            var createDbRequest = new CreateDatabaseRequest(database);
            var response = client.Send(createDbRequest);
        

Client / Server - Inserting data

Data is added to the cube by sending a CommitCubeTransactionRequest with the transaction and the database and cube id.

            var client = new DaggerHttpClient(new Uri("http://127.0.0.1:123"));

            var transaction = new CubeTransaction()
                .AddItem(new DataMap()
                .AddMemberMap("WebPageId", "StartPage")
                .AddMemberMap("Year", DateTime.Now.Year)
                .AddMemberMap("Month", DateTime.Now.Month)
                .AddValueMap("count", 1));    

            var commitTransactionRequest = new CommitCubeTransactionRequest(1 /*DatabaseId*/, 1 /*CubeId*/, transaction);
            var response = client.Send(commitTransactionRequest);
        

Client / Server - Query

And a query by sending the query wrapped in a QueryRequest.

            var client = new DaggerHttpClient(new Uri("http://127.0.0.1:123"));

            var query = new Query().Select()
                                        .Dimension("Year").Members()
                                        .ToQuery();

            var queryRequest = new QueryRequest(1 /*DatabaseId*/, 1 /*CubeId*/, query);
            var response = client.Send<QueryResponse>(queryRequest);