Table Configuration Tasks

This section provides examples of several common tasks that are achieved by using lvconf files.

Configuring a Table Join

LiveView tables can be joined so that the updates to one table trigger a change in another table. These table joins define a lookup table which holds keys and values, and a target table which is filled in based on values in the lookup table.

The <join> element of the table's lvconf file is part of the <preprocessor-chain> element. The <join> tag takes two attributes:

foreign-key-table

The name of the table from which the join is to be implemented.

liveness

The type of join. Options are:

half-active

The join will update if one table changes.

full-active

The join will update if either table changes.

For example, suppose you have two tables, JoinTargetTable and JoinForeignTable.

JoinTargetTable has the following fields:

<fields>
   <field name="OrderID" type="string"/>
   <field name="Side" type="string"/>
   <field name="Symbol" type="string"/>
   <field name="CompanyName" type="string"/>
   <field name="Account" type="string"/>
   <field name="Quantity" type="double"/>
   <field name="Price" type="double"/>
</fields> 

JoinForeignTable has the following fields:

<fields>
   <field name="Symbol" type="string" ignore-case="true"/>
   <field name="CompanyName" type="string"/>
</fields>

On each update or insert to the target table, the value is picked up from the foreign table at the time of the update.

In half-active joins, changes to the foreign table have no immediate effect on the target table. Changes will only be picked up by target table rows as each row is updated. To configure a half-active join, use the following preprocessor-chain element in the file JoinTargetTable.lvconf:

<preprocessor-chain>
   <join foreign-key-table="JoinForeignTable" liveness="half-active">
      <join-keys>
         <join-key foreign-key="Symbol">Symbol</join-key>
      </join-keys>
      <target-fields>
         <target-field ref="CompanyName">CompanyName</target-field>
      </target-fields>
   </join>
</preprocessor-chain>

When the data is published to JoinTargetTable, it will trigger a join process similar to that of the following SQL statement:

SELECT JoinForeignTable.CompanyName As CompanyName, JoinTargetTable.* As *
FROM JoinForeignTable, JoinTargetTable
WHERE JoinForeignTable.Symbol=JoinTargetTable.Symbol

Configuring Data Persistence

LiveView Server, by default, clears all tables in a project and starts data collection for every new server session. LiveView provides persistence settings to override this behavior. The persistence tag (a child of the table-space tag in the liveview-configuration) lets you set data persistence. The persistence has two required attributes:

  • folder takes a string value that specifies where you want the persisted data to be stored. If you want to back up your persisted data, you can save this folder to a backup location.

  • restore-data-on-start takes a boolean value. If true, a table is to be re-populated from its persisted log.

Using Table-Level Rules

LiveView Server allows you to set rules inside a table configuration to update table fields.

  1. Load the basic alerting sample:

    1. Start StreamBase Studio.

    2. Select FileLoad StreamBase Sample from Studio's top-level menu.

    3. In the Load StreamBase Projects dialog, open the StreamBase LiveView category.

    4. Select the sample whose description is Shows basic alerting features with pre-configured alert rules and press OK.

  2. Run the project by right-clicking on an lvconf file and selecting Run AsStreamBase LiveView Project.

  3. When you see message All tables have been loaded in the Console view, start LiveView Desktop:

    • On Windows, run StartAll ProgramsStreamBase LiveView n.mLiveView Desktop.

    • On Linux, run the following command:

      /opt/streambase/liveview/desktop/liveview &
      

Using Processing Instructions to Share Configurations Across Tables

LiveView Server allows you to share configuration files across multiple tables. This example illustrates how to use an XML processing instruction inside lvconf files to include a subset of another lvconf file as a preprocessing step.

  1. Load the basic alerting sample:

    1. Start StreamBase Studio.

    2. Select FileLoad StreamBase Sample from Studio's top-level menu.

    3. In the Load StreamBase Projects dialog, open the StreamBase LiveView category.

    4. Select the sample whose description is Shows basic alerting features with pre-configured alert rules and press OK.

  2. Add a file called incl.xml with the following contents to the project folder. This file must not have an XML or DOCTYPE declaration:

    <container>
    
        <commonFields>
            <field name="totalQty" type="int"></field>
            <field name="avgPrice" type="double"></field>
        </commonFields>
        
        <commonAggregations>
            <field ref="totalQty">Sum(quantityRemaining)</field>
            <field ref="avgPrice">Avg(lastSoldPrice)</field>
        </commonAggregations>
    
    </container>
    
  3. Edit the file ItemsByCat.lvconf file to pull in the fields from the incl.xml file:

    <liveview-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://www.streambase.com/schemas/lvconf/">
     
     <!-- for details on this configuration, see ItemsByCatColor.lvconf -->
     <data-table table-space-ref="DefaultTableSpace" id="ItemsByCat"
              description="Live view of total quantity and average last sold price, aggregating by category"
                 short-description="Rollup of items by category">
      <fields>
       <field name="category" type="string"></field>
             <!-- The following processing instruction will pull in the common fields.  
                  Note the xpath to select the elements ends with a wildcard reference (/*).  
                  This will pull in the children of commonFields, but not the commonFields node itself. -->
       <?xinclude incl.xml#/container/commonFields/* ?>
      </fields>
      <primary-key>
        <field ref="category"/>
      </primary-key>
      <data-sources>
       <data-source>
        <aggregation table-ref="Items">
         <field-map>
          <field ref="category">category</field>           
             <!-- Pull in several nodes by using /* in the xpath. -->
             <?xinclude incl.xml#/container/commonAggregations/* ?>
          </field-map>
        </aggregation>
       </data-source>
      </data-sources>
     </data-table>
    </liveview-configuration>
    
  4. Run the project by right-clicking on an lvconf file and selecting Run AsStreamBase LiveView Project.

  5. When you see message All tables have been loaded in the Console view, start LiveView Desktop:

    • On Windows, run StartAll ProgramsStreamBase LiveView n.mLiveView Desktop.

    • On Linux, run the following command:

      /opt/streambase/liveview/desktop/liveview &
      
  6. Double-click the ItemsByCat table in the Tables pane of LiveView Desktop. The table contains the field category, and, in addition, the fields totalQty and avgPrice that you configured in the incl.xml file.