diff --git a/docker-compose/timescaledb/resources/10_lofar_views.sh b/docker-compose/timescaledb/resources/10_lofar_views.sh deleted file mode 100644 index 7d7fb8cec25bd53f017fd1086636cec1be769755..0000000000000000000000000000000000000000 --- a/docker-compose/timescaledb/resources/10_lofar_views.sh +++ /dev/null @@ -1,427 +0,0 @@ -#!/bin/bash -psql << EOF -\c hdb - --- NOTE: We concatenate domain/family/member here, which means we can't index --- the resulting column. However, queries also supply the attribute name, --- which we can index. The scan on the device name is then limited to --- entries which have the same attribute name across devices. - -CREATE OR REPLACE VIEW lofar_scalar_double AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - 0 AS x, - value_r as value - FROM att_scalar_devdouble att - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devboolean AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devboolean att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devuchar AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devuchar att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devshort AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devshort att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devushort AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devushort att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devlong AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devlong att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devulong AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devulong att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devlong64 AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devlong64 att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devulong64 AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devulong64 att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devfloat AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devfloat att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devdouble AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devdouble att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devstring AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devstring att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devstate AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devstate att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devencoded AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devencoded att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_array_devenum AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - array_element.idx - 1 AS x, - array_element.val as value - FROM att_array_devenum att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devboolean AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devboolean att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devuchar AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devuchar att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devshort AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devshort att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devushort AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devushort att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devlong AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devlong att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devulong AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devulong att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devlong64 AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devlong64 att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devulong64 AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devulong64 att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devfloat AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devfloat att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devdouble AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devdouble att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devstring AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devstring att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devstate AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devstate att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devencoded AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devencoded att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; - -CREATE OR REPLACE VIEW lofar_image_devenum AS - SELECT - att.data_time AS data_time, - CONCAT_WS('/', domain, family, member) AS device, - ac.name AS name, - (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, - (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, - array_element.val as value - FROM att_image_devenum att - -- add array values, and their index - JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE - -- add the device information - JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id - WHERE att.value_r IS NOT NULL; -EOF diff --git a/docker-compose/timescaledb/resources/13_lofar_views.sql b/docker-compose/timescaledb/resources/13_lofar_views.sql index 21448342df3ff5bf2fe0fa5991309cf2bcdb676a..791e191452f769fbae60136a1746e4e2c0a1fc7c 100644 --- a/docker-compose/timescaledb/resources/13_lofar_views.sql +++ b/docker-compose/timescaledb/resources/13_lofar_views.sql @@ -7,6 +7,21 @@ -- DOUBLE -- +CREATE OR REPLACE VIEW lofar_image_double AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devdouble att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + CREATE OR REPLACE VIEW lofar_array_double AS SELECT att.data_time AS data_time, @@ -21,7 +36,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_double AS +CREATE OR REPLACE VIEW lofar_scalar_double AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -32,9 +47,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- BOOLEAN -- +-- BOOLEAN -- + +CREATE OR REPLACE VIEW lofar_image_boolean AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + CASE WHEN array_element.val THEN 1 ELSE 0 END AS value + FROM att_image_devboolean att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_array_boolean AS +CREATE OR REPLACE VIEW lofar_array_boolean AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -48,7 +78,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_boolean AS +CREATE OR REPLACE VIEW lofar_scalar_boolean AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -59,8 +89,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- UCHAR -- - CREATE OR REPLACE VIEW lofar_array_uchar AS +-- UCHAR -- + +CREATE OR REPLACE VIEW lofar_image_uchar AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devuchar att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_uchar AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -74,7 +120,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_uchar AS +CREATE OR REPLACE VIEW lofar_scalar_uchar AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -85,8 +131,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- SHORT -- - CREATE OR REPLACE VIEW lofar_array_short AS +-- SHORT -- + +CREATE OR REPLACE VIEW lofar_image_short AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devshort att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_short AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -100,7 +162,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_short AS +CREATE OR REPLACE VIEW lofar_scalar_short AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -111,8 +173,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- USHORT -- - CREATE OR REPLACE VIEW lofar_array_ushort AS +-- USHORT -- + +CREATE OR REPLACE VIEW lofar_image_ushort AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devushort att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_ushort AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -126,7 +204,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_ushort AS +CREATE OR REPLACE VIEW lofar_scalar_ushort AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -137,8 +215,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- LONG -- - CREATE OR REPLACE VIEW lofar_array_long AS +-- LONG -- + +CREATE OR REPLACE VIEW lofar_image_long AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devlong att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_long AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -152,7 +246,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_long AS +CREATE OR REPLACE VIEW lofar_scalar_long AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -163,8 +257,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- ULONG -- - CREATE OR REPLACE VIEW lofar_array_ulong AS +-- ULONG -- + +CREATE OR REPLACE VIEW lofar_image_ulong AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devulong att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_ulong AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -178,7 +288,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_ulong AS +CREATE OR REPLACE VIEW lofar_scalar_ulong AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -189,8 +299,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- LONG64 -- - CREATE OR REPLACE VIEW lofar_array_long64 AS +-- LONG64 -- + +CREATE OR REPLACE VIEW lofar_image_long64 AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devlong64 att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_long64 AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -204,7 +330,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_long64 AS +CREATE OR REPLACE VIEW lofar_scalar_long64 AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -215,8 +341,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- ULONG64 -- - CREATE OR REPLACE VIEW lofar_array_ulong64 AS +-- ULONG64 -- + +CREATE OR REPLACE VIEW lofar_image_ulong64 AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devulong64 att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_ulong64 AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -230,7 +372,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_ulong64 AS +CREATE OR REPLACE VIEW lofar_scalar_ulong64 AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -241,8 +383,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- FLOAT -- - CREATE OR REPLACE VIEW lofar_array_float AS +-- FLOAT -- + +CREATE OR REPLACE VIEW lofar_image_float AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devfloat att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_float AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -256,7 +414,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_float AS +CREATE OR REPLACE VIEW lofar_scalar_float AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -267,8 +425,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- STRING -- - CREATE OR REPLACE VIEW lofar_array_string AS +-- STRING -- + +CREATE OR REPLACE VIEW lofar_image_string AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devstring att +-- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_string AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -282,7 +456,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_string AS +CREATE OR REPLACE VIEW lofar_scalar_string AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -293,8 +467,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- STATE -- - CREATE OR REPLACE VIEW lofar_array_state AS +-- STATE -- + +CREATE OR REPLACE VIEW lofar_image_state AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devstate att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_state AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -308,7 +498,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_state AS +CREATE OR REPLACE VIEW lofar_scalar_state AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -319,8 +509,24 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- ENCODED -- - CREATE OR REPLACE VIEW lofar_array_encoded AS +-- ENCODED -- + +CREATE OR REPLACE VIEW lofar_image_encoded AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devencoded att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + +CREATE OR REPLACE VIEW lofar_array_encoded AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -334,7 +540,7 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - CREATE OR REPLACE VIEW lofar_scalar_encoded AS +CREATE OR REPLACE VIEW lofar_scalar_encoded AS SELECT att.data_time AS data_time, CONCAT_WS('/', domain, family, member) AS device, @@ -345,7 +551,23 @@ CREATE OR REPLACE VIEW lofar_array_double AS JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - -- ENUM -- +-- ENUM -- + +CREATE OR REPLACE VIEW lofar_image_enum AS + SELECT + att.data_time AS data_time, + CONCAT_WS('/', domain, family, member) AS device, + ac.name AS name, + (array_element.idx - 1) / ARRAY_LENGTH(att.value_r, 1) AS x, + (array_element.idx - 1) % ARRAY_LENGTH(att.value_r, 1) AS y, + array_element.val as value + FROM att_image_devenum att + -- add array values, and their index + JOIN LATERAL UNNEST(att.value_r) WITH ORDINALITY AS array_element(val,idx) ON TRUE + -- add the device information + JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id + WHERE att.value_r IS NOT NULL; + CREATE OR REPLACE VIEW lofar_array_enum AS SELECT att.data_time AS data_time, @@ -370,8 +592,3 @@ CREATE OR REPLACE VIEW lofar_scalar_enum AS -- add the device information JOIN att_conf ac ON att.att_conf_id = ac.att_conf_id WHERE att.value_r IS NOT NULL; - - - - -