LiveView Query Input Adapter

Introduction

The StreamBase LiveView Query Adapter allows a StreamBase application to register ad hoc queries with LiveView servers and receive snapshot and real time results.

Properties

This section describes the properties you can set for this adapter, using the various tabs of the Properties view for the adapter's icon in StreamBase Studio.

General Tab

Name: Use this field to specify or change the component's name, which must be unique in the application. The name must contain only alphabetic characters, numbers, and underscores, and no hyphens or other special characters. The first character must be alphabetic or an underscore.

Adapter Name: A read-only field that shows the formal name of the adapter.

Class: A field that shows the fully qualified class name that implements the functionality of this adapter. Use this class name when loading the adapter in StreamSQL programs with the APPLY JAVA statement. You can right-click this field and select Copy from the context menu to place the full class name in the system clipboard.

Start with application: If this field is set to Yes or a module parameter that evaluates to true, an instance of this adapter starts as part of the containing StreamBase Server. If this field is set to No or a module parameter that evaluates to false, the adapter is loaded with the server, but does not start until you send an sbadmin resume command, or start the component with StreamBase Manager. With this option No or false, the adapter does not start even if the application as a whole is suspended and later resumed. The recommended setting is selected by default.

Enable Error Output Port: Select this check box to add an Error Port to this component. In the EventFlow canvas, the Error Port shows as a red output port, always the last port for the component. See Using Error Ports and Error Streams to learn about Error Ports.

Description: Optionally enter text to briefly describe the component's purpose and function. In the EventFlow canvas, you can see the description by pressing Ctrl while the component's tooltip is displayed.

Adapter Properties Tab

This section describes the properties on the Adapter Properties tab in the Properties view for the LiveViewQuery adapter.

Property Description
LiveView Server URI A LiveView server URI. For example, the local machine and default port is lv://localhost:10080.
Set Server URI to encapsulating LiveView When checked the adapter must be part of a LiveView project. The adapter will connect to whatever port number the running LiveView server is running.
Target Table Name The name of the LiveView table to issue the queries
Include old row Include both new and old row values in Updates. This feature uses more client memory to hold old values.
Query Input Port If checked an input port is provided to allow ad hoc queries to be configured/removed.

Initial Queries Tab

This tab allows you to configure a set of queries that will be registered each time the adapter connects to the configured LiveView server.

The tab has two columns, the first column is the key, or query ID, that identifies the query. This ID can be used in a delete command sent to the Query In port, for example.

The Value column has a semicolon separated string. The first part of the string is the select, projection expression for the query. For non-aggregate queries, this is usually just "*" - meaning provide all fields. The dynamic aggregation queries, this expression defines the aggregate functions and values to use. For example:

avg(lastSoldPrice) as AvgSoldPrice

The second part of the string is the query predicate. This predicate can include order by, time windows, group by, etc. where appropriate.

Edit Schemas Tab

Use the Edit Schemas tab to specify the schema of the LiveView table this adapter will query.

For general instructions on using the Edit Schemas tab, see Defining Input Streams.

Concurrency Tab

Use the Concurrency tab to specify parallel regions for this instance of this component, or multiplicity options, or both. The Concurrency tab settings are described in Concurrency Options, and dispatch styles are described in Dispatch Styles.

Caution

Concurrency settings are not suitable for every application, and using these settings requires a thorough analysis of your application. For details, see Execution Order and Concurrency, which includes important guidelines for using the concurrency options.

Using the Adapter in a StreamBase Application

The StreamBase LiveView Query adapter has three output ports. The status port provide information about queries, connection status, etc. The QueryOut port provides the result of simple queries. Finally an AggQueryOut port provides the results of dynamic aggregration queries.

As with other StreamBase adapters and operators, you can optionally enable an Error Output Port, as described in Using Error Ports and Error Streams.

LiveView Query Adapter Input Port

An optional QueryIn port is available. This port can be used to register and delete (unregister) queries to the LiveView server.

Field Data Type Description
QueryName string Arbitrary string you provide to identify queries. Must be unique for all currently registered queries.
Select string The Select, or projection, expression for this query. For simple queries this is just "*", for dynamic aggregation queries it is the aggregate functions and the associated field names.
Query string The predicate for the query. You may include order by, time windows, limit, etc.
SnapshotOnly boolean If true, only issue a snapshot query. If false, or null, issue snapshot plus continuous.
Unregister boolean Delete the query that matches the supplied QueryName.

LiveView Query Adapter Output Ports

The StreamBase LiveView Query adapter has one output status port, plus two query out ports. The status port has the following fields:

Field Data Type Description
Type string The basic state reported, always one of the following:
CONNECTION ADMIN
QUERY ERROR
Object string The name on the EventFlow canvas of the adapter reporting the status.
Action string The action that occurred, one of the following:
CONNECTED FAILED
REGISTER_QUERY ERROR
UNREGISTER_QUERY  
Message string A human-readable string that provides additional context for the status message.
Time timestamp The time the action occurred.

The StreamBase LiveView Query adapter has a QueryOut port that has the results of all registered non-aggregate queries. The schema of this output has 6 fields, two of these are tuple types which simply have the schema configured in the schema tab.

Field Data Type Description
QuerName string The QueryID that this row is associated with.
CQSInternalID long A LiveView internal ID for this row
CQSScopeTransistion int One of 3 values:
0 - row added 2 - row updated
1 - row deleted  
Snapshot boolean This tuple is part of the snapshot. CQSScopeTransistion will be 0.
New tuple The new value for the row. The schema of this tuple type must match the LiveView table schema, and be specified in the Schema tab.
Old tuple The old value for the row. The schema of this tuple type must match the LiveView table schema, and be specified in the Schema tab. Will be null unless the "Include old row value" is selected.

The final output port is for Dynamic aggregation results. Since the input query selection expression defines the schema of the result, this variable output schema is represented in a JSON string. You can use StreamBase expression language functions, such as parsejson, to extra the values from these JSON strings.

Field Data Type Description
QuerName string The QueryID that this row is associated with.
CQSInternalID long A LiveView internal ID for this row
CQSReferredCount int The number of rows in this group
CQSScopeTransistion int One of 3 values:
0 - row added 2 - row updated
1 - row deleted  
Snapshot boolean This tuple is part of the snapshot. CQSScopeTransistion will be 0.
NewJSON string The JSON string representation of the new value for the row.
OldJSON string The JSON string representation of the old value for the row. Will be null unless the "Include old row value" is selected.

Adding the Adapter to an EventFlow Application

Add an instance of the adapter to a new StreamBase EventFlow application as follows:

  1. In StreamBase Studio, create a project, including an empty StreamBase EventFlow Application file to host the adapter.

  2. From the Operators and Adapters drawer of the Palette view, drag the Output Adapter icon to the palette. This opens the Insert Output Adapter dialog.

  3. In the search field, type a string such as LiveView to narrow the list of adapters. When found, select the icon for the LiveView Query adapter, then click OK.

  4. Double-click the adapter icon and select the Adapter Properties tab in the Properties view. You must provide the LiveView URI, table name, and table schema.

  5. Select the Edit Schemas tab. You must provide the schema of the LiveView table. The generated LiveView interfaces file will have the schema for the table.

Typechecking and Error Handling

The StreamBase LiveView Query adapter uses typecheck messages to help you configure the adapter.

The adapter generates warning messages at runtime under various conditions, including:

  • The configured schema of this adapter does not match the LiveView table

  • The configured LiveView server is not available.

Suspend and Resume Behavior

When suspended, the adapter continues to receive and process LiveView updates, but no longer emits tuples on its primary output ports.

When resumed, the adapter once again starts emitting tuples on its primary output ports.

Related Topics