Managing Data Cube
This Section further describes
Populating a Cube
Query a Cube
Populating a Cube
In the below cube example, you can extract the data from the incoming event and use the System.buildCube()
API to populate the cube with the incoming data.
var data = {
"quarter": "q1",
"city": "chicago",
"product": "phone",
"placedOrder": 200
};
System.buildCube("ProductsPurchased", data);
var data = {
"quarter": "q1",
"city": "chicago",
"product": "phone",
"placedOrder": 300
};
System.buildCube("ProductsPurchased", data);
var data = {
"quarter": "q3",
"city": "new york",
"product": "mouse",
"placedOrder": 500
};
System.buildCube("ProductsPurchased", data);
var data = {
"quarter": "q3",
"city": "new york",
"product": "mouse",
"placedOrder": 400
};
System.buildCube("ProductsPurchased", data);
To simplify, the above javascript presents all instances of System.buildCube() with hardcoded data, which will be called successively as the events come into the Cloud.
Query a Cube
To query a cube, perform the following:
- In the Data menu, click Cubes.
The Cubes screen displays all the existing cubes. - To query a cube select and click on the cube
![querycube.png 1354](https://files.readme.io/310b7bf-querycube.png)
The cube page displays XML editor under the Definition tab
3. Click the Queries tab and then click Create New.
![SelectQuery.png 1270](https://files.readme.io/88cf8c1-SelectQuery.png)
Cube Query screen displays the Code editor and Results pane.
4. Provide a unique name for the cube query and Call a cube query to retrieve data
Request Body
{
"cube": "ProductsPurchased",
"aggregate": "quarter,city,product",
"dataPoint": [
{
"id": "totalProductOrdered",
"src": "totalProductOrdered",
"method": "udc.system.aggregation:sum"
}
],
"axis": [
{
"id": "quarter",
"src": "quarter/*"
},
{
"id": "city",
"src": "city/*"
},
{
"id": "product",
"src": "product/*"
}
]
}
The following describes the query cube syntax:
- cube: Name of the cube.
- aggregate: The computed data is grouped by the given axes parameters. In this example, the total number of products ordered are grouped by quarter, city, and product.
- datapoint: The measurement of the data based on the source defined. In this example, the datapoint is totalProductOrdered. It contains the following:
- id: Unique ID of the datapoint.
- src: Name of the data item in the incoming data set used for computation.
- method: Computation that is used to determine the data point. In this example, the udc.system.aggregation:sum method has been used.
- axis: The data dimension that is used to measure the data. In this example, the three axes are quarter, product, and city. Each axis contains the following:
- id: Unique ID of the axis.
- src: Name of the data item in the incoming data set.
- After providing code Run Query. Response to the cube is seen in the Results pane.
![ProductQuery.png 1623](https://files.readme.io/c51bfe2-ProductQuery.png)
The output displays a summation of total products purchased for each data set. Every time each set is updated with new incoming data, the totalProductOrdered displays a summation of the total products purchased.
Note
We can download the cube output in CSV format. To download click Download CSV. The cube output will be downloaded.
To view the results in tabular format, click the tabular form icon
![tabularformCube.png 770](https://files.readme.io/f949a42-tabularformCube.png)
You can now use the populated cube in your use case(s) as per requirements or use them to build charts.
For more information about cube APIs, refer to the REST APIs section in the Session AI Developer's Guide.
Updated 9 months ago