PDGGK opened a new pull request, #114:
URL: https://github.com/apache/iotdb-extras/pull/114
## What
Adds table-model query support to the IoTDB Grafana data source plugin — the
first slice of #18258.
The plugin previously only spoke the tree model: both QueryEditor modes
build `root.*` paths and the backend calls `/grafana/v1/query/expression`,
which has no table-model equivalent, so table-model users could not visualize
their data.
## How
- **New QueryEditor mode "SQL: Table Model"** — a database field, a SQL
editor and a result format option, alongside the existing "SQL: Full
Customized" and "SQL: Drop-down List" modes.
- **Reuses IoTDB's existing table REST API** (`POST /rest/table/v1/query`)
instead of adding a new server endpoint — the Go backend sends `{database,
sql}` and parses the row-major `QueryDataSet`.
- **Typed, nullable fields driven by `data_types`** — TIMESTAMP → time,
INT32/INT64 → int64, FLOAT/DOUBLE → float64, BOOLEAN → bool, TEXT/others →
string — so column types are exact instead of guessed the way the tree-model
path is.
- **Multi-device results render as separate series**: in the default `Time
series` format, rows are sorted by the first TIMESTAMP column and a long-shaped
result (time + tag columns + value columns) is pivoted with the SDK's
`data.LongToWide`, turning tag columns into field labels — `SELECT time,
device_id, temperature FROM t` draws one line per device instead of one
interleaved series. The `Table` format returns rows untouched (preserves a
user's `ORDER BY`). If the pivot cannot apply (e.g. null timestamps), the plain
frame is returned.
- **`$__timeFilter(col)` / `$__timeFrom` / `$__timeTo` macros** expand to
the panel's range; the function forms `$__timeFrom()` / `$__timeTo()` familiar
from Grafana's SQL data sources are accepted too, and `$__timeFilter` allows
one level of nested parentheses.
- **Timestamp precision support**: the table REST endpoint returns TIMESTAMP
values (and compares integer time literals) in the server's configured
`timestamp_precision`, unlike the tree-model `/grafana/v1` endpoints which
normalize to ms server-side. A new data source `time precision` option (ms
default / us / ns) scales both the macro expansion and the TIMESTAMP field
rendering, so the mode works on non-ms servers. (Auto-discovery was considered
and rejected: `SHOW VARIABLES` requires the SYSTEM privilege in the table
model.)
- **`UseNumber` decoding** so INT64 values above 2^53 keep full precision.
- **README**: documents the new mode, the macros, the format option, the
precision option and the server-side row limit
(`rest_query_default_row_size_limit`).
## Testing
- Backend: `go build`, `go vet`, and `go test ./pkg/plugin` (13 unit tests)
pass — covering row-major frame building, per-type conversion, null handling,
macro expansion (including the function forms and nested parentheses), INT64
precision, us/ns timestamp rendering, the long-to-wide pivot for multi-device
results (including the unsorted-input and null-timestamp fallback paths),
Table-format row-order preservation, and error responses. The orientation and
precision tests are written to fail against an incorrect implementation.
- Frontend: type-checked with `tsc --noEmit` against the `@grafana` types.
- The request/response contract was verified against the `/rest/table/v1`
OpenAPI spec, `QueryDataSetHandler`, `RestApiServiceImpl` and
`IoTDBRestServiceIT` (row-major orientation, per-type JSON serialization incl.
DATE/BLOB/STRING, error shape, row-limit behavior, and the precision behavior
above). It has not yet been smoke-tested against a live server.
## Follow-ups (same issue)
Database → table → column browser, a visual query builder, a default row
limit to bound large `SELECT`s, path-picker performance, and the Grafana plugin
SDK / Go backend modernization (the current `@grafana/toolkit` toolchain is
deprecated).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]