How to insert rows into a LiveView table via feed simulation

How to insert rows into a LiveView table via feed simulation

book

Article ID: KB0075186

calendar_today

Updated On:

Products Versions
TIBCO Live Datamart 2.x

Description

This article provides guidance for creating feed simulations that can insert rows into LiveView tables. This is a supplement to the existing guidance found in the LiveView Help (under $STREAMBASE_HOME/liveview/doc/lv-intro/lv-create-hello.html#lv-build-feedsim), as additional configuration may be required in certain cases.

Issue/Introduction

How to insert rows into a LiveView table via feed simulation

Resolution

Case 1: The table's primary index has a string field and you need to insert a large number of rows.


By default, the random string generator used by sbfeedsim will only produce strings of 4 characters in length. If your table's primary index is a string field, this limits the amount of rows that can be inserted via feed simulation.

To quickly load a large number of rows, increase the range of min and max string lengths that will be randomly generated for the primary index field. For example, in the Hello World sample that ships with LiveView, modify the feed simulation used to populate the 'Items' table ( Items.sbfs). Change the Generation Method for the 'sku' field to 'RandomString', and set min and max lengths to 1 and 10 respectively.



 

Case 2: You are using fixed order id chaining and you need to insert a large number of rows.


When using fixed order ID chaining in your table's configuration, note that the fields specified for <server-key> and <client-key> should be unique when attempting to load a large number of rows via feed simulation. If these field values are the same, the feed simulation's insert rate to the table will decrease over time, as more updates begin to occur due to repeating keys. For example, if the table's configuration includes the following chain..
 
<fixed-order-id-chaining>
<server-key primary-field-ref="OrdID" />
<client-key primary-field-ref="ClientOrdID" secondary-field-ref="SecClientOrdID" />
</fixed-order-id-chaining>


..ensure that OrdID, ClientOrdID, and SecClientOrdID are never given the same value in the feed simulation. For each of these fields, set the Generation Method to 'RandomString' and set the min and max ranges for each to be different values. For example:

         

 

Case 3: The table has insert/update rules for certain fields.


If the table that you are populating has insert/update rules configured, you may need to modify the feed simulation to comply with these rules. For example, if your table has the following configuration..
 
<fields>
<field name="sku" type="string"></field>
<field name="category" type="string">
<insert-rule>if (sku == 0) then 'toys' else
if (sku == 1) then 'automotive' else
if (sku == 2) then 'electronics' else 'books'
</insert-rule>
</field>
...
</fields>


..your feed simulation should regularly produce sku values of 0, 1, and 2 to ensure that different values for the 'category' field are inserted. If your feed simulation does not produce sku values of 0, 1, or 2, then the 'category' field will always be reset to 'books', regardless of the value originally produced by your feed simulation.

 

Case 4: The table you are feeding is itself a data source for another table.


If the table you are populating via feed simulation is itself a data source for an additional aggregation table, you need to ensure that your feed simulation complies with the insert/update rules for that aggregation table. For example, consider the following configuration..
 
<data-table table-space-ref="DefaultTableSpace" id="ItemsByCatColor">
<fields>
<field name="category" type="string">
<insert-rule>if (avgPrice == 0) then 'toys' else
if (avgPrice > 100) then 'automotive' else
if (avgPrice < 10) then 'electronics' else 'books'
</insert-rule>
</field>
<field name="color" type="string" />
<field name="totalQty" type="int" />
<field name="avgPrice" type="double" />
</fields>
...
<data-sources>
<data-source>
<aggregation table-ref="Items">
<field-map>
<field ref="category">category</field>
<field ref="color">color</field>
<field ref="totalQty">Sum(quantityRemaining)</field>
<field ref="avgPrice">Avg(lastSoldPrice)</field>
</field-map>
</aggregation>
</data-source>
</data-sources>
</data-table>


In this case, the Items table is the data source for the ItemsByCatColor aggregation table. A feed simulation for the Items table should ensure that its generated values for lastSoldPrice will result in avgPrice values (in the ItemsByCatColor table) that fall within the ranges specified in the insert rule for the 'category' field (i.e. >100, <10, and 0). Otherwise, all 'category' values in the ItemsByCatColor table will be reset to 'books'.