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.
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.
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.
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);