4 Replies Latest reply: Dec 2, 2016 10:42 AM by Patric Amatulli RSS

    Qliksense SDK - GetHyperCubeContinuousData how to use?

    Patric Amatulli

      Hi all,

       

      I am writing an converter app and I would like to export all data from a single Qliksense object to different file formats (.xls, .csv).
      I have encounterd an issue when I try to get the data from the Hypercube, when dealing with a higher amount of records.

      I have read there is a limit from 10000 cell's per Datapage.

       

      How i can retrieve all the data from a hypercube ?
                

      This works when I have less than 10000 cell's to export:

                           //qsobject is a IGenericObject object

                          var qsPager = qsObject.GetHyperCubePager("/qHyperCubeDef");

                          var qsWidth = qsPager.NumberOfColumns;

                          var qsHeight = qsPager.NumberOfRows;          

                          var rowsPerPage = new NxPage { Top = 0, Left = 0, Width = qsWidth, Height = qsHeight };

                          IEnumerable<NxDataPage> Datapage = qsObject.GetHyperCubeData("/qHyperCubeDef", new[] { rowsPerPage });
                       

      Is there an option to retrieve all the data?

      If yes someboday can give a small sample.
      I have seen there is a method GetHyperCubeContinuousData which takes as input the path and in addition requires an input parameter from type NxContinuousDataOptions.

      I have not understood what the NxContinuousDataOptions stands for:

       

                         //Raises an exception

                          NxContinuousDataOptions opt = new NxContinuousDataOptions();

                          GetHyperCubeContinuousDataResult r = qsObject.GetHyperCubeContinuousData("/qHyperCubeDef", opt);

       

      {"Invalid parameters [LOCERR_GENERIC_INVALID_PARAMETERS]:Invalid parameters(Continuous field must be numeric or date)"}

       

      Can someone assist?

       

      Thanks,

      Patric

        • Re: Qliksense SDK - GetHyperCubeContinuousData how to use?
          Øystein Kolsrud

          Typically, if you have data that large, then you would page through the data so that you don't have to collect it all at once.

           

          In your case you seem to just want to dump all the data though, and I would recommend that you have a look at the DataPager class of the SDK. It provides a method called DataPager.IteratePages that allows you to traverse across a hypercube and collect all the data. Have a look at the following page:

           

          http://help.qlik.com/en-US/sense-developer/3.1/Subsystems/NetSDKAPI/Content/HowTos/Net-Sdk-How-To-Paging.htm

           

          In particular, have a look at the example titled "Iterate across all pages using the Pager.Next method". It illustrates how to iterate through all the data of a hypercube 10 rows at a time. The method returns an IEnumerable<NxDataPage> where each element contains the data from one iteration. So if the hypercube in that example had 100 rows, then the call would return 10 NxDataPage instances. You could either merge the pages into one your self, or stream the pages directly to a file. The latter would consume less memory as it would only need to have one data page in memory at a time.

          • Re: Qliksense SDK - GetHyperCubeContinuousData how to use?
            Øystein Kolsrud

            By the way, the "GetHyperCubeContinuousData" is used to group data data of a continuous type (Double) and present it in a set of buckets for a visualization object to consume.

              • Re: Qliksense SDK - GetHyperCubeContinuousData how to use?
                Patric Amatulli

                Hi,

                 

                this is the implemented solution. If someone of you guys here are looking for something similar here the code snippet:

                 

                  var qsPager = qsObject.GetHyperCubePager("/qHyperCubeDef");
                  var qsWidth = qsPager.NumberOfColumns;
                  var qsHeight = qsPager.NumberOfRows;
                  var maxHeight = (int)(10000/qsWidth);
                  var pageHeight = Math.Min(qsHeight, maxHeight);
                
                  var rowsPerPage = new NxPage { Top = 0, Left = 0, Width = qsWidth, Height = pageHeight};
                  IEnumerable<IEnumerable<NxDataPage>> DataPages = qsPager.IteratePages(new[] { rowsPerPage }, Pager.Next);
                  IEnumerable<NxDataPage> DataPage = DataPages.SelectMany(x => x);              
                               
                  foreach (var dataPage in DataPage)
                  {
                       foreach (NxCellRows rows in dataPage.Matrix)
                       {
                            NxCell[] cell = rows.ToArray();
                            System.Data.DataRow dtRow = dt.NewRow();
                
                            for (int i = 0; i <= cell.Length - 1; i++)
                            {
                                dtRow[i] = cell[i].Text;
                            }
                            dt.Rows.Add(dtRow);
                       }
                  }
                
                           
                
                
                

                 

                               

                Cheers,

                Patric