Retrieving data
This section describes how to retrieve data, or fetch data, which can be done in two different ways:
- Initial data fetch
- Direct data fetch
Retrieval (or fetching) of data in Qlik Sense is primarily done through the use of hypercubes and list objects. As list objects can be seen as a special case of hypercubes, this text will primarily focus on hypercubes and only mention list objects where they deviate from hypercubes.
Generic objects can have hypercubes defined as part of their properties, and the Qlik Sense Engine provides a method called GetHyperCubeData that can be used to retrieve data from such entities. (The method is called GetListObjectData when working with list objects.) The first argument of this method is a path to the hypercube from which data should be fetched, and the second argument is a set of pages to retrieve.
Example: Retrieve first 10 cells of the first column of a hypercube
var first10CellsPage = new NxPage {
Top = 0,
Left = 0,
Width = 1,
Height = 10
};
IEnumerable<NxDataPage> data = myObject.GetHyperCubeData(“/qHyperCubeDef”, new [] {
first10CellsPage
});
Example: Retrieve first 10 rows of a hypercube
var first10RowsPage = new NxPage {
Top = 0,
Left = 0,
Width = myObject.HyperCube.Size.Cx,
Height = 10
};
IEnumerable<NxDataPage> data = myObject.GetHyperCubeData(“/qHyperCubeDef”, new [] {
first10RowsPage
});
Example: Retrieve first and last 10 rows of a hypercube
var last10RowsPage = new NxPage {
Top = myObject.HyperCube.Size.Cy - 10,
Left = 0,
Width = first10RowsPage.Width,
Height = 10
};
IEnumerable<NxDataPage> data = myObject.GetHyperCubeData(“/qHyperCubeDef”, new [] {
first10RowsPage,
last10RowsPage
});
Direct data fetching in hypercubes
Hypercubes support the following additional methods for retrieving data:
-
GetHyperCubeReducedData
-
GetHyperCubePivotData
-
GetHyperCubeStackData
Any of the above data fetch methods can also fetch multiple pages simultaneously. Please refer to the documentation for the individual methods for more information concerning how these methods deviate from the method GetHyperCubeData.
Initial data fetch
As clients displaying visualization objects often want to have immediate access to data from those objects, Qlik Sense provides the option of defining the property InitialDataFetch for hypercubes. Use of InitialDataFetch will have the effect that data will be included directly as part of the layout of the hypercube. This means that the first set of data can be read directly from the layout of the generic object containing the hypercube without having to go through an additional call to the method GetHyperCubeData.
Example: Retrieve first 10 cells of the first column of a hypercube using initial data fetch
using (myObject.SuspendedLayout)
{
myObject.Properties.HyperCubeDef.InitialDataFetch = new [] { first10CellsPage };
}
IEnumerable<NxDataPage> data = myObject.HyperCube.DataPages;