Creating on-demand apps with Qlik Associative Big Data Index

Qlik Sense on-demand apps can extract data from a Qlik Associative Big Data Index. The process for creating on-demand apps is basically the same as when you use other data sources except that you use the Qlik Selection Language (QSL) to connect to a Qlik Associative Big Data Index data model.

Qlik Associative Big Data Index offers a new linkage between on-demand selection and template apps. The linkage is based on QSL set handles. As a result, the load scripts are much simpler than in on-demand apps that do not use Qlik Associative Big Data Index. That is because the data does not have to be reformatted when an on-demand app is generated. A special set handle (odb_setHandle) internalizes the filtering criteria so all that is needed for the generated app is that handle.

Qlik Associative Big Data Index template apps can also build selections dynamically from data passed from a traditional on-demand selection app that passes data in an aggregated form. On-demand apps that use Qlik Associative Big Data Index are not required to use the special set handle odb_setHandle. Instructions for writing a Qlik Associative Big Data Index template app that builds selections dynamically are provided below--Dynamic variables in a template app

Qlik Associative Big Data Index selection apps pass the set handle odb_setHandle to QABDI template apps, but they can pass a data selection instead if the Qlik Associative Big Data Index template app is constructed to build selections dynamically. When an on-demand navigation link is created between a Qlik Associative Big Data Index selection app and a template app, the selection app determines how it must present the data selection, either in the set handle odb_setHandle or as an aggregation.

Selection apps

On-demand selection apps are built in Qlik Associative Big Data Index Live mode. For that reason, at this point on-demand selection apps can only use Filter panes for selecting records. In this respect, selection apps are similar to the QABDI Selector. (See Qlik Associative Big Data Index Selector.) On-demand selection apps, however, provide for generating multiple apps on-demand.

The connection script for a selection app is like the following:

BDI CONNECT TO 'tpch_mini 34.204.96.225:55000'; IMPORT LIVE 'tpch_mini';

The selection app with Filter panes for selecting records would look like the following:

This on-demand selection app has two KPI objects that use the COUNT aggregation function to display the total number of p_containers and the number of distinct p_brands. At the bottom, the app contains two on-demand app navigation points. These are used to generate on-demand apps based on the navigation link created by linking the selection app to an on-demand template app. The number of records selected must be reduced to turn the navigation points green, which indicates they can then be used to generate on-demand apps.

When the number of records selected fits within the limits specified for the navigation links, the circles for the two navigation points turn green.

 

Template apps with Qlik Associative Big Data Index linkage

The load scripts for on-demand template apps contain connection and data load commands whose parameters are set by a special variable (odb_setHandle) that the on-demand app service uses for linkage. The odb_setHandle is used specifically for Qlik Associative Big Data Index linkage. On-demand apps that link data values use ods_FieldName, odso_FieldName, odo_FieldName, and od_FieldName. See Dynamic variables in a template app for examples of how these bindings are used.

The connection statement is followed either by a metadata load statement or by data import statements. In the following script, the connection uses data import statements.

See Connecting to a Qlik Associative Big Data Index data model with the Qlik Selection Language for the syntax of connections with metadata load and data import statements.

BDI CONNECT TO 'tpch_mini 34.204.96.225:55000'; QSL SET H1 = { [tpch_mini].1 <p_part_key={1,2}> }; SET odb_setHandle = H1; //In generated apps, the odb_setHandle is replaced with the selection representing selections in the selection app. Load *; QSL SELECT p_name, p_part_key, p_brand, p_size, p_retail_rpice FROM [tpch_mini].[parts] AT STATE $(odb_setHandle);

The SET statement sets a default selection p_part_key={1,2} that is used to populate the template app with data to support dashboard development in the template app. The fields loaded can be used to add objects that visualize the data in meaningful ways. That selection is not used when a linked selection app passes the Qlik Associative Big Data Index set handle odb_setHandle for the generation of an on-demand app.

When selections are made in a selection app, a new on-demand app can be generated from the link to the template app. The load script generated for the on-demand app replaces the handle variable odb_setHandle with an actual model scope Qlik Associative Big Data Index handle representing the state of the selection:

BDI CONNECT TO 'tpch_mini 34.204.96.225:55000'; QSL SET H1 = { [tpch_mini].1 <p_part_key={1,2}> }; SET odb_setHandle = H1; //The odb_setHandle is replaced with the selection representing selections in the selection app. Load *; QSL Select p_name, p_part_key, p_brand, p_size, p_retail_rpice FROM [tpch_mini].[parts] AT STATE [tpch_mini].[h05a856f0_2d60_4097_b8cc_53a3bf02c767];

Based on the selections made in the selection app, the template app visualizations in the on-demand app can be transformed as follows:

This template app illustrates how QSL set handles are used to filter selections. In other cases, template apps need to generate variables dynamically based on various possible selections made in linked selection apps.

Dynamic variables in a template app

Instead of using the set handle odb_setHandle to define a selection, you can write the Qlik Associative Big Data Index template app to generate variables dynamically from selections made in a selection app. This dynamic generation of selection variables requires subroutines to filter the data. Template apps written in this way can be used with legacy on-demand selection apps, that is, selection apps that do not use Qlik Associative Big Data Index IMPORT LIVE mode.

An example of the subroutines used in on-demand template apps is included in the Qlik Sense installation at ProgramData\Qlik\Examples\OnDemandApp\sample.

You can use the sample template app (ODAG Sample Detail) as a starting point and adapt the ExtendQVDWhere subroutine to create a selection state.

  1. Rename the subroutineExtendQVDWhere to ExtendSelectionState.

    // Subroutine to be changed for QABDI script generation SUB ExtendSelectionState(Name, ValVarName) LET T = Name & '_COLNAME'; LET ColName = $(T); LET Values = $(ValVarName); IF len(Values) > 0 THEN IF len(SELECTION_STATE) > 0 THEN LET SELECTION_STATE = replace('$(SELECTION_STATE)','>}', ',') &' $(ColName)={ $(Values) }>}'; ELSE LET SELECTION_STATE = '{ [data_model_name].1 <$(ColName)={$(Values)}>} '; ENDIF ENDIF END SUB;
  2. Change the CALL statement to refer to the new subroutine name.

    FOR EACH fldname IN 'Rate_Code','Payment_Type','Pickup_Date' LET vallist = $(fldname); WHEN (IsNull(vallist)) LET vallist = ''; IF len(vallist) > 0 THEN CALL ExtendSelectionState('$(fldname)','vallist'); ENDIF NEXT fldname

    Note that the field names in this example have been changed from those in the sample app. You must also change those to reflect the fields you are selecting from your Qlik Associative Big Data Index data model.

  3. Change all calls to the BuildValueList subroutine to accommodate the QSL syntax.

    All The QuoteChrNum variables must be changed to 32, as in the following example.

    SET [Rate_Code] =''; OdagBinding: LOAD * INLINE [ VAL $(odso_Rate_Code){"quote": "", "delimiter": ""} ]; SET [Rate_Code_COLNAME]='rate_code'; CALL BuildValueList('Rate_Code', 'OdagBinding', 'VAL', 32); //chr(32) for SELECTION STATE quoting

    Note again that you must change the field name in the sample app to reflect fields you are selecting from your Qlik Associative Big Data Index data model.

  4. Insert the connection string at the CHANGE # 2 section in the sample app, after the CALL statements to the BuildValueList subroutine.

    The connection string can be the BDI CONNECT statement as illustrated in the first example above:

    BDI CONNECT TO 'tpch_mini 34.204.96.225:55000';

    Or you can insert a connection string from a QABDI connection that has been created from the Create new BDI connection dialog. That connection string would look like:

    LIB CONNECT TO 'BDI-Sample';

    BDI-Sample is the name given the connection when it was created in the Create new BDI connection dialog.

  5. After the connection string, set the SELECTION_STATE:

    SET SELECTION_STATE = '';

    If you are working directly in the sample template app (ODAG Sample Detail), this SET statement replaces the SET WHERE_PART = ''; in the sample app.

  6. Change the TRACE statements:

    TRACE Generated SELECTION STATE clause: ; TRACE SELECTION_STATE;

    The TRACE statements in the sample template app (ODAG Sample Detail app) refer to WHERE clause and WHERE_PART, which are not used in the Qlik Associative Big Data Index template app.

  7. Before the first LOAD statement, add the Set handle:

    QSL SET hPassedSelection = $(SELECTION_STATE);
  8. Add the QSL SELECT statements instead of SQL SELECT.

    The LOAD and SELECT section should like the following:

    FACT: LOAD 1 as Fares, vendor_id as [Vendor ID], pickup_datetime as [Pickup_DateTime], year(pickup_datetime) as Pickup_Year, dropoff_datetime as [Dropoff_DateTime], passenger_count as [#Passengers], trip_distance as [Trip Distance], pickup_longitude, pickup_latitude, dropoff_longitude, dropoff_latitude, rate_code as [Rate_Code], store_and_fwd_flag as [Store and Fwd Flag], payment_type as [Payment_Type], fare_amount as [Fare Amount], extra as Extra, mta_tax as [MTA Tax], tip_amount as [Tip Amount], tolls_amount as [Tolls Amount], imp_surcharge as [Imp Surcharge], total_amount as [Total Amount]; QSL SELECT [vendor_id], [pickup_datetime], [pickupyear], [pickupmonth], [dropoff_datetime], [pickup_longitude], [pickup_latitude], [dropoff_longitude], [dropoff_latitude], [rate_code], [passenger_count], [trip_distance], [payment_type], [fare_amount], [extra], [mta_tax], [imp_surcharge], [tip_amount], [tolls_amount], [total_amount], [store_and_fwd_flag] FROM [nycicd].[fares] AT STATE hPassedSelection;
  9. Add the AT STATE statement as in the example above.

    The AT STATE statement holds the selection state that contains the actual selections made in the selection app when a new on-demand app is generated.

  10. If you built the template app from a copy of the sample template app (ODAG Sample Detail), comment out or remove any unused statements, such as the LET statements in the CHANGE # 5 section that use data that is not relevant to the Qlik Associative Big Data Index template app.

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?