grafana / clickhouse-datasource

Grafana Plugin for ClickHouse
Apache License 2.0
127 stars 58 forks source link

Feature: Column alias tables for simplified querying #862

Closed SpencerTorres closed 2 months ago

SpencerTorres commented 2 months ago

Purpose

Some schemas have complicated maps such as OTel LogAttributes. This feature allows configuring a table like this:

CREATE TABLE otel_logs_query_aliases (
    `alias` String,
    `select` String,
    `type` String
)
Engine = MergeTree
ORDER BY (alias);
INSERT INTO otel_logs_query_aliases (`alias`, `select`, `type`) VALUES
('productId', 'LogAttributes[\'productId\']', 'UInt64'),
('quantity', 'LogAttributes[\'quantity\']', 'String'),
('userId', 'LogAttributes[\'userId\']', 'UInt64'),
('code.filepath', 'LogAttributes[\'code.filepath\']', 'String'),
('code.function', 'LogAttributes[\'code.function\']', 'String'),
('code.lineno', 'LogAttributes[\'code.lineno\']', 'Int64'),
. . .

This table can then be configured in the plugin: config query alias tables

And then be used for the target table's column suggestions: column suggestions

With the column selection simplified, the correct SQL will be generated using the underlying select syntax: generated SQL

Notes:

Changes

SpencerTorres commented 2 months ago

The array change you suggested worked locally, I didn't get any errors when unit testing or in-editor, but the build seemed to be failing. I tried updating to a typescript version that supports that extension and it lead to a complete collapse of the plugin's package ecosystem. I think I even saw leftpad mentioned in the logs.

Anyway, let me know if you want me to try again. I want to use that new feature, but there's a lot of dependencies affected by updating TS.