Hi all,

This email summarizes the recent work to improve template-variable queries and 
query-type support for IoTDB table-model SQL in the Grafana plugin. The changes 
have been implemented, reviewed, and merged in PRs 
https://github.com/apache/iotdb-extras/pull/126, 
https://github.com/apache/iotdb-extras/pull/128, and 
https://github.com/apache/iotdb-extras/pull/129.

Background

Grafana dashboards commonly use template variables to select databases, nodes, 
instances, or other dimensions dynamically. They also support different query 
types, including Range queries for historical data and Instant queries for 
point-in-time values.

The IoTDB Grafana plugin needed corresponding support for table-model SQL so 
that dashboards could use dynamic variable values and point-in-time query 
semantics consistently.

Table-Model Template Variables

PR https://github.com/apache/iotdb-extras/pull/126 adds support for 
table-model template-variable queries using the following format:

table:<database&gt;:<SQL&gt;

These queries are executed through the native IoTDB table-model RPC client. A 
valid variable query must return exactly one column. The result is converted 
into a Grafana-compatible string list while preserving its original order and 
skipping NULL&nbsp;values.

The change also introduces the $__activeFrom&nbsp;macro, which expands to the 
current time minus five minutes. This allows dashboards to discover recently 
active nodes dynamically and remove inactive nodes from variable options 
without deleting their historical data.

Existing tree-model variable queries continue to use the legacy REST-based path.

Variable Query Object Compatibility

PR https://github.com/apache/iotdb-extras/pull/128&nbsp;updates the frontend 
variable-query handling to support both query formats used by Grafana:

Legacy string queries

Standard query objects containing a string query&nbsp;field

Before execution, the extracted query text is expanded using Grafana's scoped 
template variables. Invalid query objects are rejected with a clear error 
instead of being forwarded incorrectly.

This preserves compatibility with existing dashboards while supporting 
Grafana's current object-form variable-query interface.

Instant Query Support

PR https://github.com/apache/iotdb-extras/pull/129&nbsp;adds Range, Instant, 
and Both&nbsp;query types for IoTDB table-model SQL.

Range mode retains the existing behavior and returns data across the complete 
Grafana time range.

Instant mode evaluates the SQL over the complete query range, selects the 
latest eligible row at or before the range end for each series, and normalizes 
its timestamp to the evaluation time. Multi-series labels, value types, and 
zero-valued samples are preserved. Scalar results without a timestamp column 
receive a synthetic evaluation-time timestamp.

Both mode executes Range and Instant queries independently and returns their 
results in separate frames.

The $__evaluationTime&nbsp;and $__evaluationTime()&nbsp;macros were also added 
for SQL constructs that require an explicit point-in-time boundary, such as 
HOP(... ORIGIN =&gt; ...).

Compatibility and Scope

Queries saved before the query-type option was introduced remain Range queries 
by default. Existing string-form and tree-model variable queries also continue 
to work unchanged.

These changes are limited to table-model template-variable execution, Grafana 
variable-query format compatibility, and Range/Instant query processing.

Best regards,
Xinqi Zhao

Reply via email to