ZettaScale Knowledge Base ZettaScale Knowledge Base

  • Home
  • DDS Products
    • DDS Overview and Concepts
    • OpenSplice DDS
      • OpenSplice DDS
        • OpenSplice FAQ
        • Why OpenSplice DDS?
        • Installation
          • OpenSplice Licensing FAQ
        • Best Practice and Possible Errors
        • API and IDL
        • Configuration
        • Networking
          • DDSI
          • RT Networking
        • Durability Service
        • DDS Security
        • Logging
        • Databases and DBMS
        • Release Notes
      • OpenSplice Tools
        • Overview
        • OpenSplice Launcher
        • OpenSplice Tuner
        • OpenSplice Tester
        • Record and Replay Manager
        • MMStat
    • Cyclone DDS
  • Zenoh
  • Contact Support
Home / DDS, OpenSplice DDS, DDS Overview and Concepts / How to Filter Topic Content : Query Conditions and Content Filtering

How to Filter Topic Content : Query Conditions and Content Filtering

There are three main ways to filter Topic content.

Instance-Handle Filter during read

This option allows you to manually filter content based on the topic key.  This is a very efficient way of obtaining data of a specific instance as it doesn’t require the execution of any SQL query on content. It instead ‘points’ directly to the key-value for which the data is requested.

http://download.zettascale.online/www/docs/OpenSplice/v6/html/ospl/DDSTutorial/readandwrite.html#instance-based-selection

Content Filtered Topic

This is executed with the frequency of arriving data. If data is received at a high frequency but would be read (taken by the Data Reader) at a low frequency, then this might not be the most efficient approach. This option is fundamentally different from a Query Condition/Filter in that data is filtered before it is inserted into the Data Readers cache, therefore keeping the Data Readers cache relatively small, containing only relevant data.

http://download.zettascale.online/www/docs/OpenSplice/v6/html/ospl/DDSTutorial/topics-etc.html#content-filtering

Query Condition/Filter

In this case a query is typically executed with the frequency of a read/take so should be used if you read/take data at a low-frequency. This, for example, can be used with the KEEP_LAST history option for QoS to ‘down sample’ data for each instance.

http://download.zettascale.online/www/docs/OpenSplice/v6/html/ospl/DDSTutorial/readandwrite.html#content-based-selection

Note: Parameters and Expression values

For Content Filtering and Query Conditions the syntax used in the API must be carefully constructed. All APIS includes these two parameters

expression (string) – Expression (query string, which must be a subset of the SQL query language.)
parameters (list) – list of parameters in string (a sequence of strings which are the parameter values used in the SQL query string (i.e., the “%n” tokens in the   expression). The number of values in query_parameters must be equal or greater than the highest referenced %n token in the query_expression.)

The expression must not use hard coded values but should use the parameter list to fill in the expression .

e.g. for C++ this works

std::string expression = “(temp NOT BETWEEN (%0 AND %1)) OR (hum NOT BETWEEN (%2 and %3))”;

std::vector<std::string> params = {“20.5”, “21.5”, “30”, “50”};

dds::sub::Query query(dr, expression, params);

this fails

std::string expression = “(temp NOT BETWEEN (20.5 AND 21.5)) OR (hum NOT BETWEEN (30 and 50))”;

std::vector<std::string> params = {};

dds::sub::Query query(dr, expression, params);

Related

DDSOpenSplice DDSDDS Overview and Concepts
twitter logo linkedin logo
News and Events
Copyright © 2022 ZettaScale Technology Ltd. All Rights Reserved