From a76f79381cbb68515225672f318b277e601f38b9 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 21 Dec 2024 14:25:29 +0000 Subject: [PATCH] feat: add a default SQL view for easy Grafana querying (#1289) --- .../V0_44__add_view_for_grafana_querying.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 search-service/src/main/resources/db/migration/V0_44__add_view_for_grafana_querying.sql diff --git a/search-service/src/main/resources/db/migration/V0_44__add_view_for_grafana_querying.sql b/search-service/src/main/resources/db/migration/V0_44__add_view_for_grafana_querying.sql new file mode 100644 index 000000000..5287c5daa --- /dev/null +++ b/search-service/src/main/resources/db/migration/V0_44__add_view_for_grafana_querying.sql @@ -0,0 +1,11 @@ +CREATE VIEW flattened_entities_attributes_values AS ( + SELECT entity_payload.entity_id, + TRIM(JSONB_PATH_QUERY_FIRST(entity_payload.payload, '$."https://schema.org/name"[0]."https://uri.etsi.org/ngsi-ld/hasValue"[0]."@value"')::TEXT, '"') AS "entity_name", + attribute_name, + dataset_id, + time, + measured_value AS value + FROM attribute_instance + LEFT JOIN temporal_entity_attribute ON temporal_entity_attribute.id = attribute_instance.temporal_entity_attribute + LEFT JOIN entity_payload ON entity_payload.entity_id = temporal_entity_attribute.entity_id +);