PDGGK opened a new pull request, #134:
URL: https://github.com/apache/iotdb-extras/pull/134

   In the table-model mode, the query editor currently asks for the database 
name as free text and gives no view of what the server holds: you have to know 
the table and column names before you can write a query. This change makes the 
editor list them, one step toward the kind of editor the SQL datasources in 
Grafana offer.
   
   ## What changes
   
   **Backend.** Three resource endpoints run fixed metadata statements on the 
pooled native session:
   
   | endpoint | statement | returns |
   |---|---|---|
   | `tableDatabases` | `SHOW DATABASES` | database names |
   | `tableTables?database=` | `SHOW TABLES` after `USE <database>` | table 
names |
   | `tableColumns?database=&table=` | `DESC "<table>"` after `USE <database>` 
| name, data type and category of each column |
   
   A request that is missing a parameter gets a 400 and never reaches the 
server. Server errors, such as a table that does not exist, come back with the 
server's message. The table name reaches the server only as a quoted identifier.
   
   **Frontend.** In *SQL: Table Model* mode:
   
   - DATABASE becomes a picker filled from the server. It still accepts a typed 
name, for example a `$database` template variable.
   - A new TABLE picker lists the tables of the chosen database. Picking one 
shows its columns grouped by category (TAG, FIELD, ATTRIBUTE).
   - **Use starter query** replaces the SQL with a query that selects the 
table's time, TAG and FIELD columns within the dashboard time range, for 
example:
   
     ```sql
     SELECT "time", "region", "device_id", "temperature", "humidity" FROM 
"weather station" WHERE $__timeFilter("time")
     ```
   
     Names are always quoted. I checked that an unquoted reserved word fails 
(`SELECT group, order ...` gives `mismatched input 'group'`), so unquoted 
output would break on such tables. A table without a time column, like the 
views in `information_schema`, gets no time filter. ATTRIBUTE columns are left 
out, since they do not change over time.
   
   The SQL is still what runs. The picked table (`query.table`) is only a 
helper for the column list and the starter query, and the tree-model modes are 
untouched. If metadata cannot be read, the editor shows the server's message 
and the pickers still accept typed names.
   
   ## Testing
   
   - Go: 6 new tests for the three handlers, covering the statements sent, 
quoting of a name with an embedded `"`, missing parameters (no server call), 
server errors, and an unexpected result shape. The whole `pkg/...` suite 
passes. Removing the quoting makes the quoting test fail.
   - Jest: 8 new tests for identifier quoting and the starter query. The full 
suite of 29 passes. Dropping the TAG columns from the starter query makes two 
of them fail.
   - Playwright: a new `tests/tableModelEditor.spec.ts` drives the real editor 
against `information_schema`, so it needs no seeding. It picks the database and 
table, checks the column list, checks the starter query, and runs that query 
through `/api/ds/query`. I added it to the `minimum-grafana-version` job next 
to the existing smoke test. Locally it passes on Grafana 12.3.0 (the declared 
floor) with the compose IoTDB 2.0.8, and it fails when the starter query is 
broken on purpose.
   - By hand, on the same Grafana 12.3.0 with a seeded table named `weather 
station` (3 devices, 60 points each): the pickers list the database, table and 
columns, and the starter query draws one series per device and field. 
Screenshots are in the first comment.
   - `npm run typecheck` and `mvn clean package -Pwith-grafana-plugin 
-DskipTests` pass. `npm run lint` has no errors; the only new warnings are the 
two `Select` deprecation warnings in `TablePicker.tsx` (see Notes).
   
   ## Notes
   
   - The pickers use `Select` from `@grafana/ui`. I first used `Combobox`, 
which Grafana now recommends. On Grafana 12.3, picking `information_schema` 
with it crashed Explore with React error 185, raised from the popover's 
floating-ui reference. With `Select` the same steps work, so I kept `Select` 
and left a comment at the call site.
   - A full visual builder (choose columns and aggregations, filter on TAG 
columns, group by `date_bin`) is the natural next step. Grafana's shared SQL 
editor lives in two packages. `@grafana/sql` is AGPL-3.0, so an Apache project 
cannot depend on it. `@grafana/plugin-ui` (Apache-2.0) has a `SqlQueryEditor` 
too, but it expects the whole datasource to be a `SqlDatasource`, which this 
plugin cannot become without splitting the tree and table modes. I kept this PR 
to the pickers and would like to hear whether the builder is wanted and in 
which form before starting it.
   


-- 
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]

Reply via email to